From 2d06c48a0444806dedbd574473cad16b9312e3a2 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 9 Feb 2025 15:41:31 +0100 Subject: [PATCH] Restructure --- Makefile | 64 +++++++++++++++++++++++++------------------------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index f0c8caa..2e908a6 100644 --- a/Makefile +++ b/Makefile @@ -6,15 +6,24 @@ TARGET = blink TARGET_MCU?=CH32V003 NEWLIB=/usr/arm-none-eabi/include CFLAGS=-g -Os -flto -ffunction-sections -fdata-sections -fmessage-length=0 -msmall-data-limit=8 -LDFLAGS+=-Wl,--print-memory-usage -Wl,-Map=$(TARGET).map -PREFIX := riscv64-linux-gnu -CC := $(PREFIX)-gcc +LDFLAGS+=-Wl,--print-memory-usage -Wl,-Map=$(TARGET).map,--build-id=none +TOOL_PREFIX := riscv64-linux-gnu +CC := $(TOOL_PREFIX)-gcc +OBJDUMP := $(TOOL_PREFIX)-objdump +OBJCOPY := $(TOOL_PREFIX)-objcopy -# riscv64-linux-gnu-gcc -E -P -x c -DTARGET_MCU=CH32V003 -DMCU_PACKAGE= -DTARGET_MCU_LD=0 -DTARGET_MCU_MEMORY_SPLIT= ../../ch32fun/ch32fun.ld > ../../ch32fun/generated_ch32v003.ld -# riscv64-linux-gnu-gcc -o blink.elf ../../ch32fun/ch32fun.c blink.c -g -Os -flto -ffunction-sections -fdata-sections -fmessage-length=0 -msmall-data-limit=8 -march=rv32ec -mabi=ilp32e -DCH32V003=1 -static-libgcc -I/usr/arm-none-eabi/include -I../../ch32fun/../extralibs -I../../ch32fun -nostdlib -I. -Wall -Wl,--print-memory-usage -Wl,-Map=blink.map -L../../ch32fun/../misc -lgcc -T ../../ch32fun/generated_ch32v003.ld -Wl,--gc-sections - -# Correct? -EXTFLAGS := -march=rv32ec -mabi=ilp32e -DCH32V003=1 -static-libgcc -I/usr/arm-none-eabi/include -nostdlib -I. -Wall -L. -lgcc -T ch32v003.ld -Wl,--gc-sections +EXTFLAGS := -march=rv32ec \ + -mabi=ilp32e \ + -DCH32V003=1 \ + -static-libgcc \ + -I$(NEWLIB) \ + -nostdlib \ + -I. \ + -Wall \ + -L. \ + -lgcc \ + -T ch32v003.ld \ + -Wl,--gc-sections default: $(TARGET).bin @@ -25,41 +34,26 @@ $(TARGET).elf: ch32fun.c blink.c | ch32v003.ld ch32fun.h ch32v003hw.h ch32v003.ld: ch32fun.ld @riscv64-linux-gnu-gcc -E -P -x c -DTARGET_MCU=$(TARGET_MCU) -DMCU_PACKAGE= -DTARGET_MCU_LD=0 -DTARGET_MCU_MEMORY_SPLIT= $< > $@ -ch32fun.ld: - @curl $(CURL_FLAGS) $(BASE)/ch32fun.ld - -ch32fun.c: - @curl $(CURL_FLAGS) $(BASE)/ch32fun.c - -ch32v003hw.h: - @curl $(CURL_FLAGS) $(BASE)/ch32v003hw.h - -ch32fun.h: - @curl $(CURL_FLAGS) $(BASE)/ch32fun.h - -deps: - @curl $(CURL_FLAGS) $(BASE)/ch32fun.ld - @curl $(CURL_FLAGS) $(BASE)/ch32v003hw.h - @curl $(CURL_FLAGS) $(BASE)/ch32fun.c - @curl $(CURL_FLAGS) $(BASE)/ch32fun.h +# Rule to use curl to fetch all files beginning with ch32 +ch32%: + @echo "Fetching $@" + @curl $(CURL_FLAGS) $(BASE)/$@ $(TARGET).bin : $(TARGET).elf - $(PREFIX)-objdump -S $^ > $(TARGET).lst - $(PREFIX)-objcopy -O binary $< $(TARGET).bin - $(PREFIX)-objcopy -O ihex $< $(TARGET).hex + @$(OBJCOPY) -O binary $< $(TARGET).bin + +$(TARGET).lst : $(TARGET).elf + @$(OBJDUMP) -S $^ > $(TARGET).lst + +$(TARGET).hex : $(TARGET).elf + @$(OBJCOPY) -O ihex $< $(TARGET).hex flash: minichlink -w $(TARGET).bin flash -b clean: rm -f ch32*.[ch] - rm -f *.ld - rm -f *.hex - rm -f *.bin - rm -f *.map - rm -f *.lst - rm -f *.elf - rm -f *.ld + rm -f *.{ld,hex,bin,map,lst,elf} .PHONY: clean flash deps default