Makefile 2.8 KB

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