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
24
votes
1 answer

Makefile to put object files from source files different directories into a single, separate directory?

I'm using UnitTest++ to allow me to create unit tests for some C++ code (that should build on Linux or Mac OS X). I have a directory structure like this: src - Foo.cpp - Bar.cpp test - FooTest.cpp - BarTest.cpp - Main.cpp - Makefile UnitTest++ -…
Daryl Spitzer
  • 143,156
  • 76
  • 154
  • 173
24
votes
4 answers

Building C-program "out of source tree" with GNU make

I would like to build a C-project for my microcontroller with the GNU make tool. I would like to do it in a clean way, such that my source code is not cluttered with object files and other stuff after the build. So imagine that I have a project…
K.Mulier
  • 8,069
  • 15
  • 79
  • 141
24
votes
1 answer

Generate multiple target using single action/rule

How do I write a rule to generate set of files using a single action. Example: Files x, y, z are generated as a result of single execution of script t.sh which takes file a as input. x y z: a t.sh $@ GNU make tries to execute t.sh 3 times.
shoban
  • 650
  • 1
  • 9
  • 14
24
votes
1 answer

Order-only prerequisites not working correctly in GNU make?

I have a problem with order-only prerequisites. These do not execute first at all. Am I mis-understanding the way order-only prerequisites work? The following make script: .PHONY: mefirst mefirst2 mefirst: @echo "I'm first!" mefirst2: …
George André
  • 770
  • 1
  • 6
  • 14
24
votes
3 answers

Makefile pattern rule for no extension?

I have a bunch of applications that are built with the same type of make rule: apps = foo bar baz all: $(apps) foo: foo.o $(objects) $(link) bar: bar.o $(objects) $(link) baz: baz.o $(objects) $(link) If they had an extension (for…
Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319
23
votes
4 answers

GNU make conditional function $(if ...) inside a user-defined function always evaluates to true

I am trying to write a make function to touch/create an empty file and/or set the permissions, user and group, where possible, or warn if not. However, every conditional check within my function seems to evaluate to true. The essentials of my…
nshew13
  • 3,052
  • 5
  • 25
  • 39
23
votes
2 answers

Measure (profile) time spent in each target of a Makefile

Is there a way to echo the (system, user, real) time spent in each target of a Makefile recursively when I do make all? I'd like to benchmark the compilation of a project in a more granular way than just time make all. Ideally, it would echo a tree…
mqtthiqs
  • 445
  • 3
  • 9
23
votes
3 answers

How to handle shell expansions in GNU Make under Ubuntu?

Given this very simple Makefile: all: @mkdir -pv test/{a,b} I get this output on OS X 10.6.8 and CentOS 5.5: mkdir: created directory `test' mkdir: created directory `test/a' mkdir: created directory `test/b' But on Ubuntu 11.04 I get…
Adam Lindberg
  • 16,447
  • 6
  • 65
  • 85
23
votes
1 answer

Makefile : Automatically compile all c files, keeping .o files in separate folder

What I have is a directory with 3 sub-directories. src/ for .c and .h files, bin/ where the compiled executable is supposed to go and obj/ where I want the .obj files to go. Now I want the makefile to compile every .c file from src (without me…
Max
  • 431
  • 1
  • 5
  • 13
23
votes
2 answers

How to speed up Compile Time of my CMake enabled C++ Project?

I came across several SO questions regarding specific aspects of improving the turn-around time of CMake enabled C++ projects lately (like "At what level should I distribute my build process?" or "cmake rebuild_cache for just a subdirectory?"), I…
Florian
  • 39,996
  • 9
  • 133
  • 149
23
votes
2 answers

How can I clean up after an error in a Makefile?

foobar may create the output file even when it fails, so I need to delete it in that case. I can do this: foo: bar baz foobar $^ -o $@ || (rm -f $@ && exit 1) But this does not propagate the same exit code returned by foobar (which is then…
Matt
  • 21,026
  • 18
  • 63
  • 115
23
votes
2 answers

clang: warning: -l*: 'linker' input unused

When I compile code using GNU Make I get multiple warnings like: clang: warning: -lGui: 'linker' input unused This is probably because I have messed something up in my Makefile (below). Can anyone point me toward the…
mareks
  • 481
  • 2
  • 5
  • 13
22
votes
1 answer

How to implement "make install" in a Makefile?

So here's the repo I'm working with: https://github.com/Garuda1/unixlib I'd like to know where my compiled lib (unixlib.a) and where my header (unixlib.h) should be so as to be able to use the lib (under Linux-x86 or Linux-x86_64) simply by…
Garuda1
  • 331
  • 1
  • 2
  • 3
22
votes
1 answer

How can i split string with dot in makefile

I have make target like this test.% export var1=$(basename $*) && export var2=$(subst .,,$(suffix $*)) and i use like test.var1.var2 Now i want to do one more level like test.var1.var2.var3 how can i get that in makefile edit: The reason i…
Karl
  • 2,903
  • 5
  • 27
  • 43
22
votes
2 answers

How to break a string across lines in a makefile without spaces?

In a makefile, escaping a new-line with \ allows to split a single-line long string content across multiple source lines. However, the new-line is replaced with a space. Is there a transparent line break in the source that does not affect the string…
alexei
  • 2,031
  • 1
  • 26
  • 28