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
 
   28 ifeq ($(filter $(TARGET_BOARDS),$(target_board)),)
 
   29  $(error Board $(target_board) is not in supported board list: ($(TARGET_BOARDS)))
 
   32 # File to store app version
 
   33 VERSION_FILE := $(BUILDPREFIX_APP)version.txt
 
   35 # App different formats
 
   36 APP_ELF := $(BUILDPREFIX_APP)$(APP_NAME).elf
 
   38 # For backward compatibility as app makefile except SRCS_PATH variable
 
   39 SRCS_PATH := $(APP_SRCS_PATH)
 
   41 #=============================================================================
 
   42 # PHASE 2: COMPILER FLAGS GENERATION
 
   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)
 
   51 #   - Preprocessor definitions (-D flags in CFLAGS)
 
   52 #   - Security warnings/errors to console
 
   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 #=============================================================================
 
   60 # Convert default network settings to CFLAGS to be used in code
 
   61 ifneq ($(default_network_address),)
 
   62 CFLAGS += -DNETWORK_ADDRESS=$(default_network_address)
 
   64 ifneq ($(default_network_channel),)
 
   65 CFLAGS += -DNETWORK_CHANNEL=$(default_network_channel)
 
   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)
 
   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.)
 
   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)
 
   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.)
 
   98 CFLAGS += -DVER_MAJOR=$(app_major) -DVER_MINOR=$(app_minor) -DVER_MAINT=$(app_maintenance) -DVER_DEV=$(app_development)
 
  101 ifeq ("$(mac_profile)","ism_24_ghz")
 
  102     CFLAGS += -DMAC_PROFILE_ISM24
 
  103 else ifeq ("$(mac_profile)","subg")
 
  104     CFLAGS += -DMAC_PROFILE_SUBG
 
  106     CFLAGS += -DMAC_PROFILE_DECTNR
 
  109 #=============================================================================
 
  110 # PHASE 3: SOURCE COLLECTION AND DEPENDENCY SETUP
 
  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
 
  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 #=============================================================================
 
  129 # Include board init part
 
  130 -include board/makefile
 
  132 # Include app specific makefile
 
  133 -include $(APP_SRCS_PATH)makefile
 
  136 # Include Libraries config first (dependencies)
 
  137 -include $(WP_LIB_PATH)config.mk
 
  139 # Generic util functions are needed for all apps (api.c)
 
  140 -include $(UTIL_PATH)makefile
 
  142 # Include libraries code
 
  143 -include $(WP_LIB_PATH)makefile
 
  144 INCLUDES += -I$(WP_LIB_PATH)
 
  146 # Include MCU config first
 
  147 -include $(MCU_PATH)config.mk
 
  149 # Include MCU HAL drivers code
 
  150 -include $(HAL_API_PATH)makefile
 
  152 # Include common MCU sources
 
  153 include $(MCU_PATH)common/makefile
 
  156 # Sources & includes paths
 
  158 SRCS += $(APP_SRCS_PATH)app.c
 
  159 INCLUDES += -I$(API_PATH) -I$(APP_SRCS_PATH)include -I$(UTIL_PATH)
 
  162 OBJS_ = $(SRCS:.c=.o) $(ASM_SRCS:.s=.o)
 
  163 OBJS = $(addprefix $(BUILDPREFIX_APP), $(OBJS_))
 
  166 DEPS_ = $(SRCS:.c=.d)
 
  167 DEPS = $(addprefix $(BUILDPREFIX_APP), $(DEPS_))
 
  169 # Files to be cleaned
 
  170 CLEAN := $(OBJS) $(APP_ELF) $(APP_HEX) $(DEPS)
 
  172 #=============================================================================
 
  173 # PHASE 4: COMPILATION RULES
 
  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)
 
  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 #=============================================================================
 
  187 $(BUILDPREFIX_APP)%.o : %.c $(APP_SRCS_PATH)makefile $(APP_CONFIG) $(BOARD_CONFIG) $(MCU_CONFIG)
 
  189     @echo "$(COLOR_CC)CC$(COLOR_END) $<"
 
  190     $(D)$(CC) $(INCLUDES) $(CFLAGS) -MMD -MP -c $< -o $@
 
  192 $(BUILDPREFIX_APP)%.o : %.s
 
  194     @echo "$(COLOR_CC)CC$(COLOR_END) $<"
 
  195     $(D)$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@
 
  197 #=============================================================================
 
  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)
 
  206 #   - Executable ELF file (APP_ELF)
 
  207 #   - Memory layout map file (.map)
 
  208 #   - Linking progress and memory usage information
 
  209 #=============================================================================
 
  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)
 
  217 #=============================================================================
 
  218 # PHASE 6: FORMAT CONVERSION
 
  220 #   - ELF executable file (APP_ELF)
 
  221 #   - Compiler and linker flags (for console display)
 
  222 #   - Object copy tool and color definitions
 
  224 #   - Intel HEX file for microcontroller programming (APP_HEX)
 
  225 #   - OTAP file generation support
 
  226 #   - Build configuration summary
 
  227 #   - Generation status messages
 
  228 #=============================================================================
 
  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 $@
 
  236 #=============================================================================
 
  237 # PHASE 7: VERSION FILE GENERATION
 
  239 #   - Application version variables (app_major, app_minor, app_maintenance, app_development)
 
  240 #   - Git repository commit history
 
  241 #   - Version file path (VERSION_FILE)
 
  243 #   - Version tracking file (version.txt)
 
  244 #   - Git SHA for build traceability
 
  245 #   - Version information for deployment scripts
 
  246 #=============================================================================
 
  248 .PHONY: $(VERSION_FILE)
 
  250     @echo "app_version=$(app_major).$(app_minor).$(app_maintenance).$(app_development)" > $(@)
 
  251     @echo "sha1=$(shell git log -1 --pretty=format:"%h")" >> $(@)
 
  253 #=============================================================================
 
  254 # MAIN TARGETS AND CLEANUP
 
  255 # INPUTS: All previous phases
 
  257 #   - Main build target dependencies
 
  258 #   - Clean target for removing generated files
 
  259 #   - Automatic dependency file inclusion
 
  260 #=============================================================================
 
  263 all: $(APP_HEX) $(VERSION_FILE)
 
  266     $(D)$(RM) -rf $(CLEAN)