Wirepas SDK
makefile_app.mk
Go to the documentation of this file.
1include makefile_common.mk
2
3.DEFAULT_GOAL := all
4
5#=============================================================================
6# PHASE 1: CONFIGURATION AND SETUP
7# INPUTS:
8# - MCU configuration (MCU_PATH, MCU_FAMILY, MCU, MCU_SUB, MCU_MEM_VAR)
9# - Build paths (BUILDPREFIX_APP, APP_NAME, APP_SRCS_PATH)
10# - Board validation (TARGET_BOARDS, AVAILABLE_BOARDS)
11# - Optional MCU RAM variant (MCU_RAM_VAR)
12# - Target board selection (target_board)
13# OUTPUTS:
14# - Linker script path (LDSCRIPT)
15# - Validated build environment
16# - File paths for version generation and cleanup
17#=============================================================================
18
19# Linker script
20ifndef MCU_RAM_VAR
21LDSCRIPT = $(MCU_PATH)$(MCU_FAMILY)/$(MCU)/linker/gcc_app_$(MCU)$(MCU_SUB)$(MCU_MEM_VAR).ld
22else
23LDSCRIPT = $(MCU_PATH)$(MCU_FAMILY)/$(MCU)/linker/gcc_app_$(MCU)$(MCU_SUB)$(MCU_MEM_VAR)_$(MCU_RAM_VAR).ld
24endif
25
26# Application-specific libraries, e.g., my_lib.a
27LIBS :=
28
29# Compiler-provided libraries, e.g., -lm
30LDLIBS :=
31
32ifeq ($(filter $(TARGET_BOARDS),$(target_board)),)
33 $(error Board $(target_board) is not in supported board list: ($(TARGET_BOARDS)))
34endif
35
36# File to store app version
37VERSION_FILE := $(BUILDPREFIX_APP)version.txt
38
39# App different formats
40APP_ELF := $(BUILDPREFIX_APP)$(APP_NAME).elf
41
42# For backward compatibility as app makefile except SRCS_PATH variable
43SRCS_PATH := $(APP_SRCS_PATH)
44
45#=============================================================================
46# PHASE 2: COMPILER FLAGS GENERATION
47# INPUTS:
48# - Network configuration (default_network_address, default_network_channel)
49# - Security keys (default_network_cipher_key, default_network_authen_key)
50# - Application version (app_major, app_minor, app_maintenance, app_development)
51# - MAC profile selection (mac_profile)
52# - Base compiler flags (CFLAGS)
53# - Security control flag (allow_insecure_key_injection)
54# OUTPUTS:
55# - Preprocessor definitions (-D flags in CFLAGS)
56# - Security warnings/errors to console
57# SECURITY POLICY:
58# - Network keys require allow_insecure_key_injection=yes flag to compile
59# - Build fails with error if keys defined without security flag
60# - Build succeeds with warnings if keys defined with security flag
61# - Address/channel settings have no security restrictions
62#=============================================================================
63
64# Convert default network settings to CFLAGS to be used in code
65ifneq ($(default_network_address),)
66CFLAGS += -DNETWORK_ADDRESS=$(default_network_address)
67endif
68ifneq ($(default_network_channel),)
69CFLAGS += -DNETWORK_CHANNEL=$(default_network_channel)
70endif
71
72# Security-controlled key injection
73ifneq ($(default_network_cipher_key),)
74ifeq ($(allow_insecure_key_injection),yes)
75$(warning ***********************************************************************)
76$(warning WARNING: Insecure key injection is enabled!)
77$(warning Network cipher key is being compiled into the binary.)
78$(warning This is NOT recommended for production builds.)
79$(warning Use app setup application with key provisioning library instead.)
80$(warning ***********************************************************************)
81CFLAGS += -DNET_CIPHER_KEY=$(default_network_cipher_key)
82else
83$(error ERROR: Network cipher key is defined but insecure key injection is not allowed. To compile keys into binary (NOT RECOMMENDED), use: make allow_insecure_key_injection=yes ... For secure key management, use app setup application with key provisioning library.)
84endif
85endif
86
87ifneq ($(default_network_authen_key),)
88ifeq ($(allow_insecure_key_injection),yes)
89$(warning ***********************************************************************)
90$(warning WARNING: Insecure key injection is enabled!)
91$(warning Network authentication key is being compiled into the binary.)
92$(warning This is NOT recommended for production builds.)
93$(warning Use app setup application with key provisioning library instead.)
94$(warning ***********************************************************************)
95CFLAGS += -DNET_AUTHEN_KEY=$(default_network_authen_key)
96else
97$(error ERROR: Network authentication key is defined but insecure key injection is not allowed. To compile keys into binary (NOT RECOMMENDED), use: make allow_insecure_key_injection=yes ... For secure key management, use app setup application with key provisioning library.)
98endif
99endif
100
101# And version numbers
102CFLAGS += -DVER_MAJOR=$(app_major) -DVER_MINOR=$(app_minor) -DVER_MAINT=$(app_maintenance) -DVER_DEV=$(app_development)
103
104# Mac profile
105ifeq ("$(mac_profile)","ism_24_ghz")
106 CFLAGS += -DMAC_PROFILE_ISM24
107else ifeq ("$(mac_profile)","subg")
108 CFLAGS += -DMAC_PROFILE_SUBG
109else
110 CFLAGS += -DMAC_PROFILE_DECTNR
111endif
112
113#=============================================================================
114# PHASE 3: SOURCE COLLECTION AND DEPENDENCY SETUP
115# INPUTS:
116# - Board-specific sources and configuration
117# - Application-specific sources and settings
118# - Debug functionality (INTERNAL_USE_ONLY)
119# - Library configuration and dependencies
120# - Generic utility functions (api.c for all apps)
121# - Wirepas library sources and includes
122# - MCU-specific configuration
123# - Hardware Abstraction Layer drivers
124# - Common MCU sources
125# OUTPUTS:
126# - Source file lists (SRCS, ASM_SRCS)
127# - Include paths (INCLUDES)
128# - Object and dependency file lists (OBJS, DEPS)
129# - Cleanup file list (CLEAN)
130# - Collected libraries for linking
131#=============================================================================
132
133# Include board init part
134-include board/makefile
135
136# Include app specific makefile
137-include $(APP_SRCS_PATH)makefile
138
139
140# Include Libraries config first (dependencies)
141-include $(WP_LIB_PATH)config.mk
142
143# Generic util functions are needed for all apps (api.c)
144-include $(UTIL_PATH)makefile
145
146# Include libraries code
147-include $(WP_LIB_PATH)makefile
148INCLUDES += -I$(WP_LIB_PATH)
149
150# Include MCU config first
151-include $(MCU_PATH)config.mk
152
153# Include MCU HAL drivers code
154-include $(HAL_API_PATH)makefile
155
156# Include common MCU sources
157include $(MCU_PATH)common/makefile
158
159#
160# Sources & includes paths
161#
162SRCS += $(APP_SRCS_PATH)app.c
163INCLUDES += -I$(API_PATH) -I$(APP_SRCS_PATH)include -I$(UTIL_PATH)
164
165# Objects list
166OBJS_ = $(SRCS:.c=.o) $(ASM_SRCS:.s=.o)
167OBJS = $(addprefix $(BUILDPREFIX_APP), $(OBJS_))
168
169# Dependent list
170DEPS_ = $(SRCS:.c=.d)
171DEPS = $(addprefix $(BUILDPREFIX_APP), $(DEPS_))
172
173# Files to be cleaned
174CLEAN := $(OBJS) $(APP_ELF) $(APP_HEX) $(DEPS)
175
176#=============================================================================
177# PHASE 4: COMPILATION RULES
178# INPUTS:
179# - Individual source files (.c and .s files)
180# - Configuration files (APP_CONFIG, BOARD_CONFIG, MCU_CONFIG)
181# - Compiler flags with preprocessor definitions (CFLAGS)
182# - Include paths (-I flags for header locations)
183# - Build tools (CC compiler, MKDIR, color definitions)
184# OUTPUTS:
185# - Compiled object files (.o files)
186# - Dependency files (.d files) for incremental builds
187# - Build directory structure
188# - Compilation progress messages with color coding
189#=============================================================================
190
191$(BUILDPREFIX_APP)%.o : %.c $(APP_SRCS_PATH)makefile $(APP_CONFIG) $(BOARD_CONFIG) $(MCU_CONFIG)
192 $(DD)$(MKDIR) $(@D)
193 @echo "$(COLOR_CC)CC$(COLOR_END) $<"
194 $(D)$(CC) $(INCLUDES) $(CFLAGS) -MMD -MP -c $< -o $@
195
196$(BUILDPREFIX_APP)%.o : %.s
197 $(DD)$(MKDIR) $(@D)
198 @echo "$(COLOR_CC)CC$(COLOR_END) $<"
199 $(D)$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@
200
201#=============================================================================
202# PHASE 5: LINKING
203# INPUTS:
204# - All compiled object files (OBJS list)
205# - Linker script with memory layout (LDSCRIPT)
206# - Compiler and linker flags (CFLAGS, LDFLAGS)
207# - Libraries collected from various components, e.g., my_lib.a (LIBS)
208# - Linker flags for compiler-provided libraries, e.g., -lm (LDLIBS)
209# - Build tools (CC compiler/linker)
210# OUTPUTS:
211# - Executable ELF file (APP_ELF)
212# - Memory layout map file (.map)
213# - Linking progress and memory usage information
214#=============================================================================
215
216$(APP_ELF): $(OBJS) $(LIBS)
217 @echo "$(COLOR_LINK)Linking$(COLOR_END) $@"
218 $(D)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ \
219 -Wl,-Map=$(BUILDPREFIX_APP)$(APP_NAME).map \
220 -Wl,-T,$(LDSCRIPT),--print-memory-usage $(LIBS) $(LDLIBS)
221
222#=============================================================================
223# PHASE 6: FORMAT CONVERSION
224# INPUTS:
225# - ELF executable file (APP_ELF)
226# - Compiler and linker flags (for console display)
227# - Object copy tool and color definitions
228# OUTPUTS:
229# - Intel HEX file for microcontroller programming (APP_HEX)
230# - OTAP file generation support
231# - Build configuration summary
232# - Generation status messages
233#=============================================================================
234
235$(APP_HEX): $(APP_ELF)
236 @echo "$(COLOR_DETAILS)CFLAGS are:\n $(CFLAGS)$(COLOR_END)"
237 @echo "$(COLOR_DETAILS)LDFLAGS are:\n $(LDFLAGS)$(COLOR_END)"
238 @echo "$(COLOR_INFO)Generating:$(COLOR_END) $@"
239 $(D)@$(OBJCOPY) $< -O ihex $@
240
241#=============================================================================
242# PHASE 7: VERSION FILE GENERATION
243# INPUTS:
244# - Application version variables (app_major, app_minor, app_maintenance, app_development)
245# - Git repository commit history
246# - Version file path (VERSION_FILE)
247# OUTPUTS:
248# - Version tracking file (version.txt)
249# - Git SHA for build traceability
250# - Version information for deployment scripts
251#=============================================================================
252
253.PHONY: $(VERSION_FILE)
254$(VERSION_FILE):
255 @echo "app_version=$(app_major).$(app_minor).$(app_maintenance).$(app_development)" > $(@)
256 @echo "sha1=$(shell git log -1 --pretty=format:"%h")" >> $(@)
257
258#=============================================================================
259# MAIN TARGETS AND CLEANUP
260# INPUTS: All previous phases
261# OUTPUTS:
262# - Main build target dependencies
263# - Clean target for removing generated files
264# - Automatic dependency file inclusion
265#=============================================================================
266
267.PHONY: all
268all: $(APP_HEX) $(VERSION_FILE)
269
270clean:
271 $(D)$(RM) -rf $(CLEAN)
272
273-include $(DEPS)