Skip to content

Commit

Permalink
sw: Properly encode prerequisite linker inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
colluca committed Sep 4, 2024
1 parent 198f5aa commit 49a9c28
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 6 additions & 3 deletions target/snitch_cluster/sw/apps/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ ifeq ($(SELECT_RUNTIME), banshee)
$(APP)_RISCV_CFLAGS += -DBIST
endif

$(APP)_LIBS += $(SNRT_BUILDDIR)/libsnRuntime.a
$(APP)_LIBS += $(SNRT_LIB)

$(APP)_LIBDIRS = $(dir $($(APP)_LIBS))
$(APP)_LIBNAMES = $(patsubst lib%,%,$(notdir $(basename $($(APP)_LIBS))))

BASE_LD = $(SNRT_DIR)/base.ld
MEMORY_LD ?= $(ROOT)/target/snitch_cluster/sw/runtime/memory.ld

$(APP)_RISCV_LDFLAGS += $(RISCV_LDFLAGS)
$(APP)_RISCV_LDFLAGS += -L$(dir $(MEMORY_LD))
$(APP)_RISCV_LDFLAGS += -T$(abspath $(SNRT_DIR)/base.ld)
$(APP)_RISCV_LDFLAGS += -T$(BASE_LD)
$(APP)_RISCV_LDFLAGS += $(addprefix -L,$($(APP)_LIBDIRS))
$(APP)_RISCV_LDFLAGS += $(addprefix -l,$($(APP)_LIBNAMES))

LD_DEPS = $(MEMORY_LD) $(BASE_LD) $(APP)_LIBS

###########
# Outputs #
###########
Expand Down Expand Up @@ -74,7 +77,7 @@ $(ELF): RISCV_LDFLAGS := $($(APP)_RISCV_LDFLAGS)
$(DEP): $(SRCS) | $($(APP)_BUILD_DIR) $($(APP)_HEADERS)
$(RISCV_CC) $(RISCV_CFLAGS) -MM -MT '$(ELF)' $< > $@

$(ELF): $(SRCS) $(DEP) $($(APP)_LIBS) | $($(APP)_BUILD_DIR)
$(ELF): $(SRCS) $(DEP) $(LD_DEPS) | $($(APP)_BUILD_DIR)
$(RISCV_CC) $(RISCV_CFLAGS) $(RISCV_LDFLAGS) $(SRCS) -o $@

$(DUMP): $(ELF) | $($(APP)_BUILD_DIR)
Expand Down
13 changes: 9 additions & 4 deletions target/snitch_cluster/sw/tests/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ TESTS_BUILDDIR = $(ROOT)/target/snitch_cluster/sw/tests/build
TESTS_RISCV_CFLAGS += $(RISCV_CFLAGS)
TESTS_RISCV_CFLAGS += $(addprefix -I,$(SNRT_INCDIRS))

BASE_LD = $(SNRT_DIR)/base.ld
MEMORY_LD ?= $(ROOT)/target/snitch_cluster/sw/runtime/memory.ld

TESTS_RISCV_LDFLAGS += $(RISCV_LDFLAGS)
TESTS_RISCV_LDFLAGS += -L$(abspath $(SNRT_TARGET_DIR)/..)
TESTS_RISCV_LDFLAGS += -T$(abspath $(SNRT_DIR)/base.ld)
TESTS_RISCV_LDFLAGS += -L$(SNRT_TARGET_DIR)/build
TESTS_RISCV_LDFLAGS += -L$(dir $(MEMORY_LD))
TESTS_RISCV_LDFLAGS += -T$(BASE_LD)
TESTS_RISCV_LDFLAGS += -L$(SNRT_BUILDDIR)
TESTS_RISCV_LDFLAGS += -lsnRuntime

LD_DEPS = $(MEMORY_LD) $(BASE_LD) $(SNRT_LIB)

###########
# Outputs #
###########
Expand Down Expand Up @@ -58,7 +63,7 @@ $(TESTS_BUILDDIR):
$(TESTS_BUILDDIR)/%.d: $(TESTS_SRCDIR)/%.c | $(TESTS_BUILDDIR)
$(RISCV_CC) $(TESTS_RISCV_CFLAGS) -MM -MT '$(TESTS_BUILDDIR)/$*.elf' $< > $@

$(TESTS_BUILDDIR)/%.elf: $(TESTS_SRCDIR)/%.c $(SNRT_LIB) $(TESTS_BUILDDIR)/%.d | $(TESTS_BUILDDIR)
$(TESTS_BUILDDIR)/%.elf: $(TESTS_SRCDIR)/%.c $(LD_DEPS) $(TESTS_BUILDDIR)/%.d | $(TESTS_BUILDDIR)
$(RISCV_CC) $(TESTS_RISCV_CFLAGS) $(TESTS_RISCV_LDFLAGS) $(TESTS_SRCDIR)/$*.c -o $@

$(TESTS_BUILDDIR)/%.dump: $(TESTS_BUILDDIR)/%.elf | $(TESTS_BUILDDIR)
Expand Down

0 comments on commit 49a9c28

Please sign in to comment.