Makefile 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. max80.elf: head.o die.o dummy.o irqtable.o irqasm.o sbrk.o hello.o \
  32. console.o rtc.o \
  33. sdcard.o diskcache.o abcdrive.o \
  34. memset.o memcpy.o \
  35. testdata.o \
  36. fatfs.a
  37. FATFS_C = $(wildcard fatfs/source/*.c)
  38. FATFS_O = $(FATFS_C:.c=.o)
  39. fatfs.a: $(FATFS_O)
  40. rm -f $@
  41. $(AR) cq $@ $(FATFS_O)
  42. CFLAGS_memset.c := -O2
  43. %.mif: %.bin bin2mif.pl
  44. $(PERL) bin2mif.pl $< $@ $($*_depth) $($*_width) $($*_stride)
  45. %.hex: %.elf
  46. $(OBJCOPY) -O ihex $< $@
  47. %.mem: %.bin
  48. $(BIN2MEM) $< > $@
  49. boot.bin: max80.elf
  50. $(OBJCOPY) -O binary -R '.dram*' $< $@
  51. dram.bin: max80.elf
  52. $(OBJCOPY) -O binary -j '.dram*' $< $@
  53. dram.hex: max80.elf
  54. $(OBJCOPY) -O ihex -j '.dram*' $< $@
  55. %.elf: $(LDSCRIPT)
  56. $(CC) $(LDFLAGS) -o $@ $(filter-out $(LDSCRIPT),$^)
  57. %.o: %.c | $(genhdrs)
  58. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -c -o $@ $<
  59. %.s: %.c | $(genhdrs)
  60. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -S -o $@ $<
  61. %.i: %.c | $(genhdrs)
  62. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -E -o $@ $<
  63. %.o: %.S | $(genhdrs)
  64. $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -c -o $@ $<
  65. %.s: %.S | $(genhdrs)
  66. $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -E -o $@ $<
  67. %.ild: %.ld | $(genhdrs)
  68. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) \
  69. -x assembler-with-cpp \
  70. -fdollars-in-identifiers \
  71. -C -P -E $< | $(PERL) -pe 's:^(#.*)$$:/* $$1 */:' > $@
  72. iodevs.h: ../iodevs.conf ../tools/iodevs.pl
  73. $(PERL) ../tools/iodevs.pl h $< $@
  74. irqtable.c: ../iodevs.conf ../tools/iodevs.pl
  75. $(PERL) ../tools/iodevs.pl c $< $@
  76. clean:
  77. rm -f *.o *.i *.s *.elf *.bin .*.d *.ild $(genhdrs) $(gensrcs)
  78. spotless: clean
  79. rm -f *.mem *.hex *.mif
  80. -include .*.d