Commit fa59e85b authored by Federico Vaga's avatar Federico Vaga

sw:rt: building improvements

parents 7c67f55f 98392eef
*.o
*.bin
*.elf
\ No newline at end of file
*.elf
*.d
......@@ -5,6 +5,8 @@ INSTALL_PREFIX ?= .
PATH_COMMON_RT ?= .
PATH_COMMON_H ?= ../include
TRTL ?= ../../
TRTL_SW ?= $(TRTL)/software
TRTL_HDL ?= $(TRTL)/hdl/rtl
RT_GIT_VERSION = 0x$(shell git rev-parse --short=8 HEAD)
......@@ -13,8 +15,19 @@ CROSS_COMPILE_TARGET ?= riscv32-elf-
# -march=rv32im should be the future option
CFLAGS += -mabi=ilp32 -march=rv32i -ffunction-sections -fdata-sections
LDFLAGS += -lgcc -lc -Wl,--gc-sections
OBJS += $(TRTL)/software/rt/urv/irq.o
OBJS += $(TRTL)/software/rt/urv/emulate.o
# provide search patch for sources
vpath %.c $(TRTL)/software/rt
vpath %.S $(TRTL)/software/rt
BUILDDIR := build
# auto dependency generation from
# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
DEPDIR := .d
$(shell mkdir -p $(BUILDDIR)/$(DEPDIR) >/dev/null)
DEPFLAGS = -MT $@ -MMD -MP -MF $(@D)/$(*F).Td
POSTCOMPILE = mv -f $(@D)/$(*F).Td $(@D)/$(DEPDIR)/$(*F).d && touch $@
CC = $(CROSS_COMPILE_TARGET)gcc
LD = $(CROSS_COMPILE_TARGET)ld
......@@ -63,52 +76,86 @@ endif
CFLAGS += $(EXTRA_CFLAGS)
OBJDIR := urv
OBJS += urv/irq.o
OBJS += urv/emulate.o
OBJS += urv/crt0.o
OBJDIR += lib
OBJS += lib/vsprintf-xint.o
OBJS += lib/printf.o
OBJS += lib/mockturtle-rt-common.o
OBJS += $(TRTL)/software/rt/urv/crt0.o
OBJS += $(TRTL)/software/rt/lib/vsprintf-xint.o
OBJS += $(TRTL)/software/rt/lib/printf.o
OBJS += $(TRTL)/software/rt/lib/mockturtle-rt-common.o
ifeq ($(MOCKTURTLE_FRAMEWORK_ENABLE), 1)
OBJS += $(TRTL)/software/rt/framework/mockturtle-frm-core.o
OBJS += $(TRTL)/software/rt/framework/mockturtle-frm-debug.o
OBJS += $(TRTL)/software/rt/framework/mockturtle-frm-action.o
OBJS += $(TRTL)/software/rt/framework/mockturtle-frm-mqueue.o
OBJDIR += framework
OBJS += framework/mockturtle-frm-core.o
OBJS += framework/mockturtle-frm-debug.o
OBJS += framework/mockturtle-frm-action.o
OBJS += framework/mockturtle-frm-mqueue.o
endif
OBJS_BUILD = $(addprefix $(BUILDDIR)/, $(OBJS))
OBJDIR_BUILD = $(addprefix $(BUILDDIR)/, $(OBJDIR))
MOCKTURTLE_LDSCRIPT ?= $(TRTL)/software/rt/urv/mockturtle.ld
all: post-build
.PHONY: all clean check-def
all: $(OUTPUT).bin
headers:
@make -C $(TRTL_SW) $@
WBGEN_FILES = mt_cpu_csr.wb mt_cpu_lr.wb
WBGEN_HEADERS = mockturtle_cpu_csr.h mockturtle_cpu_lr.h
pre-build: clean headers
# .wb files should simply be there. This is used to check against the changes
$(addprefix $(TRTL_HDL)/cpu/,$(WBGEN_FILES)):
# dependencies between .h and .wb files
$(TRTL_SW)/include/hw/mockturtle_cpu_csr.h: $(TRTL_HDL)/cpu/mt_cpu_csr.wb
$(TRTL_SW)/include/hw/mockturtle_cpu_lr.h: $(TRTL_HDL)/cpu/mt_cpu_lr.wb
# target to let wbgen2 to generate headers
$(addprefix $(TRTL_SW)/include/hw/,$(WBGEN_HEADERS)): | check-def
make -C $(TRTL_SW) headers
# check needed env variables
check-def:
ifndef OUTPUT
@echo "OUTPUT variable is mandatory"
@exit 1
endif
post-build: $(OUTPUT)
$(SIZE) $(OUTPUT).elf
# create dirs for object files
$(OBJDIR_BUILD):
mkdir -p $@
mkdir -p $@/$(DEPDIR)
$(OBJS_BUILD): | $(OBJDIR_BUILD)
$(OUTPUT): pre-build $(MOCKTURTLE_LDSCRIPT) $(OBJS)
${CC} $(CFLAGS) $(LDFLAGS) -o $(OUTPUT).elf -nostartfiles $(OBJS) -T $(MOCKTURTLE_LDSCRIPT)
$(OUTPUT).elf: $(addprefix $(TRTL_SW)/include/hw/,$(WBGEN_HEADERS)) $(MOCKTURTLE_LDSCRIPT) $(OBJS_BUILD) | check-def
${CC} $(CFLAGS) $(LDFLAGS) -o $(OUTPUT).elf -nostartfiles $(OBJS_BUILD) -T $(MOCKTURTLE_LDSCRIPT)
$(OUTPUT).bin: $(OUTPUT).elf | check-def
${OBJCOPY} --remove-section .smem -O binary $(OUTPUT).elf $(OUTPUT).bin
$(SIZE) $(OUTPUT).elf
$(TRTL)/software/rt/urv/emulate.o: $(TRTL)/software/rt/urv/emulate.c
${CC} $(CFLAGS) -march=rv32i -c $^ -o $@
$(BUILDDIR)/urv/emulate.o: urv/emulate.c
${CC} $(DEPFLAGS) $(CFLAGS) -march=rv32i -c $< -o $@
$(POSTCOMPILE)
%.o: %.c
${CC} $(CFLAGS) $(LDFLAGS) -c $^ -o $@
$(BUILDDIR)/%.o: %.c
${CC} $(DEPFLAGS) $(CFLAGS) $(LDFLAGS) -c $< -o $@
$(POSTCOMPILE)
%.o: %.S
${CC} $(CFLAGS) $(LDFLAGS) -c $^ -o $@
$(BUILDDIR)/%.o: %.S
${CC} $(DEPFLAGS) $(CFLAGS) $(LDFLAGS) -c $< -o $@
$(POSTCOMPILE)
clean:
@rm -f $(OBJS) $(OUTPUT).bin $(OUTPUT).elf
rm -f $(OUTPUT).bin $(OUTPUT).elf
rm -rf $(BUILDDIR)
install:
@cp $(OUTPUT).bin $(INSTALL_PREFIX)
.PHONY: all clean pre-build post-build headers
include $(wildcard $(patsubst %,%/.d/*.d,$(basename $(OBJDIR_BUILD))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment