Makefile 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. MAKEFLAGS += -R -r
  2. export PATH := $(CURDIR)/tools/gnu/bin:$(PATH)
  3. CROSS = riscv32-unknown-elf-
  4. CC = $(CROSS)gcc
  5. LD = $(CROSS)ld
  6. OBJCOPY = $(CROSS)objcopy
  7. PERL = perl
  8. INCLUDE = -I. -I./include
  9. include ../riscv-opts.mk
  10. CPPFLAGS = $(INCLUDE) $(riscv_flags)
  11. CFLAGS = $(CPPFLAGS)
  12. SFLAGS = $(CPPFLAGS) -D__ASSEMBLY__
  13. LDFLAGS = $(CFLAGS) \
  14. -Wl,--gc-sections \
  15. -Wl,--section-start=.init=0 \
  16. -Wl,-z,common-page-size=16 \
  17. -Wl,-z,max-page-size=16
  18. gendeps = -MD -MF .$(@F).d
  19. # Delete output files on error
  20. .DELETE_ON_ERROR:
  21. # Don't delete intermediate files
  22. .SECONDARY:
  23. all: boot.mif testdata.hex
  24. # Generate MIF file for 2Kx32 RAM
  25. boot_depth := 2048
  26. boot_width := 32
  27. boot_stride := 1
  28. boot.elf: head.o die.o hello.o console.o
  29. %.mif: %.bin bin2mif.pl
  30. $(PERL) bin2mif.pl $< $@ $($*_depth) $($*_width) $($*_stride)
  31. %.hex: %.elf
  32. $(OBJCOPY) -O ihex $< $@
  33. %.mem: %.bin
  34. $(BIN2MEM) $< > $@
  35. %.bin: %.elf
  36. $(OBJCOPY) -O binary $< $@
  37. %.elf:
  38. $(CC) $(LDFLAGS) -o $@ $^
  39. %.o: %.c
  40. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -c -o $@ $<
  41. %.s: %.c
  42. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -S -o $@ $<
  43. %.i: %.c
  44. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -E -o $@ $<
  45. %.o: %.S
  46. $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -c -o $@ $<
  47. %.s: %.S
  48. $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -E -o $@ $<
  49. testdata.bin: testdata.pl
  50. $(PERL) $< > $@
  51. testdata.hex: testdata.bin
  52. $(OBJCOPY) -I binary -O ihex $< $@
  53. clean:
  54. rm -f *.o *.i *.s *.elf *.bin .*.d
  55. spotless: clean
  56. rm -f *.mem *.hex *.mif
  57. -include .*.d