Change build output dir structure and filenames

This commit is contained in:
George Oikonomou 2018-10-13 23:14:51 +01:00
parent ab5d5ba33c
commit f8ea68c3eb
4 changed files with 33 additions and 23 deletions

View File

@ -13,8 +13,6 @@ include $(CONTIKI)/Makefile.identify-target
### Include Makefile.tools to pull in targets that allow us to build tools dir
include $(CONTIKI)/Makefile.tools
CONTIKI_NG_TARGET_LIB = contiki-ng-$(TARGET).a
ifeq ($(DEFINES),)
-include Makefile.$(TARGET).defines
ifneq ($(DEFINES),)
@ -39,7 +37,12 @@ ifdef CI
endif
endif
OBJECTDIR = obj_$(TARGET)
BUILD_DIR = build
BUILD_DIR_TARGET = $(BUILD_DIR)/$(TARGET)
BUILD_DIR_BOARD = $(BUILD_DIR_TARGET)/$(BOARD)
OBJECTDIR = $(BUILD_DIR_BOARD)/obj
CONTIKI_NG_TARGET_LIB = $(BUILD_DIR_BOARD)/contiki-ng-$(TARGET).a
LOWERCASE = -abcdefghijklmnopqrstuvwxyz/
UPPERCASE = _ABCDEFGHIJKLMNOPQRSTUVWXYZ_
@ -75,11 +78,6 @@ endef
CONTIKI_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CONTIKI_SOURCEFILES)}}
PROJECT_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(PROJECT_SOURCEFILES)}}
# Provide way to create $(OBJECTDIR) if it has been removed by make clean
$(OBJECTDIR):
$(TRACE_MKDIR)
$(Q)mkdir $@
uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
### Include target makefile (TODO Unsafe?)
@ -125,6 +123,11 @@ endif # $(BOARD) not empty
PLATFORM_ACTION ?= build
# Provide way to create $(OBJECTDIR) if it has been removed by make clean
$(OBJECTDIR):
$(TRACE_MKDIR)
$(Q)mkdir -p $@
ifneq ($(BOARD),)
TARGET_BOARD_UPPERCASE := ${strip ${shell echo $(BOARD) | sed y!$(LOWERCASE)!$(UPPERCASE)!}}
CFLAGS += -DCONTIKI_BOARD_$(TARGET_BOARD_UPPERCASE)=1
@ -312,14 +315,13 @@ endef
### Harmonize filename of a .map file, if the platform's build system wants
### to create one
CONTIKI_NG_PROJECT_MAP = $(addsuffix -$(TARGET).map, $(basename $@))
CONTIKI_NG_PROJECT_MAP = $(BUILD_DIR_BOARD)/$(basename $(notdir $@)).map
.PHONY: clean distclean usage help targets boards savetarget savedefines viewconf
clean:
-$(Q)rm -f *.d *.e *.o $(CONTIKI_NG_TARGET_LIB) $(CLEAN)
-$(Q)rm -rf $(OBJECTDIR)
-$(Q)rm -f $(addsuffix -$(TARGET).map, $(CONTIKI_PROJECT))
-$(Q)rm -f *.d *.e *.o $(CLEAN)
-$(Q)rm -rf $(BUILD_DIR_TARGET)
-$(Q)rm -f $(addsuffix .$(TARGET), $(CONTIKI_PROJECT))
@echo Target $(TARGET) cleaned
@ -328,6 +330,7 @@ distclean:
echo Running: $(MAKE) TARGET=$$TARG clean; \
$(MAKE) TARGET=$$TARG clean; \
done
rmdir $(BUILD_DIR)
-include $(CONTIKI)/arch/platform/$(TARGET)/Makefile.customrules-$(TARGET)

View File

@ -51,27 +51,32 @@ endif
### CPU-dependent cleanup files
CLEAN += *.elf *.bin *.lst *.hex *.i16hex
### Don't treat the following files as intermediate
.PRECIOUS: %.elf %.hex %.bin
OUT_HEX = $(BUILD_DIR_BOARD)/%.hex
OUT_I16HEX = $(BUILD_DIR_BOARD)/%.i16hex
OUT_BIN = $(BUILD_DIR_BOARD)/%.bin
OUT_LST = $(BUILD_DIR_BOARD)/%.lst
%.i16hex: %.elf
### Don't treat the following files as intermediate
.PRECIOUS: $(OUT_ELF) $(OUT_HEX) $(OUT_BIN)
$(OUT_I16HEX): $(OUT_ELF)
$(TRACE_OBJCOPY)
$(Q)$(OBJCOPY) -O ihex $< $@
%.hex: %.i16hex
$(OUT_HEX): $(OUT_I16HEX)
$(TRACE_SREC_CAT)
$(Q)$(SREC_CAT) $< -intel -o $@ -intel
%.bin: %.elf
$(OUT_BIN): $(OUT_ELF)
$(TRACE_OBJCOPY)
$(Q)$(OBJCOPY) -O binary $(OBJCOPY_FLAGS) $< $@
%.lst: %.elf
$(OUT_LST): $(OUT_ELF)
$(TRACE_OBJDUMP)
$(Q)$(OBJDUMP) $(OBJDUMP_FLAGS) $< > $@
### We don't really need the .hex and .bin for the .$(TARGET) but let's make
### sure they get built
%.$(TARGET): %.elf %.hex %.bin
%.$(TARGET): $(OUT_ELF) $(OUT_HEX) $(OUT_BIN)
$(TRACE_CP)
$(Q)cp $< $@

View File

@ -17,9 +17,11 @@ TARGET_LIBFLAGS := -Wl,--start-group $(TARGET_LIBFILES) -Wl,--end-group
CUSTOM_RULE_LINK = 1
OUT_ELF = $(BUILD_DIR_BOARD)/%.elf
.SECONDEXPANSION:
%.elf: $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(LDSCRIPT) $(TARGET_LIBS)
$(OUT_ELF): $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(LDSCRIPT) $(TARGET_LIBS)
$(TRACE_LD)
$(Q)$(LD) $(LDFLAGS) ${filter-out $(LDSCRIPT) %.a,$^} ${filter %.a,$^} $(TARGET_LIBFLAGS) -o $@

View File

@ -172,11 +172,11 @@ vpath %.s $(ASM_PATHS)
OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)
CLEAN += nrf52832.a
NRFLIB = $(BUILD_DIR_BOARD)/nrf52832.a
TARGET_LIBS = nrf52832.a $(NRF52_SDK_ROOT)/components/iot/ble_6lowpan/lib/ble_6lowpan.a
TARGET_LIBS = $(NRFLIB) $(NRF52_SDK_ROOT)/components/iot/ble_6lowpan/lib/ble_6lowpan.a
nrf52832.a: $(OBJECTS)
$(NRFLIB): $(OBJECTS)
$(TRACE_AR)
$(Q)$(AR) $(AROPTS) $@ $^