MAKEFLAGS += -R -r SUBDIRS := include test roms fatfs/source CROSS = ../tools/gnu/bin/riscv32-unknown-elf- CC = $(CROSS)gcc LD = $(CROSS)ld OBJCOPY = $(CROSS)objcopy AR = $(CROSS)ar PERL = perl INCLUDE = -I. -I./include -I./fatfs/source include ../riscv-opts.mk CPPFLAGS = $(INCLUDE) $(riscv_flags) CFLAGS = $(CPPFLAGS) -W -Wextra SFLAGS = $(CPPFLAGS) -D__ASSEMBLY__ LDSCRIPT = max80.ild LDFLAGS = $(CFLAGS) \ -Wl,--gc-sections \ -Wl,-T,$(LDSCRIPT) \ -Wl,-z,common-page-size=16 \ -Wl,-z,max-page-size=16 gendeps = -MD -MF $(@D)/.$(@F).d -MT $@ # Delete output files on error .DELETE_ON_ERROR: # Don't delete intermediate files .SECONDARY: genhdrs = iodevs.h gensrcs = irqtable.c all: boot.mif dram.hex # Generate MIF file for 8Kx32 RAM boot_depth := 8192 boot_width := 32 boot_stride := 1 ROMS := $(wildcard roms/*.rom) ROMOBJS = $(ROMS:.rom=.o) max80.elf: head.o dummy.o die.o main.o system.o \ irqtable.o irqasm.o sbrk.o \ console.o rtc.o romcopy.o \ sdcard.o diskcache.o \ abcmem.o abcio.o abcdisk.o abcrtc.o \ memset.o memcpy.o \ runtest.o start_test.o \ $(ROMOBJS) \ testimg.o \ fatfs.a testimg.elf: head.o dummy.o die.o test/main.o test/system.o \ irqtable.o irqasm.o sbrk.o \ console.o rtc.o romcopy.o \ sdcard.o diskcache.o \ abcmem.o abcio.o abcdisk.o abcrtc.o \ memset.o memcpy.o \ testdata.o $(ROMOBJS) \ fatfs.a FATFS_C = $(wildcard fatfs/source/*.c) FATFS_O = $(FATFS_C:.c=.o) fatfs.a: $(FATFS_O) rm -f $@ $(AR) cq $@ $(FATFS_O) CFLAGS_memset.c := -O2 %.mif: %.bin bin2mif.pl $(PERL) bin2mif.pl $< $@ $($*_depth) $($*_width) $($*_stride) %.hex: %.elf $(OBJCOPY) -O ihex $< $@ %.mem: %.bin $(BIN2MEM) $< > $@ boot.bin: max80.elf $(OBJCOPY) -O binary -R '.dram*' $< $@ dram.bin: max80.elf $(OBJCOPY) -O binary -j '.dram*' $< $@ testimg.bin: testimg.elf $(OBJCOPY) -O binary $< $@ testimg.o: testimg.S testimg.bin %.hex: %.bin $(OBJCOPY) -I binary -O ihex $< $@ %.elf: $(LDSCRIPT) $(CC) $(LDFLAGS) -o $@ $(filter-out $(LDSCRIPT),$^) %.o: %.c | $(genhdrs) $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -c -o $@ $< %.s: %.c | $(genhdrs) $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -S -o $@ $< %.i: %.c | $(genhdrs) $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -E -o $@ $< %.o: %.S | $(genhdrs) $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -c -o $@ $< %.s: %.S | $(genhdrs) $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -E -o $@ $< roms/%.o: roms/%.rom rom.S $(CC) $(SFLAGS) $(SFLAGS_$(F<)) -DNAME='rom_$*' -DFILE='"$<"' \ -c -o $@ rom.S %.ild: %.ld | $(genhdrs) $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) \ -x assembler-with-cpp \ -fdollars-in-identifiers \ -C -P -E $< | $(PERL) -pe 's:^(#.*)$$:/* $$1 */:' > $@ iodevs.h: ../iodevs.conf ../tools/iodevs.pl $(PERL) ../tools/iodevs.pl h $< $@ irqtable.c: ../iodevs.conf ../tools/iodevs.pl $(PERL) ../tools/iodevs.pl c $< $@ clean: for d in . $(SUBDIRS); do \ rm -f $$d/*.o $$d/*.i $$d/*.s $$d/*.elf $$d/*.bin \ $$d/.*.d $$d/*.ild; \ done rm -f $(genhdrs) $(gensrcs) spotless: clean rm -f *.mem *.hex *.mif -include $(patsubst %,%/.*.d,. $(SUBDIRS))