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

What is the difference between gmake and make?

I am trying to understand the difference between 'gmake' and 'make'? On my linux box they are identical: % gmake --version GNU Make 3.81 Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying…
Nick Haddad
  • 8,767
  • 3
  • 34
  • 38
148
votes
5 answers

How do I make a simple makefile for gcc on Linux?

I have three files: program.c, program.h and headers.h. program.c includes program.h and headers.h. I need to compile this on Linux using gcc compiler. I'm not sure how to do this. Netbeans created one for me, but it's empty.
user69514
  • 26,935
  • 59
  • 154
  • 188
148
votes
2 answers

How to use shell commands in Makefile

I'm trying to use the result of ls in other commands (e.g. echo, rsync): all: FILES = $(shell ls) echo $(FILES) But I get: make FILES = Makefile file1.tgz file2.tgz…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
144
votes
6 answers

How to add multi line comments in makefiles

Is there a way to comment out multiple lines in makefiles like as in C syntax /* */ ?
Ankur Agarwal
  • 23,692
  • 41
  • 137
  • 208
142
votes
4 answers

What does "all" stand for in a makefile?

I read some tutorials concerning Makefiles but for me it is still unclear for what the target "all" stands for and what it does. Any ideas?
Chris Smullian
  • 2,237
  • 4
  • 18
  • 8
141
votes
10 answers

make: Nothing to be done for `all'

I am going through an eg pgm to create a make file. http://mrbook.org/tutorials/make/ My folder eg_make_creation contains the following files, desktop:~/eg_make_creation$ ls factorial.c functions.h hello hello.c main.c Makefile Makefile # I am…
Angus
  • 12,133
  • 29
  • 96
  • 151
137
votes
6 answers

How to pass macro definition from "make" command line arguments (-D) to C source code?

I usually pass macro definitions from "make command line" to a "makefile" using the option : -Dname=value. The definition is accessible inside the makefile. I also pass macro definitions from the "makefile" to the "source code" using the similar…
MohamedEzz
  • 2,830
  • 3
  • 20
  • 26
136
votes
2 answers

Can I compile all .cpp files in src/ to .o's in obj/, then link to binary in ./?

My project directory looks like this: /project Makefile main /src main.cpp foo.cpp foo.h bar.cpp bar.h /obj main.o foo.o bar.o What I would like my makefile to do would…
Austin Hyde
  • 26,347
  • 28
  • 96
  • 129
135
votes
10 answers

Can you make valid Makefiles without tab characters?

target: dependencies command1 command2 On my system (Mac OS X), make seems to require that that Makefiles have a tab character preceding the the content of each command line, or it throws a syntax error. This is an annoyance when creating…
xyz
  • 27,223
  • 29
  • 105
  • 125
134
votes
4 answers

Define a Makefile variable using a ENV variable or a default value

I am trying to do a simple thing: TMPDIR ?= /tmp test: @echo $(TMPDIR) This works if I run: $ make test /tmp It also works if I run: $ make test -e TMPDIR=~/tmp /home/user/tmp What can I do to also have it works for: $ TMPDIR=~/tmp make…
Natim
  • 17,274
  • 23
  • 92
  • 150
132
votes
7 answers

Makefile ifeq logical or

How do you perform a logical OR using make's ifeq operator? e.g., I have (simplified): ifeq ($(GCC_MINOR), 4) CFLAGS += -fno-strict-overflow endif ifeq ($(GCC_MINOR), 5) CFLAGS += -fno-strict-overflow endif but would like to consolidate…
Pat
  • 1,882
  • 2
  • 15
  • 22
131
votes
3 answers

Cmake vs make sample codes?

I was wondering if there was any sample code for Makefiles (make) and CMakeLists.txt (cmake) that both do the same thing (the only difference being that one is written in make and the other in cmake). I tried looking for 'cmake vs make', but I…
jlo
  • 2,157
  • 2
  • 17
  • 23
129
votes
11 answers

Create directories using make file

I want to create directories using makefile. My project directory is like this +--Project +--output +--source +Testfile.cpp +Makefile I want to put all the objects and output into the respective output folder. I want to…
Jabez
  • 1,883
  • 6
  • 19
  • 18
127
votes
11 answers

How to overcome "'aclocal-1.15' is missing on your system" warning?

Im trying to run a c++ program on github. (available at the following link https://github.com/mortehu/text-classifier) I have a mac, and am trying to run it in the terminal. I think I have downloaded autoconf and automake but am not sure. To run the…
Liam Flynn
  • 2,009
  • 3
  • 17
  • 16
125
votes
6 answers

CFLAGS vs CPPFLAGS

I understand that CFLAGS (or CXXFLAGS for C++) are for the compiler, whereas CPPFLAGS is used by the preprocessor. But I still don't understand the difference. I need to specify an include path for a header file that is included with #include --…
EBM
  • 1,683
  • 5
  • 15
  • 13