Makefile 3.7 KB

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