2
0

Makefile 3.7 KB

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