Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. LDSCRIPT = max80.ild
  17. LDFLAGS = $(CFLAGS) \
  18. -Wl,-Map=$*.map \
  19. -Wl,--gc-sections \
  20. -Wl,--sort-section=alignment \
  21. -Wl,-T,$(LDSCRIPT) \
  22. -Wl,-z,common-page-size=16 \
  23. -Wl,-z,max-page-size=16
  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: boot.bin dram.bin.gz dram.hex checksum.h
  32. ROMS := $(wildcard roms/*.rom)
  33. ROMOBJS = $(ROMS:.rom=.o)
  34. max80.elf: head.o dummy.o die.o main.o system.o \
  35. ioregsa.o irqasm.o irqtable.o spurious_irq.o sbrk.o \
  36. console.o rtc.o romcopy.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. testimg.o \
  43. fatfs.a
  44. testimg.elf: head.o dummy.o die.o test/main.o test/system.o \
  45. ioregsa.o irqasm.o irqtable.o spurious_irq.o sbrk.o \
  46. console.o rtc.o romcopy.o \
  47. sdcard.o diskcache.o \
  48. abcmem.o abcio.o abcdisk.o abcrtc.o abcpun80.o \
  49. memset.o memcpy.o \
  50. testdata.o $(ROMOBJS) \
  51. fatfs.a
  52. FATFS_C = $(wildcard fatfs/source/*.c)
  53. FATFS_O = $(FATFS_C:.c=.o)
  54. fatfs.a: $(FATFS_O)
  55. rm -f $@
  56. $(AR) cq $@ $(FATFS_O)
  57. ZLIB_C = $(wildcard zlib/*.c)
  58. ZLIB_O = $(ZLIB_C:.c=.o)
  59. zlib.a: $(ZLIB_O)
  60. rm -f $@
  61. $(AR) cq $@ $(ZLIB_O)
  62. CFLAGS_zlib/inflate.c := -Wno-implicit-fallthrough
  63. CFLAGS_zlib/infback.c := -Wno-implicit-fallthrough
  64. CFLAGS_memset.c := -O2
  65. %.hex: %.elf
  66. $(OBJCOPY) -O ihex $< $@
  67. %.mem: %.bin
  68. $(BIN2MEM) $< > $@
  69. boot.bin: max80.elf
  70. $(OBJCOPY) -O binary -R '.dram*' $< $@
  71. dram.bin: max80.elf
  72. $(OBJCOPY) -O binary -j '.dram*' $< $@
  73. %.gz: %
  74. $(GZIP) -9 < $< > $@
  75. checksum.h: dram.bin boot.bin checksum.pl
  76. $(PERL) checksum.pl -o $@ -p boot.bin \
  77. -l $$(($$($(NM) -n max80.elf --radix=decimal | \
  78. grep ' [A-Z] __dram_init_end$$' | \
  79. awk '{ print $$1; }') - (1 << 30))) \
  80. dram.bin
  81. testimg.bin: testimg.elf
  82. $(OBJCOPY) -O binary $< $@
  83. testimg.o: testimg.S testimg.bin
  84. %.hex: %.bin
  85. $(OBJCOPY) -I binary -O ihex $< $@
  86. %.elf: $(LDSCRIPT)
  87. $(CC) $(LDFLAGS) -o $@ $(filter-out $(LDSCRIPT),$^)
  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))