How can I configure my makefile for debug and release builds?

You can use Target-specific Variable Values. Example: CXXFLAGS = -g3 -gdwarf2 CCFLAGS = -g3 -gdwarf2 all: executable debug: CXXFLAGS += -DDEBUG -g debug: CCFLAGS += -DDEBUG -g debug: executable executable: CommandParser.yy.o Command.o $(CXX) -o output CommandParser.yy.o Command.o -lfl CommandParser.yy.o: CommandParser.l flex -o CommandParser.yy.c CommandParser.l $(CC) -c CommandParser.yy.c Remember to use $(CXX) or $(CC) … Read more

What are and is a programmer-defined file and is used by automake to generate the file (the .am stands for automake). The configure script typically seen in source tarballs will use the to generate a Makefile. The configure script itself is generated from a programmer-defined file named either or (deprecated). I prefer .ac … Read more

Sources from subdirectories in Makefile

This should do it: SOURCES = $(wildcard *.cpp) $(wildcard */*.cpp) If you change you mind and want a recursive solution (i.e. to any depth), it can be done but it involves some of the more powerful Make functions. You know, the ones that allow you to do things you really shouldn’t. EDIT: Jack Kelly points … Read more

Difference in details between “make install” and “make altinstall”

Let’s take a look at the generated Makefile! First, the install target: install: altinstall bininstall maninstall It does everything altinstall does, along with bininstall and maninstall Here’s bininstall; it just creates the python and other symbolic links. # Install the interpreter by creating a symlink chain: # $(PYTHON) -> python2 -> python$(VERSION)) # Also create … Read more

Why .SECONDARY does not work with patterns (%) while .PRECIOUS does?

Thanks to Alex (see answer) i went further in my search. What i found is that it is recorded in TODO.private of make project for 15 years …. Using git:// you can see history of TODO.private content : 6) Right now the .PRECIOUS, .INTERMEDIATE, and .SECONDARY pseudo-targets have different capabilities. For example, .PRECIOUS can take … Read more

Best practice for building a make file

Here is an example makefile for you, tested on your github project. Features: Automatic dependency generation. Automatic rebuild when Makefile is changed. Debug/release builds in different directories. Debug build is the default, use make BUILD=release for release builds. Supports gcc and clang. gcc is the default, use make COMPILER=clang for clang. clean target works by … Read more