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 is the GNU implementation of the Make utility. It is probably the most common version in use today.

GNU Make supports extensions to the Make language beyond the POSIX standard, therefore GNU Make solutions may not work under other versions, so the gnu-make tag is appropriate for questions from those using GNU Make, or pertaining to makefiles written for it.

Documentation

The latest GNU Make manual can be found in several formats here.

See also

make makefile

4424 questions
73
votes
8 answers

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 also welcome. I've found several references to using…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
67
votes
8 answers

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 the GNU makefile documentation and got almost an…
Navaneeth K N
  • 15,295
  • 38
  • 126
  • 184
64
votes
3 answers

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: $(GRAPHDIR)/Simple.dot dot…
Robert Munteanu
  • 67,031
  • 36
  • 206
  • 278
64
votes
1 answer

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 prerequisite all files underneath that directory. How…
Mechanical snail
  • 29,755
  • 14
  • 88
  • 113
63
votes
3 answers

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, etc. I'm trying to create a test target which will…
GreenMatt
  • 18,244
  • 7
  • 53
  • 79
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
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

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 worked fine once I went back to singlethreaded…
pythonic metaphor
  • 10,296
  • 18
  • 68
  • 110
56
votes
4 answers

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 $?, $$? \$? etc in the makefile. But they gives me syntax…
Lunar Mushrooms
  • 8,358
  • 18
  • 66
  • 88
56
votes
2 answers

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 suppresses output and ignores errors? I don't…
Andrew Lee
  • 2,543
  • 3
  • 20
  • 31
56
votes
1 answer

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 example: dep.o: dep.src config1.cfg config2.cfg …
Yu Zhou
  • 788
  • 6
  • 11
55
votes
2 answers

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 assign it to a variable? Further more, if more than…
Justin
  • 693
  • 1
  • 5
  • 7
55
votes
6 answers

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/ /usr/local/lib/: directory Inside…
Rodrigo Gurgel
  • 1,696
  • 2
  • 15
  • 32