Makefile 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. PERL = perl
  9. INCLUDE = -I. -I./include -I./fatfs/source
  10. include ../riscv-opts.mk
  11. CPPFLAGS = $(INCLUDE) $(riscv_flags)
  12. CFLAGS = $(CPPFLAGS) -W -Wextra
  13. SFLAGS = $(CPPFLAGS) -D__ASSEMBLY__
  14. LDSCRIPT = max80.ild
  15. LDFLAGS = $(CFLAGS) \
  16. -Wl,-Map=$*.map \
  17. -Wl,--gc-sections \
  18. -Wl,--sort-section=alignment \
  19. -Wl,-T,$(LDSCRIPT) \
  20. -Wl,-z,common-page-size=16 \
  21. -Wl,-z,max-page-size=16
  22. gendeps = -MD -MF $(@D)/.$(@F).d -MT $@
  23. # Delete output files on error
  24. .DELETE_ON_ERROR:
  25. # Don't delete intermediate files
  26. .SECONDARY:
  27. genhdrs = iodevs.h irqtable.h
  28. gensrcs =
  29. all: boot.mif dram.hex
  30. # Generate MIF file for 8Kx32 RAM
  31. boot_depth := 8192
  32. boot_width := 32
  33. boot_stride := 1
  34. ROMS := $(wildcard roms/*.rom)
  35. ROMOBJS = $(ROMS:.rom=.o)
  36. max80.elf: head.o dummy.o die.o main.o system.o \
  37. irqasm.o irqtable.o spurious_irq.o sbrk.o \
  38. console.o rtc.o romcopy.o \
  39. sdcard.o diskcache.o \
  40. abcmem.o abcio.o abcdisk.o abcrtc.o \
  41. memset.o memcpy.o \
  42. runtest.o start_test.o \
  43. $(ROMOBJS) \
  44. testimg.o \
  45. fatfs.a
  46. testimg.elf: head.o dummy.o die.o test/main.o test/system.o \
  47. irqasm.o irqtable.o spurious_irq.o sbrk.o \
  48. console.o rtc.o romcopy.o \
  49. sdcard.o diskcache.o \
  50. abcmem.o abcio.o abcdisk.o abcrtc.o \
  51. memset.o memcpy.o \
  52. testdata.o $(ROMOBJS) \
  53. fatfs.a
  54. FATFS_C = $(wildcard fatfs/source/*.c)
  55. FATFS_O = $(FATFS_C:.c=.o)
  56. fatfs.a: $(FATFS_O)
  57. rm -f $@
  58. $(AR) cq $@ $(FATFS_O)
  59. CFLAGS_memset.c := -O2
  60. %.mif: %.bin bin2mif.pl
  61. $(PERL) bin2mif.pl $< $@ $($*_depth) $($*_width) $($*_stride)
  62. %.hex: %.elf
  63. $(OBJCOPY) -O ihex $< $@
  64. %.mem: %.bin
  65. $(BIN2MEM) $< > $@
  66. boot.bin: max80.elf
  67. $(OBJCOPY) -O binary -R '.dram*' $< $@
  68. dram.bin: max80.elf
  69. $(OBJCOPY) -O binary -j '.dram*' $< $@
  70. testimg.bin: testimg.elf
  71. $(OBJCOPY) -O binary $< $@
  72. testimg.o: testimg.S testimg.bin
  73. %.hex: %.bin
  74. $(OBJCOPY) -I binary -O ihex $< $@
  75. %.elf: $(LDSCRIPT)
  76. $(CC) $(LDFLAGS) -o $@ $(filter-out $(LDSCRIPT),$^)
  77. %.o: %.c | $(genhdrs)
  78. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -c -o $@ $<
  79. %.s: %.c | $(genhdrs)
  80. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -S -o $@ $<
  81. %.i: %.c | $(genhdrs)
  82. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -E -o $@ $<
  83. %.o: %.S | $(genhdrs)
  84. $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -c -o $@ $<
  85. %.s: %.S | $(genhdrs)
  86. $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -E -o $@ $<
  87. roms/%.o: roms/%.rom rom.S
  88. $(CC) $(SFLAGS) $(SFLAGS_$(F<)) -DNAME='rom_$*' -DFILE='"$<"' \
  89. -c -o $@ rom.S
  90. %.ild: %.ld | $(genhdrs)
  91. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) \
  92. -x assembler-with-cpp \
  93. -fdollars-in-identifiers \
  94. -C -P -E $< | $(PERL) -pe 's:^(#.*)$$:/* $$1 */:' > $@
  95. iodevs.h: ../iodevs.conf ../tools/iodevs.pl
  96. $(PERL) ../tools/iodevs.pl h $< $@
  97. irqtable.h: ../iodevs.conf ../tools/iodevs.pl
  98. $(PERL) ../tools/iodevs.pl irqh $< $@
  99. clean:
  100. for d in . $(SUBDIRS); do \
  101. rm -f $$d/*.o $$d/*.i $$d/*.s $$d/*.elf $$d/*.bin \
  102. $$d/.*.d $$d/*.ild $$d/*.map; \
  103. done
  104. rm -f $(genhdrs) $(gensrcs)
  105. spotless: clean
  106. rm -f *.mem *.hex *.mif
  107. -include $(patsubst %,%/.*.d,. $(SUBDIRS))