Questions tagged [gnu-make]
This tag is for questions about `gmake`, the GNU version of the `make` utility to maintain and update programs.
gnu-make
4,525
questions
962
votes
6
answers
277k
views
What is the difference between the GNU Makefile variable assignments =, ?=, := and +=?
Can anybody give a clear explanation of how variable assignment really works in Makefiles.
What is the difference between :
VARIABLE = value
VARIABLE ?= value
VARIABLE := value
VARIABLE += ...
505
votes
8
answers
344k
views
How do I write the 'cd' command in a makefile?
For example, I have something like this in my makefile:
all:
cd some_directory
But when I typed make I saw only 'cd some_directory', like in the echo command.
415
votes
14
answers
1.0m
views
How to install and use "make" in Windows?
I'm following the instructions of someone whose repository I cloned to my machine. I want to use the make command as part of setting up the code environment, but I'm using Windows. I searched online, ...
369
votes
16
answers
589k
views
How to print out a variable in makefile
In my makefile, I have a variable 'NDK_PROJECT_PATH', my question is how can I print it out when it compiles?
I read Make file echo displaying "$PATH" string and I tried:
@echo $(...
362
votes
8
answers
251k
views
Using CMake with GNU Make: How can I see the exact commands?
I use CMake with GNU Make and would like to see all commands exactly (for example how the compiler is executed, all the flags etc.).
GNU make has --debug, but it does not seem to be that helpful are ...
342
votes
29
answers
257k
views
How do you get the list of targets in a makefile?
I've used rake a bit (a Ruby make program), and it has an option to get a list of all the available targets, eg
> rake --tasks
rake db:charset # retrieve the charset for your data...
rake db:...
322
votes
14
answers
481k
views
How to get current relative directory of your Makefile?
I have a several Makefiles in app specific directories like this:
/project1/apps/app_typeA/Makefile
/project1/apps/app_typeB/Makefile
/project1/apps/app_typeC/Makefile
Each Makefile includes a .inc ...
297
votes
4
answers
253k
views
Define make variable at rule execution time
In my GNUmakefile, I would like to have a rule that uses a temporary directory. For example:
out.tar: TMP := $(shell mktemp -d)
echo hi $(TMP)/hi.txt
tar -C $(TMP) cf $@ .
rm ...
264
votes
2
answers
71k
views
What do @, - and + do as prefixes to recipe lines in Make?
In the GNU Makefile manual, it mentions these prefixes.
If .ONESHELL is provided, then only the first line of the recipe will be checked for the special prefix characters (‘@’, ‘-’, and ‘+’).
What ...
233
votes
2
answers
104k
views
What does @: (at symbol colon) mean in a Makefile?
What does the following do in a Makefile?
rule: $(deps)
@:
I can't seem to find this in the make manual.
214
votes
7
answers
295k
views
How can I configure my makefile for debug and release builds?
I have the following makefile for my project, and I'd like to configure it for release and debug builds. In my code, I have lots of #ifdef DEBUG macros in place, so it's simply a matter of setting ...
205
votes
7
answers
99k
views
What's the difference between := and = in Makefile?
For variable assignment in Make, I see := and = operator. What's the difference between them?
166
votes
5
answers
218k
views
How to call Makefile from another Makefile?
I'm getting some unexpected results calling one makefile from another. I have two makefiles, one called /path/to/project/makefile and one called /path/to/project/gtest-1.4.0/make/Makefile. I'm ...
160
votes
15
answers
99k
views
Check if a program exists from a Makefile
How can I check if a program is callable from a Makefile?
(That is, the program should exist in the path or otherwise be callable.)
It could be used to check for which compiler is installed, for ...
158
votes
4
answers
72k
views
Difference between CPPFLAGS and CXXFLAGS in GNU Make
What's the difference between CPPFLAGS and CXXFLAGS in GNU Make?
156
votes
4
answers
97k
views
What is the difference between gmake and make?
I am trying to understand the difference between 'gmake' and 'make'?
On my linux box they are identical:
% gmake --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is ...
117
votes
7
answers
82k
views
Recursive wildcards in GNU make?
It's been a while since I've used make, so bear with me...
I've got a directory, flac, containing .FLAC files. I've got a corresponding directory, mp3 containing MP3 files. If a FLAC file is newer ...
110
votes
10
answers
79k
views
GNU make: should the number of jobs equal the number of CPU cores in a system?
There seems to be some controversy on whether the number of jobs in GNU make is supposed to be equal to the number of cores, or if you can optimize the build time by adding one extra job that can be ...
107
votes
1
answer
76k
views
How to change the extension of each file in a list with multiple extensions in GNU make?
In a GNU makefile, I am wondering if it is possible, with an file list input, to make a file list output with new extensions.
In input, I get this list:
FILES_IN=file1.doc file2.xls
And I would ...
101
votes
16
answers
64k
views
List goals/targets in GNU make that contain variables in their definition
I have a fairly large makefile that creates a number of targets on the fly by computing names from variables. (eg foo$(VAR) : $(PREREQS)). Is there any way that gnu make can be convinced to spit out ...
101
votes
7
answers
186k
views
How to use GNU Make on Windows?
I installed MinGW and MSYS, added C:\MinGW\bin to PATH but I still can't run Makefile on Windows' cmd. I would like to run cmd.exe and there type, for example, make all but my cmd says that there is ...
100
votes
3
answers
69k
views
Remove item from a Makefile variable?
I have a makefile, which includes several other makefiles, which in turn all add to a variable like this:
VAR := Something SomethingElse
VAR += SomeOtherThing
(...)
Now I wish to remove ...
94
votes
1
answer
155k
views
Makefile - missing separator [duplicate]
Possible Duplicate:
Make error: missing separator
Have this code in makefile:
PROG = semsearch
all: $(PROG)
%: %.c
gcc -o $@ $< -lpthread
clean:
rm $(PROG)
and the error
missing separator. ...
92
votes
9
answers
116k
views
Run make in each subdirectory
I have a directory (root_dir), that contains a number of sub-directories (subdir1, subdir2, ...).
I want to run the make in each directory in root_dir, using a Makefile placed in it.
(Obviously ...
92
votes
1
answer
78k
views
:= vs = in make macros [duplicate]
Possible Duplicate:
What is the difference between the GNU Makefile variable assignments =, ?=, := and +=?
I only know very basic makefile syntax, and was reading through another project's makefile ...
85
votes
7
answers
116k
views
Debugging GNU make
Is there a command line way in make to find out which of the prerequisites of a target is not updated?
83
votes
9
answers
172k
views
How to place object files in separate subdirectory
I'm having trouble with trying to use make to place object files in a separate subdirectory, probably a very basic technique. I have tried to use the information in this page:
http://www.gnu.org/...
83
votes
4
answers
48k
views
Making CMake print commands before executing
I'm working on a large C++ project built with CMake on Linux. CMake runs okay, producing a horde of Makefiles in the tree of modules and applications. Running GNU make leads to linker errors. How ...
82
votes
3
answers
89k
views
How to force an error in a gnumake file
I want to detect a condition in my makefile where a tool is the wrong version and force the make to fail with an error message indicating the item is not the right version.
Can anyone give an example ...
77
votes
8
answers
34k
views
Disable make builtin rules and variables from inside the make file
I want to disable builtin rules and variables as per passing the -r and -R options to GNU make, from inside the make file. Other solutions that allow me to do this implicitly and transparently are ...
76
votes
4
answers
68k
views
Append to GNU 'make' variables via the command line
I am using a GNU Make Makefile to build a C project with several targets (all, clean, and a few project specific targets). In the process of debugging, I would like to append some flags to a single ...
68
votes
1
answer
36k
views
Makefile rule that depends on all files under a directory (including within subdirectories)
One rule in my Makefile zips an entire directory (res/) into a ZIP file. Obviously, this rule needs to execute when any file under the res/ directory changes. Thus, I want the rule to have as a ...
67
votes
8
answers
19k
views
Why use build tools like Autotools when we can just write our own makefiles?
Recently, I switched my development environment from Windows to Linux. So far, I have only used Visual Studio for C++ development, so many concepts, like make and Autotools, are new to me. I have read ...
64
votes
3
answers
22k
views
How to have GNU make explicitly test for failure?
After years of not using make, I find myself needing it again, the gnu version now. I'm pretty sure I should be able to do what I want, but haven't figured out how, or found an answer with Google, ...
64
votes
3
answers
75k
views
Wildcard targets in a Makefile
How can I compact the folllowing Makefile targets?
$(GRAPHDIR)/Complex.png: $(GRAPHDIR)/Complex.dot
dot $(GRAPHDIR)/Complex.dot -Tpng -o $(GRAPHDIR)/Complex.png
$(GRAPHDIR)/Simple.png: $(...
62
votes
3
answers
274k
views
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 /...
61
votes
1
answer
18k
views
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
60
votes
4
answers
77k
views
How to get exit status of a shell command used in GNU Makefile?
I have a makefile rule in while I am executing a linux tool. I need to check the exit status of the tool command, and if that command fails the make has to be aborted.
I tried checking with $?, $$? \...
59
votes
9
answers
51k
views
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
...
59
votes
5
answers
60k
views
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?
59
votes
6
answers
48k
views
GNU make's -j option
Ever since I learned about -j I've used -j8 blithely. The other day I was compiling an atlas installation and the make failed. Eventually I tracked it down to things being made out of order - and it ...
58
votes
1
answer
10k
views
How to get the second dependency file using Automatic Variables in a Makefile?
I need to get the nth dependency file from a rule, something similar to $n in bash. I need this because I'd like to feed in individual dependency files as options to the build program.
Here's an ...
58
votes
5
answers
28k
views
why "make" before "make install"
I know the process of installing from source are.
./configure
make
make install
But why "make" before /etc/cups/cupsd.conf, why not just do "make install"?
My understanding so far is "make" only ...
57
votes
2
answers
45k
views
Suppress and ignore output for Makefile?
I know that the @ prefix suppresses output from a shell command in Makefiles, and also that the - prefix will ignore errors from a shell command. Is there a way to combine the two, i.e. a prefix that ...
56
votes
2
answers
37k
views
How to get the invoking target of makefile?
How to get the invoking target of the GNU make Makefile?
for example, I invoke make with the following command line:
make a-target
How can I get the invoking target "a-target" in the Makefile and ...
56
votes
7
answers
141k
views
ldconfig error:"is not a symbolic link" when using Linux loader
When running:
sudo /sbin/ldconfig
the following error appears:
/sbin/ldconfig: /usr/local/lib/ is not a symbolic link
When I run the file command, the below appears:
file /usr/local/lib/
...
55
votes
5
answers
62k
views
Order of processing components in makefile
In a makefile, the dependency line is of the form -
abc: x y z
All three of the components (x,y,z) are themselves targets in dependency lines further down in the makefile.
If make abc is invoked, ...
53
votes
5
answers
27k
views
What are double-colon rules in a Makefile for?
Section 4.13 of the GNU Make manual describes the so-called double-colon rules:
Double-colon rules are rules written with ‘::’ instead of ‘:’ after the target names. They are handled differently from ...
52
votes
2
answers
44k
views
How can I capture the current directory as an absolute pathname in a make variable?
I'd like to get the current directory during a GNUmake file run put into a make variable.
What is the syntax to do this? Something like this?
DIR := $(PWD)
52
votes
2
answers
37k
views
Functions in Makefile
I am writing a Makefile with a lot of repetitive stuff, e.g.
debug_ifort_Linux:
if [ $(UNAME) = Linux ]; then \
$(MAKE) FC=ifort FFLAGS=$(difort) ...