Questions tagged [makefile]

A makefile is an input file for the build control language/tool make. It specifies targets and dependencies along with associated commands to perform (a.k.a. recipes) to update the targets.

A makefile is usually an input file for the build control language/tool make. The make utility and the corresponding makefile format is standardized by POSIX.

Common newbie mistakes:

Makefile variable assignment error in echo - running two distinct commands in a recipe and not realizing the shell from the first will exit and lose any changes to the environment.

Make implementations

More information

25125 questions
60
votes
4 answers

Making make print commands before executing when NOT using CMake

I see that this is the same question as Making cmake print commands before executing But that answer doesn't work for me. I'm guessing that answer only works with cmake. What options work without cmake? Note tried these make VERBOSE=1 target make…
gman
  • 100,619
  • 31
  • 269
  • 393
59
votes
5 answers

How to recompile just a single kernel module?

Usually kernel source are stored in /usr/src/linux-2.6.x/. To avoid to recompile the entire kernel if I modify a module's source, how can I recompile just that module?
user1056635
  • 785
  • 2
  • 9
  • 12
59
votes
8 answers

gnu make: list the values of all variables (or "macros") in a particular run

How can I list the current value of all variables (also called macros) in a Makefile when running make? E.g. if this is in the Makefile: CUR-DIR := $(shell /bin/pwd) LOG-DIR := $(CUR-DIR)/make-logs Then I would like it to tell me: CUR-DIR =…
johv
  • 4,424
  • 3
  • 26
  • 42
59
votes
8 answers

bash completion of makefile target

Suppose I have a simple makefile like: hello: echo "hello world" bye: echo "bye bye" Then in bash I want something like: make h < tab > so it can complete to make hello I found a simple way like creating empty files hello and bye but I'm…
Guillaume Massé
  • 8,004
  • 8
  • 44
  • 57
59
votes
1 answer

Is it possible to have multiple .PHONY targets in a GNU makefile?

I have a big .PHONY command: .PHONY: clean cleanall Can I split it into multiple parts, as shown below? .PHONY: clean clean: rm -rf build/ .PHONY: cleanall
wickedchicken
  • 4,553
  • 5
  • 22
  • 28
59
votes
3 answers

Make file echo displaying "$PATH" string

I am trying to force make file to display next string: "Please execute next commands: setenv PATH /usr/local/greenhills/mips5/linux86:$PATH" The problem is with "$PATH". Command @echo "setenv PATH /usr/local/greenhills/mips5/linux86:$PATH" cause a…
BaruchLi
  • 1,021
  • 2
  • 11
  • 18
59
votes
6 answers

Suppress messages in make clean (Makefile silent remove)

I'm wondering how I can avoid some echo in a Makefile : clean: rm -fr *.o this rule will print: $>make clean rm -fr *.o $> How can I avoid that?
claf
  • 9,043
  • 17
  • 62
  • 79
59
votes
9 answers

How do I perform arithmetic in a makefile?

Is it possible to perform some operations on variables in a makefile? For instance, defining JPI=4 JPJ=2 is it possible to define in the same makefile a variable JPIJ equal to the expanded value of $(JPI)*$(JPJ)?
malaboca
  • 591
  • 1
  • 4
  • 3
59
votes
4 answers

Where does the value of CXX in a makefile come from?

Code Snippet: target_test : test.cc $(CXX) $(CPPFLAGS) $(CFLAGS) test.cc I know that CXX is a variable (containing the compiler command to call), but I was wondering where this variable comes from. The variable is not defined in the makefile…
Ananke Leda
  • 833
  • 2
  • 7
  • 8
58
votes
6 answers

How to define C++ preprocessor variable in Makefile

I have a C++ preprocessor written like this: #ifdef cpp_variable //x+y; #endif Can anyone tell me how to define this in Makefile.
Joel
  • 581
  • 1
  • 4
  • 4
58
votes
5 answers

C++ Qt - How to add "-std=c++11" to the makefile which is generated by qmake?

I'm developing a program in Qt. Its makefile is generated automatically from the .pro file. I need to use some code which need the -std=c++11 flag to be set up for g++. Where in .pro should I add this flag? (changing only the Makefile won't work…
Natalia Zoń
  • 980
  • 2
  • 12
  • 22
57
votes
6 answers

Make (install from source) python without running tests

I compiling python from source tar. All works good, but tests running 2 hours and two times. How to bypass these tests? 0:16:20 [178/405] test_inspect 0:16:26 [179/405] test_int 0:16:27 [180/405] test_int_literal 0:16:27 [181/405] test_io 0:18:18…
eri
  • 3,133
  • 1
  • 23
  • 35
57
votes
6 answers

How do I create a library?

Let's say I have 10 *.hpp and *.cpp files that I need to compile a code. I know that I will need those same files for many different codes. Can I create a "package" with those files that would allow me to simply write: #include instead…
PinkFloyd
  • 2,103
  • 4
  • 28
  • 47
57
votes
8 answers

Override target in makefile to add more commands?

At work we use a common makefile that other makefiles include (via the include statement) and it has a generic "clean" target that kills some common files. I want to add on to that target in my new makefile so I can delete some specific files, but…
Paul D.
  • 1,785
  • 2
  • 19
  • 25
56
votes
8 answers

Checking the gcc version in a Makefile?

I would like to use some gcc warning switchs that aren't available in older gcc versions (eg. -Wtype-limits). Is there an easy way to check the gcc version and only add those extra options if a recent gcc is used ?
Gene Vincent
  • 5,237
  • 9
  • 50
  • 86