On Mon, 2005-05-16 at 23:28 -0400, [EMAIL PROTECTED] 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/ _______________________________________________ Help-make mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-make
