inverse_thermal_camera/makefile

129 lines
4.4 KiB
Makefile
Raw Permalink Normal View History

2018-07-29 18:24:52 +02:00
PROJECT = main
SOURCE_DIRS = src
ADDITIONAL_SOURCES =
2019-11-14 13:27:19 +01:00
INCLUDE_DIRS = third_party/core third_party/device
2018-07-29 18:24:52 +02:00
EXCLUDE_SOURCES =
BUILD_DIR = build
DEBUG := yes
H_DEVICE = STM32F103xB
2019-11-14 13:27:19 +01:00
STARTUP_SOURCE_DIR = src
STARTUP_SOURCES = $(STARTUP_SOURCE_DIR)/startup.S
LD_SCRIPT = ld/stm32f103c8t6_flash.ld
2018-07-29 18:24:52 +02:00
ifeq ($(DEBUG),yes)
DEBUG_FLAGS = -DDEBUG -g3
endif
2019-11-14 13:27:19 +01:00
ifneq ($(V),1)
Q = @
endif
2018-07-29 18:24:52 +02:00
CFLAGS = -mcpu=cortex-m3 -mthumb \
-Os -fno-common -Werror \
2019-11-14 13:27:19 +01:00
-nostartfiles \
-Wall -Xlinker --gc-sections \
2018-07-29 18:24:52 +02:00
-D$(H_DEVICE) -D_DEFAULT_SOURCE -T$(LD_SCRIPT) \
-Wl,-Map=$(BUILD_DIR)/$(PROJECT).map -std=c99 \
$(addprefix -I,$(SOURCE_DIRS) $(INCLUDE_DIRS)) $(DEBUG_FLAGS)
RM = rm -f
CC = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
SIZE = arm-none-eabi-size
OBJDUMP = arm-none-eabi-objdump
BUILD_NUMBER_FILE = build-number.txt
BUILD_ID_FLAGS = -Xlinker --defsym -Xlinker __BUILD_DATE=$$(date +'%Y%m%d') \
-Xlinker --defsym -Xlinker __BUILD_NUMBER=$$(cat $(BUILD_NUMBER_FILE))
2019-11-14 13:27:19 +01:00
CURRENT_BUILD_CONFIG := $(shell cat makefile | md5sum) DEBUG = $(DEBUG)
2018-07-29 18:24:52 +02:00
LAST_BUILD_CONFIG := $(shell if [ -e $(BUILD_DIR)/build-config.txt ] ; then cat $(BUILD_DIR)/build-config.txt ; fi)
SOURCES = $(filter-out $(addprefix %/,$(EXCLUDE_SOURCES)),$(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.c))) \
$(ADDITIONAL_SOURCES)
OBJECTS = $(addprefix $(BUILD_DIR)/,$(addsuffix .o,$(basename $(notdir $(SOURCES)))))
DEPENDS = $(addprefix $(BUILD_DIR)/,$(addsuffix .d,$(basename $(notdir $(SOURCES)))))
2019-11-14 13:27:19 +01:00
STARTUP_OBJECTS = $(patsubst $(STARTUP_SOURCE_DIR)/%.S, $(BUILD_DIR)/%.o, $(STARTUP_SOURCES))
2018-07-29 18:24:52 +02:00
.DEFAULT_GOAL = all
.DELETE_ON_ERROR:
define define_compile_rules
$(addprefix $(BUILD_DIR)/,$(addsuffix .o,$(basename $(filter-out $(EXCLUDE_SOURCES),$(notdir $(wildcard $(1)/*.c)))))): $(BUILD_DIR)/%.o: $(1)/%.c
@echo " CC $$@"
2019-11-14 13:27:19 +01:00
$(Q)$$(CC) $$(CFLAGS) -o $$@ -c $$<
2018-07-29 18:24:52 +02:00
$(addprefix $(BUILD_DIR)/,$(addsuffix .d,$(basename $(filter-out $(EXCLUDE_SOURCES),$(notdir $(wildcard $(1)/*.c)))))): $(BUILD_DIR)/%.d: $(1)/%.c
@#echo " DP $$@"
2019-11-14 13:27:19 +01:00
$(Q)set -e; rm -f $$@; $$(CC) -MM $$(CFLAGS) $$< > $$@.$$$$$$$$; sed 's,\($$*\)\.o[ :]*,build\/\1.o $$@ : ,g' < $$@.$$$$$$$$ > $$@; rm -f $$@.$$$$$$$$
2018-07-29 18:24:52 +02:00
endef
$(foreach directory,$(SOURCE_DIRS),$(eval $(call define_compile_rules,$(directory))))
# Additional sources
define define_compile_rule
$(addprefix $(BUILD_DIR)/,$(notdir $(1:.c=.o))): $(1)
@echo " CC $$@"
2019-11-14 13:27:19 +01:00
$(Q)$$(CC) $$(CFLAGS) -o $$@ -c $$<
2018-07-29 18:24:52 +02:00
$(addprefix $(BUILD_DIR)/,$(notdir $(1:.c=.d))): $(1)
@#echo " DP $$@"
2019-11-14 13:27:19 +01:00
$(Q)set -e; rm -f $$@; $$(CC) -MM $$(CFLAGS) $$< > $$@.$$$$$$$$; sed 's,\($$*\)\.o[ :]*,build\/\1.o $$@ : ,g' < $$@.$$$$$$$$ > $$@; rm -f $$@.$$$$$$$$
2018-07-29 18:24:52 +02:00
endef
$(foreach src,$(ADDITIONAL_SOURCES),$(eval $(call define_compile_rule,$(src))))
2019-11-14 13:27:19 +01:00
$(STARTUP_OBJECTS): $(BUILD_DIR)/%.o: $(STARTUP_SOURCE_DIR)/%.S
2018-07-29 18:24:52 +02:00
@echo " AS $@"
2019-11-14 13:27:19 +01:00
$(Q)$(CC) $< -c -o $@ $(CFLAGS)
2018-07-29 18:24:52 +02:00
$(DEPENDS):| $(BUILD_DIR)
include $(DEPENDS)
$(BUILD_DIR)/$(PROJECT).elf: $(OBJECTS) $(STARTUP_OBJECTS) $(BUILD_NUMBER_FILE)
@echo " LD $@"
2019-11-14 13:27:19 +01:00
$(Q)$(CC) $(OBJECTS) $(STARTUP_OBJECTS) $(CFLAGS) $(BUILD_ID_FLAGS) -o $@
2018-07-29 18:24:52 +02:00
$(BUILD_DIR)/$(PROJECT).bin: $(BUILD_DIR)/$(PROJECT).elf
@echo " OC $@"
2019-11-14 13:27:19 +01:00
$(Q)$(OBJCOPY) -O binary -S $< $@
2018-07-29 18:24:52 +02:00
$(BUILD_DIR)/$(PROJECT).lst: $(BUILD_DIR)/$(PROJECT).elf
@echo " OD $@"
2019-11-14 13:27:19 +01:00
$(Q)$(OBJDUMP) -h -S $< > $@
2018-07-29 18:24:52 +02:00
$(BUILD_DIR):
2019-11-14 13:27:19 +01:00
$(Q)if [ ! -d "$(BUILD_DIR)" ]; then mkdir "$(BUILD_DIR)"; fi
2018-07-29 18:24:52 +02:00
$(BUILD_NUMBER_FILE): $(OBJECTS) $(STARTUP_OBJECTS)
2019-11-14 13:27:19 +01:00
$(Q)if ! test -f $(BUILD_NUMBER_FILE); then echo 0 > $(BUILD_NUMBER_FILE); \
else echo $$(($$(cat $(BUILD_NUMBER_FILE)) + 1)) > $(BUILD_NUMBER_FILE) ; fi
2018-07-29 18:24:52 +02:00
# Rebuild everything in case of a makefile/configuration change
.PHONY: all
ifneq ("$(CURRENT_BUILD_CONFIG)","$(LAST_BUILD_CONFIG)")
all: clean incrementalbuild
else
all: incrementalbuild
endif
.PHONY: incrementalbuild
incrementalbuild: $(BUILD_DIR) $(OBJECTS) $(STARTUP_OBJECTS) $(BUILD_DIR)/$(PROJECT).elf $(BUILD_DIR)/$(PROJECT).bin $(BUILD_DIR)/$(PROJECT).lst
2019-11-14 13:27:19 +01:00
@echo "Finished build $$(cat $(BUILD_NUMBER_FILE)). Binary size:"
2018-07-29 18:24:52 +02:00
@echo " SZ $(BUILD_DIR)/$(PROJECT).elf"
2019-11-14 13:27:19 +01:00
$(Q)$(SIZE) $(BUILD_DIR)/$(PROJECT).elf
2018-07-29 18:24:52 +02:00
@echo "$(CURRENT_BUILD_CONFIG)" > $(BUILD_DIR)/build-config.txt
.PHONY: program
program: $(BUILD_DIR)/$(PROJECT).bin
@#if ps -e | grep openocd ; then arm-none-eabi-gdb -batch -x flash.gdb ; else st-flash --reset write $(BUILD_DIR)/$(PROJECT).bin 0x8000000 ; fi
st-flash --reset write $(BUILD_DIR)/$(PROJECT).bin 0x8000000
.PHONY: clean
clean:
@echo " RM $(BUILD_DIR)/*"
2019-11-14 13:27:19 +01:00
$(Q)$(RM) $(BUILD_DIR)/*