Makefile: Add differnet targets for debug and release builds

This commit is contained in:
Mario Hüttel 2020-06-15 21:22:05 +02:00
parent 137e846cf2
commit 56439a3b13

View File

@ -7,8 +7,8 @@ CFILES = main.c syscalls.c setup/system_stm32f4xx.c systick.c
ASFILES = boot/startup_stm32f4xx.S ASFILES = boot/startup_stm32f4xx.S
INCLUDEPATH = -Iinclude INCLUDEPATH = -Iinclude
OBJDIR = obj OBJDIR_BASE = obj
target = reflow-controller TARGET_BASE = reflow-controller
LIBRARYPATH = -L. -Lmathlib LIBRARYPATH = -L. -Lmathlib
LIBRARIES = -larm_cortexM4lf_math -lm LIBRARIES = -larm_cortexM4lf_math -lm
@ -48,30 +48,62 @@ CFILES += pid-controller.c oven-driver.c
CFILES += settings/settings.c settings/settings-sd-card.c CFILES += settings/settings.c settings/settings-sd-card.c
CFILES += safety-adc.c CFILES += safety-adc.c
DEFINES += -DDEBUGBUILD DEBUG_DEFINES = -DDEBUGBUILD
RELEASE_DEFINES =
################################################################################### ###################################################################################
CC=arm-none-eabi-gcc ifeq ($(CROSS_COMPILE),)
OBJCOPY=arm-none-eabi-objcopy CROSS_COMPILE=arm-none-eabi-
OBJDUMP=arm-none-eabi-objdump endif
SIZE=arm-none-eabi-size
CC=$(CROSS_COMPILE)gcc
OBJCOPY=$(CROSS_COMPILE)objcopy
OBJDUMP=$(CROSS_COMPILE)objdump
SIZE=$(CROSS_COMPILE)size
LFLAGS = -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork LFLAGS = -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
LFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 --disable-newlib-supplied-syscalls -nostartfiles LFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 --disable-newlib-supplied-syscalls -nostartfiles
LFLAGS += -Tstm32f407vet6_flash.ld -Wl,-Map=$(mapfile).map LFLAGS += -Tstm32f407vet6_flash.ld -Wl,-Map=$(mapfile).map
CFLAGS = -c -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork CFLAGS = -c -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostartfiles -O0 -g CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostartfiles
CFLAGS += -Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter -Wimplicit-fallthrough=3 -Wsign-compare CFLAGS += -Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter -Wimplicit-fallthrough=3 -Wsign-compare
CFLAGS_RELEASE = -O3 -g
CFLAGS_DEBUG = -O0 -g
LFLAGS_RELEASE = -Wl,--gc-sections
LFLAGS_DEBUG =
ifneq ($(DEBUGBUILD),true)
DEFINES += $(RELEASE_DEFINES)
CFLAGS += $(CFLAGS_RELEASE)
LFLAGS += $(LFLAGS_RELEASE)
target = $(TARGET_BASE)
OBJDIR = $(OBJDIR_BASE)/release
else
DEFINES += $(DEBUG_DEFINES)
target = $(TARGET_BASE)-debug
CFLAGS += $(CFLAGS_DEBUG)
LFLAGS += $(LFLAGS_DEBUG)
OBJDIR = $(OBJDIR_BASE)/debug
endif
#################################################################################### ####################################################################################
OBJ = $(CFILES:%.c=$(OBJDIR)/%.c.o) OBJ = $(CFILES:%.c=$(OBJDIR)/%.c.o)
ASOBJ += $(ASFILES:%.S=$(OBJDIR)/%.S.o) ASOBJ += $(ASFILES:%.S=$(OBJDIR)/%.S.o)
all: default
default: $(target).elf default: $(target).elf
all: debug release
release:
$(QUIET)$(MAKE) DEBUGBUILD=false
debug:
$(QUIET)$(MAKE) DEBUGBUILD=true
%.bin: %.elf %.bin: %.elf
$(QUIET)$(OBJCOPY) -O binary $^ $@ $(QUIET)$(OBJCOPY) -O binary $^ $@
%.hex: %.elf %.hex: %.elf
@ -97,7 +129,7 @@ $(ASOBJ):
$(QUIET)$(CC) $(CFLAGS) -MMD -MT $@ $(INCLUDEPATH) $(DEFINES) -o $@ $(@:$(OBJDIR)/%.S.o=%.S) $(QUIET)$(CC) $(CFLAGS) -MMD -MT $@ $(INCLUDEPATH) $(DEFINES) -o $@ $(@:$(OBJDIR)/%.S.o=%.S)
.PHONY: qtproject-legacy qtproject clean mrproper objcopy disassemble program .PHONY: qtproject-legacy qtproject qtproject-debug clean mrproper objcopy disassemble program
program: $(target).elf program: $(target).elf
./program-device.sh $< ./program-device.sh $<
@ -108,12 +140,21 @@ disassemble: $(target).elf
objcopy: $(target).bin $(target).hex objcopy: $(target).bin $(target).hex
mrproper: clean mrproper: clean
$(QUIET)rm -f $(target).pro @echo "Purging project files..."
$(QUIET)rm -f $(target).pro $(target).creator $(target).files $(target).cflags $(target).cxxflags $(target).includes $(target).config
clean: clean:
@echo "Cleaning up derived files..." @echo -n "Cleaning up derived files for "
ifneq ($(DEBUGBUILD),true)
@echo "RELEASE build"
else
@echo "DEBUG build"
endif
$(QUIET)rm -f $(target).elf $(target).bin $(target).hex $(OBJ) $(ASOBJ) $(mapfile).map $(CFILES:%.c=$(OBJDIR)/%.c.d) $(ASFILES:%.S=$(OBJDIR)/%.S.d) $(QUIET)rm -f $(target).elf $(target).bin $(target).hex $(OBJ) $(ASOBJ) $(mapfile).map $(CFILES:%.c=$(OBJDIR)/%.c.d) $(ASFILES:%.S=$(OBJDIR)/%.S.d)
$(QUIET)rm -rf $(OBJDIR)/* $(QUIET)rm -rf $(OBJDIR)/*
ifneq ($(DEBUGBUILD),true)
$(QUIET)$(MAKE) DEBUGBUILD=true clean
endif
qtproject-legacy: qtproject-legacy:
echo -e "TEMPLATE = app\nCONFIG -= console app_bundle qt" > $(target).pro echo -e "TEMPLATE = app\nCONFIG -= console app_bundle qt" > $(target).pro
@ -125,9 +166,13 @@ qtproject-legacy:
echo -ne "\nDEFINES += " >> $(target).pro echo -ne "\nDEFINES += " >> $(target).pro
echo "$(DEFINES)" | sed "s/-D//g" >> $(target).pro echo "$(DEFINES)" | sed "s/-D//g" >> $(target).pro
qtproject-debug:
@echo "Generating debug build project"
$(QUIET)$(MAKE) DEBUGBUILD=true qtproject
qtproject: qtproject:
$(QUIET)rm -f $(target).files $(target).cflags $(target).config $(target).creator $(target).includes $(target).creator.user $(QUIET)rm -f $(target).files $(target).cflags $(target).config $(target).creator $(target).includes $(target).creator.user
echo "Generating source file list" @echo "Generating source file list"
$(QUIET)echo "$(CFILES)" | tr ' ' '\n' > $(target).files $(QUIET)echo "$(CFILES)" | tr ' ' '\n' > $(target).files
@echo -n "Appending found header files from folders " @echo -n "Appending found header files from folders "
@echo `echo $(INCLUDEPATH) | sed "s/-I//g"` @echo `echo $(INCLUDEPATH) | sed "s/-I//g"`