Skip to content

Commit

Permalink
Added support for USER_LIBS in the command SW makefile. (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
stnolting authored Mar 16, 2023
2 parents e69b598 + c365503 commit 9c42cdf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/datasheet/software.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ Make sure to add the bin folder of RISC-V GCC to your PATH variable.
=== Variables ===
USER_FLAGS - Custom toolchain flags [append only], default ""
USER_LIBS - Custom libraries [append only], default ""
EFFORT - Optimization level, default "-Os"
MARCH - Machine architecture, default "rv32i_zicsr"
MABI - Machine binary interface, default "ilp32"
Expand Down Expand Up @@ -212,6 +213,8 @@ MARCH ?= rv32i_zicsr
MABI ?= ilp32
# User flags for additional configuration (will be added to compiler flags)
USER_FLAGS ?=
# User libraries (will be included by linker)
USER_LIBS ?=
# Relative or absolute path to the NEORV32 home folder
NEORV32_HOME ?= ../../..
# *****************************************************************************
Expand All @@ -229,6 +232,7 @@ NEORV32_HOME ?= ../../..
| `MARCH` | The targeted RISC-V architecture/ISA
| `MABI` | Application binary interface (default: 32-bit integer ABI `ilp32`)
| `USER_FLAGS` | Additional flags that will be forwarded to the compiler tools
| `USER_LIBS` | Additional libraries to include during linking (`*.a`)
| `NEORV32_HOME` | Relative or absolute path to the NEORV32 project home folder; adapt this if the makefile/project is not in the project's default `sw/example` folder
|=======================
Expand Down
12 changes: 9 additions & 3 deletions sw/common/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ CORE_SRC = $(wildcard $(NEORV32_SRC_PATH)/*.c)
CORE_SRC += $(NEORV32_COM_PATH)/crt0.S

# Linker script
LD_SCRIPT = $(NEORV32_COM_PATH)/neorv32.ld
LD_SCRIPT ?= $(NEORV32_COM_PATH)/neorv32.ld

# Main output files
APP_EXE = neorv32_exe.bin
Expand Down Expand Up @@ -126,8 +126,10 @@ IMAGE_GEN = $(NEORV32_EXG_PATH)/image_gen

# Compiler & linker flags
CC_OPTS = -march=$(MARCH) -mabi=$(MABI) $(EFFORT) -Wall -ffunction-sections -fdata-sections -nostartfiles -mno-fdiv
CC_OPTS += -Wl,--gc-sections -lm -lc -lgcc -lc -g
CC_OPTS += -g -Wl,--gc-sections
CC_OPTS += $(USER_FLAGS)
LD_LIBS = -lm -lc -lgcc
LD_LIBS += $(USER_LIBS)


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -184,7 +186,7 @@ $(IMAGE_GEN): $(NEORV32_EXG_PATH)/image_gen.c

# Link object files and show memory utilization
$(APP_ELF): $(OBJ)
@$(CC) $(CC_OPTS) -T $(LD_SCRIPT) $(OBJ) -o $@ -lm
@$(CC) $(CC_OPTS) -T $(LD_SCRIPT) $(OBJ) $(LD_LIBS) -o $@
@echo "Memory utilization:"
@$(SIZE) $(APP_ELF)

Expand Down Expand Up @@ -342,6 +344,9 @@ info:
@echo "---------------- Info: Flags ----------------"
@echo "USER_FLAGS: $(USER_FLAGS)"
@echo "CC_OPTS: $(CC_OPTS)"
@echo "---------------- Info: Libraries ----------------"
@echo "USER_LIBS: $(USER_LIBS)"
@echo "LD_LIBS: $(LD_LIBS)"
@echo "---------------- Info: Host Native GCC Flags ----------------"
@echo "CC_X86: $(CC_X86)"

Expand Down Expand Up @@ -374,6 +379,7 @@ help:
@echo ""
@echo "=== Variables ==="
@echo " USER_FLAGS - Custom toolchain flags [append only]: \"$(USER_FLAGS)\""
@echo " USER_LIBS - Custom libraries [append only]: \"$(USER_LIBS)\""
@echo " EFFORT - Optimization level: \"$(EFFORT)\""
@echo " MARCH - Machine architecture: \"$(MARCH)\""
@echo " MABI - Machine binary interface: \"$(MABI)\""
Expand Down

0 comments on commit 9c42cdf

Please sign in to comment.