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
27
votes
2 answers

GNU Make Convert Spaces to Colons

Given a colon-delimited list of paths, getting a space-delimited list with GNU Make is straightforward: CPATHS := /usr/bin/foo:/usr/bin/baz:/usr/bin/baz SPATHS := $(subst :, ,$(CPATHS)) However, I couldn't find a nice way to go the opposite…
5gon12eder
  • 24,280
  • 5
  • 45
  • 92
26
votes
1 answer

How to copy a directory in a Makefile?

I have a directory images/ that I want to copy to build/images/ from within a Makefile. The directory might contain multiple levels of subdirectories. What would be the most elegant way to do that? I want: avoid a full directory copy on each make…
Grumbel
  • 6,585
  • 6
  • 39
  • 50
26
votes
7 answers

How to define global shell functions in a Makefile?

I want to define a shell function #!/bin/sh test () { do_some_complicated_tests $1 $2; if something; then build_thisway $1 $2; else build_otherway $1 $2; fi } in such a way that I can use it in every rule of my Makefile, such…
Holger
  • 1,078
  • 2
  • 11
  • 12
26
votes
5 answers

telling 'make' to ignore dependencies when the top target has been created

I'm running the following kind of pipeline: digestA: hugefileB hugefileC cat $^ > $@ rm $^ hugefileB: touch $@ hugefileC: touch $@ The targets hugefileB and hugefileC are very big and take a long time to compute (and need the…
Pierre
  • 34,472
  • 31
  • 113
  • 192
25
votes
6 answers

How can I trap errors and interrupts in GNU make?

I'm wondering if there's a way to implement trap in GNU make, similar to that built into BASH? If the user presses CTRL-C, or if make itself fails (non-zero exit), I'd like to call a particular target or macro.
khosrow
  • 8,799
  • 4
  • 21
  • 24
25
votes
2 answers

Where does make store its cache?

Make seems to compare a file modification time with some sort of internal cache of modification times. Does anyone know where is this cache located or how to access it?
Matt
  • 22,224
  • 25
  • 80
  • 116
25
votes
3 answers

Is there a naming convention for makefile targets and variables

I couldn't find anything in the GNU Makefile Conventions.
Waqas Ilyas
  • 3,116
  • 1
  • 17
  • 27
25
votes
1 answer

How similar/different are gnu make, microsoft nmake and posix standard make?

How similar/different are gnu make, microsoft nmake and posix standard make? Obviously there's things like "which OS?", "which compiler?" and "which linker?", but I'm referring specifically to the syntax, semantics and command-line options of the…
user180247
25
votes
4 answers

Is it possible to "unset" an environment variable in a Makefile?

I'm using GNU make, and including a 3rd party library in a project that has a build system that goes berserk if CFLAGS is defined in the environment when it is called. I like to have CFLAGS defined in my environment for other reasons. The…
Jay Walker
  • 251
  • 1
  • 3
  • 3
25
votes
8 answers

Escaping colons in filenames in a Makefile

Is there a way to get GNU make to work correctly with filenames that contain colons? The specific problem I'm running into happens to involve a pattern rule. Here's a simplified version that does not depend on cutting and pasting tab characters: %…
zaphod
  • 4,561
  • 3
  • 25
  • 26
25
votes
2 answers

How to change default values of variables like CC in Makefile

(GNU) make uses several variables like: CC -- C compiler, by default cc CFLAGS -- flags for the C compiler, by default empty I would like to specify my own default values of some of them in my Makefile. In the example below I used the conditional…
25
votes
4 answers

Makefile ifeq: when are they evaluated?

The following is a very simple makefile that does not seem to work properly. TEST=ON buildbegin: ifeq ($(TEST),ON) @echo TEST PASSED else @echo TEST FAILED endif No matter what I set the TEST variable to, my ifeq statement passes. …
kalden
  • 273
  • 1
  • 3
  • 5
24
votes
1 answer

variable target in a makefile

I am trying to compile set of targets. However it only seems to do the first one. Below is a cut down of the my makefile that shows the error. OBJECTS = abc def ghi SOURCES = abc.c def.c ghi.c $(OBJECTS): $(SOURCES) @echo target…
wmercer
  • 1,102
  • 2
  • 11
  • 24
24
votes
7 answers

Makefile profiling

So I have this Makefile based build system that my users feel is working too slowly. For the sake of this question lets define performance as the time it takes make to figure out what it should actually do. I can see some avenues for optimization…
Chen Levy
  • 15,438
  • 17
  • 74
  • 92
24
votes
8 answers

How can I force gnu make to not build recipe in parallel?

How can I tell gnu make not to build some recipe in parallel. Let's say I have the following makefile : sources = a.xxx b.xxx c.xxx target = program all : $(target) $(target) : $(patsubst %.xxx,%.o,$(sources)) $(CXX) -o $@ $< %.o : %.cpp …
Sylvain Defresne
  • 42,429
  • 12
  • 75
  • 85