82 lines
1.2 KiB
Plaintext
82 lines
1.2 KiB
Plaintext
|
|
||
|
ARCH=riscv64-unknown-elf
|
||
|
GNU_DIR=$(HOME)/riscv/riscv/
|
||
|
GNU_BIN=$(GNU_DIR)/bin
|
||
|
|
||
|
|
||
|
CC=$(GNU_BIN)/$(ARCH)-gcc
|
||
|
CXX=$(GNU_BIN)/$(ARCH)-g++
|
||
|
AS=$(GNU_BIN)/$(ARCH)-as
|
||
|
LD=$(GNU_BIN)/$(ARCH)-ld
|
||
|
OBJCOPY=$(GNU_BIN)/$(ARCH)-objcopy
|
||
|
OBJDUMP=$(GNU_BIN)/$(ARCH)-objdump
|
||
|
SIZE=$(GNU_BIN)/$(ARCH)-size
|
||
|
AR=$(GNU_BIN)/$(ARCH)-ar
|
||
|
RANLIB=$(GNU_BIN)/$(ARCH)-ranlib
|
||
|
|
||
|
|
||
|
CFLAGS+=-ffreestanding
|
||
|
CFLAGS+=-fno-pic
|
||
|
CFLAGS+=-march=rv32i -mabi=ilp32
|
||
|
CFLAGS+= -g
|
||
|
|
||
|
|
||
|
LDFLAGS+=-nostdlib
|
||
|
LDFLAGS+=-Wl,-Ttext=0x00000000
|
||
|
|
||
|
# see: https://github.com/riscv/riscv-gcc/issues/120
|
||
|
#LDFLAGS+=-Wl,--no-relax
|
||
|
|
||
|
|
||
|
|
||
|
ASFLAGS+=$(CFLAGS)
|
||
|
CXXFLAGS+=$(CFLAGS)
|
||
|
|
||
|
CLEAN_DIRS=$(SUBDIRS:%=clean-%)
|
||
|
ALL_DIRS=$(SUBDIRS:%=all-%)
|
||
|
|
||
|
OBJDUMPFLAGS+=-Mnumeric,no-aliases
|
||
|
|
||
|
.PHONY: all clean world $(CLEAN_DIRS) $(ALL_DIRS)
|
||
|
|
||
|
|
||
|
%.bin : %
|
||
|
$(OBJCOPY) $< -O binary $@
|
||
|
|
||
|
%.lst : %
|
||
|
$(OBJDUMP) $(OBJDUMPFLAGS) -dr --disassemble-all $< > $<.lst
|
||
|
|
||
|
% : %.o
|
||
|
$(LINK.cc) $(LDFLAGS) -o $@ $^ $(LDLIBS)
|
||
|
$(SIZE) -x -A $@
|
||
|
|
||
|
%.s: %.c
|
||
|
$(COMPILE.c) -S -o $@ $<
|
||
|
|
||
|
%.s: %.cc
|
||
|
$(COMPILE.cc) -S -o $@ $<
|
||
|
|
||
|
%.o: %.c
|
||
|
$(COMPILE.c) -o $@ $<
|
||
|
|
||
|
%.o: %.cc
|
||
|
$(COMPILE.cc) -o $@ $<
|
||
|
|
||
|
%.srec: %
|
||
|
$(OBJCOPY) $< -O srec $@
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
all:: $(ALL_DIRS)
|
||
|
|
||
|
clean:: $(CLEAN_DIRS)
|
||
|
|
||
|
$(ALL_DIRS)::
|
||
|
$(MAKE) -C $(@:all-%=%) all
|
||
|
|
||
|
$(CLEAN_DIRS)::
|
||
|
$(MAKE) -C $(@:clean-%=%) clean
|
||
|
|
||
|
world:: clean all
|