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
2452
votes
10 answers

What is the purpose of .PHONY in a Makefile?

What does .PHONY mean in a Makefile? I have gone through this, but it is too complicated. Can somebody explain it to me in simple terms?
Lazer
  • 90,700
  • 113
  • 281
  • 364
946
votes
6 answers

What is the difference between the GNU Makefile variable assignments =, ?=, := and +=?

Can anybody give a clear explanation of how variable assignment really works in Makefiles. What is the difference between : VARIABLE = value VARIABLE ?= value VARIABLE := value VARIABLE += value I have read the section in GNU Make's manual,…
mmoris
  • 9,970
  • 3
  • 18
  • 12
907
votes
8 answers

Passing additional variables from command line to make

Can I pass variables to a GNU Makefile as command line arguments? In other words, I want to pass some arguments which will eventually become variables in the Makefile.
Pablo
  • 28,133
  • 34
  • 125
  • 215
823
votes
19 answers

makefile:4: *** missing separator. Stop

This is my makefile: all:ll ll:ll.c gcc -c -Wall -Werror -02 c.c ll.c -o ll $@ $< clean : \rm -fr ll When I try to make clean or make make, I get this error: :makefile:4: *** missing separator. Stop. How can I fix it?
Rahul Reddy
  • 12,613
  • 10
  • 22
  • 21
614
votes
6 answers

What do the makefile symbols $@ and $< mean?

CC=g++ CFLAGS=-c -Wall LDFLAGS= SOURCES=main.cpp hello.cpp factorial.cpp OBJECTS=$(SOURCES:.cpp=.o) EXECUTABLE=hello all: $(SOURCES) $(EXECUTABLE) $(EXECUTABLE): $(OBJECTS) $(CC) $(LDFLAGS) $(OBJECTS) -o $@ .cpp.o: $(CC) $(CFLAGS) $< -o…
Mohit Deshpande
  • 53,877
  • 76
  • 193
  • 251
508
votes
3 answers

What is the difference between using a Makefile and CMake to compile the code?

I code in C/C++ and use a (GNU) Makefile to compile the code. I can do the same with CMake and get a Makefile. However, what is the difference between using a Makefile and CMake to compile the code?
rish
  • 5,575
  • 6
  • 22
  • 27
504
votes
15 answers

Passing arguments to "make run"

I use Makefiles. I have a target called run which runs the build target. Simplified, it looks like the following: prog: .... ... run: prog ./prog Is there any way to pass arguments? So that make run asdf --> ./prog asdf make run the dog kicked…
anon
  • 41,035
  • 53
  • 197
  • 293
491
votes
8 answers

How do I write the 'cd' command in a makefile?

For example, I have something like this in my makefile: all: cd some_directory But when I typed make I saw only 'cd some_directory', like in the echo command.
Davit Siradeghyan
  • 6,053
  • 6
  • 24
  • 29
482
votes
13 answers

What's the opposite of 'make install', i.e. how do you uninstall a library in Linux?

While running ./configure --prefix=/mingw on a MinGW/MSYS system for a library I had previously run './configure --prefix=/mingw && make && make install' I came across this message: WARNING: A version of the Vamp plugin SDK is already…
psas
474
votes
22 answers

gcc makefile error: "No rule to make target ..."

I'm trying to use GCC (linux) with a makefile to compile my project. I get the following error which is can't seem to decipher in this context: "No rule to make target 'vertex.cpp', needed by 'vertex.o'. Stop." This is the makefile: a.out:…
Meir
  • 12,285
  • 19
  • 58
  • 70
439
votes
15 answers

How to discover number of *logical* cores on Mac OS X?

How can you tell, from the command line, how many cores are on the machine when you're running Mac OS X? On Linux, I use: x=$(awk '/^processor/ {++n} END {print n+1}' /proc/cpuinfo) It's not perfect, but it's close. This is intended to get fed to…
Mike DeSimone
  • 41,631
  • 10
  • 72
  • 96
435
votes
4 answers

What are Makefile.am and Makefile.in?

These two files are mostly seen in open source projects. What are they for, and how do they work?
Mask
  • 33,129
  • 48
  • 101
  • 125
388
votes
8 answers

How do I force make/GCC to show me the commands?

I'm trying to debug a compilation problem, but I cannot seem to get GCC (or maybe it is make??) to show me the actual compiler and linker commands it is executing. Here is the output I am seeing: CCLD …
hernejj
  • 3,889
  • 2
  • 15
  • 3
366
votes
14 answers

How to install and use "make" in Windows?

I'm following the instructions of someone whose repository I cloned to my machine. I want to use the make command as part of setting up the code environment, but I'm using Windows. I searched online, but I could only find a make.exe file, a…
Hashem Elezabi
  • 3,827
  • 3
  • 12
  • 7
362
votes
8 answers

How to assign the output of a command to a Makefile variable

I need to execute some make rules conditionally, only if the Python installed is greater than a certain version (say 2.5). I thought I could do something like executing: python -c 'import sys; print int(sys.version_info >= (2,5))' and then using…
fortran
  • 74,053
  • 25
  • 135
  • 175
1
2 3
99 100