Makefile 1.5 KB

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