Makefile 2.2 KB

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