RISC-V/V203F6P6/midi/Makefile
2025-02-19 15:33:04 +01:00

65 lines
1.5 KiB
Makefile

# ch32v203
TARGET?= ch32v203
TOOL ?= gcc
#TOOL ?= clang
PRJ = example
VPATH = . ./$(TARGET)
BLD = ./build/
DFLAGS = -d
LFLAGS = -g
LDLIBS = -L./$(TARGET)/usbd -lusbd
BFLAGS = --strip-unneeded
CFLAGS = -MMD -Wall -ggdb -fno-exceptions -ffunction-sections -fdata-sections
CFLAGS+= -I. -I./common -I./$(TARGET) -I./$(TARGET)/usbd
DEL = rm -f
# zdrojaky
OBJS = main.o hack.o pwmclass.o
OBJS += tone.o midiplayer.o miditone.o
OBJS += spiblocked.o norflash.o
OBJS += intelhex.o linkprotocol.o usb_desc.o
include $(TARGET)/$(TOOL).mk
BOBJS = $(addprefix $(BLD),$(OBJS))
all: $(BLD) $(PRJ).elf
# ... atd.
-include $(BLD)*.d
# linker
$(PRJ).elf: $(BOBJS)
-@echo [LD $(TOOL),$(TARGET)] $@
@$(LD) $(LFLAGS) -o $(PRJ).elf $(BOBJS) $(LDLIBS)
-@echo "size:"
@$(SIZE) $(PRJ).elf
-@echo "listing:"
$(DUMP) $(DFLAGS) $(PRJ).elf > $(PRJ).lst
-@echo "OK."
$(COPY) $(BFLAGS) -O binary $(PRJ).elf $(PRJ).bin
$(COPY) $(BFLAGS) -O ihex $(PRJ).elf $(PRJ).hex
# preloz co je potreba
$(BLD)%.o: %.c
-@echo [CC $(TOOL),$(TARGET)] $@
@$(CC) -c $(CFLAGS) $< -o $@
$(BLD)%.o: %.cpp
-@echo [CX $(TOOL),$(TARGET)] $@
@$(CXX) -std=c++17 -fno-rtti -c $(CFLAGS) $< -o $@
$(BLD):
mkdir $(BLD)
flash: $(PRJ).elf
minichlink -w $(PRJ).bin flash -b
miditone.c: ton/gen
ton/gen
ton/gen: ton/gen.cpp
g++ -Os ton/gen.cpp -o ton/gen
# vycisti
clean:
$(DEL) $(BLD)* *.lst *.bin *.hex *.elf *.map *~ miditone.c
distclean: clean
$(DEL) ton/gen
cd ./img && make distclean
.PHONY: all clean distclean flash