Skip to content

Commit

Permalink
🧪 [makefile] pass CC_OPTS variable as define string (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
stnolting committed Feb 19, 2024
2 parents f6ea5b9 + c4a0e64 commit f306f6f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
8 changes: 6 additions & 2 deletions docs/datasheet/software.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ GDB_ARGS ?= -ex "target extended-remote localhost:3333"
The following default compiler flags are used for compiling an application. These flags are defined via the
`CC_OPTS` variable.
[TIP]
The makefile's `CC_OPTS` is exported as **define** to be available within a C program; for example
`neorv32_uart0_printf("%s\n", CC_OPTS);`.
[cols="<3,<9"]
[grid="none"]
|=======================
Expand All @@ -268,7 +272,7 @@ The following default compiler flags are used for compiling an application. Thes
| `-mno-fdiv` | Use built-in software functions for floating-point divisions and square roots (since the according instructions are not supported yet).
| `-g` | Include debugging information/symbols in ELF.
| `-mstrict-align` | Unaligned memory accesses cannot be resolved by the hardware and require emulation.
| `-mbranch-cost=...` | Branches cost a lot cycles on a multi-cycle architecture.
| `-mbranch-cost=10` | Branching costs a lot of cycles.
|=======================
:sectnums:
Expand Down Expand Up @@ -341,7 +345,7 @@ __neorv32_ram_base = DEFINED(__neorv32_ram_base) ? __neorv32_ram_base : 0x800000

The region size and base address configuration can be edited by the user - either by explicitly
changing the default values in the linker script or by overriding them when invoking `make`:

.Overriding default `rom` size configuration (configuring 4096 bytes)
[source, bash]
----
Expand Down
31 changes: 18 additions & 13 deletions sw/common/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# ********************************************************************************************* #
# BSD 3-Clause License #
# #
# Copyright (c) 2023, Stephan Nolting. All rights reserved. #
# The NEORV32 RISC-V Processor, https://github.com/stnolting/neorv32 #
# Copyright (c) 2024, Stephan Nolting. All rights reserved. #
# #
# Redistribution and use in source and binary forms, with or without modification, are #
# permitted provided that the following conditions are met: #
Expand All @@ -28,8 +29,6 @@
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED #
# OF THE POSSIBILITY OF SUCH DAMAGE. #
# ********************************************************************************************* #
# The NEORV32 Processor - https://github.com/stnolting/neorv32 (c) Stephan Nolting #
#################################################################################################


Expand Down Expand Up @@ -125,8 +124,8 @@ OBJCOPY = $(RISCV_PREFIX)objcopy
SIZE = $(RISCV_PREFIX)size
GDB = $(RISCV_PREFIX)gdb

# Host native compiler
CC_X86 = gcc -Wall -O -g
# Host's native compiler
CC_HOST = gcc -Wall -O -g

# NEORV32 executable image generator
IMAGE_GEN = $(NEORV32_EXG_PATH)/image_gen
Expand All @@ -138,6 +137,12 @@ CC_OPTS += $(USER_FLAGS)
LD_LIBS = -lm -lc -lgcc
LD_LIBS += $(USER_LIBS)

# Actual flags passed to the compiler
CC_FLAGS = $(CC_OPTS)

# Export compiler flags as define string
CC_FLAGS += -DCC_OPTS="\"$(CC_OPTS)\""


# -----------------------------------------------------------------------------
# Application output definitions
Expand Down Expand Up @@ -169,31 +174,31 @@ target bl_image: CC_OPTS += -Wl,--defsym=make_bootloader=1 -Dmake_bootloader -
# install/compile tools
$(IMAGE_GEN): $(NEORV32_EXG_PATH)/image_gen.c
@echo Compiling $(IMAGE_GEN)
@$(CC_X86) $< -o $(IMAGE_GEN)
@$(CC_HOST) $< -o $(IMAGE_GEN)


# -----------------------------------------------------------------------------
# General targets: Assemble, compile, link, dump
# -----------------------------------------------------------------------------
# Compile app *.s sources (assembly)
%.s.o: %.s
@$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
@$(CC) -c $(CC_FLAGS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@

# Compile app *.S sources (assembly + C pre-processor)
%.S.o: %.S
@$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@
@$(CC) -c $(CC_FLAGS) -I $(NEORV32_INC_PATH) $(ASM_INC) $< -o $@

# Compile app *.c sources
%.c.o: %.c
@$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
@$(CC) -c $(CC_FLAGS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@

# Compile app *.cpp sources
%.cpp.o: %.cpp
@$(CC) -c $(CC_OPTS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@
@$(CC) -c $(CC_FLAGS) -I $(NEORV32_INC_PATH) $(APP_INC) $< -o $@

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

Expand Down Expand Up @@ -282,8 +287,8 @@ endif
@$(SIZE) -V
@echo "---------------- Check: NEORV32 image_gen ----------------"
@$(IMAGE_GEN) -help
@echo "---------------- Check: Native GCC ----------------"
@$(CC_X86) -v
@echo "---------------- Check: Host's native GCC ----------------"
@$(CC_HOST) -v
@echo
@echo "Toolchain check OK"

Expand Down
2 changes: 1 addition & 1 deletion sw/example/coremark/core_portme.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Original Author: Shay Gal-on
/************************/
#define BAUD_RATE (19200)
#define ITERATIONS (2000)
#define FLAGS_STR "see makefile"
#define FLAGS_STR CC_OPTS

/************************/
/* Data types and settings */
Expand Down

0 comments on commit f306f6f

Please sign in to comment.