From 3da1e2e24fb713e87984bc18d7c1c4c44a97fa47 Mon Sep 17 00:00:00 2001 From: Nathaniel Graff Date: Fri, 8 Mar 2019 10:24:33 -0800 Subject: 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 --- scripts/libmetal.mk | 2 +- scripts/standalone.mk | 46 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 5 deletions(-) (limited to 'scripts') 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 ############################################################# @@ -72,11 +77,43 @@ endif 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 -- cgit v1.2.3 From ebe73c01fbdf73b3b4c6beaf089edb7ee394aa0b Mon Sep 17 00:00:00 2001 From: Nathaniel Graff Date: Tue, 12 Mar 2019 09:58:13 -0700 Subject: ELF output has .elf extension Signed-off-by: Nathaniel Graff --- scripts/standalone.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/standalone.mk b/scripts/standalone.mk index 6fa3da4..ac5635f 100644 --- a/scripts/standalone.mk +++ b/scripts/standalone.mk @@ -112,7 +112,7 @@ include $(CONFIGURATION).mk # Software ############################################################# -PROGRAM_ELF ?= $(SRC_DIR)/$(PROGRAM) +PROGRAM_ELF ?= $(SRC_DIR)/$(PROGRAM).elf PROGRAM_HEX ?= $(SRC_DIR)/$(PROGRAM).hex .PHONY: all @@ -135,7 +135,7 @@ $(PROGRAM_ELF): \ $(BSP_DIR)/install/lib/libmetal.a \ $(BSP_DIR)/install/lib/libmetal-gloss.a \ $(BSP_DIR)/metal.lds - $(MAKE) -C $(dir $@) $(notdir $@) \ + $(MAKE) -C $(dir $@) $(basename $(notdir $@)) \ AR=$(RISCV_AR) \ CC=$(RISCV_GCC) \ CXX=$(RISCV_GXX) \ -- cgit v1.2.3 From 1b72ca73835d6064b467a126a392f4539fa2f10a Mon Sep 17 00:00:00 2001 From: Nathaniel Graff Date: Tue, 12 Mar 2019 10:09:10 -0700 Subject: Build metal libs into install/lib/CONFIGURATION Removes the INCLUDE_METAL_SOURCES option. If we want to be able to support multiple build configurations for standalone projects, the Metal library must be rebuilt to take into account those options. An alternative is to put back the prebuilt library option and just remove the configuration option from standalone projects without the Metal library sources. Signed-off-by: Nathaniel Graff --- scripts/libmetal.mk | 23 ++++++++++++++--------- scripts/standalone.mk | 4 ++-- 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'scripts') diff --git a/scripts/libmetal.mk b/scripts/libmetal.mk index 97ce543..b443ca7 100644 --- a/scripts/libmetal.mk +++ b/scripts/libmetal.mk @@ -6,17 +6,22 @@ METAL_SOURCE_PATH ?= freedom-metal METAL_LDSCRIPT = $(BSP_DIR)/metal.lds METAL_HEADER = $(BSP_DIR)/metal.h +METAL_PREFIX = $(abspath $(BSP_DIR)/install) +METAL_BUILD_DIR = $(abspath $(BSP_DIR)/build/$(CONFIGURATION)) +METAL_LIB_DIR = $(abspath $(BSP_DIR)/install/lib/$(CONFIGURATION)) + .PHONY: metal -metal: $(BSP_DIR)/install/stamp +metal: $(METAL_LIB_DIR)/stamp -$(BSP_DIR)/build/Makefile: +$(METAL_BUILD_DIR)/Makefile: @rm -rf $(dir $@) @mkdir -p $(dir $@) cd $(dir $@) && \ CFLAGS="$(RISCV_CFLAGS)" \ $(abspath $(METAL_SOURCE_PATH)/configure) \ --host=$(CROSS_COMPILE) \ - --prefix=$(abspath $(BSP_DIR)/install) \ + --prefix=$(METAL_PREFIX) \ + --libdir=$(METAL_LIB_DIR) \ --disable-maintainer-mode \ --with-preconfigured \ --with-machine-name=$(TARGET) \ @@ -25,21 +30,21 @@ $(BSP_DIR)/build/Makefile: --with-builtin-libgloss touch -c $@ -$(BSP_DIR)/install/stamp: $(BSP_DIR)/build/Makefile - $(MAKE) -C $(abspath $(BSP_DIR)/build) install +$(METAL_LIB_DIR)/stamp: $(BSP_DIR)/build/$(CONFIGURATION)/Makefile + $(MAKE) -C $(abspath $(BSP_DIR)/build/$(CONFIGURATION)) install date > $@ -$(BSP_DIR)/install/lib/libriscv%.a: $(BSP_DIR)/install/stamp ;@: +$(METAL_LIB_DIR)/libriscv%.a: $(METAL_LIB_DIR)/stamp ;@: -$(BSP_DIR)/install/lib/libmetal.a: $(BSP_DIR)/install/lib/libriscv__mmachine__$(TARGET).a +$(METAL_LIB_DIR)/libmetal.a: $(METAL_LIB_DIR)/libriscv__mmachine__$(TARGET).a cp $< $@ -$(BSP_DIR)/install/lib/libmetal-gloss.a: $(BSP_DIR)/install/lib/libriscv__menv__metal.a +$(METAL_LIB_DIR)/libmetal-gloss.a: $(METAL_LIB_DIR)/libriscv__menv__metal.a cp $< $@ .PHONY: clean-metal clean-metal: - rm -rf $(BSP_DIR)/install + rm -rf $(METAL_PREFIX) rm -rf $(BSP_DIR)/build clean: clean-metal diff --git a/scripts/standalone.mk b/scripts/standalone.mk index ac5635f..73b9776 100644 --- a/scripts/standalone.mk +++ b/scripts/standalone.mk @@ -132,8 +132,8 @@ PROGRAM_SRCS = $(wildcard $(SRC_DIR)/*.c) $(wildcard $(SRC_DIR)/*.h) $(wildcard $(PROGRAM_ELF): \ $(PROGRAM_SRCS) \ - $(BSP_DIR)/install/lib/libmetal.a \ - $(BSP_DIR)/install/lib/libmetal-gloss.a \ + $(BSP_DIR)/install/lib/$(CONFIGURATION)/libmetal.a \ + $(BSP_DIR)/install/lib/$(CONFIGURATION)/libmetal-gloss.a \ $(BSP_DIR)/metal.lds $(MAKE) -C $(dir $@) $(basename $(notdir $@)) \ AR=$(RISCV_AR) \ -- cgit v1.2.3 From e106e9e51e8c8e9aca053f1cdc3d49c85df98212 Mon Sep 17 00:00:00 2001 From: Nathaniel Graff Date: Tue, 12 Mar 2019 10:22:46 -0700 Subject: Build program into SRC_DIR/CONFIGURATION/PROGRAM Signed-off-by: Nathaniel Graff --- scripts/standalone.mk | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/standalone.mk b/scripts/standalone.mk index 73b9776..17fec17 100644 --- a/scripts/standalone.mk +++ b/scripts/standalone.mk @@ -112,8 +112,8 @@ include $(CONFIGURATION).mk # Software ############################################################# -PROGRAM_ELF ?= $(SRC_DIR)/$(PROGRAM).elf -PROGRAM_HEX ?= $(SRC_DIR)/$(PROGRAM).hex +PROGRAM_ELF ?= $(SRC_DIR)/$(CONFIGURATION)/$(PROGRAM).elf +PROGRAM_HEX ?= $(SRC_DIR)/$(CONFIGURATION)/$(PROGRAM).hex .PHONY: all all: software @@ -135,7 +135,8 @@ $(PROGRAM_ELF): \ $(BSP_DIR)/install/lib/$(CONFIGURATION)/libmetal.a \ $(BSP_DIR)/install/lib/$(CONFIGURATION)/libmetal-gloss.a \ $(BSP_DIR)/metal.lds - $(MAKE) -C $(dir $@) $(basename $(notdir $@)) \ + mkdir -p $(dir $@) + $(MAKE) -C $(SRC_DIR) $(basename $(notdir $@)) \ AR=$(RISCV_AR) \ CC=$(RISCV_GCC) \ CXX=$(RISCV_GXX) \ @@ -143,6 +144,7 @@ $(PROGRAM_ELF): \ CXXFLAGS="$(RISCV_CXXFLAGS)" \ LDFLAGS="$(RISCV_LDFLAGS)" \ LDLIBS="$(RISCV_LDLIBS)" + mv $(SRC_DIR)/$(basename $(notdir $@)) $@ touch -c $@ $(RISCV_SIZE) $@ @@ -158,6 +160,7 @@ endif .PHONY: clean-software clean-software: $(MAKE) -C $(SRC_DIR) clean + rm -rf $(SRC_DIR)/$(CONFIGURATION) .PHONY: clean clean: clean-software -- cgit v1.2.3 From d971028e328b99867322ad38f540f76e2b83e100 Mon Sep 17 00:00:00 2001 From: Nathaniel Graff Date: Wed, 13 Mar 2019 08:37:07 -0700 Subject: Clean a single Metal configuration at a time Signed-off-by: Nathaniel Graff --- scripts/libmetal.mk | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/libmetal.mk b/scripts/libmetal.mk index b443ca7..b50c599 100644 --- a/scripts/libmetal.mk +++ b/scripts/libmetal.mk @@ -42,10 +42,19 @@ $(METAL_LIB_DIR)/libmetal.a: $(METAL_LIB_DIR)/libriscv__mmachine__$(TARGET).a $(METAL_LIB_DIR)/libmetal-gloss.a: $(METAL_LIB_DIR)/libriscv__menv__metal.a cp $< $@ +# If we're cleaning the last Metal library for a TARGET, then remove +# the install directory, otherwise just remove the built libs for that +# CONFIGURATION. +ifeq ($(words $(wildcard $(METAL_PREFIX)/lib/*)),1) +METAL_CLEAN = $(METAL_PREFIX) +else +METAL_CLEAN = $(METAL_LIB_DIR) +endif + .PHONY: clean-metal clean-metal: - rm -rf $(METAL_PREFIX) - rm -rf $(BSP_DIR)/build + rm -rf $(METAL_CLEAN) + rm -rf $(METAL_BUILD_DIR) clean: clean-metal metal_install: metal -- cgit v1.2.3