help-make
[Top][All Lists]
Advanced

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

variables-as-targets driving me insane


From: Matt.Vandewerken
Subject: variables-as-targets driving me insane
Date: Fri, 1 Oct 2010 10:46:13 +1000

Hi All:

I have a problem with my Makefile, where I'm trying to change the destination 
directory of the objects/output depending on the target selected.

Here's the snippet that is giving me grief:

######## BEGIN #########

TARGET := frameMaker

SRC :=  $(TARGET).c
                
ALLPLATFORMS := osx \
                win32 \
                i386_linux \
                avr

# AVR Static library:
avrlib avrtest: PLATFORM=avr
avrlib avrtest: OPT=2
avrlib avrtest: CC=avr-gcc
avrlib avrtest: AR=avr-ar

avrtest : SRC+=avrtest.c

# OSX dynamic library:
dylib : OPT=2
dylib : PLATFORM=osx
dylib : CC=gcc

dylibtest : SRC += dylibtest.c

#Let's make a default PLATFORM:
PLATFORM ?= osx

avrlib avrtest : CFLAGS = -g -O$(OPT) -DSMALL_MEMORY_TARGET -DGCC_MEGA_AVR \
        -D__AVR__ -funsigned-char -funsigned-bitfields -fpack-struct 
-fshort-enums \
        -Wall -Wstrict-prototypes \
        $(patsubst %,-I%,$(EXTRAINCDIRS)) 

dylib : CFLAGS = -arch i386 -arch ppc -c -D__LIB__

dylib : IFLAGS = $(patsubst %,-I%,$(INCDIRS))

dylib : LFLAGS = -arch i386 -arch ppc -dynamiclib

define make-depend
        $(CC) $(IFLAGS) -MM -MF $3 -MP -MT $2 $1
endef           

OBJS = $(subst .c,.o,$(foreach src,$(SRC),../arch/$(PLATFORM)/$(src)))
                
DEPS := $(OBJS:.o=.d)

#dylib : $(OBJS) $(DEPS)
        
CFLAGS += -std=gnu99

avrlib: ../arch/$(PLATFORM)/lib$(TARGET).a
        @echo PLATFORM = $(PLATFORM)

dylib:  ../arch/$(PLATFORM)/$(TARGET)Library.dylib

../arch/$(PLATFORM)/$(TARGET)Library.dylib : $(OBJS) $(DEPS)
        $(CC) $(LFLAGS) $(OBJS)

../arch/$(PLATFORM)/%.d : %.c
        $(call make-depend,$<,$@,$(subst .c,.d,$@))
        
../arch/$(PLATFORM)/%.o : %.c
        $(CC) $(CFLAGS) -c -o $@ $<


../arch/$(PLATFORM)/lib$(TARGET).a : $(OBJS) $(DEPS)
        $(AR) -rcs $@ $<

clean :
        @echo cleaning $(ALLPLATFORMS)
        $(shell for arch in $(ALLPLATFORMS); do \
                rm -f ../arch/$$arch/*.* ; \
        done)

# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
        clean clean_list program javr avrdude dylib solib 

########### END ############

Running "make -n avrlib" results in the following:


avr-gcc -g -O2 -DSMALL_MEMORY_TARGET -DGCC_MEGA_AVR -D__AVR__ -funsigned-char 
-funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes   -c 
-o ../arch/osx/frameMaker.o frameMaker.c
avr-gcc  -MM -MF ../arch/osx/frameMaker.d -MP -MT ../arch/osx/frameMaker.d 
frameMaker.c
avr-ar -rcs ../arch/osx/libframeMaker.a ../arch/osx/frameMaker.o
echo PLATFORM = avr

So it seems that the PLATFORM variable is picked up incorrectly early on, but 
later it is correct. 

This behaviour is exhibited under both GNU Make v3.81 as shipped with OSX snow 
leapord and also GNU Make 3.81 under cygwin.

Note that the build happens correctly, just in the wrong directory. Also the 
osx platform is built in the correct directory. Another clue is that removing 
the "PLATFORM ?= osx" line results in a BLANK $(PLATFORM) for the avrlib target 
(so it seems that's where the problem lies). Finally, I have also tried other 
methods of defining a default $(PLATFORM), all to no avail.

Any help will be appreciated; this is driving me wild.

Cheers,
Matt van de Werken.



reply via email to

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