diff --git a/Makefile.include b/Makefile.include index 39ec53974..dd24fcacb 100644 --- a/Makefile.include +++ b/Makefile.include @@ -10,6 +10,8 @@ WERROR ?= 1 include $(CONTIKI)/Makefile.identify-target +CONTIKI_NG_TARGET_LIB = contiki-ng-$(TARGET).a + ifeq ($(DEFINES),) -include Makefile.$(TARGET).defines ifneq ($(DEFINES),) @@ -289,15 +291,23 @@ sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ rm -f $(@:.o=.$$$$) endef -clean: - -rm -f *~ *core core *.srec \ - *.lst *.map *.o \ - *.cprg *.bin *.data contiki*.a *.firmware core-labels.S *.ihex *.ini \ - rm -rf $(CLEAN) - -rm -rf $(OBJECTDIR) +### Harmonize filename of a .map file, if the platform's build system wants +### to create one +CONTIKI_NG_PROJECT_MAP = $(addsuffix -$(TARGET).map, $(basename $@)) -distclean: clean - -rm -f ${addsuffix .$(TARGET),$(CONTIKI_PROJECT)} +.PHONY: clean distclean usage help targets boards savetarget savedefines viewconf + +clean: + -rm -f *.d *.e *.o $(CONTIKI_NG_TARGET_LIB) $(CLEAN) + -rm -rf $(OBJECTDIR) + -rm -f $(addsuffix -$(TARGET).map, $(CONTIKI_PROJECT)) + -rm -f $(addsuffix .$(TARGET), $(CONTIKI_PROJECT)) + +distclean: + @for TARG in `ls $(CONTIKI)/arch/platform $(TARGETDIRS)`; do \ + echo make $$TARG clean; \ + make TARGET=$$TARG clean; \ + done -include $(CONTIKI)/arch/platform/$(TARGET)/Makefile.customrules-$(TARGET) @@ -352,7 +362,7 @@ ifndef AROPTS endif ifndef CUSTOM_RULE_ALLOBJS_TO_TARGETLIB -contiki-$(TARGET).a: $(CONTIKI_OBJECTFILES) +$(CONTIKI_NG_TARGET_LIB): $(CONTIKI_OBJECTFILES) $(TRACE_AR) $(Q)$(AR) $(AROPTS) $@ $^ endif @@ -362,7 +372,7 @@ ifndef LD endif ifndef CUSTOM_RULE_LINK -%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a +%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(TRACE_LD) $(Q)$(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter-out %.a,$^} \ ${filter %.a,$^} $(TARGET_LIBFILES) -o $@ @@ -375,7 +385,25 @@ endif $(NM) -S -td --size-sort $< | grep -i " [t] " | cut -d' ' -f2,4 usage: - @echo "make MAKETARGETS... [TARGET=(TARGET)] [BOARD=(BOARD)] [savetarget] [targets]" + @echo "Usage:" + @echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [DEFINES=(DEFINES)] [target]" + @echo "" + @echo "Typical usage:" + @echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [all]" + @echo "" + @echo " Will build Contiki-NG firmware(s) from the current example dir" + @echo " for platform TARGET, board BOARD." + @echo "" + @echo "Miscellaneous targets:" + @echo " targets Prints list of supported platforms" + @echo " boards Prints a list of supported boards for TARGET" + @echo " savegtarget Saves TARGET and BOARD for future invocations of make" + @echo " savedefines Saves DEFINES for future invocations of make" + @echo " clean Removes all compiled files for TARGET" + @echo " distclean Removes all compiled files for all TARGETs" + @echo " viewconf Prints Contiki-NG build configuration for TARGET" + +help: usage targets: @ls $(CONTIKI)/arch/platform $(TARGETDIRS) diff --git a/arch/cpu/arm/Makefile.arm b/arch/cpu/arm/Makefile.arm index ba93b82a0..0b2662423 100644 --- a/arch/cpu/arm/Makefile.arm +++ b/arch/cpu/arm/Makefile.arm @@ -31,7 +31,7 @@ CONTIKI_ARM_DIRS += . common/dbg-io CONTIKI_CPU_DIRS += $(addprefix ../arm/, $(CONTIKI_ARM_DIRS)) ### CPU-dependent cleanup files -CLEAN += *.d *.elf *.hex +CLEAN += *.elf *.bin *.lst *.hex *.i16hex ### Don't treat the following files as intermediate .PRECIOUS: %.elf %.hex %.bin diff --git a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 index f5547fea0..f5e8d2a3c 100644 --- a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 +++ b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 @@ -5,7 +5,7 @@ CFLAGS += -mcpu=cortex-m3 LDFLAGS += -mcpu=cortex-m3 -nostartfiles LDFLAGS += -T $(LDSCRIPT) LDFLAGS += -Wl,--gc-sections,--sort-section=alignment -LDFLAGS += -Wl,-Map=$(@:.elf=-$(TARGET).map),--cref,--no-warn-mismatch +LDFLAGS += -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP),--cref,--no-warn-mismatch OBJCOPY_FLAGS += --gap-fill 0xff diff --git a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 index 78367b0eb..1f3cdd00b 100644 --- a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 +++ b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 @@ -6,7 +6,7 @@ LDFLAGS += -mcpu=cortex-m4 ### Compilation rules CUSTOM_RULE_LINK=1 -%.elf: $(TARGET_STARTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a $(TARGET_LIBS) +%.elf: $(TARGET_STARTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(TARGET_LIBS) $(TRACE_LD) $(Q)$(CC) $(LDFLAGS) ${filter %.o %.a,$^} -o $@ diff --git a/arch/cpu/msp430/Makefile.msp430 b/arch/cpu/msp430/Makefile.msp430 index ec8c33664..841e11285 100644 --- a/arch/cpu/msp430/Makefile.msp430 +++ b/arch/cpu/msp430/Makefile.msp430 @@ -75,7 +75,7 @@ CFLAGSNO = --dlib_config "$(IAR_PATH)/LIB/DLIB/dl430xlfn.h" $(CFLAGSWERROR) # CFLAGSNO = --dlib_config $(IAR_PATH)/LIB/DLIB/dl430xlfn.h -Ohz --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40 --core=430X $(CFLAGSWERROR) --data_model large --double=32 endif -LDFLAGSNO += -B -l contiki-$(TARGET).map -s __program_start +LDFLAGSNO += -B -l $(CONTIKI_NG_PROJECT_MAP) -s __program_start # Stack and heap size in hex ifndef IAR_STACK_SIZE IAR_STACK_SIZE=300 @@ -165,7 +165,7 @@ ifndef CFLAGSNO CFLAGSNO = -Wall -mmcu=$(CC_MCU) $(CFLAGSWERROR) endif CFLAGS += -Os -fno-strict-aliasing -LDFLAGS += -mmcu=$(CC_MCU) -Wl,-Map=contiki-$(TARGET).map +LDFLAGS += -mmcu=$(CC_MCU) -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP) ### These flags can reduce the code size and RAM usage with up to 10% SMALL ?= 1 @@ -184,6 +184,9 @@ CFLAGS += $(CFLAGSNO) PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,$(CONTIKI_TARGET_MAIN:.c=.o)} +### CPU-dependent cleanup files +CLEAN += *.firmware *.ihex + ### Compilation rules %-stripped.o: %.c @@ -197,7 +200,7 @@ PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,$(CONTIKI_TARGET_MAIN:.c=.o)} mv $< $@ ifdef IAR -%.ihex: %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a +%.ihex: %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(LD) $(LDFLAGSNO) -Fintel-extended $(TARGET_STARTFILES) ${filter-out %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -o $@ else %.ihex: %.$(TARGET) @@ -220,8 +223,8 @@ $(COOJA_PATH)/mspsim/mspsim.jar: $(COOJA_PATH)/mspsim/build.xml %.mspsim: %.${TARGET} ${COOJA_PATH}/mspsim/mspsim.jar java -jar ${COOJA_PATH}/mspsim/mspsim.jar -platform=${TARGET} $< -mspsim-maptable: contiki-${TARGET}.map - java -classpath ${COOJA_PATH}/mspsim/mspsim.jar se.sics.mspsim.util.MapTable $< +%.mspsim-maptable: %.$(TARGET) + java -classpath ${COOJA_PATH}/mspsim/mspsim.jar se.sics.mspsim.util.MapTable $(CONTIKI_NG_PROJECT_MAP) core-labels.o: core.${TARGET} ${CONTIKI}/tools/msp430-make-labels core.${TARGET} > core-labels.S diff --git a/arch/cpu/native/Makefile.native b/arch/cpu/native/Makefile.native index 90a784e34..cda288e65 100644 --- a/arch/cpu/native/Makefile.native +++ b/arch/cpu/native/Makefile.native @@ -21,11 +21,11 @@ CFLAGS += $(CFLAGSNO) ifeq ($(HOST_OS),Darwin) AROPTS = -r -LDFLAGS += -Wl,-flat_namespace +LDFLAGS += -Wl,-flat_namespace,-map,$(CONTIKI_NG_PROJECT_MAP) CFLAGS += -DHAVE_SNPRINTF=1 -U__ASSERT_USE_STDERR else ifeq ($(HOST_OS),Linux) -LDFLAGS += -Wl,-Map=contiki-$(TARGET).map,-export-dynamic +LDFLAGS += -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP),-export-dynamic endif endif diff --git a/arch/cpu/nrf52832/Makefile.nrf52832 b/arch/cpu/nrf52832/Makefile.nrf52832 index 5e0db414d..3765484d8 100644 --- a/arch/cpu/nrf52832/Makefile.nrf52832 +++ b/arch/cpu/nrf52832/Makefile.nrf52832 @@ -139,7 +139,7 @@ CFLAGS += -ggdb CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 # keep every function in separate section. This will allow linker to dump unused functions -LDFLAGS += -Xlinker -Map=$(@:.elf=-$(TARGET).map) +LDFLAGS += -Xlinker -Map=$(CONTIKI_NG_PROJECT_MAP) LDFLAGS += -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT) LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 # let linker to dump unused sections @@ -182,7 +182,7 @@ nrf52832.a: $(OBJECTS) # Assemble files $(OBJECT_DIRECTORY)/%.o: %.s - @echo Compiling file: $(notdir $<) + $(TRACE_CC) $(Q)$(CC) $(ASMFLAGS) $(addprefix -I$(NRF52_SDK_ROOT)/, $(INC_PATHS)) -c -o $@ $< %.jlink: diff --git a/arch/platform/cc2538dk/Makefile.cc2538dk b/arch/platform/cc2538dk/Makefile.cc2538dk index 2b88479d2..c452ccfaf 100644 --- a/arch/platform/cc2538dk/Makefile.cc2538dk +++ b/arch/platform/cc2538dk/Makefile.cc2538dk @@ -13,8 +13,6 @@ CONTIKI_TARGET_SOURCEFILES += board-buttons.c als-sensor.c CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) -CLEAN += *.cc2538dk - ### Define the CPU directory CONTIKI_CPU=$(CONTIKI)/arch/cpu/cc2538 include $(CONTIKI_CPU)/Makefile.cc2538 diff --git a/arch/platform/cooja/Makefile.cooja b/arch/platform/cooja/Makefile.cooja index 541ae51f0..d06aa08d5 100644 --- a/arch/platform/cooja/Makefile.cooja +++ b/arch/platform/cooja/Makefile.cooja @@ -64,6 +64,8 @@ CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) .SUFFIXES: +CLEAN += COOJA.log + ### Define the CPU directory CONTIKI_CPU=$(CONTIKI)/arch/cpu/x86 diff --git a/arch/platform/jn516x/Makefile.jn516x b/arch/platform/jn516x/Makefile.jn516x index a2e7dc571..9f7a31adf 100644 --- a/arch/platform/jn516x/Makefile.jn516x +++ b/arch/platform/jn516x/Makefile.jn516x @@ -142,7 +142,6 @@ ifdef nodemac CFLAGS += -DMACID=$(nodemac) endif -CLEAN += *.jn516x CLEAN += *.jn516x.bin CONTIKI_TARGET_SOURCEFILES += $(ARCH) @@ -236,16 +235,16 @@ ABS_APPLIBS = $(addsuffix _$(JENNIC_CHIP_FAMILY).a,$(addprefix $(COMPONENTS_BASE ifneq ($(wildcard $(SDK_BASE_DIR)/Components/Library/*),) # The SDK is fully installed, proceed to linking and objcopy to ready-to-upload .jn516x.bin file -%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a $(ABS_APPLIBS) +%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(ABS_APPLIBS) echo ${filter %.a,$^} $(Q)$(CC) -Wl,--gc-sections $(LDFLAGS) -T$(LINKCMD) -o $@ -Wl,--start-group \ $(patsubst /cygdrive/c/%,c:/%,${filter-out %.a,$^}) \ $(patsubst /cygdrive/c/%,c:/%,${filter %.a,$^}) \ - $(ALLLIBS) -Wl,--end-group -Wl,-Map,contiki-$(TARGET).map + $(ALLLIBS) -Wl,--end-group -Wl,-Map,$(CONTIKI_NG_PROJECT_MAP) $(OBJCOPY) -S -O binary $@ $@.bin else # The SDK does not include libraries, only build objects and libraries, skip linking -%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a +%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) echo Creating empty $@ touch $@ endif diff --git a/arch/platform/native/Makefile.native b/arch/platform/native/Makefile.native index bee104a6c..24f433796 100644 --- a/arch/platform/native/Makefile.native +++ b/arch/platform/native/Makefile.native @@ -30,8 +30,6 @@ CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) # Enable nullmac by default MAKE_MAC ?= MAKE_MAC_NULLMAC -CLEAN += *.native - ### Define the CPU directory CONTIKI_CPU=$(CONTIKI)/arch/cpu/native include $(CONTIKI)/arch/cpu/native/Makefile.native diff --git a/arch/platform/nrf52dk/Makefile.nrf52dk b/arch/platform/nrf52dk/Makefile.nrf52dk index 6561de980..7e931880a 100644 --- a/arch/platform/nrf52dk/Makefile.nrf52dk +++ b/arch/platform/nrf52dk/Makefile.nrf52dk @@ -17,8 +17,6 @@ CONTIKI_SOURCEFILES += dbg.c MODULES += os/lib/dbg-io endif -CLEAN += *.nrf52dk - ### Unless the example dictates otherwise, build with code size optimisations switched off SMALL ?= 0 diff --git a/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 b/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 index 14aa46f78..d3863fdbc 100644 --- a/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 +++ b/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 @@ -20,8 +20,6 @@ CONTIKI_TARGET_SOURCEFILES += antenna.c adxl346.c max44009.c sht21.c tps62730.c CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) -CLEAN += *.openmote-cc2538 - ### Define the CPU directory CONTIKI_CPU=$(CONTIKI)/arch/cpu/cc2538 include $(CONTIKI_CPU)/Makefile.cc2538 diff --git a/arch/platform/sky/Makefile.sky b/arch/platform/sky/Makefile.sky index 9467603a4..0398486b0 100644 --- a/arch/platform/sky/Makefile.sky +++ b/arch/platform/sky/Makefile.sky @@ -4,8 +4,6 @@ CONTIKI_TARGET_SOURCEFILES += contiki-sky-platform.c \ sht11.c sht11-sensor.c light-sensor.c battery-sensor.c \ button-sensor.c -CLEAN += *.sky - include $(CONTIKI)/arch/platform/sky/Makefile.common MODULES += arch/dev/cc2420 arch/dev/sht11 arch/dev/ds2411 os/storage/cfs diff --git a/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx b/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx index 7bead9fff..db4209adc 100644 --- a/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx +++ b/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx @@ -19,8 +19,6 @@ CONTIKI_TARGET_SOURCEFILES += $(BOARD_SOURCEFILES) CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) -CLEAN += *.srf06-cc26xx - ### Unless the example dictates otherwise, build without code size optimisations SMALL ?= 0 diff --git a/arch/platform/zoul/Makefile.zoul b/arch/platform/zoul/Makefile.zoul index 6bbcd675b..586a74ae2 100644 --- a/arch/platform/zoul/Makefile.zoul +++ b/arch/platform/zoul/Makefile.zoul @@ -38,8 +38,6 @@ CONTIKI_TARGET_SOURCEFILES += $(BOARD_SOURCEFILES) CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) -CLEAN += *.zoul - ### Define the CPU directory CONTIKI_CPU=$(CONTIKI)/arch/cpu/cc2538 include $(CONTIKI_CPU)/Makefile.cc2538