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
125
votes
4 answers

Why always ./configure; make; make install; as 3 separate steps?

Every time you compile something from source, you go through the same 3 steps: $ ./configure $ make $ make install I understand, that it makes sense to divide the installing process into different steps, but I don't get it, why each and every coder…
erikbstack
  • 12,878
  • 21
  • 81
  • 115
123
votes
9 answers

GNU Makefile rule generating a few targets from a single source file

I am attempting to do the following. There is a program, call it foo-bin, that takes in a single input file and generates two output files. A dumb Makefile rule for this would be: file-a.out file-b.out: input.in foo-bin input.in file-a.out…
makesaurus
  • 1,393
  • 3
  • 10
  • 7
122
votes
12 answers

how to prevent "directory already exists error" in a makefile when using mkdir

I need to generate a directory in my makefile and I would like to not get the "directory already exists error" over and over even though I can easily ignore it. I mainly use mingw/msys but would like something that works across other shells/systems …
KPexEA
  • 16,560
  • 16
  • 61
  • 78
118
votes
3 answers

How to define several include path in Makefile

New to C++; Basic understanding of includes, libraries and the compile process. Did a few simple makefiles yet. My current project involves using an informix DB api and i need to include header files in more than one nonstandard dirs. How to write…
groovehunter
  • 3,050
  • 7
  • 26
  • 38
117
votes
5 answers

How I could add dir to $PATH in Makefile?

I want to write a Makefile which would run tests. Test are in a directory './tests' and executable files to be tested are in the directory './bin'. When I run the tests, they don't see the exec files, as the directory ./bin is not in the $PATH. When…
Szymon Lipiński
  • 27,098
  • 17
  • 75
  • 77
115
votes
7 answers

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 than the corresponding MP3 file (or the…
Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
115
votes
10 answers

Makefile, header dependencies

Let's say I have a makefile with the rule %.o: %.c gcc -Wall -Iinclude ... I want *.o to be rebuilt whenever a header file changes. Rather than work out a list of dependencies, whenever any header file in /include changes, then all objects in the…
Mike
  • 58,961
  • 76
  • 175
  • 221
113
votes
2 answers

Difference in details between "make install" and "make altinstall"

Here is my case: I am using Ubuntu 10.04 (Lucid Lynx). The system's default Python is v2.6.5, but I need Python v2.7. So I downloaded the source from python.org and tried to install it. The first time I installed it, I ran: cd…
qiuhan1989
  • 1,523
  • 2
  • 13
  • 18
109
votes
6 answers

How to add include and lib paths to configure/make cycle?

I need a place to install libraries in a linux box I have no su access to. I'm using ~/local[/bin,/lib,/include], but I don't know how can I tell ./configure to look for libraries there (particularly, I'm trying to compile emacs, which needs libgif,…
Lacrymology
  • 2,269
  • 2
  • 20
  • 28
109
votes
10 answers

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 queued up while the others "work". Is it better to…
Johan
  • 20,067
  • 28
  • 92
  • 110
108
votes
2 answers

If conditions in a Makefile, inside a target

I'm trying to setup a Makefile that will search and copy some files (if-else condition) and I can't figure out what exactly is wrong with it? (thou I'm pretty sure it's because a combination of spaces/tabs written in the wrong place). Can I get some…
alexandernst
  • 14,352
  • 22
  • 97
  • 197
107
votes
4 answers

CFLAGS, CCFLAGS, CXXFLAGS - what exactly do these variables control?

I am using GNU make to compile my C++ code, and i would like to understand how to make my compilations customizable. I read in different places that CFLAGS, CCFLAGS and CXXFLAGS are used for this purpose. So how should i use them? If i have…
anatolyg
  • 26,506
  • 9
  • 60
  • 134
107
votes
10 answers

Debugging the error "gcc: error: x86_64-linux-gnu-gcc: No such file or directory"

I'm trying to build: https://github.com/kanzure/nanoengineer But it looks like it errors out on: gcc -DHAVE_CONFIG_H -I. -I../.. -I/usr/include/python2.7 -std=c99 x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall…
cat pants
  • 1,485
  • 4
  • 13
  • 22
107
votes
4 answers

How do I create a configure script?

This may sound like a very generic question but here it goes. I have a requirement to create a configure script for my application, the result of this configure would be a generated makefile (basic configure, make, make install). My question is,…
godzilla
  • 3,005
  • 7
  • 44
  • 60
106
votes
7 answers

How to conditionally set Makefile variable to something if it is empty?

I want to set a variable if it is empty. I tried in this way: .... TEST := $(something) ... TEST ?= $(something else) The first $(something) may return an empty string, however the conditional assignment ?= works only if the previous variable is…
ocirocir
  • 3,543
  • 2
  • 24
  • 34