1 include makefile_common.mk
5 #=============================================================================
6 # PHASE 1: CONFIGURATION AND SETUP
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)
14 # - Linker script path (LDSCRIPT)
15 # - Validated build environment
16 # - File paths for version generation and cleanup
17 #=============================================================================
21 LDSCRIPT = $(MCU_PATH)$(MCU_FAMILY)/$(MCU)/linker/gcc_app_$(MCU)$(MCU_SUB)$(MCU_MEM_VAR).ld
23 LDSCRIPT = $(MCU_PATH)$(MCU_FAMILY)/$(MCU)/linker/gcc_app_$(MCU)$(MCU_SUB)$(MCU_MEM_VAR)_$(MCU_RAM_VAR).ld
26 # Application-specific libraries, e.g., my_lib.a
29 # Compiler-provided libraries, e.g., -lm
32 ifeq ($(filter $(TARGET_BOARDS),$(target_board)),)
33 $(error Board $(target_board) is not in supported board list: ($(TARGET_BOARDS)))
36 # File to store app version
37 VERSION_FILE := $(BUILDPREFIX_APP)version.txt
39 # App different formats
40 APP_ELF := $(BUILDPREFIX_APP)$(APP_NAME).elf
42 # For backward compatibility as app makefile except SRCS_PATH variable
43 SRCS_PATH := $(APP_SRCS_PATH)
45 #=============================================================================
46 # PHASE 2: COMPILER FLAGS GENERATION
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)
55 # - Preprocessor definitions (-D flags in CFLAGS)
56 # - Security warnings/errors to console
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 #=============================================================================
64 # Convert default network settings to CFLAGS to be used in code
65 ifneq ($(default_network_address),)
66 CFLAGS += -DNETWORK_ADDRESS=$(default_network_address)
68 ifneq ($(default_network_channel),)
69 CFLAGS += -DNETWORK_CHANNEL=$(default_network_channel)
72 # Security-controlled key injection
73 ifneq ($(default_network_cipher_key),)
74 ifeq ($(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 ***********************************************************************)
81 CFLAGS += -DNET_CIPHER_KEY=$(default_network_cipher_key)
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.)
87 ifneq ($(default_network_authen_key),)
88 ifeq ($(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 ***********************************************************************)
95 CFLAGS += -DNET_AUTHEN_KEY=$(default_network_authen_key)
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.)
101 # And version numbers
102 CFLAGS += -DVER_MAJOR=$(app_major) -DVER_MINOR=$(app_minor) -DVER_MAINT=$(app_maintenance) -DVER_DEV=$(app_development)
105 ifeq ("$(mac_profile)","ism_24_ghz")
106 CFLAGS += -DMAC_PROFILE_ISM24
107 else ifeq ("$(mac_profile)","subg")
108 CFLAGS += -DMAC_PROFILE_SUBG
110 CFLAGS += -DMAC_PROFILE_DECTNR
113 #=============================================================================
114 # PHASE 3: SOURCE COLLECTION AND DEPENDENCY SETUP
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
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 #=============================================================================
133 # Include board init part
134 -include board/makefile
136 # Include app specific makefile
137 -include $(APP_SRCS_PATH)makefile
140 # Include Libraries config first (dependencies)
141 -include $(WP_LIB_PATH)config.mk
143 # Generic util functions are needed for all apps (api.c)
144 -include $(UTIL_PATH)makefile
146 # Include libraries code
147 -include $(WP_LIB_PATH)makefile
148 INCLUDES += -I$(WP_LIB_PATH)
150 # Include MCU config first
151 -include $(MCU_PATH)config.mk
153 # Include MCU HAL drivers code
154 -include $(HAL_API_PATH)makefile
156 # Include common MCU sources
157 include $(MCU_PATH)common/makefile
160 # Sources & includes paths
162 SRCS += $(APP_SRCS_PATH)app.c
163 INCLUDES += -I$(API_PATH) -I$(APP_SRCS_PATH)include -I$(UTIL_PATH)
166 OBJS_ = $(SRCS:.c=.o) $(ASM_SRCS:.s=.o)
167 OBJS = $(addprefix $(BUILDPREFIX_APP), $(OBJS_))
170 DEPS_ = $(SRCS:.c=.d)
171 DEPS = $(addprefix $(BUILDPREFIX_APP), $(DEPS_))
173 # Files to be cleaned
174 CLEAN := $(OBJS) $(APP_ELF) $(APP_HEX) $(DEPS)
176 #=============================================================================
177 # PHASE 4: COMPILATION RULES
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)
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 #=============================================================================
191 $(BUILDPREFIX_APP)%.o : %.c $(APP_SRCS_PATH)makefile $(APP_CONFIG) $(BOARD_CONFIG) $(MCU_CONFIG)
193 @echo "$(COLOR_CC)CC$(COLOR_END) $<"
194 $(D)$(CC) $(INCLUDES) $(CFLAGS) -MMD -MP -c $< -o $@
196 $(BUILDPREFIX_APP)%.o : %.s
198 @echo "$(COLOR_CC)CC$(COLOR_END) $<"
199 $(D)$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@
201 #=============================================================================
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)
211 # - Executable ELF file (APP_ELF)
212 # - Memory layout map file (.map)
213 # - Linking progress and memory usage information
214 #=============================================================================
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)
222 #=============================================================================
223 # PHASE 6: FORMAT CONVERSION
225 # - ELF executable file (APP_ELF)
226 # - Compiler and linker flags (for console display)
227 # - Object copy tool and color definitions
229 # - Intel HEX file for microcontroller programming (APP_HEX)
230 # - OTAP file generation support
231 # - Build configuration summary
232 # - Generation status messages
233 #=============================================================================
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 $@
241 #=============================================================================
242 # PHASE 7: VERSION FILE GENERATION
244 # - Application version variables (app_major, app_minor, app_maintenance, app_development)
245 # - Git repository commit history
246 # - Version file path (VERSION_FILE)
248 # - Version tracking file (version.txt)
249 # - Git SHA for build traceability
250 # - Version information for deployment scripts
251 #=============================================================================
253 .PHONY: $(VERSION_FILE)
255 @echo "app_version=$(app_major).$(app_minor).$(app_maintenance).$(app_development)" > $(@)
256 @echo "sha1=$(shell git log -1 --pretty=format:"%h")" >> $(@)
258 #=============================================================================
259 # MAIN TARGETS AND CLEANUP
260 # INPUTS: All previous phases
262 # - Main build target dependencies
263 # - Clean target for removing generated files
264 # - Automatic dependency file inclusion
265 #=============================================================================
268 all: $(APP_HEX) $(VERSION_FILE)
271 $(D)$(RM) -rf $(CLEAN)