2022-05-15 15:47:12 +02:00
|
|
|
TOOLCHAIN = arm-none-eabi-
|
2021-09-25 20:00:36 +02:00
|
|
|
CC = $(TOOLCHAIN)gcc
|
2021-12-10 17:36:30 +01:00
|
|
|
CXX = $(TOOLCHAIN)g++
|
2021-09-25 20:00:36 +02:00
|
|
|
OBJCOPY = $(TOOLCHAIN)objcopy
|
2021-11-16 22:37:48 +01:00
|
|
|
OBJDUMP = $(TOOLCHAIN)objdump
|
2021-09-25 20:00:36 +02:00
|
|
|
SIZE = $(TOOLCHAIN)size
|
|
|
|
|
2022-05-15 15:47:12 +02:00
|
|
|
FLAGS = -mcpu=cortex-m0plus -mthumb -DSTM32G030xx $(USER_FLAGS) -g -ggdb3
|
|
|
|
CFLAGS = -Og -Wall -ffunction-sections -fdata-sections -ffreestanding -MMD -MP -I./lib
|
2021-09-25 20:00:36 +02:00
|
|
|
LDFLAGS = -nostartfiles -Wl,--gc-sections
|
|
|
|
|
|
|
|
SRC_DIR = src
|
2021-11-16 22:37:48 +01:00
|
|
|
|
|
|
|
SRCS = $(addprefix $(SRC_DIR)/, $(SRC_FILES))
|
|
|
|
OBJS = $(addprefix $(BUILD_DIR)/, $(notdir $(patsubst %,%.o,$(SRCS))))
|
2021-09-25 20:00:36 +02:00
|
|
|
DEPS = $(OBJS:.o=.d)
|
|
|
|
|
|
|
|
VPATH = $(SRC_DIR)
|
|
|
|
|
|
|
|
$(@info $(shell mkdir -p ./$(BUILD_DIR) &> /dev/null))
|
|
|
|
|
2021-12-10 17:36:30 +01:00
|
|
|
$(BUILD_DIR)/%.S.o: %.S
|
|
|
|
$(CC) -x assembler-with-cpp $(FLAGS) $(CFLAGS) -c $< -o $@
|
2021-09-25 20:00:36 +02:00
|
|
|
|
2021-11-16 22:37:48 +01:00
|
|
|
$(BUILD_DIR)/%.c.o: %.c
|
2021-12-10 17:36:30 +01:00
|
|
|
$(CC) $(FLAGS) $(CFLAGS) -c $< -o $@
|
2021-09-25 20:00:36 +02:00
|
|
|
|
2022-08-03 08:53:30 +02:00
|
|
|
$(BUILD_DIR)/$(EXE_NAME).elf: $(OBJS) $(LD_SCRIPT)
|
|
|
|
$(CXX) $(FLAGS) $(LDFLAGS) -T$(LD_SCRIPT) $(OBJS) -o $@
|
|
|
|
@$(OBJDUMP) -S -D $@ > $(BUILD_DIR)/$(EXE_NAME).lst
|
2021-12-10 17:36:30 +01:00
|
|
|
|
2022-08-03 08:53:30 +02:00
|
|
|
$(BUILD_DIR)/$(EXE_NAME).bin: $(BUILD_DIR)/$(EXE_NAME).elf
|
2022-08-18 23:12:04 +02:00
|
|
|
$(OBJCOPY) -O binary --gap-fill 0xFF --pad-to $(PAD_TO) $< $@
|
2021-09-25 20:00:36 +02:00
|
|
|
|
2022-08-03 08:53:30 +02:00
|
|
|
$(BUILD_DIR)/$(EXE_NAME).hex: $(BUILD_DIR)/$(EXE_NAME).bin
|
2021-12-10 17:36:30 +01:00
|
|
|
@$(OBJCOPY) -I binary -O ihex $< $@
|
|
|
|
|
2022-08-03 08:53:30 +02:00
|
|
|
print_size: $(BUILD_DIR)/$(EXE_NAME).elf
|
2021-11-16 22:37:48 +01:00
|
|
|
@echo 'Size of modules:'
|
2021-12-10 17:36:30 +01:00
|
|
|
@$(SIZE) -B -d -t --common $(OBJS)
|
2022-08-03 08:53:30 +02:00
|
|
|
@echo 'Size of $(EXE_NAME):'
|
2021-12-10 17:36:30 +01:00
|
|
|
@$(SIZE) -B -d $<
|
|
|
|
|
2022-08-03 08:53:30 +02:00
|
|
|
all: $(BUILD_DIR)/$(EXE_NAME).hex print_size
|
2021-09-25 20:00:36 +02:00
|
|
|
|
|
|
|
clean:
|
2021-12-10 17:36:30 +01:00
|
|
|
@rm -rf ./$(BUILD_DIR)/*
|
2021-09-25 20:00:36 +02:00
|
|
|
|
2021-12-10 17:36:30 +01:00
|
|
|
.PHONY: all clean print_size
|
2021-09-25 20:00:36 +02:00
|
|
|
|
|
|
|
-include $(DEPS)
|