From de32bd245c7b2d3911e7a0bbb4ebcb9c16539abd Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Thu, 23 Apr 2026 20:13:06 +0200 Subject: [PATCH] parallel compilation with redefined make rules --- fw/.gitignore | 2 ++ fw/Makefile | 31 +++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/fw/.gitignore b/fw/.gitignore index 567b1e0..c7a9452 100644 --- a/fw/.gitignore +++ b/fw/.gitignore @@ -7,4 +7,6 @@ *.map *.elf *.hex +*.o +.build compile_commands.json diff --git a/fw/Makefile b/fw/Makefile index b914619..5aa6221 100644 --- a/fw/Makefile +++ b/fw/Makefile @@ -3,24 +3,43 @@ all : build TARGET := main TARGET_MCU := CH32X035 TARGET_MCU_PACKAGE := CH32X035F8U6 +BUILD_DIR := .build +DISPLAY := ssd1312 # include u8g2 U8G2_DIR:=u8g2/csrc -U8G2_SRC:=u8g2/csrc/u8x8_d_ssd1312.c $(filter-out $(U8G2_DIR)/u8x8_d_%.c, $(wildcard $(U8G2_DIR)/*.c)) -# U8G2_SRC:=u8g2/csrc/u8x8_d_ssd1306_128x32.c $(filter-out $(U8G2_DIR)/u8x8_d_%.c, $(wildcard $(U8G2_DIR)/*.c)) +U8G2_SRC:=$(U8G2_DIR)/u8x8_d_$(DISPLAY).c $(filter-out $(U8G2_DIR)/u8x8_d_%.c, \ + $(filter-out $(U8G2_DIR)/mui%.c, $(wildcard $(U8G2_DIR)/*.c))) EXTRA_CFLAGS += -I$(U8G2_DIR) - -ADDITIONAL_C_FILES += $(U8G2_SRC) -ADDITIONAL_C_FILES += lib_i2c.c -ADDITIONAL_C_FILES += display.c +ADDITIONAL_C_FILES += lib_i2c.c display.c include ch32fun/ch32fun/ch32fun.mk FLASH_COMMAND=$(MINICHLINK)/minichlink -C isp -w $< $(WRITE_SECTION) -b +# create build directory +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + +# build u8g2 +U8G2_OBJS := $(addprefix $(BUILD_DIR)/, $(notdir $(U8G2_SRC:.c=.o))) +$(BUILD_DIR)/%.o : $(U8G2_DIR)/%.c | $(BUILD_DIR) + $(PREFIX)-gcc $(CFLAGS) -c $< -o $@ + +# build target +TARGET_OBJS := $(addprefix $(BUILD_DIR)/, $(filter-out ch32fun.o, $(notdir $(FILES_TO_COMPILE:.c=.o)))) +$(BUILD_DIR)/%.o : %.c | $(BUILD_DIR) + $(PREFIX)-gcc $(CFLAGS) -c $< -o $@ + +# link target, the rest of the build is specified in ch32fun.mk +$(TARGET).elf : $(FILES_TO_COMPILE) $(LINKER_SCRIPT) $(EXTRA_ELF_DEPENDENCIES) $(U8G2_OBJS) $(TARGET_OBJS) ch32fun.o + $(PREFIX)-gcc -o $@ $(U8G2_OBJS) $(TARGET_OBJS) ch32fun.o $(CFLAGS) $(LDFLAGS) + + flash : cv_flash clean : cv_clean + rm -f $(BUILD_DIR)/*.o *.o || true monitor : picocom --imap lfcrlf /dev/ttyACM0