Makefile 1.3 KB

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