Makefile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. MAKEFLAGS += -R -r
  2. SUBDIRS := include test roms fatfs/source
  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./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. CFLAGS_memset.c := -O2
  58. %.hex: %.elf
  59. $(OBJCOPY) -O ihex $< $@
  60. %.mem: %.bin
  61. $(BIN2MEM) $< > $@
  62. boot.bin: max80.elf
  63. $(OBJCOPY) -O binary -R '.dram*' $< $@
  64. dram.bin: max80.elf
  65. $(OBJCOPY) -O binary -j '.dram*' $< $@
  66. %.gz: %
  67. $(GZIP) -9 < $< > $@
  68. checksum.h: dram.bin boot.bin checksum.pl
  69. $(PERL) checksum.pl -o $@ -p boot.bin \
  70. -l $$(($$($(NM) -n max80.elf --radix=decimal | \
  71. grep ' [A-Z] __dram_init_end$$' | \
  72. awk '{ print $$1; }') - (1 << 30))) \
  73. dram.bin
  74. testimg.bin: testimg.elf
  75. $(OBJCOPY) -O binary $< $@
  76. testimg.o: testimg.S testimg.bin
  77. %.hex: %.bin
  78. $(OBJCOPY) -I binary -O ihex $< $@
  79. %.elf: $(LDSCRIPT)
  80. $(CC) $(LDFLAGS) -o $@ $(filter-out $(LDSCRIPT),$^)
  81. %.o: %.c | $(genhdrs)
  82. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -c -o $@ $<
  83. %.s: %.c | $(genhdrs)
  84. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -S -o $@ $<
  85. %.i: %.c | $(genhdrs)
  86. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -E -o $@ $<
  87. %.o: %.S | $(genhdrs)
  88. $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -c -o $@ $<
  89. %.s: %.S | $(genhdrs)
  90. $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -E -o $@ $<
  91. ioregsa.S: ioregs.h ioregsa.pl | $(genhdrs)
  92. $(PERL) ioregsa.pl $< $@
  93. roms/%.o: roms/%.rom rom.S
  94. $(CC) $(SFLAGS) $(SFLAGS_$(F<)) -DNAME='rom_$*' -DFILE='"$<"' \
  95. -c -o $@ rom.S
  96. %.ild: %.ld | $(genhdrs)
  97. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) \
  98. -x assembler-with-cpp \
  99. -fdollars-in-identifiers \
  100. -C -P -E $< | $(PERL) -pe 's:^(#.*)$$:/* $$1 */:' > $@
  101. iodevs.h: ../iodevs.conf ../tools/iodevs.pl
  102. $(PERL) ../tools/iodevs.pl h $< $@
  103. irqtable.h: ../iodevs.conf ../tools/iodevs.pl
  104. $(PERL) ../tools/iodevs.pl irqh $< $@
  105. clean:
  106. for d in . $(SUBDIRS); do \
  107. rm -f $$d/*.o $$d/*.i $$d/*.s $$d/*.elf $$d/*.bin \
  108. $$d/.*.d $$d/*.ild $$d/*.map; \
  109. done
  110. rm -f $(genhdrs) $(gensrcs)
  111. spotless: clean
  112. rm -f *.mem *.hex *.mif checksum.h
  113. -include $(patsubst %,%/.*.d,. $(SUBDIRS))