Makefile 1.9 KB

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