From d74a92bf4596d229a3176fab2f91c45eabff6d3a Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Mar 2020 14:06:51 +0700 Subject: makefile clean up allow board to define CROSS_COMPILE (default to arm gcc) --- examples/make.mk | 65 +++++++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 38 deletions(-) (limited to 'examples/make.mk') diff --git a/examples/make.mk b/examples/make.mk index 25b618896..5fc596f63 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -1,56 +1,45 @@ -# +# --------------------------------------- # Common make definition for all examples -# +# --------------------------------------- -# Compiler -ifeq ($(BOARD), msp_exp430f5529lp) - CROSS_COMPILE = msp430-elf- -else ifeq ($(BOARD), fomu) - CROSS_COMPILE = riscv-none-embed- -else - CROSS_COMPILE = arm-none-eabi- +#-------------- Select the board to build for. ------------ +BOARD_LIST = $(sort $(subst /.,,$(subst $(TOP)/hw/bsp/,,$(wildcard $(TOP)/hw/bsp/*/.)))) + +ifeq ($(filter $(BOARD),$(BOARD_LIST)),) + $(info You must provide a BOARD parameter with 'BOARD=', supported boards are:) + $(foreach b,$(BOARD_LIST),$(info - $(b))) + $(error Invalid BOARD specified) endif -CC = $(CROSS_COMPILE)gcc -CXX = $(CROSS_COMPILE)g++ -OBJCOPY = $(CROSS_COMPILE)objcopy -SIZE = $(CROSS_COMPILE)size -MKDIR = mkdir -SED = sed -CP = cp -RM = rm -PYTHON ?= python +# Handy check parameter function check_defined = \ $(strip $(foreach 1,$1, \ $(call __check_defined,$1,$(strip $(value 2))))) __check_defined = \ $(if $(value $1),, \ $(error Undefined make flag: $1$(if $2, ($2)))) - - -define newline - - -endef - -# Select the board to build for. -ifeq ($(BOARD),) - $(info You must provide a BOARD parameter with 'BOARD=') - $(info Supported boards are:) - $(info $(sort $(subst /.,,$(subst $(TOP)/hw/bsp/, $(newline)-,$(wildcard $(TOP)/hw/bsp/*/.))))) - $(error BOARD not defined) -else - ifeq ($(wildcard $(TOP)/hw/bsp/$(BOARD)/.),) - $(error Invalid BOARD specified) - endif -endif - + # Build directory BUILD = _build/build-$(BOARD) -# Board specific +# Board specific define include $(TOP)/hw/bsp/$(BOARD)/board.mk +#-------------- Cross Compiler ------------ +# Can be set by board, default to ARM GCC +CROSS_COMPILE ?= arm-none-eabi- + +CC = $(CROSS_COMPILE)gcc +CXX = $(CROSS_COMPILE)g++ +OBJCOPY = $(CROSS_COMPILE)objcopy +SIZE = $(CROSS_COMPILE)size +MKDIR = mkdir +SED = sed +CP = cp +RM = rm + +#-------------- Source files and compiler flags -------------- + # Include all source C in board folder SRC_C += hw/bsp/board.c SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/hw/bsp/$(BOARD)/*.c)) -- cgit v1.3.1 From 09262d7f7e7bc462e2badac6caeb03cc57bf6761 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 26 Mar 2020 22:04:24 +0700 Subject: house keeping --- examples/make.mk | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'examples/make.mk') diff --git a/examples/make.mk b/examples/make.mk index 5fc596f63..f2a8b979e 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -46,26 +46,24 @@ SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/hw/bsp/$(BOARD)/*.c)) # Compiler Flags CFLAGS += \ + -fdata-sections \ + -ffunction-sections \ -fsingle-precision-constant \ -fno-strict-aliasing \ -Wdouble-promotion \ - -Wno-endif-labels \ -Wstrict-prototypes \ -Wall \ -Wextra \ -Werror \ - -Werror-implicit-function-declaration \ -Wfatal-errors \ + -Werror-implicit-function-declaration \ -Wfloat-equal \ -Wundef \ -Wshadow \ -Wwrite-strings \ -Wsign-compare \ -Wmissing-format-attribute \ - -Wno-deprecated-declarations \ - -Wunreachable-code \ - -ffunction-sections \ - -fdata-sections + -Wunreachable-code # This causes lots of warning with nrf5x build due to nrfx code # CFLAGS += -Wcast-align -- cgit v1.3.1