Makefile 3.1 KB

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