Wirepas SDK
makefile_common.mk
Go to the documentation of this file.
1 include makefile_color.mk
2 
3 # Minimum binaries version required by this SDK version
4 MIN_BOOTLOADER_VERSION := 7
5 MIN_STACK_VERSION := 5.5.0.0
6 
7 # SDK itself
8 SDK_PATH := .
9 INCLUDES := -I$(SDK_PATH)
10 
11 build_directory?= build/
12 board_directory?= board/
13 
14 # Manage verbosity
15 # Command are prefixed by @(D) or @(DD)
16 # By default all is silent
17 D=@
18 DD=@
19 
20 ifeq ($(V),2)
21 # Explicitly print everything
22 D=
23 DD=
24 else ifeq ($(V), 1)
25 # Explicitly print level 1
26 D=
27 endif
28 
29 # General SDK folder structure
30 API_PATH := api/
31 UTIL_PATH := util/
32 HAL_API_PATH := mcu/hal_api/
33 WP_LIB_PATH := libraries/
34 GLOBAL_BUILD := $(build_directory)
35 BOARDS_PATH := $(board_directory)
36 BOARDS_PATH_INTERNAL := board_internal/
37 MCU_PATH := mcu/
38 
39 # General compiler flags (Define it before specific makefile in order to allow app to overwrite it)
40 CFLAGS := -Wall -Werror -Wextra
41 CFLAGS += -std=gnu99 -mthumb -nostartfiles -lgcc -lnosys -ggdb --specs=nano.specs
42 CFLAGS += -Os -ffunction-sections -fdata-sections
43 
44 # Flags for linker
45 LDFLAGS := -Wl,--gc-sections -Wl,-L$(MCU_PATH)common/linker
46 
47 # include global config file
48 -include config.mk
49 
50 # Check that a correct version of python is installed by trying to launch check_python
51 # This script has python3 shebang so try it without specifying interpreter
52 PYTHON_STATUS := $(shell tools/check_python.py > /dev/null 2>&1; echo $$?)
53 ifneq ($(PYTHON_STATUS),0)
54 ifeq ($(python_interpreter),)
55 python=python
56 else
57 python=$(python_interpreter)
58 endif
59 # It looks like python3 cannot be found or does not exist as a cmd (windows)
60 # Force the launch with python cmd
61 PYTHON_STATUS := $(shell $(python) tools/check_python.py > /dev/null; echo $$?)
62 ifneq ($(PYTHON_STATUS),0)
63 $(error Cannot find a suitable python version. You can force the python interpreter from config.mk)
64 endif
65 # Display a message if python version is 2.
66 VERSION := $(shell $(python) tools/check_python.py)
67 ifeq ($(VERSION),2)
68 $(warning ***********************************************************************)
69 $(warning "SDK supports python3 and python2 but uses python3 by default.)
70 $(warning "It looks like python3 is not installed on your system.)
71 $(warning "Using the python2 fallback for now but python2 support will be removed in a future release.)
72 $(warning ***********************************************************************)
73 endif
74 endif
75 
76 #
77 # Tools
78 #
79 # Prefix for Arm tools
80 PREFIX := $(arm_toolchain)arm-none-eabi-
81 
82 # Toolchain programs
83 CC := $(PREFIX)gcc
84 AR := $(PREFIX)ar
85 OBJCOPY := $(PREFIX)objcopy
86 RM := rm
87 MV := mv
88 CP := cp
89 MKDIR := mkdir -p
90 CMP := cmp -s
91 SCRAT_GEN := $(python) tools/genscratchpad.py
92 HEX_GEN := $(python) tools/genhex.py
93 HEXTOOL := $(python) tools/hextool.py
94 FMW_SEL := $(python) tools/firmware_selector.py
95 BOOT_CONF := $(python) tools/bootloader_config.py
96 BL_UPD_CONF := $(python) tools/bl_updater_config.py
97 WIZARD := $(python) tools/sdk_wizard.py
98 HEX2ARRAY32 := $(python) tools/hextoarray32.py
99 MAKE := make
100 
101 # List of available boards found under board/
102 AVAILABLE_BOARDS := $(patsubst $(BOARDS_PATH)%/,%,$(sort $(dir $(wildcard $(BOARDS_PATH)*/.))))
103 
104 # Generic name of stack
105 FIRMWARE_NAME := wpc_stack
106 
107 ifeq (,$(filter clean_all,$(MAKECMDGOALS)))
108 ifeq (,$(filter doxygen,$(MAKECMDGOALS)))
109 ifeq ($(target_board),)
110 $(error No board defined, please use target_board=... on your command line. Available boards are: $(AVAILABLE_BOARDS))
111 endif
112 endif
113 endif
114 
115 BOARD_FOLDER := $(BOARDS_PATH)$(target_board)
116 
117 ifeq (,$(wildcard $(BOARD_FOLDER)))
118 $(error Board $(target_board) doesn't exist. Available boards are: $(AVAILABLE_BOARDS))
119 endif
120 
121 # Board config file
122 BOARD_CONFIG := $(BOARD_FOLDER)/config.mk
123 
124 # Include board specific config
125 -include $(BOARD_CONFIG)
126 
127 # Include makefile for mcu family
128 -include $(MCU_PATH)$(MCU_FAMILY)/makefile
129 
130 # Folder for Wirepas stack binary image
131 IMAGE_PATH := image/
132 
133 # Folder for compressed archives of binaries
134 ARCHIVE_PATH := image/
135 
136 # Add new flags as board and mcu are known
137 CFLAGS += -DTARGET_BOARD=$(target_board)
138 CFLAGS += -DMCU=$(MCU)
139 CFLAGS += -DMCU_SUB=$(MCU_SUB)
140 
141 MCU_UPPER=$(shell echo $(MCU) | tr a-z A-Z)
142 CFLAGS += -D$(MCU_UPPER)
143 
144 CFLAGS += -march=$(ARCH)
145 
146 INCLUDES += -I$(MCU_PATH)common/cmsis -I$(BOARD_FOLDER)
147 
148 # Folder where the application sources are located (and config file)
149 # Can be in different folders, try them one by one
150 APP_POSSIBLE_FOLDER := source/*/$(app_name)/ source/$(app_name)/
151 APP_POSSIBLE_FOLDER += $(app_extra_folder)/$(app_name)/
152 
153 APP_SRCS_PATH := $(wildcard $(APP_POSSIBLE_FOLDER))
154 ifeq (,$(wildcard $(APP_SRCS_PATH)))
155 $(error App $(app_name) doesn't exist)
156 endif
157 
158 # Check if an alternative config is given
159 ifeq ($(app_config),)
160 APP_CONFIG_FILE = config.mk
161 APP_NAME := $(app_name)
162 else
163 $(info Using alternate app config: $(app_config))
164 APP_CONFIG_FILE = $(app_config).mk
165 # Modify app_name for build folder
166 APP_NAME := $(app_name)_$(app_config)
167 endif
168 
169 APP_CONFIG = $(APP_SRCS_PATH)$(APP_CONFIG_FILE)
170 ifeq (,$(wildcard $(APP_CONFIG)))
171 $(error Config file $(APP_CONFIG) doesn't exist)
172 endif
173 
174 # Include app specific config
175 include $(APP_CONFIG)
176 
177 # Build prefixes
178 BUILDPREFIX := $(GLOBAL_BUILD)$(target_board)/
179 BUILDPREFIX_APP := $(BUILDPREFIX)$(APP_NAME)/
180 # Stack is under an app specific folder as config may depend on app
181 BUILDPREFIX_STACK := $(BUILDPREFIX_APP)stack/
182 # Bootloader is under an app specific folder as config may depend on app (unlocked/locked)
183 BUILDPREFIX_BOOTLOADER := $(BUILDPREFIX_APP)bootloader/
184 BUILDPREFIX_TEST_BOOTLOADER := $(BUILDPREFIX_APP)bootloader_test/
185 # Bootloader updater is under an app specific folder as it depends on bootloader
186 BUILDPREFIX_BL_UPDATER := $(BUILDPREFIX_APP)bl_updater/
187 # Board-specific files in archive are extracted here for processing
188 BUILDPREFIX_IMAGE := $(BUILDPREFIX_APP)image/
189 
190 # Where to extract binaries from archive
191 EXTRACT_PATH := $(BUILDPREFIX_IMAGE)
192 
193 # Where to search binaries from, in order
194 FIRMWARE_PATH := $(EXTRACT_PATH):$(IMAGE_PATH)
195 
196 BOOTLOADER_HEX := $(BUILDPREFIX_BOOTLOADER)bootloader.hex
197 BOOTLOADER_TEST_HEX := $(BUILDPREFIX_APP)bootloader_test/bootloader_test.hex
198 BOOTLOADER_CONFIG_INI := $(BUILDPREFIX_APP)bootloader_full_config.ini
199 
200 BL_UPDATER_HEX := $(BUILDPREFIX_BL_UPDATER)bl_updater.hex
201 BL_UPDATER_CMD_LIST := $(APP_SRCS_PATH)bl_updater_cmd_list.conf
202 BL_UPDATER_NEW_BL_DATA := $(BUILDPREFIX_BL_UPDATER)new_bootloader_data.c
203 BL_UPDATER_CONFIG := $(BUILDPREFIX_BL_UPDATER)bl_updater_config.c
204 BL_UPDATER_STACK_BACKUP := $(BUILDPREFIX_BL_UPDATER)stack_backup.c
205 BL_UPDATER_OLD_CONFIG_INI := $(BUILDPREFIX_BL_UPDATER)old_bootloader_config.ini
206 BL_UPDATER_STACK_HEX := $(BUILDPREFIX_STACK)$(FIRMWARE_NAME)_for_bl_updater.hex
207 BL_UPDATER_BUILD_VARIABLES_MK := $(BUILDPREFIX_BL_UPDATER)old_bootloader_build_variables.mk
208 
209 STACK_HEX := $(BUILDPREFIX_STACK)$(FIRMWARE_NAME).hex
210 STACK_WITH_BL_UPDATER_HEX := $(BUILDPREFIX_STACK)$(FIRMWARE_NAME)_with_bl_updater.hex
211 STACK_CONF := $(BUILDPREFIX_STACK)$(FIRMWARE_NAME).conf
212 
213 APP_HEX := $(BUILDPREFIX_APP)$(APP_NAME).hex
214 
215 # Build-time make variables that depend on the selected configuration
216 BUILD_VARIABLES_MK := $(BUILDPREFIX_APP)build_variables.mk
217 
218 # Files to track make command line parameters, to do a rebuild after any changes
219 MAKE_PARAMS_FILE := $(BUILDPREFIX_APP)make_params.txt
220 MAKE_PARAMS_TEMP_FILE := $(BUILDPREFIX_APP)make_params_temp.txt
221 
222 mac_profile?=ism_24_ghz