2
0

Makefile 1.9 KB

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