[NTLUG:Discuss] makefile guidance..
kbrannen@gte.net
kbrannen at gte.net
Tue Apr 24 23:10:21 CDT 2001
You can solve the problem multiple ways. George's solution is one.
Another is define a var just for the debug flag (e.g. CCOPT = -g), and
reference that in $(CFLAGS), which would normally make it compile in debug
mode. Then if you want optimized, or nothing, use the command line to
override that; e.g.:
make CCOPT=-O2
or
make CCOPT=
Another common way is to reference $(CCOPT) in $(CFLAGS), but don't define it
in your makefile. Instead, require it in the builder's environment; make will
automatically pick up the env. var. If you're using GNU make, you could even
put an "if" statement in your makefile checking that it was defined, and if
not abort (or set CC=exit which would cause an abort, or my favorite is to
make the first dependency of "all" be a target which does the check, and if
the check fails, "exit 1" which will cause the make to abort).
Last but not least is have the makefile normally make the objects with no -g,
because CCOPT is blank. Then create a new target called "alldebug" which
would look something like:
alldebug:
make CCOPT=-g all
There may be other ways, but that's all that comes to mind at the moment. You
should be able to reverse the normal way and the override if desired for any
of the methods. Of the 4 solutions, I prefer #3 or #4, but there is no
techical advantage to any of them that I know of, just personal preference and
how much you like to type.
HTH,
Kevin
"George E. Lass" wrote:
>
> I *think* you can just pass the compiler into the makefile:
>
> make CC=gcc -g -Wall (and don't forget -Werror)
>
> --or--
>
> make CC=g++ -g .......
>
> This *should* override the the CC= whatever that is contained in the
> makefile itself. Is this what you want to do?
>
> george
>
> don wrote:
> >
> > Any one have any insight of how to structure a makefile to produce a
> > non-debug executable and a debug executable ? I could do this in a
> > brute force option, but I was wondering if anyone has any tricks up
> > his/her sleeve they'd like to share. Using -d on the command line
> > isn't really an option due to the size and existing setup of the project.
> >
> > Currently, we have to do "make tgt=xxx all" to build all the
> > executables. I'd like to modify it so that the target "all" is
> > unchanged, and add a "alldebug" and "allnodebug" option. We currently
> > have to define the compilers as such :
> >
> > $CC = gcc -g -Wall ...
> > $CXX = g++ -g -Wall....
> >
> > and cannot change this either.
> >
> > Any suggestions ? I have a few ideas, but would be interested in what
> > y'all have to say.
> >
> > Thanks in advance,
> > Don
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
More information about the Discuss
mailing list