Restructure

This commit is contained in:
Imbus 2025-02-09 15:41:31 +01:00
parent 2b51711e0e
commit 2d06c48a04

View file

@ -6,15 +6,24 @@ TARGET = blink
TARGET_MCU?=CH32V003 TARGET_MCU?=CH32V003
NEWLIB=/usr/arm-none-eabi/include NEWLIB=/usr/arm-none-eabi/include
CFLAGS=-g -Os -flto -ffunction-sections -fdata-sections -fmessage-length=0 -msmall-data-limit=8 CFLAGS=-g -Os -flto -ffunction-sections -fdata-sections -fmessage-length=0 -msmall-data-limit=8
LDFLAGS+=-Wl,--print-memory-usage -Wl,-Map=$(TARGET).map LDFLAGS+=-Wl,--print-memory-usage -Wl,-Map=$(TARGET).map,--build-id=none
PREFIX := riscv64-linux-gnu TOOL_PREFIX := riscv64-linux-gnu
CC := $(PREFIX)-gcc 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 EXTFLAGS := -march=rv32ec \
# 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 -mabi=ilp32e \
-DCH32V003=1 \
# Correct? -static-libgcc \
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 -I$(NEWLIB) \
-nostdlib \
-I. \
-Wall \
-L. \
-lgcc \
-T ch32v003.ld \
-Wl,--gc-sections
default: $(TARGET).bin default: $(TARGET).bin
@ -25,41 +34,26 @@ $(TARGET).elf: ch32fun.c blink.c | ch32v003.ld ch32fun.h ch32v003hw.h
ch32v003.ld: ch32fun.ld 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= $< > $@ @riscv64-linux-gnu-gcc -E -P -x c -DTARGET_MCU=$(TARGET_MCU) -DMCU_PACKAGE= -DTARGET_MCU_LD=0 -DTARGET_MCU_MEMORY_SPLIT= $< > $@
ch32fun.ld: # Rule to use curl to fetch all files beginning with ch32
@curl $(CURL_FLAGS) $(BASE)/ch32fun.ld ch32%:
@echo "Fetching $@"
ch32fun.c: @curl $(CURL_FLAGS) $(BASE)/$@
@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
$(TARGET).bin : $(TARGET).elf $(TARGET).bin : $(TARGET).elf
$(PREFIX)-objdump -S $^ > $(TARGET).lst @$(OBJCOPY) -O binary $< $(TARGET).bin
$(PREFIX)-objcopy -O binary $< $(TARGET).bin
$(PREFIX)-objcopy -O ihex $< $(TARGET).hex $(TARGET).lst : $(TARGET).elf
@$(OBJDUMP) -S $^ > $(TARGET).lst
$(TARGET).hex : $(TARGET).elf
@$(OBJCOPY) -O ihex $< $(TARGET).hex
flash: flash:
minichlink -w $(TARGET).bin flash -b minichlink -w $(TARGET).bin flash -b
clean: clean:
rm -f ch32*.[ch] rm -f ch32*.[ch]
rm -f *.ld rm -f *.{ld,hex,bin,map,lst,elf}
rm -f *.hex
rm -f *.bin
rm -f *.map
rm -f *.lst
rm -f *.elf
rm -f *.ld
.PHONY: clean flash deps default .PHONY: clean flash deps default