diff --git a/Makefile b/Makefile index 9afa982f2..ff18a14c8 100644 --- a/Makefile +++ b/Makefile @@ -45,12 +45,16 @@ X_HEEP_CFG ?= configs/general.hjson PAD_CFG ?= pad_cfg.hjson EXT_PAD_CFG ?= + # Compiler options are 'gcc' (default) and 'clang' COMPILER ?= gcc # Compiler prefix options are 'riscv32-unknown-' (default) COMPILER_PREFIX ?= riscv32-unknown- +# Compiler flags to be passed (for both linking and compiling) +COMPILER_FLAGS ?= + # Arch options are any RISC-V ISA string supported by the CPU. Default 'rv32imc' ARCH ?= rv32imc @@ -155,7 +159,7 @@ verible: ## @param COMPILER_PREFIX=riscv32-unknown-(default) ## @param ARCH=rv32imc(default), app: clean-app - @$(MAKE) -C sw PROJECT=$(PROJECT) TARGET=$(TARGET) LINKER=$(LINKER) LINK_FOLDER=$(LINK_FOLDER) COMPILER=$(COMPILER) COMPILER_PREFIX=$(COMPILER_PREFIX) ARCH=$(ARCH) SOURCE=$(SOURCE) \ + @$(MAKE) -C sw PROJECT=$(PROJECT) TARGET=$(TARGET) LINKER=$(LINKER) LINK_FOLDER=$(LINK_FOLDER) COMPILER=$(COMPILER) COMPILER_PREFIX=$(COMPILER_PREFIX) COMPILER_FLAGS=$(COMPILER_FLAGS) ARCH=$(ARCH) SOURCE=$(SOURCE) \ || { \ echo "\033[0;31mHmmm... seems like the compilation failed...\033[0m"; \ echo "\033[0;31mIf you do not understand why, it is likely that you either:\033[0m"; \ diff --git a/docs/source/How_to/CompileApps.md b/docs/source/How_to/CompileApps.md index e9dd0eb80..583d099f7 100644 --- a/docs/source/How_to/CompileApps.md +++ b/docs/source/How_to/CompileApps.md @@ -13,8 +13,7 @@ X-HEEP is using CMake to compile and link. Thus, the generated files after havin Don't forget to set the `RISCV` env variable to the compiler folder (without the `/bin` included). ``` -You can select the application to run, the target, compiler, etc. by modifying the parameters. - +You can select the application to run, the target, compiler, etc. by modifying the parameters. The compiler flags explicitely specified by the user will override those already existing (e.g. the default optimization level is `-O2`, passing `COMPILER_FLAGS=-Os` will override the `-O2`). This can be used to pass preprocessor definitions (e.g. pasing `make app COMPILER_FLAGS=-DENABLE_PRINTF` is equivalent to adding `#define ENABLE_PRINTF` on all included files). ``` app PROJECT= TARGET=sim(default),systemc,pynq-z2,nexys-a7-100t,zcu104 LINKER=on_chip(default),flash_load,flash_exec COMPILER=gcc(default),clang COMPILER_PREFIX=riscv32-unknown-(default) ARCH=rv32imc(default), @@ -24,6 +23,7 @@ Params: - LINKER (ex: on_chip(default),flash_load,flash_exec) - COMPILER (ex: gcc(default),clang) - COMPILER_PREFIX (ex: riscv32-unknown-(default)) + - COMPILER_FLAGS (ex: -O0, "-Wall -l") - ARCH (ex: rv32imc(default),) ``` diff --git a/sw/CMakeLists.txt b/sw/CMakeLists.txt index de0608a92..972496e33 100644 --- a/sw/CMakeLists.txt +++ b/sw/CMakeLists.txt @@ -355,6 +355,7 @@ if(NOT ${PROJECT} MATCHES "coremark") -D${CRT_TYPE} \ -D${CRTO} \ -DportasmHANDLE_INTERRUPT=vSystemIrqHandler\ + ${COMPILER_FLAGS}\ ") else() set(COMPILER_LINKER_FLAGS "\ @@ -370,6 +371,11 @@ endif() set(CMAKE_C_FLAGS ${COMPILER_LINKER_FLAGS}) set(CMAKE_CXX_FLAGS ${COMPILER_LINKER_FLAGS}) + +message( "${Yellow}Compiler/linker flags: ${COMPILER_LINKER_FLAGS}${ColourReset}") + +message( "${Magenta}Linked files: ${LINKED_FILES}${ColourReset}") + if (${COMPILER} MATCHES "clang") set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --target=riscv32 \ --gcc-toolchain=${RISCV} \ diff --git a/sw/cmake/targets.mak b/sw/cmake/targets.mak index d7679da5e..abd568169 100644 --- a/sw/cmake/targets.mak +++ b/sw/cmake/targets.mak @@ -36,6 +36,7 @@ build/Makefile : CMakeLists.txt ${CMAKE_DIR}/riscv.cmake -DLINKER:STRING=${LINKER} \ -DCOMPILER:STRING=${COMPILER} \ -DCOMPILER_PREFIX:STRING=${COMPILER_PREFIX} \ + -DCOMPILER_FLAGS:STRING=${COMPILER_FLAGS}\ -DVERBOSE:STRING=${VERBOSE} \ ../