ch552: Reorganize file directory structure

- Move source files to separate directory.
- Move include files to separate directory.
- Add specific output direcory for intermediate files.
This commit is contained in:
Jonas Thörnblad 2025-03-19 15:44:37 +01:00
parent 8d8f4c7faf
commit 7de49d2021
No known key found for this signature in database
GPG key ID: 2D318AD00A326F95
11 changed files with 19 additions and 23 deletions

View file

@ -10,7 +10,7 @@ CHPROG = chprog
TARGET = usb_device TARGET = usb_device
ROOT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) OUT_DIR = _out
XRAM_SIZE = 0x0400 # 1 KB on-chip xRAM XRAM_SIZE = 0x0400 # 1 KB on-chip xRAM
XRAM_LOC = 0x0000 # xRAM area starts at address 0 in the External Data Address Space XRAM_LOC = 0x0000 # xRAM area starts at address 0 in the External Data Address Space
@ -26,7 +26,7 @@ CFLAGS = \
--xram-size $(XRAM_SIZE) \ --xram-size $(XRAM_SIZE) \
--xram-loc $(XRAM_LOC) \ --xram-loc $(XRAM_LOC) \
--code-size $(CODE_SIZE) \ --code-size $(CODE_SIZE) \
-I$(ROOT_DIR)include \ -Iinc \
-DFREQ_SYS=$(FREQ_SYS) \ -DFREQ_SYS=$(FREQ_SYS) \
$(EXTRA_FLAGS) $(EXTRA_FLAGS)
@ -34,25 +34,28 @@ LFLAGS = \
$(CFLAGS) $(CFLAGS)
C_FILES = \ C_FILES = \
main.c \ src/main.c \
include/debug.c \ src/debug.c \
include/print.c src/print.c
# Create a .rel file for each .c file # Create a .rel file for each .c file in $(OUT_DIR)/
RELS = $(C_FILES:.c=.rel) RELS = $(patsubst %.c,$(OUT_DIR)/%.rel,$(C_FILES))
%.rel : %.c OUT_SUBDIRS = $(sort $(dir $(RELS)))
$(CC) -c $(CFLAGS) $<
# Ensure out directory exists
$(OUT_DIR):
mkdir -p $(OUT_SUBDIRS)
$(OUT_DIR)/%.rel: %.c | $(OUT_DIR)
$(CC) -c $(CFLAGS) $< -o $@
usb_strings.h: encode_usb_strings.py usb_strings.h: encode_usb_strings.py
./encode_usb_strings.py ./encode_usb_strings.py
# Note: SDCC will dump all of the temporary files into this one, # Compile the final ihx file
# so strip the paths from RELS
# For now, get around this by stripping the paths off of the RELS list.
$(TARGET).ihx: $(RELS) $(TARGET).ihx: $(RELS)
$(CC) $(notdir $(RELS)) $(LFLAGS) -o $(TARGET).ihx $(CC) $(RELS) $(LFLAGS) -o $(TARGET).ihx
$(TARGET).hex: $(TARGET).ihx $(TARGET).hex: $(TARGET).ihx
$(PACK_HEX) $(TARGET).ihx > $(TARGET).hex $(PACK_HEX) $(TARGET).ihx > $(TARGET).hex
@ -72,14 +75,7 @@ flash_patched: $(TARGET).bin
all: $(TARGET).bin $(TARGET).hex all: $(TARGET).bin $(TARGET).hex
clean: clean:
rm -f \ rm -rf $(OUT_DIR) \
$(notdir $(RELS:.rel=.asm)) \
$(notdir $(RELS:.rel=.lst)) \
$(notdir $(RELS:.rel=.mem)) \
$(notdir $(RELS:.rel=.rel)) \
$(notdir $(RELS:.rel=.rst)) \
$(notdir $(RELS:.rel=.sym)) \
$(notdir $(RELS:.rel=.adb)) \
$(TARGET).lk \ $(TARGET).lk \
$(TARGET).map \ $(TARGET).map \
$(TARGET).mem \ $(TARGET).mem \

View file

@ -57,7 +57,7 @@ if __name__ == "__main__":
"TkeyCtrlInterfaceDesc": "TKEY-Ctrl" "TkeyCtrlInterfaceDesc": "TKEY-Ctrl"
} }
with open('include/usb_strings.h', 'w') as f: with open('inc/usb_strings.h', 'w') as f:
f.write('#ifndef __USB_STRINGS_H__\n') f.write('#ifndef __USB_STRINGS_H__\n')
f.write('#define __USB_STRINGS_H__\n') f.write('#define __USB_STRINGS_H__\n')
f.write('\n') f.write('\n')