Skip to content

Commit

Permalink
Added COMPILER_FLAGS to Makefile (#624)
Browse files Browse the repository at this point in the history
* Added a Makefile variable COMPILER_FLAGS to ad compiler/linker flags passed down to cmake

* Added documentation on compiler flags

* Added comment on docu about using -DMYDEFINE

* deleted unwanted doc files
  • Loading branch information
JuanSapriza authored Jan 21, 2025
1 parent 5473b56 commit 01514b8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -155,7 +159,7 @@ verible:
## @param COMPILER_PREFIX=riscv32-unknown-(default)
## @param ARCH=rv32imc(default),<any_RISC-V_ISA_string_supported_by_the_CPU>
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"; \
Expand Down
4 changes: 2 additions & 2 deletions docs/source/How_to/CompileApps.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<folder_name_of_the_project_to_be_built> 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),<any_RISC-V_ISA_string_supported_by_the_CPU>
Expand All @@ -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<library>")
- ARCH (ex: rv32imc(default),<any_RISC-V_ISA_string_supported_by_the_CPU>)
```

Expand Down
6 changes: 6 additions & 0 deletions sw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ if(NOT ${PROJECT} MATCHES "coremark")
-D${CRT_TYPE} \
-D${CRTO} \
-DportasmHANDLE_INTERRUPT=vSystemIrqHandler\
${COMPILER_FLAGS}\
")
else()
set(COMPILER_LINKER_FLAGS "\
Expand All @@ -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} \
Expand Down
1 change: 1 addition & 0 deletions sw/cmake/targets.mak
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
../

Expand Down

0 comments on commit 01514b8

Please sign in to comment.