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
191
votes
7 answers

What's the difference between := and = in Makefile?

For variable assignment in Make, I see := and = operator. What's the difference between them?
prosseek
  • 182,215
  • 215
  • 566
  • 871
191
votes
9 answers

How to ensure Makefile variable is set as a prerequisite?

A Makefile deploy recipe needs an environment variable ENV to be set to properly execute itself, whereas other recipes don't care, e.g., ENV = .PHONY: deploy hello deploy: rsync . $(ENV).example.com:/var/www/myapp/ hello: echo "I don't…
abernier
  • 27,030
  • 20
  • 83
  • 114
189
votes
5 answers

Why use make over a shell script?

Make seems to me simply a shell script with slightly easier handling of command line arguments. Why is it standard to run make instead of ./make.sh
HoboBen
  • 2,900
  • 4
  • 21
  • 26
189
votes
17 answers

Why is no one using make for Java?

Just about every Java project that I've seen either uses Maven or Ant. They are fine tools and I think just about any project can use them. But what ever happened to make? It's used for a variety of non-Java projects and can easily handle Java. …
User1
  • 39,458
  • 69
  • 187
  • 265
182
votes
6 answers

How to pass argument to Makefile from command line?

How to pass argument to Makefile from command line? I understand I can do $ make action VAR="value" $ value with Makefile VAR = "default" action: @echo $(VAR) How do I get the following behavior? $ make action value value How about $make…
Meng Lu
  • 13,726
  • 12
  • 39
  • 47
175
votes
6 answers

Multi-line bash commands in makefile

Considering that every command is run in its own shell, what is the best way to run a multi-line bash command in a makefile? For example, like this: for i in `find` do all="$all $i" done gcc $all
Nelson Tatius
  • 7,693
  • 8
  • 47
  • 70
174
votes
2 answers

What is ?= in Makefile

KDIR ?= $(shell uname -r) What is the meaning of ?=? I have understood the difference between :=, += and = from another thread available in Stack Overflow, but unable to find the explanation for ?=.
codedoc
  • 2,079
  • 2
  • 11
  • 15
171
votes
3 answers

DESTDIR and PREFIX of make

I am trying to make software install to a specific directory. I found several ways, but not sure what are the differences between them. ./configure --prefix=*** make install DESTDIR=*** make install prefix=*** I am confused about the functions of…
Sean
  • 2,649
  • 3
  • 21
  • 27
169
votes
6 answers

What's the difference between parenthesis $() and curly bracket ${} syntax in Makefile?

Is there any differences in invoking variables with syntax ${var} and $(var)? For instance, in the way the variable will be expanded or anything?
Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178
168
votes
6 answers

Using local makefile for CLion instead of CMake

Is there a way to configure CLion to use a local makefile to compile code, rather than CMake? I can't seem to find the way to do it from the build options.
hlin117
  • 20,764
  • 31
  • 72
  • 93
161
votes
10 answers

Makefiles with source files in different directories

I have a project where the directory structure is like this: $projectroot | +---------------+----------------+ | | | part1/ …
devin
  • 6,407
  • 14
  • 48
  • 53
159
votes
4 answers

How to call Makefile from another Makefile?

I'm getting some unexpected results calling one makefile from another. I have two makefiles, one called /path/to/project/makefile and one called /path/to/project/gtest-1.4.0/make/Makefile. I'm attempting to have the former call the latter. In…
Chris Tonkinson
  • 13,823
  • 14
  • 58
  • 90
157
votes
19 answers

Is it possible to create a multi-line string variable in a Makefile

I want to create a makefile variable that is a multi-line string (e.g. the body of an email release announcement). something like ANNOUNCE_BODY=" Version $(VERSION) of $(PACKAGE_NAME) has been released It can be downloaded from…
jonner
  • 6,331
  • 6
  • 30
  • 28
156
votes
14 answers

Check if a program exists from a Makefile

How can I check if a program is callable from a Makefile? (That is, the program should exist in the path or otherwise be callable.) It could be used to check for which compiler is installed, for instance. E.g. something like this question, but…
Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
156
votes
4 answers

Difference between CPPFLAGS and CXXFLAGS in GNU Make

What's the difference between CPPFLAGS and CXXFLAGS in GNU Make?
elasticrat
  • 7,060
  • 5
  • 36
  • 36