Hello.
Is it possible somehow to specify a debug option in a Makefile. So I can run
> make debug module
The only solution I have found now is to use debug-module for every module I have.
Anyone knows?
Hello.
Is it possible somehow to specify a debug option in a Makefile. So I can run
> make debug module
The only solution I have found now is to use debug-module for every module I have.
Anyone knows?
Are you talking about #ifdef'ing stuff out? If that is the case, you need something like this:
make EXTRA_CFLAGS=-DMYDBGVAR=2234 modules
--- since you appear to be using the kernel source build, this will trigger a "special" flag that tells the make system to build with the extra compiler flags -DMY<bla> -- which is like a #define. So, you can then ifdef out stuff from your module.
Clear as mud?
Well it's really not the precompiler-stuff I'm asking for. I have that worked out.
I just wonder if I can do something like:
if the Makefile so I can execute the Makefile likeCode:debug: target gcc -Wall ...
> make debug target
or
> make target -debug
or something like that...
One thing that you could do isNext, make your make file with two different rules, one that links ONLY the source file, the other that links the source file with the source-dbg.o.Code:#ifdef DEBUG #include "source-dbg.h" #else #define function_debug(...) #define function1_debug(...) //etc #endif
Again, have I confused you enough?
You need to do some macro programming in your makefile for this. It's been awhile, so I don't remember the syntax, but it is pretty common to set up your makefile to allow something like:
make RELEASE=1 target
bit∙hub [bit-huhb] n. A source and destination for information.
Yes, bithub, that's what I need. Do you know where I can get more information about this? Or does anyone else know how to do it?
Then, when you build:Code:-------------------------------- # File "Makefile" BUILD = release # Default is release -include $(BUILD).mak # Rest of your makefile -------------------------------- # File "release.mak" CFLAGS = whatever cflags you want to use for release -------------------------------- # File "debug.mak" CFLAGS = whatever cflags you want to use for debug -------------------------------- # File "supergoofy.mak" CFLAGS = some super goofy flags
make target # defaults to release
make target BUILD=release # explicitly specify release build
make target BUILD=debug # explicitly specify debug build
make target BUILD=supergoofy # explicitly specify the super goofy build
Etc...
One problem you WILL encounter is that the makefile is completely unaware of changes in flags. So if you do a "make BUILD=release" followed by a "make BUILD=debug" it will NOT rebuild anything, since as far as make knows, nothing has changed. You need to "make clean" before switching to a different build type. It is easy to forget this and end up with corrupted or incomplete builds.
It's possible to write some complicated make stuff to hack around this problem, but it's not very robust. In general, make sucks for this sort of thing (make is a very primitive build system, period)
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
CMake is a nice cross-platform make system (have used it on projects spanning linux, windows and mac). The only reason that I mention this is that CMake makes makefiles simpler and setting special build settings like DEBUG, OTHER PLATFORM or whatever almost childs-play....
Check it out at CMake - Cross Platform Make.
My 0.02
To add to brewbuck's inputs, an alternative would be something like this (if you need just a small single Makefile):
A trick to make sure clean is done for a different kind of a build is... Name your build log file according to the build type, check the logfile name each time you build, and clean if needed (if name differs from current option).Code:BUILD ?= release # default build option CFLAGS = flags common to all builds ifeq("$(BUILD)","release") CFLAGS += whatever cflags you want to use for release endif ifeq("$(BUILD)","debug") CFLAGS += whatever cflags you want to use for debug endif ifeq("$(BUILD)","supergoofy") CFLAGS += some super goofy flags endif
It works, but forcing a clean is really painful. Just because you are flipping between debug and release (for instance, tracking down bugs, then profiling, iteratively) shouldn't require you to rebuild the entire project every time. The problem is that most simple makefile systems place the generated targets in the same directory as the source code, making it impossible to keep multiple builds around simultaneously.
Again, it's POSSIBLE to do all this with make, but it feels like forcing the tool to do something it's not really meant to do. I long ago switched to Boost.Build and never looked back
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
there is also an alternative with recent versions of (gnu?)make by updating the flags according to the current rule:
CFLAGS=<flags>
debug: CFLAGS+=<debug flags>
debug: all
all: ...
then $ make debug
it doesn't solve the issues raised in the last post though.
I think the best option to solve the overhead of switching between release/debug build etc is to take a leaf out of the Linux kernel build system. Write the Makefiles in such a way that all .o, .a, .so or whatever output files which get created are put in different directories. A general convention is to use a directory tree similar to the source tree, and change the parent directory only.