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
64
votes
5 answers

What is the preferred way to structure and build OCaml projects?

It is unclear to newcomers to the ecosystem what is the canonically preferred way to structure and manage building small to medium sized OCaml projects. I understand the basics of ocamlc, &c.--they mirror conventional UNIX C compilers enough to seem…
jrk
  • 2,896
  • 1
  • 22
  • 35
64
votes
8 answers

What is your experience with non-recursive make?

A few years ago, I read the Recursive Make Considered Harmful paper and implemented the idea in my own build process. Recently, I read another article with ideas about how to implement non-recursive make. So I have a few data points that…
Jon 'links in bio' Ericson
  • 20,880
  • 12
  • 98
  • 148
64
votes
6 answers

Make GNU make use a different compiler

How can I make GNU Make use a different compiler without manually editing the makefile?
Clark Gaebel
  • 17,280
  • 20
  • 66
  • 93
64
votes
3 answers

Wildcard targets in a Makefile

How can I compact the folllowing Makefile targets? $(GRAPHDIR)/Complex.png: $(GRAPHDIR)/Complex.dot dot $(GRAPHDIR)/Complex.dot -Tpng -o $(GRAPHDIR)/Complex.png $(GRAPHDIR)/Simple.png: $(GRAPHDIR)/Simple.dot dot…
Robert Munteanu
  • 67,031
  • 36
  • 206
  • 278
64
votes
1 answer

Makefile rule that depends on all files under a directory (including within subdirectories)

One rule in my Makefile zips an entire directory (res/) into a ZIP file. Obviously, this rule needs to execute when any file under the res/ directory changes. Thus, I want the rule to have as a prerequisite all files underneath that directory. How…
Mechanical snail
  • 29,755
  • 14
  • 88
  • 113
63
votes
3 answers

How to have GNU make explicitly test for failure?

After years of not using make, I find myself needing it again, the gnu version now. I'm pretty sure I should be able to do what I want, but haven't figured out how, or found an answer with Google, etc. I'm trying to create a test target which will…
GreenMatt
  • 18,244
  • 7
  • 53
  • 79
62
votes
6 answers

Change Makefile variable value inside the target body

Is there a way to reassign Makefile variable value inside of the target body? What I am trying to do is to add some extra flags for debug compilation: %.erl: %.beam $(ERLC) $(ERLFLAGS) -o ebin $< test: clean debug_compile_flag compile…
paulgray
  • 623
  • 1
  • 5
  • 4
61
votes
1 answer

How to read a CMake Variable in C++ source code

I'd like to store the version number of my library in just one place. So I have defined such a variable in the CMake-file: SET(LIBINTERFACE_VERSION 1 CACHE INTEGER "Version of libInterface") With this definition I can generate a version.rc file…
Snowfox
  • 1,112
  • 1
  • 10
  • 12
61
votes
2 answers

Subdirectories and Makefiles

I think this is a question that has been asked many times but I cannot find the right way to do it. I have the following structure: project/ project/Makefile project/code project/code/*.cc project/code/Makefile When I am in the directory…
Cedric H.
  • 7,980
  • 10
  • 55
  • 82
61
votes
3 answers

GCC with Visual Studio?

How hard would it be to use GCC instead of VC++ from within Visual Studio 2008? Obviously, some of the keywords won't match, and some may not get syntax highlighting (unless you made a new language service). Is this what a 'makefile project' is for,…
TraumaPony
  • 10,742
  • 12
  • 54
  • 74
61
votes
7 answers

Where can I set path to make.exe on Windows?

When I try run make from cmd-console on Windows, it runs Turbo Delphi's make.exe but I need MSYS's make.exe. There is no mention about Turbo Delphi in %path% variable, maybe I can change it to MSYS in registry?
d9k
  • 1,476
  • 3
  • 15
  • 28
60
votes
5 answers

Makefile that distinguishes between Windows and Unix-like systems

I would like to have the same Makefile for building on Linux and on Windows. I use the default GNU make on Linux and the mingw32-make (also GNU make) on Windows. I want the Makefile to detect whether it operates on Windows or Linux. For example…
Tom Pažourek
  • 9,582
  • 8
  • 66
  • 107
60
votes
1 answer

Linker error: "linker input file unused because linking not done", undefined reference to a function in that file

I'm having trouble with the linking of my files. Basically, my program consists of: The main program, gen1. gen1 - receives input sends to str2value for processing, outputs results str2value, breaks input into tokens using "tokenizer" determines…
Frames Catherine White
  • 27,368
  • 21
  • 87
  • 137
60
votes
7 answers

How to turn makefile into JSON Compilation Database?

Say we have make files (not cmake/premake/ninja etc) for our project that do work for gcc and clang. We want to generate out from them JSON Compilation Database to feed it into clang-modernize tool. How to do such thing? (is there any parser in…
DuckQueen
  • 772
  • 10
  • 62
  • 134
60
votes
4 answers

Makefile If-Then Else and Loops

Can someone explain how to use if-then statements and for loops in Makefiles? I can't seem to find any good documentation with examples.
GavinR
  • 6,094
  • 7
  • 33
  • 44