Makefile 1.5 KB

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