help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Two executables


From: John Graham-Cumming
Subject: Re: Two executables
Date: Wed, 18 May 2005 09:58:38 -0400

On Mon, 2005-05-16 at 23:28 -0400, address@hidden wrote: 
> BUILD_A_EXECUTABLE = mw_A_exec
> BUILD_B_EXECUTABLE = mw_B_exec
> 
> all :
>         $(MAKE) build_a build_b
> 
> build_a : $(DIRS)
>         $(MAKE) $(BUILD_A_EXECUTABLE)
> 
> build_b : $(DIRS)
>         $(MAKE) $(BUILD_B_EXECUTABLE)
> 
> ...
> 
> ############## BUILD A ##############
> ifeq ($(MW_TYPE_A),1)
> 
> CPPFLAGS = -g -Wall $(INCLS) \
>          -DDtHLA=1 -DRTI_USES_STD_FSTREAM
> else ########## BUILD B ##############
> 
> CPPFLAGS = -g -Wall $(INCLS) \
>          -DDtDIS=1
> endif
> 
> How can I define MW_TYPE_A = 1 only when I'm creating BUILD_A_EXECUTABLE
> and not when I'm building BUILD_B_EXECUTABLE?

Couple of comments.  Your top level Makefile seems to be more complex
than necessary.  Why do you do $(MAKE) build_a build_b in the all rule?
I think this is simpler:

.PHONY: all build_a build_b
all: build_a build_b

build_a: $(DIRS) ; $(MAKE) $(BUILD_A_EXECUTABLE)
build_b: $(DIRS) ; $(MAKE) $(BUILD_B_EXECUTABLE)

To answer your question you can define variables on the Make command-
line and hence you could do:

.PHONY: all build_a build_b
all: build_a build_b

build_a: $(DIRS) ; $(MAKE) $(BUILD_A_EXECUTABLE) MW_TYPE_A=1
build_b: $(DIRS) ; $(MAKE) $(BUILD_B_EXECUTABLE) MW_TYPE_A=0

But I think you can do even better than that.  All you are trying to do
is set CPPFLAGS differently for the different build_a and build_b
targets (and their prereqs).

Assuming that $(BUILD_A_EXECUTABLE) is the name of a target in the top-
level Makefile (and similarly for $(BUILD_B_EXECUTABLE)) you could do
this:

.PHONY: all build_a build_b
all: build_a build_b

build_a: $(DIRS) ; $(MAKE) $(BUILD_A_EXECUTABLE) MW_TYPE_A=1
build_b: $(DIRS) ; $(MAKE) $(BUILD_B_EXECUTABLE) MW_TYPE_A=0

build_a: CPPFLAGS = -g -Wall $(INCLS) -DDtHLA=1 -DRTI_USES_STD_FSTREAM
build_b: CPPFLAGS = -g -Wall $(INCLS) -DDtDIS=1

CPPFLAGS will be redefined for build_a (or build_b) and all its
prerequisites (which will include any invocations of the C compiler).
You should read a little more about "Target-specific variables" in the
GNU Make manual to understand this better.

John.
-- 
John Graham-Cumming

Home: http://www.jgc.org/
Work: http://www.electric-cloud.com/
POPFile: http://getpopfile.org/
GNU Make Standard Library: http://gmsl.sf.net/






reply via email to

[Prev in Thread] Current Thread [Next in Thread]