Makefile 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. CPPFLAGS = $(INCLUDE) \
  10. -march=rv32imc -mabi=ilp32 -mdiv -Os -ggdb3 \
  11. -fwrapv -fvisibility=hidden -fno-strict-aliasing \
  12. -fno-pic -mno-plt -msmall-data-limit=8192 \
  13. -frename-registers \
  14. -mshorten-memrefs -mno-strict-align
  15. # These require newlib to be built with the same options; would be nice
  16. CPPFLAGS_NOT = -fshort-enums -fshort-wchar
  17. CFLAGS = $(CPPFLAGS)
  18. SFLAGS = $(CPPFLAGS) -D__ASSEMBLY__
  19. LDFLAGS = $(CFLAGS) \
  20. -Wl,--section-start=.init=0 -Wl,-q \
  21. -Wl,-z,common-page-size=16 -Wl,-z,max-page-size=16
  22. # Delete output files on error
  23. .DELETE_ON_ERROR:
  24. # Don't delete intermediate files
  25. .SECONDARY:
  26. all: boot.mif
  27. # Generate MIF files for 4 8×2K RAMs
  28. boot_depth := 2048
  29. boot_width := 8
  30. boot_stride := 4
  31. boot.elf: head.o hello.o
  32. %.mif: %.bin bin2mif.pl
  33. $(PERL) bin2mif.pl $< $@ $($*_depth) $($*_width) $($*_stride)
  34. %.hex: %.elf
  35. $(OBJCOPY) -O ihex $< $@
  36. %.mem: %.bin
  37. $(BIN2MEM) $< > $@
  38. %.bin: %.elf
  39. $(OBJCOPY) -O binary $< $@
  40. %.elf:
  41. $(CC) $(LDFLAGS) -o $@ $^
  42. %.o: %.c
  43. $(CC) $(CFLAGS) $(CFLAGS_$<) -c -o $@ $<
  44. %.s: %.c
  45. $(CC) $(CFLAGS) $(CFLAGS_$<) -S -o $@ $<
  46. %.i: %.c
  47. $(CC) $(CFLAGS) $(CFLAGS_$<) -E -o $@ $<
  48. %.o: %.S
  49. $(CC) $(SFLAGS) $(SFLAGS_$<) -c -o $@ $<
  50. %.s: %.S
  51. $(CC) $(SFLAGS) $(SFLAGS_$<) -E -o $@ $<
  52. clean:
  53. rm -f *.o *.i *.s *.elf *.bin
  54. spotless: clean
  55. rm -f *.mem *.hex *.mif