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
246
votes
15 answers

How do you force a makefile to rebuild a target?

I have a makefile that builds and then calls another makefile. Since this makefile calls more makefiles that does the work it doesn't really change. Thus it keeps thinking the project is built and up to date. dnetdev11 ~ # make make: `release' is up…
Lodle
  • 31,277
  • 19
  • 64
  • 91
243
votes
5 answers

In Unix, can I run 'make' in a directory without cd'ing to that directory first?

In Unix, can I run make in a directory without cd'ing to that directory first?
user46795
  • 2,643
  • 3
  • 25
  • 31
238
votes
13 answers

Using G++ to compile multiple .cpp and .h files

I've just inherited some C++ code that was written poorly with one cpp file which contained the main and a bunch of other functions. There are also .h files that contain classes and their function definitions. Until now the program was compiled…
Meir
  • 12,285
  • 19
  • 58
  • 70
230
votes
2 answers

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.
cdwilson
  • 4,310
  • 4
  • 26
  • 32
224
votes
9 answers

Where can I find "make" program for Mac OS X Lion?

Just upgraded my computer to Mac OS X Lion and went to terminal and typed "make" but it says: -bash: make: command not found Where did the "make" command go?
Roman Kagan
  • 10,440
  • 26
  • 86
  • 126
217
votes
6 answers

How to abort makefile if variable not set?

How could I abort a make/makefile execution based on a makefile's variable not being set/valued? I came up with this, but works only if caller doesn't explicitly run a target (i.e. runs make only). ifeq ($(MY_FLAG),) abort: ## This MUST be the…
Caruccio
  • 3,489
  • 4
  • 18
  • 14
212
votes
4 answers

How to set child process' environment variable in Makefile

I would like to change this Makefile: SHELL := /bin/bash PATH := node_modules/.bin:$(PATH) boot: @supervisor \ --harmony \ --watch etc,lib \ --extensions js,json \ --no-restart-on error \ …
bodokaiser
  • 15,122
  • 22
  • 97
  • 140
209
votes
7 answers

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 this macro and adding the -g3 -gdwarf2 flags to the…
samoz
  • 56,849
  • 55
  • 141
  • 195
206
votes
3 answers

makefile execute another target

I have a makefile structured something like this: all : compile executable clean : rm -f *.o $(EXEC) I realized that I was consistently running "make clean" followed by "clear" in my terminal before running "make all". I like to have a…
sas4740
  • 4,510
  • 8
  • 26
  • 23
203
votes
7 answers

Make install, but not to default directories?

I want to run 'make install' so I have everything I need, but I'd like it to install the things in their own folder as opposed to the system's /usr/bin etc. is that possible? even if it references tools in the /usr/bin etc.?
Jon Phenow
  • 3,974
  • 5
  • 26
  • 30
201
votes
8 answers

Make: how to continue after a command fails?

The command $ make all gives errors such as rm: cannot remove '.lambda': No such file or directory so it stops. I want it to ignore the rm-not-found-errors. How can I force-make? Makefile all: make clean make .lambda make…
hhh
  • 50,788
  • 62
  • 179
  • 282
197
votes
9 answers

Compiling with g++ using multiple cores

Quick question: what is the compiler flag to allow g++ to spawn multiple instances of itself in order to compile large projects quicker (for example 4 source files at a time for a multi-core CPU)?
bsofman
  • 2,105
  • 2
  • 14
  • 7
193
votes
5 answers

How to get a shell environment variable in a makefile?

In shell when I enter echo $demoPath it prints /usr/local/demo How can I get the value of this variable $demoPath in a makefile?
Jialin
  • 2,415
  • 2
  • 14
  • 10
192
votes
16 answers

How do I check if file exists in Makefile so I can delete it?

In the clean section of my Makefile I am trying to check if the file exists before deleting permanently. I use this code but I receive errors. What's wrong with it? if [ -a myApp ] then rm myApp fi I get this error message if [ -a myApp ] …
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
192
votes
14 answers

Compiling C++ on remote Linux machine - "clock skew detected" warning

I'm connected to my university's small Linux cluster via PuTTY and WinSCP, transferring files using the latter and compiling and running them with the former. My work so far has been performed in the university's labs, but today I have been doing…
DMA57361
  • 3,600
  • 3
  • 27
  • 36