123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- MAKEFLAGS += -R -r
- ASMDIRS := roms/asmsrc
- SUBDIRS := include test roms fatfs/source zlib $(ROMDIRS)
- CROSS = ../tools/gnu/bin/riscv32-unknown-elf-
- CC = $(CROSS)gcc
- LD = $(CROSS)ld
- OBJCOPY = $(CROSS)objcopy
- AR = $(CROSS)ar
- NM = $(CROSS)nm
- PERL = perl
- GZIP = gzip
- INCLUDE = -I. -I./include -I../common -I./zlib -I./fatfs/source
- include ../riscv-opts.mk
- CPPFLAGS = $(INCLUDE) $(riscv_flags) -DON_FPGA
- CFLAGS = $(CPPFLAGS) -W -Wextra
- SFLAGS = $(CPPFLAGS) -D__ASSEMBLY__
- LDFLAGS = $(CFLAGS) \
- -Wl,-Map=$*.map \
- -Wl,--gc-sections \
- -Wl,--sort-section=alignment \
- -Wl,-z,common-page-size=16 \
- -Wl,-z,max-page-size=16 \
- -Wl,-z muldefs \
- -Wl,--require-defined=IODEV_BASE
- gendeps = -MD -MF $(@D)/.$(@F).d -MT $@
- VPATH := .:../common
- # Delete output files on error
- .DELETE_ON_ERROR:
- # Don't delete intermediate files
- .SECONDARY:
- genhdrs = iodevs.h irqtable.h roms.h
- gensrcs =
- all: sram.bin dram.bin dram.hex checksum.h
- LIBS = max80.a roms.a fatfs.a zlib.a
- ROMS = $(shell find roms -name '*.rom' -print)
- ROMOBJ = $(ROMS:.rom=.o)
- FORCEOBJ = head.o dummy.o die.o system.o killed.o
- COMMONOBJ := $(patsubst ../common/%.c,%.o,$(wildcard ../common/*.c))
- LIBOBJ = debug.o ioregsa.o irqasm.o irqtable.o spurious_irq.o \
- console.o rtc.o romcopy.o spiflash.o esp.o matchver.o \
- config.o shutdown.o \
- sdcard.o \
- abcmem.o abcio.o abcdisk.o abcrtc.o abcpun80.o \
- memset.o memcpy.o \
- runtest.o start_test.o \
- $(COMMONOBJ)
- max80.a: $(LIBOBJ)
- rm -f $@
- $(AR) cq $@ $(LIBOBJ)
- ROMDEPS = roms
- roms.a: $(ROMDEPS)
- rm -f $@
- $(AR) cq $@ $(ROMOBJ)
- FATFS_C = $(wildcard fatfs/source/*.c)
- FATFS_O = $(FATFS_C:.c=.o)
- fatfs.a: $(FATFS_O)
- rm -f $@
- $(AR) cq $@ $(FATFS_O)
- ZLIB_C = $(wildcard zlib/*.c)
- ZLIB_O = $(ZLIB_C:.c=.o)
- zlib.a: $(ZLIB_O)
- rm -f $@
- $(AR) cq $@ $(ZLIB_O)
- CFLAGS_zlib/inflate.c := -Wno-implicit-fallthrough
- CFLAGS_zlib/infback.c := -Wno-implicit-fallthrough
- CFLAGS_memset.c := -O2
- %.hex: %.elf
- $(OBJCOPY) -O ihex $< $@
- %.mem: %.bin
- $(BIN2MEM) $< > $@
- sram.bin: max80.elf
- $(OBJCOPY) -O binary -R '.dram*' $< $@
- dram.bin: max80.elf
- $(OBJCOPY) -O binary -j '.dram*' $< $@
- %.bin: %.elf
- $(OBJCOPY) -O binary $< $@
- %.gz: %
- $(GZIP) -9 < $< > $@
- checksum.h: dram.bin sram.bin checksum.pl
- $(PERL) checksum.pl -o $@ -p sram.bin \
- -l $$(($$($(NM) -n max80.elf --radix=decimal | \
- grep ' [A-Z] __dram_init_end$$' | \
- awk '{ print $$1; }') - (1 << 30))) \
- dram.bin
- testimg.bin: testimg.elf
- $(OBJCOPY) -O binary $< $@
- testimg.o: testimg.S testimg.bin
- %.hex: %.bin
- $(OBJCOPY) -I binary -O ihex $< $@
- # Objects specific to certain executables
- max80.elf: diskcache.o
- jtagupd.elf: sbrk.o
- %.elf: %.ild $(FORCEOBJ) %.o $(LIBS)
- $(CC) $(LDFLAGS) -Wl,-T,$< -o $@ \
- -Wl,--start-group $(filter-out $<,$^) -Wl,--end-group
- %.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_$<) -Wa,-ahlsm=$*.lst $(gendeps) -c -o $@ $<
- %.s: %.S | $(genhdrs)
- $(CC) $(SFLAGS) $(SFLAGS_$<) -Wa,-ahlsm=$*.lst $(gendeps) -E -o $@ $<
- ioregsa.S: ioregs.h ioregsa.pl | $(genhdrs)
- $(PERL) ioregsa.pl $< $@
- .PHONY: roms
- roms: asmsrc
- $(MAKE) _roms
- .PHONY: _roms
- _roms: $(ROMOBJ)
- roms/%.o: roms/%.rom rom.S
- $(CC) $(SFLAGS) $(SFLAGS_$(F<)) \
- -DNAME=rom_$$(echo '$*' | sed -r -e 's/[^A-Za-z0-9]+/_/g') \
- -DFILE='"$<"' -c -o $@ rom.S
- .PHONY: asmsrc
- asmsrc:
- for d in $(ASMDIRS); do $(MAKE) -C $$d; done
- roms.h: roms
- ( for r in $(ROMS); do \
- cn=$$(echo "$$r" | sed -r -e 's/^roms/rom_/' -e 's/\.rom$$//' \
- -e 's/[^A-Za-z0-9]+/_/g') ; \
- stat -c "extern const char $$cn[%s];" "$$r"; \
- done ) > $@
- abcmem.o: roms.h
- %.ild: %.ld | $(genhdrs)
- $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) \
- -x assembler-with-cpp \
- -fdollars-in-identifiers \
- -C -P -E $< | $(PERL) -pe 's:^(#.*)$$:/* $$1 */:' > $@
- iodevs.h: ../common/iodevs.conf ../tools/iodevs.pl
- $(PERL) ../tools/iodevs.pl h $< $@
- irqtable.h: ../common/iodevs.conf ../tools/iodevs.pl
- $(PERL) ../tools/iodevs.pl irqh $< $@
- clean:
- for d in . $(shell find $(SUBDIRS) -type d); do \
- rm -f $$d/*.a $$d/*.o $$d/*.i $$d/*.s $$d/*.elf $$d/*.bin \
- $$d/.*.d $$d/*.ild $$d/*.map; \
- done
- rm -f $(genhdrs) $(gensrcs) $(ROMOBJ)
- spotless: clean
- for d in $(ASMDIRS); do $(MAKE) -C $$d $@; done
- rm -f *.mem *.hex *.mif checksum.h
- -include $(patsubst %,%/.*.d,. $(SUBDIRS))
|