Makefile 1.5 KB

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