Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple makefile with release and debug builds - Best practices
    primarykey
    data
    text
    <p>I am new to makefiles. I learned makefile creation and other related concepts from "Managing projects with GNU make" book. The makefile is ready now and I need to make sure the one which I created is OK. Here is the makefile</p> <pre><code>#Main makefile which does the build #makedepend flags DFLAGS = #Compiler flags #if mode variable is empty, setting debug build mode ifeq ($(mode),release) CFLAGS = -Wall else mode = debug CFLAGS = -g -Wall endif CC = g++ PROG = fooexe #each module will append the source files to here SRC := main.cpp #including the description include bar/module.mk include foo/module.mk OBJ := $(patsubst %.cpp, %.o, $(filter %.cpp,$(SRC))) .PHONY:all all: information fooexe information: ifneq ($(mode),release) ifneq ($(mode),debug) @echo "Invalid build mode." @echo "Please use 'make mode=release' or 'make mode=debug'" @exit 1 endif endif @echo "Building on "$(mode)" mode" @echo ".........................." #linking the program fooexe: $(OBJ) $(CC) -o $(PROG) $(OBJ) %.o:%.cpp $(CC) $(CFLAGS) -c $&lt; -o $@ depend: makedepend -- $(DFLAGS) -- $(SRC) .PHONY:clean clean: find . -name "*.o" | xargs rm -vf rm -vf fooexe </code></pre> <p><strong>Questions</strong></p> <ol> <li>The above given makefile works well with release and debug builds. But is it in the correct format? Or do you see any flaws in that?</li> <li>Above makefile does debug build by default when invoked using <em>make</em>. For release builds, <em>make mode=release</em> is required. Is this the correct approach?</li> <li>Is the debug and release compiler flags supplied to g++ is correct? For debug, I use <em>-g -Wall</em> and for release, just <em>-Wall</em>. Is this right?</li> </ol> <p>Any help would be great.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload