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