Re: Query: How can I set precompiler macro values from the 'make' command line?

From: Gianni Mariani (gi2nospam_at_mariani.ws)
Date: 11/29/04


Date: Mon, 29 Nov 2004 09:17:44 -0800

Tropos wrote:
> I have a _TEST_ flag that I want to sometimes set for compilation,
> e.g.
>
> #if _TEST_
> #include "MyTestInterface.h"
> #else
> #include "MyRealInterface.h"
> #endif
>
> But I am in a version-controlled environment where there is a time
> penalty for checking out/checking in the source file or makefile. So I don't
> want to use
>
> #define _TEST_
>
> in my code, because then I have to edit the code to do a non-test build.
>
> Is there any way I can say something on the command line like
>
> make -D_TEST_=1
>
> to set the value of _TEST_ for a single build?
>
> (My environment is SunOS, using the native Sun compiler and make.)

if you run tcsh :

( setenv CPPFLAGS '-DXX=1' ; make xx )

if you run bash or ksh

CPPFLAGS='-DXX=1' make xx

- this assumes your Makefile compile rules use the CPPFLAGS variable



Relevant Pages