Makefile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. INCLUDE = -I. -I./include -I./fatfs/source
  11. include ../riscv-opts.mk
  12. CPPFLAGS = $(INCLUDE) $(riscv_flags)
  13. CFLAGS = $(CPPFLAGS) -W -Wextra
  14. SFLAGS = $(CPPFLAGS) -D__ASSEMBLY__
  15. LDSCRIPT = max80.ild
  16. LDFLAGS = $(CFLAGS) \
  17. -Wl,-Map=$*.map \
  18. -Wl,--gc-sections \
  19. -Wl,--sort-section=alignment \
  20. -Wl,-T,$(LDSCRIPT) \
  21. -Wl,-z,common-page-size=16 \
  22. -Wl,-z,max-page-size=16
  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: boot.bin dram.hex checksum.h
  31. ROMS := $(wildcard roms/*.rom)
  32. ROMOBJS = $(ROMS:.rom=.o)
  33. max80.elf: head.o dummy.o die.o main.o system.o \
  34. ioregsa.o irqasm.o irqtable.o spurious_irq.o sbrk.o \
  35. console.o rtc.o romcopy.o \
  36. sdcard.o diskcache.o \
  37. abcmem.o abcio.o abcdisk.o abcrtc.o abcpun80.o \
  38. memset.o memcpy.o \
  39. runtest.o start_test.o \
  40. $(ROMOBJS) \
  41. testimg.o \
  42. fatfs.a
  43. testimg.elf: head.o dummy.o die.o test/main.o test/system.o \
  44. ioregsa.o irqasm.o irqtable.o spurious_irq.o sbrk.o \
  45. console.o rtc.o romcopy.o \
  46. sdcard.o diskcache.o \
  47. abcmem.o abcio.o abcdisk.o abcrtc.o abcpun80.o \
  48. memset.o memcpy.o \
  49. testdata.o $(ROMOBJS) \
  50. fatfs.a
  51. FATFS_C = $(wildcard fatfs/source/*.c)
  52. FATFS_O = $(FATFS_C:.c=.o)
  53. fatfs.a: $(FATFS_O)
  54. rm -f $@
  55. $(AR) cq $@ $(FATFS_O)
  56. CFLAGS_memset.c := -O2
  57. %.hex: %.elf
  58. $(OBJCOPY) -O ihex $< $@
  59. %.mem: %.bin
  60. $(BIN2MEM) $< > $@
  61. boot.bin: max80.elf
  62. $(OBJCOPY) -O binary -R '.dram*' $< $@
  63. dram.bin: max80.elf
  64. $(OBJCOPY) -O binary -j '.dram*' $< $@
  65. checksum.h: dram.bin boot.bin checksum.pl
  66. $(PERL) checksum.pl -o $@ -p boot.bin \
  67. -l $$(($$($(NM) -n max80.elf --radix=decimal | \
  68. grep ' [A-Z] __dram_init_end$$' | \
  69. awk '{ print $$1; }') - (1 << 30))) \
  70. dram.bin
  71. testimg.bin: testimg.elf
  72. $(OBJCOPY) -O binary $< $@
  73. testimg.o: testimg.S testimg.bin
  74. %.hex: %.bin
  75. $(OBJCOPY) -I binary -O ihex $< $@
  76. %.elf: $(LDSCRIPT)
  77. $(CC) $(LDFLAGS) -o $@ $(filter-out $(LDSCRIPT),$^)
  78. %.o: %.c | $(genhdrs)
  79. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -c -o $@ $<
  80. %.s: %.c | $(genhdrs)
  81. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -S -o $@ $<
  82. %.i: %.c | $(genhdrs)
  83. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -E -o $@ $<
  84. %.o: %.S | $(genhdrs)
  85. $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -c -o $@ $<
  86. %.s: %.S | $(genhdrs)
  87. $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -E -o $@ $<
  88. ioregsa.S: ioregs.h ioregsa.pl | $(genhdrs)
  89. $(PERL) ioregsa.pl $< $@
  90. roms/%.o: roms/%.rom rom.S
  91. $(CC) $(SFLAGS) $(SFLAGS_$(F<)) -DNAME='rom_$*' -DFILE='"$<"' \
  92. -c -o $@ rom.S
  93. %.ild: %.ld | $(genhdrs)
  94. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) \
  95. -x assembler-with-cpp \
  96. -fdollars-in-identifiers \
  97. -C -P -E $< | $(PERL) -pe 's:^(#.*)$$:/* $$1 */:' > $@
  98. iodevs.h: ../iodevs.conf ../tools/iodevs.pl
  99. $(PERL) ../tools/iodevs.pl h $< $@
  100. irqtable.h: ../iodevs.conf ../tools/iodevs.pl
  101. $(PERL) ../tools/iodevs.pl irqh $< $@
  102. clean:
  103. for d in . $(SUBDIRS); do \
  104. rm -f $$d/*.o $$d/*.i $$d/*.s $$d/*.elf $$d/*.bin \
  105. $$d/.*.d $$d/*.ild $$d/*.map; \
  106. done
  107. rm -f $(genhdrs) $(gensrcs)
  108. spotless: clean
  109. rm -f *.mem *.hex *.mif checksum.h
  110. -include $(patsubst %,%/.*.d,. $(SUBDIRS))