Makefile 2.3 KB

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