Makefile 2.3 KB

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