Makefile 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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./zlib -I./fatfs/source
  12. include ../riscv-opts.mk
  13. CPPFLAGS = $(INCLUDE) $(riscv_flags)
  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. gendeps = -MD -MF $(@D)/.$(@F).d -MT $@
  24. # Delete output files on error
  25. .DELETE_ON_ERROR:
  26. # Don't delete intermediate files
  27. .SECONDARY:
  28. genhdrs = iodevs.h irqtable.h
  29. gensrcs =
  30. all: sram.bin jtagupd.bin dram.bin dram.hex checksum.h
  31. LIBS = max80.a fatfs.a zlib.a
  32. ROMS := $(wildcard roms/*.rom)
  33. ROMOBJS = $(ROMS:.rom=.o)
  34. LIBOBJ = head.o dummy.o die.o system.o \
  35. ioregsa.o irqasm.o irqtable.o spurious_irq.o sbrk.o \
  36. console.o rtc.o romcopy.o spiflash.o esp.o \
  37. sdcard.o diskcache.o \
  38. abcmem.o abcio.o abcdisk.o abcrtc.o abcpun80.o \
  39. memset.o memcpy.o \
  40. runtest.o start_test.o \
  41. $(ROMOBJS)
  42. max80.a: $(LIBOBJ)
  43. rm -f $@
  44. $(AR) cq $@ $(LIBOBJ)
  45. FATFS_C = $(wildcard fatfs/source/*.c)
  46. FATFS_O = $(FATFS_C:.c=.o)
  47. fatfs.a: $(FATFS_O)
  48. rm -f $@
  49. $(AR) cq $@ $(FATFS_O)
  50. ZLIB_C = $(wildcard zlib/*.c)
  51. ZLIB_O = $(ZLIB_C:.c=.o)
  52. zlib.a: $(ZLIB_O)
  53. rm -f $@
  54. $(AR) cq $@ $(ZLIB_O)
  55. CFLAGS_zlib/inflate.c := -Wno-implicit-fallthrough
  56. CFLAGS_zlib/infback.c := -Wno-implicit-fallthrough
  57. CFLAGS_memset.c := -O2
  58. %.hex: %.elf
  59. $(OBJCOPY) -O ihex $< $@
  60. %.mem: %.bin
  61. $(BIN2MEM) $< > $@
  62. sram.bin: max80.elf
  63. $(OBJCOPY) -O binary -R '.dram*' $< $@
  64. dram.bin: max80.elf
  65. $(OBJCOPY) -O binary -j '.dram*' $< $@
  66. %.bin: %.elf
  67. $(OBJCOPY) -O binary $< $@
  68. %.gz: %
  69. $(GZIP) -9 < $< > $@
  70. checksum.h: dram.bin sram.bin checksum.pl
  71. $(PERL) checksum.pl -o $@ -p sram.bin \
  72. -l $$(($$($(NM) -n max80.elf --radix=decimal | \
  73. grep ' [A-Z] __dram_init_end$$' | \
  74. awk '{ print $$1; }') - (1 << 30))) \
  75. dram.bin
  76. testimg.bin: testimg.elf
  77. $(OBJCOPY) -O binary $< $@
  78. testimg.o: testimg.S testimg.bin
  79. %.hex: %.bin
  80. $(OBJCOPY) -I binary -O ihex $< $@
  81. %.elf: %.ild %.o $(LIBS)
  82. $(CC) $(LDFLAGS) -Wl,-T,$< -o $@ \
  83. -Wl,--start-group $(filter-out $<,$^) -Wl,--end-group
  84. %.o: %.c | $(genhdrs)
  85. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -c -o $@ $<
  86. %.s: %.c | $(genhdrs)
  87. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -S -o $@ $<
  88. %.i: %.c | $(genhdrs)
  89. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -E -o $@ $<
  90. %.o: %.S | $(genhdrs)
  91. $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -c -o $@ $<
  92. %.s: %.S | $(genhdrs)
  93. $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -E -o $@ $<
  94. ioregsa.S: ioregs.h ioregsa.pl | $(genhdrs)
  95. $(PERL) ioregsa.pl $< $@
  96. roms/%.o: roms/%.rom rom.S
  97. $(CC) $(SFLAGS) $(SFLAGS_$(F<)) -DNAME='rom_$*' -DFILE='"$<"' \
  98. -c -o $@ rom.S
  99. %.ild: %.ld | $(genhdrs)
  100. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) \
  101. -x assembler-with-cpp \
  102. -fdollars-in-identifiers \
  103. -C -P -E $< | $(PERL) -pe 's:^(#.*)$$:/* $$1 */:' > $@
  104. iodevs.h: ../iodevs.conf ../tools/iodevs.pl
  105. $(PERL) ../tools/iodevs.pl h $< $@
  106. irqtable.h: ../iodevs.conf ../tools/iodevs.pl
  107. $(PERL) ../tools/iodevs.pl irqh $< $@
  108. clean:
  109. for d in . $(SUBDIRS); do \
  110. rm -f $$d/*.a $$d/*.o $$d/*.i $$d/*.s $$d/*.elf $$d/*.bin \
  111. $$d/.*.d $$d/*.ild $$d/*.map; \
  112. done
  113. rm -f $(genhdrs) $(gensrcs)
  114. spotless: clean
  115. rm -f *.mem *.hex *.mif checksum.h
  116. -include $(patsubst %,%/.*.d,. $(SUBDIRS))