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
#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 $< -o $@ depend: makedepend -- $(DFLAGS) -- $(SRC) .PHONY:clean clean: find . -name "*.o" | xargs rm -vf rm -vf fooexe
Questions
Any help would be great.
Lots of your code could be completely removed or rewritten in Release mode. The resulting executable will most likely not match up with your written code. Because of this release mode will run faster than debug mode due to the optimizations.
To use it, just set the list of variables to print on the command line, and include the debug target: $ make V="USERNAME SHELL" debug makefile:2: USERNAME = Owner makefile:2: SHELL = /bin/sh.exe make: debug is up to date. Now you can print variables by simply listing them on the command line.
You can now debug your release build application. To find a problem, step through the code (or use Just-In-Time debugging) until you find where the failure occurs, and then determine the incorrect parameters or code.
When doing a DEBUG build the project is set up to not optimize (or only very lightly optimize) the generated code, and to tell the compiler to add debug information (which includes information about functions, variables, and other information needed for debugging).
-g
flag for the release build is not automatically bad, but if your code ever produces a core dump, it is easier to make head or tail of the core dump if the program file includes debugging information. The primary cost of debugging information is extra sections in the program file that do not need to be loaded into system memory - the runtime cost is small. -g
and -O
. It is harder to debug optimized code, but it gives you (often significant) performance benefits.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With