Makefile 3.1 KB

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