Makefile 2.3 KB

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