diff options
author | Nathaniel Graff <nathaniel.graff@sifive.com> | 2019-03-08 10:24:33 -0800 |
---|---|---|
committer | Nathaniel Graff <nathaniel.graff@sifive.com> | 2019-03-12 13:36:41 -0700 |
commit | 3da1e2e24fb713e87984bc18d7c1c4c44a97fa47 (patch) | |
tree | 132315885208178adde42abf1100acf5379661a8 /scripts | |
parent | 97273d31d812b3ead12fa050fd90c03dafa4f26c (diff) |
Support Debug/Release configurations
- Puts shared flags in scripts/standalone and adds "build configurations"
for debug and release which customize the build flags for specific
purposes.
- Documents CONFIGURATION in Sphinx docs and makefile help
Signed-off-by: Nathaniel Graff <nathaniel.graff@sifive.com>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/libmetal.mk | 2 | ||||
-rw-r--r-- | scripts/standalone.mk | 46 |
2 files changed, 43 insertions, 5 deletions
diff --git a/scripts/libmetal.mk b/scripts/libmetal.mk index e00c9cf..97ce543 100644 --- a/scripts/libmetal.mk +++ b/scripts/libmetal.mk @@ -13,7 +13,7 @@ $(BSP_DIR)/build/Makefile: @rm -rf $(dir $@) @mkdir -p $(dir $@) cd $(dir $@) && \ - CFLAGS="-march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -ffunction-sections -fdata-sections -g -mcmodel=$(RISCV_CMODEL)" \ + CFLAGS="$(RISCV_CFLAGS)" \ $(abspath $(METAL_SOURCE_PATH)/configure) \ --host=$(CROSS_COMPILE) \ --prefix=$(abspath $(BSP_DIR)/install) \ diff --git a/scripts/standalone.mk b/scripts/standalone.mk index fd0c28d..6fa3da4 100644 --- a/scripts/standalone.mk +++ b/scripts/standalone.mk @@ -7,6 +7,11 @@ BSP_DIR ?= $(abspath bsp) # SRC_DIR sets the path to the program source directory SRC_DIR ?= $(abspath src) +# The configuration defaults to Debug. Valid choices are: +# - debug +# - release +CONFIGURATION ?= debug + ############################################################# # BSP loading ############################################################# @@ -73,10 +78,42 @@ SEGGER_JLINK_EXE := JLinkExe SEGGER_JLINK_GDB_SERVER := JLinkGDBServer ############################################################# +# Software Flags +############################################################# + +# Set the arch, ABI, and code model +RISCV_CFLAGS += -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -mcmodel=$(RISCV_CMODEL) +RISCV_CXXFLAGS += -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -mcmodel=$(RISCV_CMODEL) +# Prune unused functions and data +RISCV_CFLAGS += -ffunction-sections -fdata-sections +RISCV_CXXFLAGS += -ffunction-sections -fdata-sections +# Include the Metal headers +RISCV_CFLAGS += -I$(abspath $(BSP_DIR)/install/include/) +RISCV_CXXFLAGS += -I$(abspath $(BSP_DIR)/install/include/) + +# Turn on garbage collection for unused sections +RISCV_LDFLAGS += -Wl,--gc-sections +# Turn off the C standard library +RISCV_LDFLAGS += -nostartfiles -nostdlib +# Find the archive files and linker scripts +RISCV_LDFLAGS += -L$(sort $(dir $(abspath $(filter %.a,$^)))) -T$(abspath $(filter %.lds,$^)) + +# Link to the relevant libraries +RISCV_LDLIBS += -Wl,--start-group -lc -lgcc -lmetal -lmetal-gloss -Wl,--end-group + +# Load the configuration Makefile +CONFIGURATION_FILE = $(wildcard $(CONFIGURATION).mk) +ifeq ($(words $(CONFIGURATION_FILE)),0) +$(error Unable to find the Makefile $(CONFIGURATION).mk for CONFIGURATION=$(CONFIGURATION)) +endif +include $(CONFIGURATION).mk + +############################################################# # Software ############################################################# PROGRAM_ELF ?= $(SRC_DIR)/$(PROGRAM) +PROGRAM_HEX ?= $(SRC_DIR)/$(PROGRAM).hex .PHONY: all all: software @@ -102,10 +139,10 @@ $(PROGRAM_ELF): \ AR=$(RISCV_AR) \ CC=$(RISCV_GCC) \ CXX=$(RISCV_GXX) \ - CFLAGS="-Os -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -ffunction-sections -fdata-sections -g -mcmodel=$(RISCV_CMODEL) -I$(abspath $(BSP_DIR)/install/include/)" \ - CXXFLAGS="-Os -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -ffunction-sections -fdata-sections -g -mcmodel=$(RISCV_CMODEL) -I$(abspath $(BSP_DIR)/install/include/)" \ - LDFLAGS="-nostartfiles -nostdlib -L$(sort $(dir $(abspath $(filter %.a,$^)))) -T$(abspath $(filter %.lds,$^))" \ - LDLIBS="-Wl,--gc-sections -Wl,--start-group -lc -lgcc -lmetal -lmetal-gloss -Wl,--end-group" + CFLAGS="$(RISCV_CFLAGS)" \ + CXXFLAGS="$(RISCV_CXXFLAGS)" \ + LDFLAGS="$(RISCV_LDFLAGS)" \ + LDLIBS="$(RISCV_LDLIBS)" touch -c $@ $(RISCV_SIZE) $@ @@ -121,5 +158,6 @@ endif .PHONY: clean-software clean-software: $(MAKE) -C $(SRC_DIR) clean +.PHONY: clean clean: clean-software |