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
360
votes
16 answers

How to print out a variable in makefile

In my makefile, I have a variable 'NDK_PROJECT_PATH', my question is how can I print it out when it compiles? I read Make file echo displaying "$PATH" string and I tried: @echo $(NDK_PROJECT_PATH) @echo $(value NDK_PROJECT_PATH) Both gives me…
michael
  • 106,540
  • 116
  • 246
  • 346
353
votes
4 answers

Why does make think the target is up to date?

This is my Makefile: REBAR=./rebar REBAR_COMPILE=$(REBAR) get-deps compile all: compile compile: $(REBAR_COMPILE) test: $(REBAR_COMPILE) skip_deps=true eunit clean: -rm -rf deps ebin priv doc/* docs: $(REBAR_COMPILE) doc ifeq…
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
345
votes
14 answers

Make error: missing separator

I am getting the following error running make: Makefile:168: *** missing separator. Stop. What is causing this?
Renjith G
  • 6,307
  • 9
  • 27
  • 26
345
votes
7 answers

How to make a SIMPLE C++ Makefile

We are required to use a Makefile to pull everything together for our project, but our professor never showed us how to. I only have one file, a3driver.cpp. The driver imports a class from a location,…
Befall
  • 6,560
  • 9
  • 24
  • 29
331
votes
14 answers

OS detecting makefile

I routinely work on several different computers and several different operating systems, which are Mac OS X, Linux, or Solaris. For the project I'm working on, I pull my code from a remote git repository. I like to be able to work on my projects…
samoz
  • 56,849
  • 55
  • 141
  • 195
331
votes
22 answers

How to run a makefile in Windows?

I have some demos that I downloaded and they come with a Makefile.win and a Makefile.sgi. How can I run these in Windows to compile the demos?
Kim
  • 3,321
  • 2
  • 16
  • 4
317
votes
28 answers

How do you get the list of targets in a makefile?

I've used rake a bit (a Ruby make program), and it has an option to get a list of all the available targets, eg > rake --tasks rake db:charset # retrieve the charset for your data... rake db:collation # retrieve the collation for your…
Brian Burns
  • 20,575
  • 8
  • 83
  • 77
310
votes
14 answers

How to get current relative directory of your Makefile?

I have a several Makefiles in app specific directories like this: /project1/apps/app_typeA/Makefile /project1/apps/app_typeB/Makefile /project1/apps/app_typeC/Makefile Each Makefile includes a .inc file in this path one level…
boltup_im_coding
  • 6,345
  • 6
  • 40
  • 52
292
votes
8 answers

What is makeinfo, and how do I get it?

I'm trying to build GNU grep, and when I run make, I get: [snip] /bin/bash: line 9: makeinfo: command not found What is makeinfo, and how do I get it? (This is Ubuntu, if it makes a difference)
mike
  • 46,876
  • 44
  • 102
  • 112
287
votes
4 answers

Define make variable at rule execution time

In my GNUmakefile, I would like to have a rule that uses a temporary directory. For example: out.tar: TMP := $(shell mktemp -d) echo hi $(TMP)/hi.txt tar -C $(TMP) cf $@ . rm -rf $(TMP) As written, the above rule creates…
Emil Sit
  • 22,894
  • 7
  • 53
  • 75
283
votes
16 answers

How to write loop in a Makefile?

I want to execute the following commands: ./a.out 1 ./a.out 2 ./a.out 3 ./a.out 4 . . . and so on How to write this thing as a loop in a Makefile?
avd
  • 13,993
  • 32
  • 78
  • 99
272
votes
7 answers

How can I use Bash syntax in Makefile targets?

I often find Bash syntax very helpful, e.g. process substitution like in diff <(sort file1) <(sort file2). Is it possible to use such Bash commands in a Makefile? I'm thinking of something like this: file-differences: diff <(sort file1) <(sort…
Frank
  • 64,140
  • 93
  • 237
  • 324
272
votes
4 answers

How does "make" app know default target to build if no target is specified?

Most Linux apps are compiled with: make make install clean As I understand it, the make command takes names of build targets as arguments. So for example install is usually a target that copies some files to standard locations, and clean is a…
grigoryvp
  • 40,413
  • 64
  • 174
  • 277
264
votes
4 answers

Suppress echo of command invocation in makefile?

I wrote a program for an assignment which is supposed to print its output to stdout. The assignment spec requires the creation of a Makefile which when invoked as make run > outputFile should run the program and write the output to a file, which has…
noobler
  • 3,495
  • 4
  • 22
  • 26
255
votes
2 answers

What do @, - and + do as prefixes to recipe lines in Make?

In the GNU Makefile manual, it mentions these prefixes. If .ONESHELL is provided, then only the first line of the recipe will be checked for the special prefix characters (‘@’, ‘-’, and ‘+’). What do these prefixes do, and where are they…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526