Makefile 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. MAKEFLAGS += -R -r
  2. SUBDIRS := include test roms fatfs/source zlib
  3. CROSS = ../tools/gnu/bin/riscv32-unknown-elf-
  4. CC = $(CROSS)gcc
  5. LD = $(CROSS)ld
  6. OBJCOPY = $(CROSS)objcopy
  7. AR = $(CROSS)ar
  8. NM = $(CROSS)nm
  9. PERL = perl
  10. GZIP = gzip
  11. INCLUDE = -I. -I./include -I../common -I./zlib -I./fatfs/source
  12. include ../riscv-opts.mk
  13. CPPFLAGS = $(INCLUDE) $(riscv_flags) -DON_FPGA
  14. CFLAGS = $(CPPFLAGS) -W -Wextra
  15. SFLAGS = $(CPPFLAGS) -D__ASSEMBLY__
  16. LDFLAGS = $(CFLAGS) \
  17. -Wl,-Map=$*.map \
  18. -Wl,--gc-sections \
  19. -Wl,--sort-section=alignment \
  20. -Wl,-z,common-page-size=16 \
  21. -Wl,-z,max-page-size=16 \
  22. -Wl,-z muldefs \
  23. -Wl,--require-defined=IODEV_BASE
  24. gendeps = -MD -MF $(@D)/.$(@F).d -MT $@
  25. VPATH := .:../common
  26. # Delete output files on error
  27. .DELETE_ON_ERROR:
  28. # Don't delete intermediate files
  29. .SECONDARY:
  30. genhdrs = iodevs.h irqtable.h
  31. gensrcs =
  32. all: sram.bin dram.bin dram.hex checksum.h
  33. LIBS = max80.a fatfs.a zlib.a
  34. ROMS := $(wildcard roms/*.rom)
  35. ROMOBJ = $(ROMS:.rom=.o)
  36. FORCEOBJ = head.o dummy.o die.o system.o killed.o
  37. COMMONOBJ := $(patsubst ../common/%.c,%.o,$(wildcard ../common/*.c))
  38. LIBOBJ = debug.o ioregsa.o irqasm.o irqtable.o spurious_irq.o \
  39. console.o rtc.o romcopy.o spiflash.o esp.o matchver.o \
  40. config.o shutdown.o \
  41. sdcard.o \
  42. abcmem.o abcio.o abcdisk.o abcrtc.o abcpun80.o \
  43. memset.o memcpy.o \
  44. runtest.o start_test.o \
  45. $(COMMONOBJ) $(ROMOBJ)
  46. max80.a: $(LIBOBJ)
  47. rm -f $@
  48. $(AR) cq $@ $(LIBOBJ)
  49. FATFS_C = $(wildcard fatfs/source/*.c)
  50. FATFS_O = $(FATFS_C:.c=.o)
  51. fatfs.a: $(FATFS_O)
  52. rm -f $@
  53. $(AR) cq $@ $(FATFS_O)
  54. ZLIB_C = $(wildcard zlib/*.c)
  55. ZLIB_O = $(ZLIB_C:.c=.o)
  56. zlib.a: $(ZLIB_O)
  57. rm -f $@
  58. $(AR) cq $@ $(ZLIB_O)
  59. CFLAGS_zlib/inflate.c := -Wno-implicit-fallthrough
  60. CFLAGS_zlib/infback.c := -Wno-implicit-fallthrough
  61. CFLAGS_memset.c := -O2
  62. %.hex: %.elf
  63. $(OBJCOPY) -O ihex $< $@
  64. %.mem: %.bin
  65. $(BIN2MEM) $< > $@
  66. sram.bin: max80.elf
  67. $(OBJCOPY) -O binary -R '.dram*' $< $@
  68. dram.bin: max80.elf
  69. $(OBJCOPY) -O binary -j '.dram*' $< $@
  70. %.bin: %.elf
  71. $(OBJCOPY) -O binary $< $@
  72. %.gz: %
  73. $(GZIP) -9 < $< > $@
  74. checksum.h: dram.bin sram.bin checksum.pl
  75. $(PERL) checksum.pl -o $@ -p sram.bin \
  76. -l $$(($$($(NM) -n max80.elf --radix=decimal | \
  77. grep ' [A-Z] __dram_init_end$$' | \
  78. awk '{ print $$1; }') - (1 << 30))) \
  79. dram.bin
  80. testimg.bin: testimg.elf
  81. $(OBJCOPY) -O binary $< $@
  82. testimg.o: testimg.S testimg.bin
  83. %.hex: %.bin
  84. $(OBJCOPY) -I binary -O ihex $< $@
  85. # Objects specific to certain executables
  86. max80.elf: diskcache.o
  87. jtagupd.elf: sbrk.o
  88. %.elf: %.ild $(FORCEOBJ) %.o $(LIBS)
  89. $(CC) $(LDFLAGS) -Wl,-T,$< -o $@ \
  90. -Wl,--start-group $(filter-out $<,$^) -Wl,--end-group
  91. %.o: %.c | $(genhdrs)
  92. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -c -o $@ $<
  93. %.s: %.c | $(genhdrs)
  94. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -S -o $@ $<
  95. %.i: %.c | $(genhdrs)
  96. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -E -o $@ $<
  97. %.o: %.S | $(genhdrs)
  98. $(CC) $(SFLAGS) $(SFLAGS_$<) -Wa,-ahlsm=$*.lst $(gendeps) -c -o $@ $<
  99. %.s: %.S | $(genhdrs)
  100. $(CC) $(SFLAGS) $(SFLAGS_$<) -Wa,-ahlsm=$*.lst $(gendeps) -E -o $@ $<
  101. ioregsa.S: ioregs.h ioregsa.pl | $(genhdrs)
  102. $(PERL) ioregsa.pl $< $@
  103. roms/%.o: roms/%.rom rom.S
  104. $(CC) $(SFLAGS) $(SFLAGS_$(F<)) -DNAME='rom_$*' -DFILE='"$<"' \
  105. -c -o $@ rom.S
  106. %.ild: %.ld | $(genhdrs)
  107. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) \
  108. -x assembler-with-cpp \
  109. -fdollars-in-identifiers \
  110. -C -P -E $< | $(PERL) -pe 's:^(#.*)$$:/* $$1 */:' > $@
  111. iodevs.h: ../iodevs.conf ../tools/iodevs.pl
  112. $(PERL) ../tools/iodevs.pl h $< $@
  113. irqtable.h: ../iodevs.conf ../tools/iodevs.pl
  114. $(PERL) ../tools/iodevs.pl irqh $< $@
  115. clean:
  116. for d in . $(SUBDIRS); do \
  117. rm -f $$d/*.a $$d/*.o $$d/*.i $$d/*.s $$d/*.elf $$d/*.bin \
  118. $$d/.*.d $$d/*.ild $$d/*.map; \
  119. done
  120. rm -f $(genhdrs) $(gensrcs)
  121. spotless: clean
  122. rm -f *.mem *.hex *.mif checksum.h
  123. -include $(patsubst %,%/.*.d,. $(SUBDIRS))