2020-12-14 15:21:17 +00:00
|
|
|
TARGET = firmware
|
|
|
|
|
|
|
|
DEBUG = 1
|
|
|
|
OPT = -O0
|
|
|
|
|
2022-12-15 09:18:35 +00:00
|
|
|
BUILD_DIR = build
|
2020-12-14 15:21:17 +00:00
|
|
|
|
2022-12-15 09:18:35 +00:00
|
|
|
SRC_DIRS := $(shell find src -type d)
|
|
|
|
CC_SOURCES = $(foreach folder, $(SRC_DIRS), $(wildcard $(folder)/*.cc))
|
|
|
|
C_SOURCES = $(foreach folder, $(SRC_DIRS), $(wildcard $(folder)/*.c))
|
|
|
|
ASM_SOURCES = $(foreach folder, $(SRC_DIRS), $(wildcard $(folder)/*.s))
|
2020-12-14 15:21:17 +00:00
|
|
|
|
|
|
|
PREFIX = arm-none-eabi-
|
|
|
|
CC = $(PREFIX)gcc
|
2020-12-16 15:13:37 +00:00
|
|
|
CXX = $(PREFIX)g++
|
2020-12-14 15:21:17 +00:00
|
|
|
AS = $(PREFIX)gcc -x assembler-with-cpp
|
|
|
|
CP = $(PREFIX)objcopy
|
|
|
|
SZ = $(PREFIX)size
|
|
|
|
|
|
|
|
HEX = $(CP) -O ihex
|
|
|
|
BIN = $(CP) -O binary -S
|
|
|
|
|
|
|
|
CPU = -mcpu=cortex-m0plus
|
|
|
|
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
|
|
|
|
|
2021-05-28 09:06:00 +00:00
|
|
|
C_DEFS = -DSTM32G031xx
|
2022-12-15 09:18:35 +00:00
|
|
|
LDSCRIPT = src/platform/stm32g0xx/STM32G031Y8YX_FLASH.ld
|
2020-12-14 15:21:17 +00:00
|
|
|
|
|
|
|
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
|
2022-12-15 09:18:35 +00:00
|
|
|
CFLAGS = $(MCU) $(C_DEFS) $(addprefix -I,$(SRC_DIRS)) $(OPT) -Wall -fdata-sections -ffunction-sections
|
2020-12-14 15:21:17 +00:00
|
|
|
|
|
|
|
ifeq ($(DEBUG), 1)
|
|
|
|
CFLAGS += -ggdb3
|
|
|
|
endif
|
|
|
|
|
|
|
|
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
|
|
|
|
|
|
|
|
LIBS = -lc -lm -lnosys
|
|
|
|
LIBDIR =
|
|
|
|
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
|
|
|
|
|
|
|
|
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
|
|
|
|
|
2020-12-16 15:13:37 +00:00
|
|
|
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(CC_SOURCES:.cc=.o)))
|
|
|
|
vpath %.cc $(sort $(dir $(CC_SOURCES)))
|
|
|
|
|
|
|
|
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
|
2020-12-14 15:21:17 +00:00
|
|
|
vpath %.c $(sort $(dir $(C_SOURCES)))
|
|
|
|
|
|
|
|
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
|
|
|
|
vpath %.s $(sort $(dir $(ASM_SOURCES)))
|
|
|
|
|
2020-12-16 15:13:37 +00:00
|
|
|
$(BUILD_DIR)/%.o: %.cc Makefile | $(BUILD_DIR)
|
|
|
|
$(CXX) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.cc=.lst)) $< -o $@
|
|
|
|
|
2020-12-14 15:21:17 +00:00
|
|
|
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
|
|
|
|
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
|
|
|
|
|
|
|
|
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
|
|
|
|
$(AS) -c $(CFLAGS) $< -o $@
|
|
|
|
|
2021-05-28 09:06:00 +00:00
|
|
|
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) | Makefile
|
2020-12-16 15:13:37 +00:00
|
|
|
$(CXX) $(OBJECTS) $(LDFLAGS) -o $@
|
2020-12-14 15:21:17 +00:00
|
|
|
$(SZ) $@
|
|
|
|
|
|
|
|
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
|
|
|
|
$(HEX) $< $@
|
|
|
|
|
|
|
|
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
|
|
|
|
$(BIN) $< $@
|
|
|
|
|
|
|
|
$(BUILD_DIR):
|
|
|
|
mkdir $@
|
|
|
|
|
|
|
|
clean:
|
|
|
|
-rm -fR $(BUILD_DIR)
|
|
|
|
|
|
|
|
-include $(wildcard $(BUILD_DIR)/*.d)
|