Makefile not compiling when new argument passed - makefile

When I run make clean then make DEBUG=1, it correctly compiles my file. If I want to add another argument I should be able to type make DEBUG=1 SIMULATE=1 but it doesn't recompile with the new C_FLAG.
This is the spot in the makefile where object files are created. When I specify %.c.o: $(C_FLAGS) it still doesn't recompile.
# $1 command
# $2 flags
# $3 message
define run
$(info $(call PROGRESS,$(3) file: $(notdir $($#)))) \
$(NO_ECHO)$(1) -MP -MD -c -o $# $(call get_path,$($#)) $(2) $(INC_PATHS)
endef
# Create object files from C source files
%.c.o:
$(call run,$(CC) -std=c99,$(CFLAGS),Compiling)
# Create object files from C++ source files
%.cpp.o:
$(call run,$(CXX),$(CFLAGS) $(CXXFLAGS),Compiling)
# Create object files from assembly source files
%.S.o %.s.o.o:
$(call run,$(CC) -x assembler-with-cpp,$(ASMFLAGS),Assembling)
makefile
PROJECT_NAME := ble_app_hts_pca10040_s132
TARGETS := nrf52832_xxaa
OUTPUT_DIRECTORY := _build
SDK_ROOT := ../../../../../..
PROJ_DIR := ../../..
$(OUTPUT_DIRECTORY)/nrf52832_xxaa.out: \
LINKER_SCRIPT := ble_app_hts_gcc_nrf52.ld
######################################
# building variables
######################################
# debug build?
DEBUG ?= 0
DEBUG_PIN ?= 0
BAUDRATE ?= 0
# simulation build?
SIMULATE ?= 0
# devkit build?
DEVKIT ?= 0
# optimization
OPT = -O3
# Source files common to all targets
SRC_FILES += \
$(PROJ_DIR)/Src/main.c \
$(PROJ_DIR)/Src/battery.c \
$(PROJ_DIR)/Src/tension.c \
$(PROJ_DIR)/Src/temperature.c \
$(PROJ_DIR)/Src/ble_hts_custom.c \
$(PROJ_DIR)/Src/accelerometer.c \
$(PROJ_DIR)/Src/bma2x2.c \
$(SDK_ROOT)/components/ble/ble_services/ble_nus/ble_nus.c \
$(SDK_ROOT)/components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_saadc.c \
$(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52.S \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_rtt.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_uart.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_default_backends.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_frontend.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_str_formatter.c \
$(SDK_ROOT)/components/libraries/button/app_button.c \
$(SDK_ROOT)/components/libraries/util/app_error.c \
$(SDK_ROOT)/components/libraries/util/app_error_handler_gcc.c \
$(SDK_ROOT)/components/libraries/util/app_error_weak.c \
$(SDK_ROOT)/components/libraries/scheduler/app_scheduler.c \
$(SDK_ROOT)/components/libraries/timer/app_timer.c \
$(SDK_ROOT)/components/libraries/util/app_util_platform.c \
$(SDK_ROOT)/components/libraries/crc16/crc16.c \
$(SDK_ROOT)/components/libraries/fds/fds.c \
$(SDK_ROOT)/components/libraries/hardfault/hardfault_implementation.c \
$(SDK_ROOT)/components/libraries/util/nrf_assert.c \
$(SDK_ROOT)/components/libraries/atomic_fifo/nrf_atfifo.c \
$(SDK_ROOT)/components/libraries/atomic_flags/nrf_atflags.c \
$(SDK_ROOT)/components/libraries/atomic/nrf_atomic.c \
$(SDK_ROOT)/components/libraries/balloc/nrf_balloc.c \
$(SDK_ROOT)/external/fprintf/nrf_fprintf.c \
$(SDK_ROOT)/external/fprintf/nrf_fprintf_format.c \
$(SDK_ROOT)/components/libraries/fstorage/nrf_fstorage.c \
$(SDK_ROOT)/components/libraries/fstorage/nrf_fstorage_sd.c \
$(SDK_ROOT)/components/libraries/memobj/nrf_memobj.c \
$(SDK_ROOT)/components/libraries/pwr_mgmt/nrf_pwr_mgmt.c \
$(SDK_ROOT)/components/libraries/ringbuf/nrf_ringbuf.c \
$(SDK_ROOT)/components/libraries/experimental_section_vars/nrf_section_iter.c \
$(SDK_ROOT)/components/libraries/strerror/nrf_strerror.c \
$(SDK_ROOT)/components/libraries/sensorsim/sensorsim.c \
$(SDK_ROOT)/modules/nrfx/mdk/system_nrf52.c \
$(SDK_ROOT)/components/boards/boards.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_clock.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_uart.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_spi.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_clock.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_gpiote.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_power_clock.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/prs/nrfx_prs.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uart.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uarte.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_spim.c \
$(SDK_ROOT)/components/libraries/bsp/bsp.c \
$(SDK_ROOT)/components/libraries/bsp/bsp_btn_ble.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \
$(SDK_ROOT)/components/ble/peer_manager/auth_status_tracker.c \
$(SDK_ROOT)/components/ble/common/ble_advdata.c \
$(SDK_ROOT)/components/ble/ble_advertising/ble_advertising.c \
$(SDK_ROOT)/components/ble/common/ble_conn_params.c \
$(SDK_ROOT)/components/ble/common/ble_conn_state.c \
$(SDK_ROOT)/components/ble/common/ble_srv_common.c \
$(SDK_ROOT)/components/ble/peer_manager/gatt_cache_manager.c \
$(SDK_ROOT)/components/ble/peer_manager/gatts_cache_manager.c \
$(SDK_ROOT)/components/ble/peer_manager/id_manager.c \
$(SDK_ROOT)/components/ble/nrf_ble_gatt/nrf_ble_gatt.c \
$(SDK_ROOT)/components/ble/nrf_ble_qwr/nrf_ble_qwr.c \
$(SDK_ROOT)/components/ble/peer_manager/peer_data_storage.c \
$(SDK_ROOT)/components/ble/peer_manager/peer_database.c \
$(SDK_ROOT)/components/ble/peer_manager/peer_id.c \
$(SDK_ROOT)/components/ble/peer_manager/peer_manager.c \
$(SDK_ROOT)/components/ble/peer_manager/peer_manager_handler.c \
$(SDK_ROOT)/components/ble/peer_manager/pm_buffer.c \
$(SDK_ROOT)/components/ble/peer_manager/security_dispatcher.c \
$(SDK_ROOT)/components/ble/peer_manager/security_manager.c \
$(SDK_ROOT)/external/utf_converter/utf.c \
$(SDK_ROOT)/components/ble/ble_services/ble_bas/ble_bas.c \
$(SDK_ROOT)/components/ble/ble_services/ble_dis/ble_dis.c \
$(SDK_ROOT)/components/softdevice/common/nrf_sdh.c \
$(SDK_ROOT)/components/softdevice/common/nrf_sdh_ble.c \
$(SDK_ROOT)/components/softdevice/common/nrf_sdh_soc.c \
# Include folders common to all targets
INC_FOLDERS += \
$(PROJ_DIR)/Inc \
$(SDK_ROOT)/components/ble/ble_services/ble_nus \
$(SDK_ROOT)/components/ble/ble_link_ctx_manager \
$(SDK_ROOT)/components/nfc/ndef/generic/message \
$(SDK_ROOT)/components/nfc/t2t_lib \
$(SDK_ROOT)/components/nfc/t4t_parser/hl_detection_procedure \
$(SDK_ROOT)/components/ble/ble_services/ble_ancs_c \
$(SDK_ROOT)/components/ble/ble_services/ble_ias_c \
$(SDK_ROOT)/components/libraries/pwm \
$(SDK_ROOT)/components/softdevice/s132/headers/nrf52 \
$(SDK_ROOT)/components/libraries/usbd/class/cdc/acm \
$(SDK_ROOT)/components/libraries/usbd/class/hid/generic \
$(SDK_ROOT)/components/libraries/usbd/class/msc \
$(SDK_ROOT)/components/libraries/usbd/class/hid \
$(SDK_ROOT)/modules/nrfx/hal \
$(SDK_ROOT)/components/nfc/ndef/conn_hand_parser/le_oob_rec_parser \
$(SDK_ROOT)/components/libraries/log \
$(SDK_ROOT)/components/ble/ble_services/ble_gls \
$(SDK_ROOT)/components/libraries/fstorage \
$(SDK_ROOT)/components/nfc/ndef/text \
$(SDK_ROOT)/components/libraries/mutex \
$(SDK_ROOT)/components/libraries/gpiote \
$(SDK_ROOT)/components/libraries/bootloader/ble_dfu \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/common \
$(SDK_ROOT)/components/boards \
$(SDK_ROOT)/components/nfc/ndef/generic/record \
$(SDK_ROOT)/components/nfc/t4t_parser/cc_file \
$(SDK_ROOT)/components/ble/ble_advertising \
$(SDK_ROOT)/external/utf_converter \
$(SDK_ROOT)/components/ble/ble_services/ble_bas_c \
$(SDK_ROOT)/modules/nrfx/drivers/include \
$(SDK_ROOT)/components/libraries/experimental_task_manager \
$(SDK_ROOT)/components/ble/ble_services/ble_hrs_c \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/le_oob_rec \
$(SDK_ROOT)/components/libraries/queue \
$(SDK_ROOT)/components/libraries/pwr_mgmt \
$(SDK_ROOT)/components/ble/ble_dtm \
$(SDK_ROOT)/components/toolchain/cmsis/include \
$(SDK_ROOT)/components/ble/ble_services/ble_rscs_c \
$(SDK_ROOT)/components/ble/common \
$(SDK_ROOT)/components/ble/ble_services/ble_lls \
$(SDK_ROOT)/components/libraries/bsp \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/ac_rec \
$(SDK_ROOT)/components/ble/ble_services/ble_bas \
$(SDK_ROOT)/components/libraries/mpu \
$(SDK_ROOT)/components/libraries/experimental_section_vars \
$(SDK_ROOT)/components/softdevice/s132/headers \
$(SDK_ROOT)/components/ble/ble_services/ble_ans_c \
$(SDK_ROOT)/components/libraries/slip \
$(SDK_ROOT)/components/libraries/delay \
$(SDK_ROOT)/components/libraries/mem_manager \
$(SDK_ROOT)/components/libraries/csense_drv \
$(SDK_ROOT)/components/libraries/memobj \
$(SDK_ROOT)/components/ble/ble_services/ble_nus_c \
$(SDK_ROOT)/components/softdevice/common \
$(SDK_ROOT)/components/ble/ble_services/ble_ias \
$(SDK_ROOT)/components/libraries/usbd/class/hid/mouse \
$(SDK_ROOT)/components/libraries/low_power_pwm \
$(SDK_ROOT)/components/nfc/ndef/conn_hand_parser/ble_oob_advdata_parser \
$(SDK_ROOT)/components/ble/ble_services/ble_dfu \
$(SDK_ROOT)/external/fprintf \
$(SDK_ROOT)/components/libraries/svc \
$(SDK_ROOT)/components/libraries/atomic \
$(SDK_ROOT)/components \
$(SDK_ROOT)/components/libraries/scheduler \
$(SDK_ROOT)/components/libraries/cli \
$(SDK_ROOT)/components/ble/ble_services/ble_lbs \
$(SDK_ROOT)/components/libraries/crc16 \
$(SDK_ROOT)/components/nfc/t4t_parser/apdu \
$(SDK_ROOT)/components/libraries/util \
../config \
$(SDK_ROOT)/components/libraries/usbd/class/cdc \
$(SDK_ROOT)/components/libraries/csense \
$(SDK_ROOT)/components/libraries/balloc \
$(SDK_ROOT)/components/libraries/ecc \
$(SDK_ROOT)/components/libraries/hardfault \
$(SDK_ROOT)/components/ble/ble_services/ble_cscs \
$(SDK_ROOT)/components/libraries/hci \
$(SDK_ROOT)/components/libraries/usbd/class/hid/kbd \
$(SDK_ROOT)/components/libraries/timer \
$(SDK_ROOT)/integration/nrfx \
$(SDK_ROOT)/components/nfc/t4t_parser/tlv \
$(SDK_ROOT)/components/libraries/sortlist \
$(SDK_ROOT)/components/libraries/spi_mngr \
$(SDK_ROOT)/components/libraries/led_softblink \
$(SDK_ROOT)/components/nfc/ndef/conn_hand_parser \
$(SDK_ROOT)/components/libraries/sdcard \
$(SDK_ROOT)/components/nfc/ndef/parser/record \
$(SDK_ROOT)/modules/nrfx/mdk \
$(SDK_ROOT)/components/ble/ble_services/ble_cts_c \
$(SDK_ROOT)/components/ble/ble_services/ble_nus \
$(SDK_ROOT)/components/libraries/twi_mngr \
$(SDK_ROOT)/components/ble/ble_services/ble_hids \
$(SDK_ROOT)/components/libraries/strerror \
$(SDK_ROOT)/components/libraries/crc32 \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/ble_oob_advdata \
$(SDK_ROOT)/components/nfc/t2t_parser \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/ble_pair_msg \
$(SDK_ROOT)/components/libraries/usbd/class/audio \
$(SDK_ROOT)/components/nfc/t4t_lib/hal_t4t \
$(SDK_ROOT)/components/libraries/sensorsim \
$(SDK_ROOT)/components/nfc/t4t_lib \
$(SDK_ROOT)/components/ble/peer_manager \
$(SDK_ROOT)/components/drivers_nrf/usbd \
$(SDK_ROOT)/components/libraries/ringbuf \
$(SDK_ROOT)/components/ble/ble_services/ble_tps \
$(SDK_ROOT)/components/nfc/ndef/parser/message \
$(SDK_ROOT)/components/ble/ble_services/ble_dis \
$(SDK_ROOT)/components/nfc/ndef/uri \
$(SDK_ROOT)/components/ble/nrf_ble_gatt \
$(SDK_ROOT)/components/ble/nrf_ble_qwr \
$(SDK_ROOT)/components/libraries/gfx \
$(SDK_ROOT)/components/libraries/button \
$(SDK_ROOT)/modules/nrfx \
$(SDK_ROOT)/components/libraries/twi_sensor \
$(SDK_ROOT)/integration/nrfx/legacy \
$(SDK_ROOT)/components/libraries/usbd \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/ep_oob_rec \
$(SDK_ROOT)/external/segger_rtt \
$(SDK_ROOT)/components/libraries/atomic_fifo \
$(SDK_ROOT)/components/ble/ble_services/ble_lbs_c \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/ble_pair_lib \
$(SDK_ROOT)/components/libraries/crypto \
$(SDK_ROOT)/components/ble/ble_racp \
$(SDK_ROOT)/components/libraries/fds \
$(SDK_ROOT)/components/nfc/ndef/launchapp \
$(SDK_ROOT)/components/libraries/atomic_flags \
$(SDK_ROOT)/components/ble/ble_services/ble_hrs \
$(SDK_ROOT)/components/ble/ble_services/ble_rscs \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/hs_rec \
$(SDK_ROOT)/components/nfc/t2t_lib/hal_t2t \
$(SDK_ROOT)/components/nfc/ndef/conn_hand_parser/ac_rec_parser \
$(SDK_ROOT)/components/libraries/stack_guard \
$(SDK_ROOT)/components/libraries/log/src \
# Libraries common to all targets
LIB_FILES += \
# Debug option
ifeq ($(DEBUG), 1)
# use 'make sdk_config -> nRF_Log -> NRF_LOG_BACKEND_UART_ENABLED' to see default params
C_DEFS += -DDEBUG
C_DEFS += -DNRF_LOG_ENABLED=1
C_DEFS += -DNRF_LOG_BACKEND_UART_ENABLED=1
ifneq ($(DEBUG_PIN), 0)
C_DEFS += -DNRF_LOG_BACKEND_UART_TX_PIN=$(DEBUG_PIN)
endif
ifneq ($(BAUDRATE), 0)
C_DEFS += -DNRF_LOG_BACKEND_UART_BAUDRATE=$(BAUDRATE)
endif
OPT = -Og
endif
ifeq ($(SIMULATE), 1)
C_DEFS += -DSIMULATE
endif
ifeq ($(DEVKIT), 1)
C_DEFS += -DDEVKIT
endif
# C flags common to all targets
CFLAGS += $(OPT)
CFLAGS += -DBOARD_PCA10040
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
CFLAGS += -DCONFIG_NFCT_PINS_AS_GPIOS
CFLAGS += -DFLOAT_ABI_HARD
CFLAGS += -DNRF52
CFLAGS += -DNRF52832_XXAA
CFLAGS += -DNRF52_PAN_74
CFLAGS += -DNRF_SD_BLE_API_VERSION=6
CFLAGS += -DS132
CFLAGS += -DSOFTDEVICE_PRESENT
CFLAGS += -DSWI_DISABLE0
CFLAGS += -mcpu=cortex-m4
CFLAGS += -mthumb -mabi=aapcs
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# keep every function in a separate section, this allows linker to discard unused ones
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin -fshort-enums
CFLAGS += -Wall -g3
CFLAGS += $(C_DEFS)
# CFLAGS += -Werror # if you want warnings treated as errors
# C++ flags common to all targets
CXXFLAGS += $(OPT) -std=c++1z
# Assembler flags common to all targets
ASMFLAGS += -g3
ASMFLAGS += -mcpu=cortex-m4
ASMFLAGS += -mthumb -mabi=aapcs
ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
ASMFLAGS += -DBOARD_PCA10040
ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
ASMFLAGS += -DFLOAT_ABI_HARD
ASMFLAGS += -DNRF52
ASMFLAGS += -DNRF52832_XXAA
ASMFLAGS += -DNRF52_PAN_74
ASMFLAGS += -DNRF_SD_BLE_API_VERSION=6
ASMFLAGS += -DS132
ASMFLAGS += -DSOFTDEVICE_PRESENT
ASMFLAGS += -DSWI_DISABLE0
# Linker flags
LDFLAGS += $(OPT)
LDFLAGS += -mthumb -mabi=aapcs -L$(SDK_ROOT)/modules/nrfx/mdk -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m4
LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# let linker dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs
nrf52832_xxaa: CFLAGS += -D__HEAP_SIZE=8192
nrf52832_xxaa: CFLAGS += -D__STACK_SIZE=8192
nrf52832_xxaa: ASMFLAGS += -D__HEAP_SIZE=8192
nrf52832_xxaa: ASMFLAGS += -D__STACK_SIZE=8192
# Add standard libraries at the very end of the linker input, after all objects
# that may need symbols provided by these libraries.
LIB_FILES += -lc -lnosys -lm
.PHONY: default help
# Default target - first one defined
default: nrf52832_xxaa
# Print all targets that can be built
help:
#echo following targets are available:
#echo nrf52832_xxaa
#echo flash_softdevice
#echo sdk_config - starting external tool for editing sdk_config.h
#echo flash - flashing binary
TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc
include $(TEMPLATE_PATH)/Makefile.common
$(foreach target, $(TARGETS), $(call define_target, $(target)))
.PHONY: flash flash_softdevice erase
UNAME := $(shell uname)
clean:
ifeq ($(UNAME), Linux)
sudo rm -rf _build
else
#echo os not supported for clean target
endif
flash: clean
sudo $(MAKE) -j8 DEBUG=$(DEBUG) DEBUG_PIN=$(DEBUG_PIN) SIMULATE=$(SIMULATE) DEVKIT=$(DEVKIT) default
#echo Flashing: $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex
nrfjprog -f nrf52 --program $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex --sectorerase
nrfjprog -f nrf52 --reset
flash_noclean: default
#echo Flashing: $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex
nrfjprog -f nrf52 --program $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex --sectorerase
nrfjprog -f nrf52 --reset
flash_softdevice:
#echo Flashing: s132_nrf52_6.1.0_softdevice.hex
nrfjprog -f nrf52 --program $(SDK_ROOT)/components/softdevice/s132/hex/s132_nrf52_6.1.0_softdevice.hex --sectorerase
nrfjprog -f nrf52 --reset
erase:
nrfjprog -f nrf52 --eraseall
SDK_CONFIG_FILE := ../config/sdk_config.h
CMSIS_CONFIG_TOOL := $(SDK_ROOT)/external_tools/cmsisconfig/CMSIS_Configuration_Wizard.jar
sdk_config:
java -jar $(CMSIS_CONFIG_TOOL) $(SDK_CONFIG_FILE)
makefile.common (invoked from the above makefile)
# Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form, except as embedded into a Nordic
# Semiconductor ASA integrated circuit in a product or a software update for
# such product, must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# 3. Neither the name of Nordic Semiconductor ASA nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# 4. This software, with or without modification, must only be used with a
# Nordic Semiconductor ASA integrated circuit.
#
# 5. Any software provided in binary form under this license must not be reverse
# engineered, decompiled, modified and/or disassembled.
#
# THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Options:
# VERBOSE=1 (default is 0) - print each executed command
# PRETTY=1 (default is 0) - show progress, in percentage
# ABSOLUTE_PATHS=1 (default is 0) - convert all include folders and source
# file paths to their absolute forms
# PASS_INCLUDE_PATHS_VIA_FILE=1 (default is 0) - use <target>.inc file
# to pass include paths to gcc
# PASS_LINKER_INPUT_VIA_FILE=0 (default is 1) - don't use <target>.in file
# to pass the list of linker input files
VERBOSE ?= 0
PRETTY ?= 0
ABSOLUTE_PATHS ?= 0
PASS_INCLUDE_PATHS_VIA_FILE ?= 0
PASS_LINKER_INPUT_VIA_FILE ?= 1
.SUFFIXES: # ignore built-in rules
%.d: # don't try to make .d files
.PRECIOUS: %.d %.o
MK := mkdir
RM := rm -rf
# echo suspend
ifeq ($(VERBOSE),1)
NO_ECHO :=
else
NO_ECHO := #
endif
ifneq (,$(filter clean, $(MAKECMDGOALS)))
OTHER_GOALS := $(filter-out clean, $(MAKECMDGOALS))
ifneq (, $(OTHER_GOALS))
$(info Cannot make anything in parallel with "clean".)
$(info Execute "$(MAKE) clean \
$(foreach goal, $(OTHER_GOALS),&& $(MAKE) $(goal))" instead.)
$(error Cannot continue)
else
.PHONY: clean
clean:
$(RM) $(OUTPUT_DIRECTORY)
endif # ifneq(, $(OTHER_GOALS))
else # ifneq (,$(filter clean, $(MAKECMDGOALS)))
ifndef PROGRESS
ifeq ($(PRETTY),1)
X := #
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
TOTAL := $(subst $(SPACE),,$(filter $(X), \
$(shell "$(MAKE)" $(MAKECMDGOALS) --dry-run \
--no-print-directory PROGRESS=$(X))))
5 := $(X)$(X)$(X)$(X)$(X)
25 := $(5)$(5)$(5)$(5)$(5)
100 := $(25)$(25)$(25)$(25)
C :=
COUNTER = $(eval C := $(C)$(100))$(C)
P :=
count = $(if $(filter $1%,$2),$(eval \
P += 1)$(call count,$1,$(2:$1%=%)),$(eval \
C := $2))
print = [$(if $(word 99,$1),99,$(if $(word 10,$1),, )$(words $1))%]
PROGRESS = $(call count,$(TOTAL),$(COUNTER))$(call print,$(P)) $1
else
PROGRESS = $1
endif # ifeq ($(PRETTY),1)
PLATFORM_SUFFIX := $(if $(filter Windows%,$(OS)),windows,posix)
TOOLCHAIN_CONFIG_FILE := $(TEMPLATE_PATH)/Makefile.$(PLATFORM_SUFFIX)
include $(TOOLCHAIN_CONFIG_FILE)
# $1 path
define quote
'$(subst ','\'',$(1))'
endef
# Toolchain commands
CC := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-gcc)
CXX := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-c++)
AS := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-as)
AR := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-ar) -r
LD := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-ld)
NM := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-nm)
OBJDUMP := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-objdump)
OBJCOPY := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-objcopy)
SIZE := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-size)
$(if $(shell $(CC) --version),,$(info Cannot find: $(CC).) \
$(info Please set values in: "$(abspath $(TOOLCHAIN_CONFIG_FILE))") \
$(info according to the actual configuration of your system.) \
$(error Cannot continue))
# Use ccache on linux if available
CCACHE := $(if $(filter Windows%,$(OS)),, \
$(if $(wildcard /usr/bin/ccache),ccache))
CC := $(CCACHE) $(CC)
endif # ifndef PROGRESS
# $1 type of item
# $2 items paths to check
define ensure_exists_each
$(foreach item, $(2), \
$(if $(wildcard $(item)),, $(warning Cannot find $(1): $(item))))
endef
ifeq ($(PASS_INCLUDE_PATHS_VIA_FILE),1)
INC_PATHS = #$($#_INC)
GENERATE_INC_FILE := 1
else
INC_PATHS = $(call target_specific, INC_PATHS, $($#_TGT))
GENERATE_INC_FILE :=
endif
# $1 object file
# $2 source file
# $3 include paths container file
# $4 target name
define bind_obj_with_src
$(eval $(1) := $(2)) \
$(eval $(1)_INC := $(3)) \
$(eval $(1)_TGT := $(4)) \
$(eval $(1): Makefile | $(dir $(1)).) \
$(if $(GENERATE_INC_FILE), $(eval $(1): $(3)))
endef
# $1 target name
# $2 source file name
# Note: this additional .o for .s files is a workaround for issues with make 4.1
# from MinGW (it does nothing to remake .s.o files when a rule for .S.o
# files is defined as well).
define get_object_file_name
$(OUTPUT_DIRECTORY)/$(strip $(1))/$(notdir $(2:%.s=%.s.o)).o
endef
# $1 target name
# $2 include paths container file
# $3 list of source files
define get_object_files
$(call ensure_exists_each,source file, $(3)) \
$(foreach src_file, $(3), \
$(eval obj_file := $(call get_object_file_name, $(1), $(src_file))) \
$(eval DEPENDENCIES += $(obj_file:.o=.d)) \
$(call bind_obj_with_src, $(obj_file), $(src_file), $(2), $(1)) \
$(obj_file))
endef
# $1 variable name
# $2 target name
define target_specific
$($(addsuffix _$(strip $(2)), $(1)))
endef
ifeq ($(ABSOLUTE_PATHS),1)
get_path = $(call quote,$(abspath $1))
else
get_path = $1
endif
# $1 list of include folders
define get_inc_paths
$(call ensure_exists_each,include folder,$(1)) \
$(foreach folder,$(1),-I$(call get_path,$(folder)))
endef
# $1 target name
# $2 include paths container file
# $3 build goal name
define prepare_build
$(eval DEPENDENCIES :=) \
$(eval $(3): \
$(call get_object_files, $(1), $(2), \
$(SRC_FILES) $(call target_specific, SRC_FILES, $(1)))) \
$(eval -include $(DEPENDENCIES)) \
$(eval INC_PATHS_$(strip $(1)) := \
$(call get_inc_paths, \
$(INC_FOLDERS) $(call target_specific, INC_FOLDERS, $(1))))
endef
# $1 target name
define define_target
$(eval OUTPUT_FILE := $(OUTPUT_DIRECTORY)/$(strip $(1))) \
$(eval $(1): $(OUTPUT_FILE).out $(OUTPUT_FILE).hex $(OUTPUT_FILE).bin \
; #echo DONE $(strip $(1))) \
$(call prepare_build, $(1), $(OUTPUT_FILE).inc, $(OUTPUT_FILE).out)
endef
# $1 target name
# $2 library file name
define define_library
$(eval OUTPUT_FILE := $(OUTPUT_DIRECTORY)/$(strip $(1))) \
$(eval $(1) := $(2)) \
$(call prepare_build, $(1), $(OUTPUT_FILE).inc, $(1))
endef
# $1 content to be dumped
# Invokes another instance of MAKE to dump the specified content to stdout,
# which may be then redirected in shell to a file and this way stored there.
# MAKE in version prior to 4.0 does not provide the $(file ...) function.
define dump
$(eval CONTENT_TO_DUMP := $(1)) \
"$(MAKE)" -s --no-print-directory \
-f "$(TEMPLATE_PATH)/dump.mk" VARIABLE=CONTENT_TO_DUMP
endef
export CONTENT_TO_DUMP
.PHONY: $(TARGETS) all
all: $(TARGETS)
# Create build directories
$(OUTPUT_DIRECTORY):
$(MK) $#
$(OUTPUT_DIRECTORY)/%/.: | $(OUTPUT_DIRECTORY)
cd $(OUTPUT_DIRECTORY) && $(MK) $*
$(OUTPUT_DIRECTORY)/%.inc: Makefile | $(OUTPUT_DIRECTORY)
$(info Generating $#)
$(NO_ECHO)$(call dump, $(call target_specific, INC_PATHS, $*)) > $#
# $1 command
# $2 flags
# $3 message
define run
$(info $(call PROGRESS,$(3) file: $(notdir $($#)))) \
$(NO_ECHO)$(1) -MP -MD -c -o $# $(call get_path,$($#)) $(2) $(INC_PATHS)
endef
# Create object files from C source files
%.c.o:
$(call run,$(CC) -std=c99,$(CFLAGS),Compiling)
# Create object files from C++ source files
%.cpp.o:
$(call run,$(CXX),$(CFLAGS) $(CXXFLAGS),Compiling)
# Create object files from assembly source files
%.S.o %.s.o.o:
$(call run,$(CC) -x assembler-with-cpp,$(ASMFLAGS),Assembling)
ifeq ($(PASS_LINKER_INPUT_VIA_FILE),1)
GENERATE_LD_INPUT_FILE = $(call dump, $^ $(LIB_FILES)) > $(#:.out=.in)
LD_INPUT = #$(#:.out=.in)
else
GENERATE_LD_INPUT_FILE =
LD_INPUT = $^ $(LIB_FILES)
endif
# Link object files
%.out:
$(info $(call PROGRESS,Linking target: $#))
$(NO_ECHO)$(GENERATE_LD_INPUT_FILE)
$(NO_ECHO)$(CC) $(LDFLAGS) $(LD_INPUT) -Wl,-Map=$(#:.out=.map) -o $#
$(NO_ECHO)$(SIZE) $#
# Create binary .bin file from the .out file
%.bin: %.out
$(info Preparing: $#)
$(NO_ECHO)$(OBJCOPY) -O binary $< $#
# Create binary .hex file from the .out file
%.hex: %.out
$(info Preparing: $#)
$(NO_ECHO)$(OBJCOPY) -O ihex $< $#
endif # ifneq (,$(filter clean, $(MAKECMDGOALS)))
I want make to recompile whenever I use a new argument.

I think the easiest way in this Makefile would be to use different OUTPUT_DIRECTORY for each switch configuration that you care about. You can make different variants yourself or generalize, like so:
OUTPUT_DIRECTORY = $(shell echo $(CFLAGS) $(CXXFLAGS) | sha1sum | cut -f1 -d\ )
$(info Using output directory: $(OUTPUT_DIRECTORY))
.PHONY: all
all: $(OUTPUT_DIRECTORY)/foo
$(OUTPUT_DIRECTORY)/.:
mkdir -p $#
$(OUTPUT_DIRECTORY)/%: | $(OUTPUT_DIRECTORY)/.
touch $#
Output:
$ make
Using output directory: adc83b19e793491b1c6ea0fd8b46cd9f32e592fc
mkdir -p adc83b19e793491b1c6ea0fd8b46cd9f32e592fc/.
touch adc83b19e793491b1c6ea0fd8b46cd9f32e592fc/foo
$ make CFLAGS=-g
Using output directory: 4e3223fc5750f1d1ef94845b09843555aee23f69
mkdir -p 4e3223fc5750f1d1ef94845b09843555aee23f69/.
touch 4e3223fc5750f1d1ef94845b09843555aee23f69/foo
$ make CFLAGS=-g
Using output directory: 4e3223fc5750f1d1ef94845b09843555aee23f69
make: Nothing to be done for 'all'.
$ make CFLAGS="-g -O2"
Using output directory: 29020c30ba848fbbf4c208ae78b5ed0362b24ce3
mkdir -p 29020c30ba848fbbf4c208ae78b5ed0362b24ce3/.
touch 29020c30ba848fbbf4c208ae78b5ed0362b24ce3/foo
Might require fine-tuning since $(OUTPUT_DIRECTORY) will be resolved when expanded (and therefore sha1sum counted many times - costly), but actual solution depends on where exactly variables are set.

Related

makefile removing uname command

I want to just run make in windows cmd. Goal is just that i can run make in default windows CMD without that i need run make inside MSYSY or CYGWIN.
When i run make command inside windows cmd it shows message:
'uname' is not recognized as an internal or external command,
operable program or batch file.
process_begin: CreateProcess(NULL, uname -m, ...) failed.
####################################################################
# Makefile
#
# OS variable must either be 'posix' or 'win'. E.g. 'make OS=posix'.
# Error is thrown if OS variable is not equal with any of these.
#
####################################################################
.SUFFIXES: # ignore builtin rules
.PHONY: all debug release clean export
####################################################################
# Definitions #
####################################################################
# uniq is a function which removes duplicate elements from a list
uniq = $(strip $(if $1,$(firstword $1) \
$(call uniq,$(filter-out $(firstword $1),$1))))
PROJECTNAME = projectoutput
CONFIG ?= default
SDK_DIR = ../../../..
OBJ_DIR = obj
EXE_DIR = exe
LST_DIR = lst
EXPORT_DIR = export
RTL_DIR = $(SDK_DIR)/util
####################################################################
# Definitions of toolchain. #
# You might need to do changes to match your system setup #
####################################################################
RMDIRS := rm -rf
RMFILES := rm -rf
ALLFILES := /*.*
NULLDEVICE := /dev/null
SHELLNAMES := $(ComSpec)$(COMSPEC)
UNAME := $(shell uname | tr '[:upper:]' '[:lower:]')
DEVICE := x64
ifneq ($(filter arm%, $(shell uname -m)),)
DEVICE := cortexa
endif
ifeq (export,$(findstring export, $(MAKECMDGOALS)))
# Set the default OS for exporting if not specified externally
ifeq (,$(filter $(OS),posix win))
OS:=posix
endif
else
# Try autodetecting the environment: Windows
ifneq ($(SHELLNAMES),)
QUOTE :="
ifeq (,$(filter $(OS),posix win))
OS:=win
endif
ifneq ($(COMSPEC),)
ifeq ($(findstring cygdrive,$(shell set)),)
# We were not on a cygwin platform
NULLDEVICE := NUL
endif
else
# Assume we are making on a Windows platform
# This is a convenient place to override TOOLDIR, DO NOT add trailing
# whitespace chars, they do matter !
SHELL := $(SHELLNAMES)
RMDIRS := rd /s /q
RMFILES := del /s /q
ALLFILES := \*.*
NULLDEVICE := NUL
endif
# Other than Windows
else
ifeq (,$(filter $(OS),posix win))
OS:=posix
endif
endif
endif
# Create directories and do a clean which is compatible with parallell make
$(shell mkdir $(OBJ_DIR)>$(NULLDEVICE) 2>&1)
$(shell mkdir $(EXE_DIR)>$(NULLDEVICE) 2>&1)
$(shell mkdir $(LST_DIR)>$(NULLDEVICE) 2>&1)
ifeq (clean,$(findstring clean, $(MAKECMDGOALS)))
ifneq ($(filter $(MAKECMDGOALS),all debug release),)
$(shell $(RMFILES) $(OBJ_DIR)$(ALLFILES)>$(NULLDEVICE) 2>&1)
$(shell $(RMFILES) $(EXE_DIR)$(ALLFILES)>$(NULLDEVICE) 2>&1)
$(shell $(RMFILES) $(LST_DIR)$(ALLFILES)>$(NULLDEVICE) 2>&1)
endif
endif
ifeq ($(OS),posix)
CC = gcc
LD = ld
AR = ar
else
CC = x86_64-w64-mingw32-gcc
LD = x86_64-w64-mingw32-ld
AR = x86_64-w64-mingw32-ar
endif
####################################################################
# Flags #
####################################################################
INCLUDEPATHS += . \
$(SDK_DIR)/app/common_host/uart \
$(SDK_DIR)/app/common_host/tcp \
$(SDK_DIR)/app/common_host/system \
$(SDK_DIR)/app/common_host/app_assert \
$(SDK_DIR)/app/common_host/app_signal \
$(SDK_DIR)/app/common_host/log \
$(SDK_DIR)/app/common_host/log/config \
INCFLAGS = $(addprefix -I, $(INCLUDEPATHS))
# -MMD : Don't generate dependencies on system header files.
# -MP : Add phony targets, useful when a h-file is removed from a project.
# -MF : Specify a file to write the dependencies to.
DEPFLAGS = \
-MMD \
-MP \
-MF $(#:.o=.d)
# Add -Wa,-ahld=$(LST_DIR)/$(#F:.o=.lst) to CFLAGS to produce assembly list files
override CFLAGS += \
-fno-short-enums \
-Wall \
-c \
-fmessage-length=0 \
-std=c99 \
$(DEPFLAGS)
# Linux platform: if _DEFAULT_SOURCE is defined, the default is to have _POSIX_SOURCE set to one
# and _POSIX_C_SOURCE set to 200809L, as well as enabling miscellaneous functions from BSD and SVID.
# See usr/include/fetures.h for more information.
#
# _BSD_SOURCE (deprecated since glibc 2.20)
# Defining this macro with any value causes header files to expose BSD-derived definitions.
# In glibc versions up to and including 2.18, defining this macro also causes BSD definitions to be
# preferred in some situations where standards conflict, unless one or more of _SVID_SOURCE,
# _POSIX_SOURCE, _POSIX_C_SOURCE, _XOPEN_SOURCE, _XOPEN_SOURCE_EXTENDED, or _GNU_SOURCE is defined,
# in which case BSD definitions are disfavored. Since glibc 2.19, _BSD_SOURCE no longer causes BSD
# definitions to be preferred in case of conflicts. Since glibc 2.20, this macro is deprecated.
# It now has the same effect as defining _DEFAULT_SOURCE, but generates a compile-time warning
# (unless _DEFAULT_SOURCE is also defined). Use _DEFAULT_SOURCE instead.
# To allow code that requires _BSD_SOURCE in glibc 2.19 and earlier and _DEFAULT_SOURCE in glibc
# 2.20 and later to compile without warnings, define both _BSD_SOURCE and _DEFAULT_SOURCE.
#
# OSX platform: _DEFAULT_SOURCE is not used, instead _DARWIN_C_SOURCE is defined by default.
ifeq ($(OS),posix)
override CFLAGS += \
-D_DEFAULT_SOURCE \
-D_BSD_SOURCE
endif
# NOTE: The -Wl,--gc-sections flag may interfere with debugging using gdb.
ifeq ($(OS),posix)
override LDFLAGS += \
-L$(RTL_DIR)/lib/$(UNAME)_$(DEVICE)/gcc/release \
-lstdc++ \
-lpthread \
-lm
else
override LDFLAGS += \
-static \
-lstdc++ \
-lpthread \
-lWs2_32
endif
####################################################################
# Files #
####################################################################
C_SRC += \
$(SDK_DIR)/app/common_host/system/system.c \
$(SDK_DIR)/app/common_host/app_signal/app_signal_$(OS).c \
app.c \
loc.c \
conn.c \
main.c
# this file should be the last added
C_SRC += \
$(SDK_DIR)/app/common/uart/uart_$(OS).c
# Project resources
INC_FILES = $(foreach dir,$(INCLUDEPATHS),$(wildcard $(dir)/*.h))
PROJ_FILES = $(C_SRC) $(INC_FILES) $(RTL_DIR)/lib makefile
DST_DIR = $(EXPORT_DIR)/app/$(PROJECTNAME)/
DST_FILES := $(addprefix $(DST_DIR), $(PROJ_FILES))
####################################################################
# Rules #
####################################################################
C_FILES = $(notdir $(C_SRC) )
#make list of source paths, uniq removes duplicate paths
C_PATHS = $(call uniq, $(dir $(C_SRC) ) )
C_OBJS = $(addprefix $(OBJ_DIR)/, $(C_FILES:.c=.o))
C_DEPS = $(addprefix $(OBJ_DIR)/, $(C_FILES:.c=.d))
OBJS = $(C_OBJS)
vpath %.c $(C_PATHS)
# Default build is debug build
all: debug
debug: CFLAGS += -O0 -g3
debug: $(EXE_DIR)/$(PROJECTNAME)
release: $(EXE_DIR)/$(PROJECTNAME)
# Create objects from C SRC files
$(OBJ_DIR)/%.o: %.c
#echo "Building file: $<"
$(CC) $(CFLAGS) $(INCFLAGS) -c -o $# $<
# Link
$(EXE_DIR)/$(PROJECTNAME): $(OBJS)
#echo "Linking target: $#"
$(CC) $^ $(LDFLAGS) -o $#
clean:
ifeq ($(filter $(MAKECMDGOALS),all debug release),)
$(RMDIRS) $(OBJ_DIR) $(LST_DIR) $(EXE_DIR) $(EXPORT_DIR)
endif
# Collect project files for exporting
$(DST_FILES) : $(addprefix $(DST_DIR), %) : %
#mkdir -p $(dir $#) && cp -pRv $< $#
export: $(DST_FILES)
#echo "Exporting done."
# include auto-generated dependency files (explicit rules)
ifneq (clean,$(findstring clean, $(MAKECMDGOALS)))
-include $(C_DEPS)
endif
Look here:
UNAME := $(shell uname | tr '[:upper:]' '[:lower:]')
You run $(shell uname ...). That starts a shell and runs the command given. If you run make so that it uses cmd.exe as its shell without msys or Cygwin, then it's as if you typed uname | tr '[:upper:]' '[:lower:]' at your cmd.exe prompt, which obviously will fail as you've seen.
If you want to avoid msys or Cygwin then you have to fix ALL of your makefile to not use any POSIX commands, including here.

How to solve this 'Error Refreshing Makefiles'?

When I click on Run on my VeinsTutorial (the one that Christoph Sommer made and you might be familiar with it), I get error shown below. Do you have any idea? I really need to get over this error.
Error refreshing Makefiles
Reason:
you have both .cc and .cpp files -- specify -e cc or -e cpp option to select which set of files to use
make MODE=release all
make: *** No rule to make target 'all'. Stop.
"make MODE=release all" terminated with exit code 2. Build might be incomplete.
'
'Simulation terminated with exit code: 1
<!> Error: NED type 'veinstutorial.src.TutorialAppl' could not be fully resolved due to a missing base type or interface, at C:\Users\konra\git\repository\carlogicapi-master\carlogicapi-master\tutorials\VeinsTutorial\src\TutorialAppl.ned:19
End.
This is the MAKEFILES FILE where I should change something, but I cannot see where it should be changed.
#
# OMNeT++/OMNEST Makefile for $(LIB_PREFIX)veins
#
# This file was generated with the command:
# opp_makemake --make-so -f --deep -o veins -O out -pVEINS -I. -I.
#
# Name of target to be created (-o option)
TARGET = $(LIB_PREFIX)veins$(D)$(SHARED_LIB_SUFFIX)
TARGET_DIR = .
# C++ include paths (with -I)
INCLUDE_PATH = -I. -I.
# Additional object and library files to link with
EXTRA_OBJS =
# Additional libraries (-L, -l options)
LIBS =
# Output directory
PROJECT_OUTPUT_DIR = ../out
PROJECTRELATIVE_PATH = src
O = $(PROJECT_OUTPUT_DIR)/$(CONFIGNAME)/$(PROJECTRELATIVE_PATH)
# Object files for local .cc, .msg and .sm files
OBJS = \
$O/veins/base/connectionManager/BaseConnectionManager.o \
$O/veins/base/connectionManager/ChannelAccess.o \
$O/veins/base/connectionManager/ConnectionManager.o \
$O/veins/base/connectionManager/NicEntryDebug.o \
$O/veins/base/connectionManager/NicEntryDirect.o \
$O/veins/base/modules/BaseApplLayer.o \
$O/veins/base/modules/BaseBattery.o \
$O/veins/base/modules/BaseLayer.o \
$O/veins/base/modules/BaseMacLayer.o \
$O/veins/base/modules/BaseMobility.o \
$O/veins/base/modules/BaseModule.o \
$O/veins/base/modules/BaseWorldUtility.o \
$O/veins/base/modules/BatteryAccess.o \
$O/veins/base/phyLayer/Antenna.o \
$O/veins/base/phyLayer/BaseDecider.o \
$O/veins/base/phyLayer/BasePhyLayer.o \
$O/veins/base/phyLayer/ChannelInfo.o \
$O/veins/base/phyLayer/Decider.o \
$O/veins/base/phyLayer/PhyUtils.o \
$O/veins/base/toolbox/Signal.o \
$O/veins/base/toolbox/SignalUtils.o \
$O/veins/base/toolbox/Spectrum.o \
$O/veins/base/utils/Coord.o \
$O/veins/base/utils/Heading.o \
$O/veins/base/utils/NetwToMacControlInfo.o \
$O/veins/base/utils/SimpleAddress.o \
$O/veins/base/utils/winsupport.o \
$O/veins/modules/analogueModel/BreakpointPathlossModel.o \
$O/veins/modules/analogueModel/NakagamiFading.o \
$O/veins/modules/analogueModel/PERModel.o \
$O/veins/modules/analogueModel/SimpleObstacleShadowing.o \
$O/veins/modules/analogueModel/SimplePathlossModel.o \
$O/veins/modules/analogueModel/TwoRayInterferenceModel.o \
$O/veins/modules/analogueModel/VehicleObstacleShadowing.o \
$O/veins/modules/application/ieee80211p/DemoBaseApplLayer.o \
$O/veins/modules/application/traci/MyVeinsApp.o \
$O/veins/modules/application/traci/TraCIDemo11p.o \
$O/veins/modules/application/traci/TraCIDemoRSU11p.o \
$O/veins/modules/mac/ieee80211p/Mac1609_4.o \
$O/veins/modules/mobility/LinearMobility.o \
$O/veins/modules/mobility/traci/TraCIBuffer.o \
$O/veins/modules/mobility/traci/TraCIColor.o \
$O/veins/modules/mobility/traci/TraCICommandInterface.o \
$O/veins/modules/mobility/traci/TraCIConnection.o \
$O/veins/modules/mobility/traci/TraCICoordinateTransformation.o \
$O/veins/modules/mobility/traci/TraCILauncher.o \
$O/veins/modules/mobility/traci/TraCIMobility.o \
$O/veins/modules/mobility/traci/TraCIRegionOfInterest.o \
$O/veins/modules/mobility/traci/TraCIScenarioManager.o \
$O/veins/modules/mobility/traci/TraCIScenarioManagerForker.o \
$O/veins/modules/mobility/traci/TraCIScenarioManagerLaunchd.o \
$O/veins/modules/mobility/traci/TraCIScreenRecorder.o \
$O/veins/modules/mobility/traci/TraCIVehicleInserter.o \
$O/veins/modules/obstacle/MobileHostObstacle.o \
$O/veins/modules/obstacle/Obstacle.o \
$O/veins/modules/obstacle/ObstacleControl.o \
$O/veins/modules/obstacle/VehicleObstacleControl.o \
$O/veins/modules/phy/Decider80211p.o \
$O/veins/modules/phy/NistErrorRate.o \
$O/veins/modules/phy/PhyLayer80211p.o \
$O/veins/modules/phy/SampledAntenna1D.o \
$O/veins/modules/utility/BBoxLookup.o \
$O/veins/modules/utility/HasLogProxy.o \
$O/veins/modules/utility/TimerManager.o \
$O/veins/modules/world/annotations/AnnotationDummy.o \
$O/veins/modules/world/annotations/AnnotationManager.o \
$O/veins/modules/world/traci/trafficLight/TraCITrafficLightInterface.o \
$O/veins/modules/world/traci/trafficLight/TraCITrafficLightProgram.o \
$O/veins/modules/world/traci/trafficLight/logics/TraCITrafficLightAbstractLogic.o \
$O/veins/modules/world/traci/trafficLight/logics/TraCITrafficLightSimpleLogic.o \
$O/veins/base/messages/AirFrame_m.o \
$O/veins/base/messages/BorderMsg_m.o \
$O/veins/base/messages/MacPkt_m.o \
$O/veins/modules/application/traci/TraCIDemo11pMessage_m.o \
$O/veins/modules/messages/AckTimeOutMessage_m.o \
$O/veins/modules/messages/AirFrame11p_m.o \
$O/veins/modules/messages/BaseFrame1609_4_m.o \
$O/veins/modules/messages/DemoSafetyMessage_m.o \
$O/veins/modules/messages/DemoServiceAdvertisement_m.o \
$O/veins/modules/messages/Mac80211Ack_m.o \
$O/veins/modules/messages/Mac80211Pkt_m.o \
$O/veins/modules/messages/PhyControlMessage_m.o \
$O/veins/modules/messages/TraCITrafficLightMessage_m.o \
$O/veins/modules/messages/WaveShortMessage_m.o
# Message files
MSGFILES = \
veins/base/messages/AirFrame.msg \
veins/base/messages/BorderMsg.msg \
veins/base/messages/MacPkt.msg \
veins/modules/application/traci/TraCIDemo11pMessage.msg \
veins/modules/messages/AckTimeOutMessage.msg \
veins/modules/messages/AirFrame11p.msg \
veins/modules/messages/BaseFrame1609_4.msg \
veins/modules/messages/DemoSafetyMessage.msg \
veins/modules/messages/DemoServiceAdvertisement.msg \
veins/modules/messages/Mac80211Ack.msg \
veins/modules/messages/Mac80211Pkt.msg \
veins/modules/messages/PhyControlMessage.msg \
veins/modules/messages/TraCITrafficLightMessage.msg \
veins/modules/messages/WaveShortMessage.msg
# SM files
SMFILES =
#------------------------------------------------------------------------------
# Pull in OMNeT++ configuration (Makefile.inc)
ifneq ("$(OMNETPP_CONFIGFILE)","")
CONFIGFILE = $(OMNETPP_CONFIGFILE)
else
ifneq ("$(OMNETPP_ROOT)","")
CONFIGFILE = $(OMNETPP_ROOT)/Makefile.inc
else
CONFIGFILE = $(shell opp_configfilepath)
endif
endif
ifeq ("$(wildcard $(CONFIGFILE))","")
$(error Config file '$(CONFIGFILE)' does not exist -- add the OMNeT++ bin directory to the path so that opp_configfilepath can be found, or set the OMNETPP_CONFIGFILE variable to point to Makefile.inc)
endif
include $(CONFIGFILE)
# Simulation kernel and user interface libraries
OMNETPP_LIBS = -loppenvir$D $(KERNEL_LIBS) $(SYS_LIBS)
COPTS = $(CFLAGS) $(IMPORT_DEFINES) -DVEINS_EXPORT $(INCLUDE_PATH) -I$(OMNETPP_INCL_DIR)
MSGCOPTS = $(INCLUDE_PATH) -PVEINS_API
SMCOPTS =
# we want to recompile everything if COPTS changes,
# so we store COPTS into $COPTS_FILE and have object
# files depend on it (except when "make depend" was called)
COPTS_FILE = $O/.last-copts
ifneq ("$(COPTS)","$(shell cat $(COPTS_FILE) 2>/dev/null || echo '')")
$(shell $(MKPATH) "$O" && echo "$(COPTS)" >$(COPTS_FILE))
endif
#------------------------------------------------------------------------------
# User-supplied makefile fragment(s)
# >>>
# inserted from file 'makefrag':
#
# Copyright (C) 2017 Rudolf Hornig <rudi#omnetpp.org>
#
# Documentation for these modules is at http://veins.car2x.org/
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
# on windows we have to link with the ws2_32 (winsock2) library as it is no longer added to the omnetpp system libraries by default (as of OMNeT++ 5.1)
# copied from INET Framework (inet-3.6.0) makefrag
#
ifeq ($(PLATFORM),win32.x86_64)
LIBS += -lws2_32
DEFINES += -DVEINS_EXPORT
ENABLE_AUTO_IMPORT=-Wl,--enable-auto-import
LDFLAGS := $(filter-out $(ENABLE_AUTO_IMPORT), $(LDFLAGS))
endif
# <<<
#------------------------------------------------------------------------------
# Main target
all: $(TARGET_DIR)/$(TARGET)
$(TARGET_DIR)/% :: $O/%
#mkdir -p $(TARGET_DIR)
$(Q)$(LN) $< $#
ifeq ($(TOOLCHAIN_NAME),clangc2)
$(Q)-$(LN) $(<:%.dll=%.lib) $(#:%.dll=%.lib)
endif
$O/$(TARGET): $(OBJS) $(wildcard $(EXTRA_OBJS)) Makefile $(CONFIGFILE)
#$(MKPATH) $O
#echo Creating shared library: $#
$(Q)echo >.tmp$$$$ $(OBJS) $(EXTRA_OBJS) && $(AR) .tmplib$$$$ #.tmp$$$$ && $(SHLIB_LD) -o $O/$(TARGET) $(AS_NEEDED_OFF) $(WHOLE_ARCHIVE_ON) .tmplib$$$$ $(LIBS) $(WHOLE_ARCHIVE_OFF) $(OMNETPP_LIBS) $(LDFLAGS) && rm .tmp$$$$ && rm .tmplib$$$$
$(Q)$(SHLIB_POSTPROCESS) $O/$(TARGET)
.PHONY: all clean cleanall depend msgheaders smheaders
.SUFFIXES: .cc
$O/%.o: %.cc $(COPTS_FILE) | msgheaders smheaders
#$(MKPATH) $(dir $#)
$(qecho) "$<"
$(Q)$(CXX) -c $(CXXFLAGS) $(COPTS) -o $# $<
%_m.cc %_m.h: %.msg
$(qecho) MSGC: $<
$(Q)$(MSGC) -s _m.cc -MD -MP -MF $O/$(basename $<)_m.h.d $(MSGCOPTS) $?
%_sm.cc %_sm.h: %.sm
$(qecho) SMC: $<
$(Q)$(SMC) -c++ -suffix cc $(SMCOPTS) $?
msgheaders: $(MSGFILES:.msg=_m.h)
smheaders: $(SMFILES:.sm=_sm.h)
clean:
$(qecho) Cleaning $(TARGET)
$(Q)-rm -rf $O
$(Q)-rm -f $(TARGET_DIR)/$(TARGET)
$(Q)-rm -f $(TARGET_DIR)/$(TARGET:%.dll=%.lib)
$(Q)-rm -f $(call opp_rwildcard, . , *_m.cc *_m.h *_sm.cc *_sm.h)
cleanall:
$(Q)$(MAKE) -s clean MODE=release
$(Q)$(MAKE) -s clean MODE=debug
$(Q)-rm -rf $(PROJECT_OUTPUT_DIR)
# include all dependencies
-include $(OBJS:%=%.d) $(MSGFILES:%.msg=$O/%_m.h.d) ```
I just had to change the extension of the TutorialAppl.cpp to CC.
I guess sometimes we look for the difficult way to solve problems and it is actually the easy way you have to take :)
Thanks for your attention.

Using Jobs (Multicore) Flag Causes Makefile Compilation to Fail

Update: thanks for the help everyone, tripleee's recursive suggestion worked
flash: clean
sudo $(make) -j8 default
#echo Flashing: $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex
nrfjprog -f nrf52 --program $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex --sectorerase
nrfjprog -f nrf52 --reset
I noticed that sometimes when I make small change to my code and recompile using make, my code fails. A quick fix to this was to do a clean build (remove my build directory and rebuild). If I parallelise the make process (-j8) it compiles in 10 seconds, so this was an acceptable quick-n-dirty solution.
To automate the clean process, I setup
clean:
ifeq ($(UNAME), Linux)
sudo rm -rf _build
else
#echo os not supported
endif
flash: clean default
#echo Flashing: $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex
nrfjprog -f nrf52 --program $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex --sectorerase
nrfjprog -f nrf52 --reset
This worked when I was using it a few days ago, but now it to fails when I compile using the -j tag with >1 processors.
sudo rm -rf _build
mkdir _build
cd _build && mkdir nrf52832_xxaa
Compiling file: main.c
Compiling file: battery.c
Compiling file: tension.c
Compiling file: temperature.c
Compiling file: ble_hts_custom.c
Compiling file: accelerometer.c
Compiling file: bma2x2.c
Compiling file: ble_nus.c
Compiling file: ble_link_ctx_manager.c
../../../Src/temperature.c:20:1: fatal error: opening dependency file _build/nrf52832_xxaa/temperature.c.d: No such file or directory
}
^
compilation terminated.
make: *** [../../../../../../components/toolchain/gcc/Makefile.common:272: _build/nrf52832_xxaa/temperature.c.o] Error 1
make: *** Waiting for unfinished jobs....
../../../Src/main.c: In function 'TensionLevelUpdate':
../../../Src/main.c:254:13: warning: implicit declaration of function 'itoa'; did you mean '__itoa'? [-Wimplicit-function-declaration]
itoa(tension_level, tension, 10);
^~~~
__itoa
../../../Src/battery.c:19:1: fatal error: opening dependency file _build/nrf52832_xxaa/battery.c.d: No such file or directory
}
^
compilation terminated.
make: *** [../../../../../../components/toolchain/gcc/Makefile.common:272: _build/nrf52832_xxaa/battery.c.o] Error 1
../../../Src/tension.c:176:1: fatal error: opening dependency file _build/nrf52832_xxaa/tension.c.d: No such file or directory
}
^
compilation terminated.
make: *** [../../../../../../components/toolchain/gcc/Makefile.common:272: _build/nrf52832_xxaa/tension.c.o] Error 1
../../../../../../components/ble/ble_services/ble_nus/ble_nus.c:351:1: fatal error: opening dependency file _build/nrf52832_xxaa/ble_nus.c.d: No such file or directory
}
^
compilation terminated.
make: *** [../../../../../../components/toolchain/gcc/Makefile.common:272: _build/nrf52832_xxaa/ble_nus.c.o] Error 1
../../../Src/accelerometer.c:142:1: fatal error: opening dependency file _build/nrf52832_xxaa/accelerometer.c.d: No such file or directory
}
^
compilation terminated.
make: *** [../../../../../../components/toolchain/gcc/Makefile.common:272: _build/nrf52832_xxaa/accelerometer.c.o] Error 1
../../../Src/ble_hts_custom.c:470:1: fatal error: opening dependency file _build/nrf52832_xxaa/ble_hts_custom.c.d: No such file or directory
}
^
compilation terminated.
make: *** [../../../../../../components/toolchain/gcc/Makefile.common:272: _build/nrf52832_xxaa/ble_hts_custom.c.o] Error 1
../../../Src/main.c: At top level:
../../../Src/main.c:1096:1: fatal error: opening dependency file _build/nrf52832_xxaa/main.c.d: No such file or directory
}
My full makefile as requested by #code_fodder
PROJECT_NAME := ble_app_hts_pca10040_s132
TARGETS := nrf52832_xxaa
OUTPUT_DIRECTORY := _build
SDK_ROOT := ../../../../../..
PROJ_DIR := ../../..
$(OUTPUT_DIRECTORY)/nrf52832_xxaa.out: \
LINKER_SCRIPT := ble_app_hts_gcc_nrf52.ld
######################################
# building variables
######################################
# debug build?
DEBUG ?= 0
DEBUG_PIN ?= 0
BAUDRATE ?= 0
# simulation build?
SIMULATE ?= 0
# devkit build?
DEVKIT ?= 0
# optimization
OPT = -O3
# Source files common to all targets
SRC_FILES += \
$(PROJ_DIR)/Src/main.c \
$(PROJ_DIR)/Src/battery.c \
$(PROJ_DIR)/Src/tension.c \
$(PROJ_DIR)/Src/temperature.c \
$(PROJ_DIR)/Src/ble_hts_custom.c \
$(PROJ_DIR)/Src/accelerometer.c \
$(PROJ_DIR)/Src/bma2x2.c \
$(SDK_ROOT)/components/ble/ble_services/ble_nus/ble_nus.c \
$(SDK_ROOT)/components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_saadc.c \
$(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52.S \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_rtt.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_uart.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_default_backends.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_frontend.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_str_formatter.c \
$(SDK_ROOT)/components/libraries/button/app_button.c \
$(SDK_ROOT)/components/libraries/util/app_error.c \
$(SDK_ROOT)/components/libraries/util/app_error_handler_gcc.c \
$(SDK_ROOT)/components/libraries/util/app_error_weak.c \
$(SDK_ROOT)/components/libraries/scheduler/app_scheduler.c \
$(SDK_ROOT)/components/libraries/timer/app_timer.c \
$(SDK_ROOT)/components/libraries/util/app_util_platform.c \
$(SDK_ROOT)/components/libraries/crc16/crc16.c \
$(SDK_ROOT)/components/libraries/fds/fds.c \
$(SDK_ROOT)/components/libraries/hardfault/hardfault_implementation.c \
$(SDK_ROOT)/components/libraries/util/nrf_assert.c \
$(SDK_ROOT)/components/libraries/atomic_fifo/nrf_atfifo.c \
$(SDK_ROOT)/components/libraries/atomic_flags/nrf_atflags.c \
$(SDK_ROOT)/components/libraries/atomic/nrf_atomic.c \
$(SDK_ROOT)/components/libraries/balloc/nrf_balloc.c \
$(SDK_ROOT)/external/fprintf/nrf_fprintf.c \
$(SDK_ROOT)/external/fprintf/nrf_fprintf_format.c \
$(SDK_ROOT)/components/libraries/fstorage/nrf_fstorage.c \
$(SDK_ROOT)/components/libraries/fstorage/nrf_fstorage_sd.c \
$(SDK_ROOT)/components/libraries/memobj/nrf_memobj.c \
$(SDK_ROOT)/components/libraries/pwr_mgmt/nrf_pwr_mgmt.c \
$(SDK_ROOT)/components/libraries/ringbuf/nrf_ringbuf.c \
$(SDK_ROOT)/components/libraries/experimental_section_vars/nrf_section_iter.c \
$(SDK_ROOT)/components/libraries/strerror/nrf_strerror.c \
$(SDK_ROOT)/components/libraries/sensorsim/sensorsim.c \
$(SDK_ROOT)/modules/nrfx/mdk/system_nrf52.c \
$(SDK_ROOT)/components/boards/boards.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_clock.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_uart.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_spi.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_clock.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_gpiote.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_power_clock.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/prs/nrfx_prs.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uart.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uarte.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_spim.c \
$(SDK_ROOT)/components/libraries/bsp/bsp.c \
$(SDK_ROOT)/components/libraries/bsp/bsp_btn_ble.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \
$(SDK_ROOT)/components/ble/peer_manager/auth_status_tracker.c \
$(SDK_ROOT)/components/ble/common/ble_advdata.c \
$(SDK_ROOT)/components/ble/ble_advertising/ble_advertising.c \
$(SDK_ROOT)/components/ble/common/ble_conn_params.c \
$(SDK_ROOT)/components/ble/common/ble_conn_state.c \
$(SDK_ROOT)/components/ble/common/ble_srv_common.c \
$(SDK_ROOT)/components/ble/peer_manager/gatt_cache_manager.c \
$(SDK_ROOT)/components/ble/peer_manager/gatts_cache_manager.c \
$(SDK_ROOT)/components/ble/peer_manager/id_manager.c \
$(SDK_ROOT)/components/ble/nrf_ble_gatt/nrf_ble_gatt.c \
$(SDK_ROOT)/components/ble/nrf_ble_qwr/nrf_ble_qwr.c \
$(SDK_ROOT)/components/ble/peer_manager/peer_data_storage.c \
$(SDK_ROOT)/components/ble/peer_manager/peer_database.c \
$(SDK_ROOT)/components/ble/peer_manager/peer_id.c \
$(SDK_ROOT)/components/ble/peer_manager/peer_manager.c \
$(SDK_ROOT)/components/ble/peer_manager/peer_manager_handler.c \
$(SDK_ROOT)/components/ble/peer_manager/pm_buffer.c \
$(SDK_ROOT)/components/ble/peer_manager/security_dispatcher.c \
$(SDK_ROOT)/components/ble/peer_manager/security_manager.c \
$(SDK_ROOT)/external/utf_converter/utf.c \
$(SDK_ROOT)/components/ble/ble_services/ble_bas/ble_bas.c \
$(SDK_ROOT)/components/ble/ble_services/ble_dis/ble_dis.c \
$(SDK_ROOT)/components/softdevice/common/nrf_sdh.c \
$(SDK_ROOT)/components/softdevice/common/nrf_sdh_ble.c \
$(SDK_ROOT)/components/softdevice/common/nrf_sdh_soc.c \
# Include folders common to all targets
INC_FOLDERS += \
$(PROJ_DIR)/Inc \
$(SDK_ROOT)/components/ble/ble_services/ble_nus \
$(SDK_ROOT)/components/ble/ble_link_ctx_manager \
$(SDK_ROOT)/components/nfc/ndef/generic/message \
$(SDK_ROOT)/components/nfc/t2t_lib \
$(SDK_ROOT)/components/nfc/t4t_parser/hl_detection_procedure \
$(SDK_ROOT)/components/ble/ble_services/ble_ancs_c \
$(SDK_ROOT)/components/ble/ble_services/ble_ias_c \
$(SDK_ROOT)/components/libraries/pwm \
$(SDK_ROOT)/components/softdevice/s132/headers/nrf52 \
$(SDK_ROOT)/components/libraries/usbd/class/cdc/acm \
$(SDK_ROOT)/components/libraries/usbd/class/hid/generic \
$(SDK_ROOT)/components/libraries/usbd/class/msc \
$(SDK_ROOT)/components/libraries/usbd/class/hid \
$(SDK_ROOT)/modules/nrfx/hal \
$(SDK_ROOT)/components/nfc/ndef/conn_hand_parser/le_oob_rec_parser \
$(SDK_ROOT)/components/libraries/log \
$(SDK_ROOT)/components/ble/ble_services/ble_gls \
$(SDK_ROOT)/components/libraries/fstorage \
$(SDK_ROOT)/components/nfc/ndef/text \
$(SDK_ROOT)/components/libraries/mutex \
$(SDK_ROOT)/components/libraries/gpiote \
$(SDK_ROOT)/components/libraries/bootloader/ble_dfu \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/common \
$(SDK_ROOT)/components/boards \
$(SDK_ROOT)/components/nfc/ndef/generic/record \
$(SDK_ROOT)/components/nfc/t4t_parser/cc_file \
$(SDK_ROOT)/components/ble/ble_advertising \
$(SDK_ROOT)/external/utf_converter \
$(SDK_ROOT)/components/ble/ble_services/ble_bas_c \
$(SDK_ROOT)/modules/nrfx/drivers/include \
$(SDK_ROOT)/components/libraries/experimental_task_manager \
$(SDK_ROOT)/components/ble/ble_services/ble_hrs_c \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/le_oob_rec \
$(SDK_ROOT)/components/libraries/queue \
$(SDK_ROOT)/components/libraries/pwr_mgmt \
$(SDK_ROOT)/components/ble/ble_dtm \
$(SDK_ROOT)/components/toolchain/cmsis/include \
$(SDK_ROOT)/components/ble/ble_services/ble_rscs_c \
$(SDK_ROOT)/components/ble/common \
$(SDK_ROOT)/components/ble/ble_services/ble_lls \
$(SDK_ROOT)/components/libraries/bsp \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/ac_rec \
$(SDK_ROOT)/components/ble/ble_services/ble_bas \
$(SDK_ROOT)/components/libraries/mpu \
$(SDK_ROOT)/components/libraries/experimental_section_vars \
$(SDK_ROOT)/components/softdevice/s132/headers \
$(SDK_ROOT)/components/ble/ble_services/ble_ans_c \
$(SDK_ROOT)/components/libraries/slip \
$(SDK_ROOT)/components/libraries/delay \
$(SDK_ROOT)/components/libraries/mem_manager \
$(SDK_ROOT)/components/libraries/csense_drv \
$(SDK_ROOT)/components/libraries/memobj \
$(SDK_ROOT)/components/ble/ble_services/ble_nus_c \
$(SDK_ROOT)/components/softdevice/common \
$(SDK_ROOT)/components/ble/ble_services/ble_ias \
$(SDK_ROOT)/components/libraries/usbd/class/hid/mouse \
$(SDK_ROOT)/components/libraries/low_power_pwm \
$(SDK_ROOT)/components/nfc/ndef/conn_hand_parser/ble_oob_advdata_parser \
$(SDK_ROOT)/components/ble/ble_services/ble_dfu \
$(SDK_ROOT)/external/fprintf \
$(SDK_ROOT)/components/libraries/svc \
$(SDK_ROOT)/components/libraries/atomic \
$(SDK_ROOT)/components \
$(SDK_ROOT)/components/libraries/scheduler \
$(SDK_ROOT)/components/libraries/cli \
$(SDK_ROOT)/components/ble/ble_services/ble_lbs \
$(SDK_ROOT)/components/libraries/crc16 \
$(SDK_ROOT)/components/nfc/t4t_parser/apdu \
$(SDK_ROOT)/components/libraries/util \
../config \
$(SDK_ROOT)/components/libraries/usbd/class/cdc \
$(SDK_ROOT)/components/libraries/csense \
$(SDK_ROOT)/components/libraries/balloc \
$(SDK_ROOT)/components/libraries/ecc \
$(SDK_ROOT)/components/libraries/hardfault \
$(SDK_ROOT)/components/ble/ble_services/ble_cscs \
$(SDK_ROOT)/components/libraries/hci \
$(SDK_ROOT)/components/libraries/usbd/class/hid/kbd \
$(SDK_ROOT)/components/libraries/timer \
$(SDK_ROOT)/integration/nrfx \
$(SDK_ROOT)/components/nfc/t4t_parser/tlv \
$(SDK_ROOT)/components/libraries/sortlist \
$(SDK_ROOT)/components/libraries/spi_mngr \
$(SDK_ROOT)/components/libraries/led_softblink \
$(SDK_ROOT)/components/nfc/ndef/conn_hand_parser \
$(SDK_ROOT)/components/libraries/sdcard \
$(SDK_ROOT)/components/nfc/ndef/parser/record \
$(SDK_ROOT)/modules/nrfx/mdk \
$(SDK_ROOT)/components/ble/ble_services/ble_cts_c \
$(SDK_ROOT)/components/ble/ble_services/ble_nus \
$(SDK_ROOT)/components/libraries/twi_mngr \
$(SDK_ROOT)/components/ble/ble_services/ble_hids \
$(SDK_ROOT)/components/libraries/strerror \
$(SDK_ROOT)/components/libraries/crc32 \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/ble_oob_advdata \
$(SDK_ROOT)/components/nfc/t2t_parser \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/ble_pair_msg \
$(SDK_ROOT)/components/libraries/usbd/class/audio \
$(SDK_ROOT)/components/nfc/t4t_lib/hal_t4t \
$(SDK_ROOT)/components/libraries/sensorsim \
$(SDK_ROOT)/components/nfc/t4t_lib \
$(SDK_ROOT)/components/ble/peer_manager \
$(SDK_ROOT)/components/drivers_nrf/usbd \
$(SDK_ROOT)/components/libraries/ringbuf \
$(SDK_ROOT)/components/ble/ble_services/ble_tps \
$(SDK_ROOT)/components/nfc/ndef/parser/message \
$(SDK_ROOT)/components/ble/ble_services/ble_dis \
$(SDK_ROOT)/components/nfc/ndef/uri \
$(SDK_ROOT)/components/ble/nrf_ble_gatt \
$(SDK_ROOT)/components/ble/nrf_ble_qwr \
$(SDK_ROOT)/components/libraries/gfx \
$(SDK_ROOT)/components/libraries/button \
$(SDK_ROOT)/modules/nrfx \
$(SDK_ROOT)/components/libraries/twi_sensor \
$(SDK_ROOT)/integration/nrfx/legacy \
$(SDK_ROOT)/components/libraries/usbd \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/ep_oob_rec \
$(SDK_ROOT)/external/segger_rtt \
$(SDK_ROOT)/components/libraries/atomic_fifo \
$(SDK_ROOT)/components/ble/ble_services/ble_lbs_c \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/ble_pair_lib \
$(SDK_ROOT)/components/libraries/crypto \
$(SDK_ROOT)/components/ble/ble_racp \
$(SDK_ROOT)/components/libraries/fds \
$(SDK_ROOT)/components/nfc/ndef/launchapp \
$(SDK_ROOT)/components/libraries/atomic_flags \
$(SDK_ROOT)/components/ble/ble_services/ble_hrs \
$(SDK_ROOT)/components/ble/ble_services/ble_rscs \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/hs_rec \
$(SDK_ROOT)/components/nfc/t2t_lib/hal_t2t \
$(SDK_ROOT)/components/nfc/ndef/conn_hand_parser/ac_rec_parser \
$(SDK_ROOT)/components/libraries/stack_guard \
$(SDK_ROOT)/components/libraries/log/src \
# Libraries common to all targets
LIB_FILES += \
# Debug option
ifeq ($(DEBUG), 1)
# use 'make sdk_config -> nRF_Log -> NRF_LOG_BACKEND_UART_ENABLED' to see default params
C_DEFS += -DDEBUG
C_DEFS += -DNRF_LOG_ENABLED=1
C_DEFS += -DNRF_LOG_BACKEND_UART_ENABLED=1
ifneq ($(DEBUG_PIN), 0)
C_DEFS += -DNRF_LOG_BACKEND_UART_TX_PIN=$(DEBUG_PIN)
endif
ifneq ($(BAUDRATE), 0)
C_DEFS += -DNRF_LOG_BACKEND_UART_BAUDRATE=$(BAUDRATE)
endif
OPT = -Og
endif
ifeq ($(SIMULATE), 1)
C_DEFS += -DSIMULATE
endif
ifeq ($(DEVKIT), 1)
C_DEFS += -DDEVKIT
endif
# C flags common to all targets
CFLAGS += $(OPT)
CFLAGS += -DBOARD_PCA10040
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
CFLAGS += -DCONFIG_NFCT_PINS_AS_GPIOS
CFLAGS += -DFLOAT_ABI_HARD
CFLAGS += -DNRF52
CFLAGS += -DNRF52832_XXAA
CFLAGS += -DNRF52_PAN_74
CFLAGS += -DNRF_SD_BLE_API_VERSION=6
CFLAGS += -DS132
CFLAGS += -DSOFTDEVICE_PRESENT
CFLAGS += -DSWI_DISABLE0
CFLAGS += -mcpu=cortex-m4
CFLAGS += -mthumb -mabi=aapcs
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# keep every function in a separate section, this allows linker to discard unused ones
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin -fshort-enums
CFLAGS += -Wall -g3
CFLAGS += $(C_DEFS)
# CFLAGS += -Werror # if you want warnings treated as errors
# C++ flags common to all targets
CXXFLAGS += $(OPT) -std=c++1z
# Assembler flags common to all targets
ASMFLAGS += -g3
ASMFLAGS += -mcpu=cortex-m4
ASMFLAGS += -mthumb -mabi=aapcs
ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
ASMFLAGS += -DBOARD_PCA10040
ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
ASMFLAGS += -DFLOAT_ABI_HARD
ASMFLAGS += -DNRF52
ASMFLAGS += -DNRF52832_XXAA
ASMFLAGS += -DNRF52_PAN_74
ASMFLAGS += -DNRF_SD_BLE_API_VERSION=6
ASMFLAGS += -DS132
ASMFLAGS += -DSOFTDEVICE_PRESENT
ASMFLAGS += -DSWI_DISABLE0
# Linker flags
LDFLAGS += $(OPT)
LDFLAGS += -mthumb -mabi=aapcs -L$(SDK_ROOT)/modules/nrfx/mdk -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m4
LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# let linker dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs
nrf52832_xxaa: CFLAGS += -D__HEAP_SIZE=8192
nrf52832_xxaa: CFLAGS += -D__STACK_SIZE=8192
nrf52832_xxaa: ASMFLAGS += -D__HEAP_SIZE=8192
nrf52832_xxaa: ASMFLAGS += -D__STACK_SIZE=8192
# Add standard libraries at the very end of the linker input, after all objects
# that may need symbols provided by these libraries.
LIB_FILES += -lc -lnosys -lm
.PHONY: default help
# Default target - first one defined
default: nrf52832_xxaa
# Print all targets that can be built
help:
#echo following targets are available:
#echo nrf52832_xxaa
#echo flash_softdevice
#echo sdk_config - starting external tool for editing sdk_config.h
#echo flash - flashing binary
TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc
include $(TEMPLATE_PATH)/Makefile.common
$(foreach target, $(TARGETS), $(call define_target, $(target)))
.PHONY: flash flash_softdevice erase
UNAME := $(shell uname)
clean:
ifeq ($(UNAME), Linux)
sudo rm -rf _build
else
#echo os not supported for clean target
endif
flash: clean default
#echo Flashing: $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex
nrfjprog -f nrf52 --program $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex --sectorerase
nrfjprog -f nrf52 --reset
SDK_CONFIG_FILE := ../config/sdk_config.h
CMSIS_CONFIG_TOOL := $(SDK_ROOT)/external_tools/cmsisconfig/CMSIS_Configuration_Wizard.jar
sdk_config:
java -jar $(CMSIS_CONFIG_TOOL) $(SDK_CONFIG_FILE)
For completeness, makefile.common is invoked in the first makefile so I'll add it here
# Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form, except as embedded into a Nordic
# Semiconductor ASA integrated circuit in a product or a software update for
# such product, must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# 3. Neither the name of Nordic Semiconductor ASA nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# 4. This software, with or without modification, must only be used with a
# Nordic Semiconductor ASA integrated circuit.
#
# 5. Any software provided in binary form under this license must not be reverse
# engineered, decompiled, modified and/or disassembled.
#
# THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Options:
# VERBOSE=1 (default is 0) - print each executed command
# PRETTY=1 (default is 0) - show progress, in percentage
# ABSOLUTE_PATHS=1 (default is 0) - convert all include folders and source
# file paths to their absolute forms
# PASS_INCLUDE_PATHS_VIA_FILE=1 (default is 0) - use <target>.inc file
# to pass include paths to gcc
# PASS_LINKER_INPUT_VIA_FILE=0 (default is 1) - don't use <target>.in file
# to pass the list of linker input files
VERBOSE ?= 0
PRETTY ?= 0
ABSOLUTE_PATHS ?= 0
PASS_INCLUDE_PATHS_VIA_FILE ?= 0
PASS_LINKER_INPUT_VIA_FILE ?= 1
.SUFFIXES: # ignore built-in rules
%.d: # don't try to make .d files
.PRECIOUS: %.d %.o
MK := mkdir
RM := rm -rf
# echo suspend
ifeq ($(VERBOSE),1)
NO_ECHO :=
else
NO_ECHO := #
endif
ifneq (,$(filter clean, $(MAKECMDGOALS)))
OTHER_GOALS := $(filter-out clean, $(MAKECMDGOALS))
ifneq (, $(OTHER_GOALS))
$(info Cannot make anything in parallel with "clean".)
$(info Execute "$(MAKE) clean \
$(foreach goal, $(OTHER_GOALS),&& $(MAKE) $(goal))" instead.)
$(error Cannot continue)
else
.PHONY: clean
clean:
$(RM) $(OUTPUT_DIRECTORY)
endif # ifneq(, $(OTHER_GOALS))
else # ifneq (,$(filter clean, $(MAKECMDGOALS)))
ifndef PROGRESS
ifeq ($(PRETTY),1)
X := #
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
TOTAL := $(subst $(SPACE),,$(filter $(X), \
$(shell "$(MAKE)" $(MAKECMDGOALS) --dry-run \
--no-print-directory PROGRESS=$(X))))
5 := $(X)$(X)$(X)$(X)$(X)
25 := $(5)$(5)$(5)$(5)$(5)
100 := $(25)$(25)$(25)$(25)
C :=
COUNTER = $(eval C := $(C)$(100))$(C)
P :=
count = $(if $(filter $1%,$2),$(eval \
P += 1)$(call count,$1,$(2:$1%=%)),$(eval \
C := $2))
print = [$(if $(word 99,$1),99,$(if $(word 10,$1),, )$(words $1))%]
PROGRESS = $(call count,$(TOTAL),$(COUNTER))$(call print,$(P)) $1
else
PROGRESS = $1
endif # ifeq ($(PRETTY),1)
PLATFORM_SUFFIX := $(if $(filter Windows%,$(OS)),windows,posix)
TOOLCHAIN_CONFIG_FILE := $(TEMPLATE_PATH)/Makefile.$(PLATFORM_SUFFIX)
include $(TOOLCHAIN_CONFIG_FILE)
# $1 path
define quote
'$(subst ','\'',$(1))'
endef
# Toolchain commands
CC := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-gcc)
CXX := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-c++)
AS := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-as)
AR := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-ar) -r
LD := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-ld)
NM := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-nm)
OBJDUMP := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-objdump)
OBJCOPY := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-objcopy)
SIZE := $(call quote,$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-size)
$(if $(shell $(CC) --version),,$(info Cannot find: $(CC).) \
$(info Please set values in: "$(abspath $(TOOLCHAIN_CONFIG_FILE))") \
$(info according to the actual configuration of your system.) \
$(error Cannot continue))
# Use ccache on linux if available
CCACHE := $(if $(filter Windows%,$(OS)),, \
$(if $(wildcard /usr/bin/ccache),ccache))
CC := $(CCACHE) $(CC)
endif # ifndef PROGRESS
# $1 type of item
# $2 items paths to check
define ensure_exists_each
$(foreach item, $(2), \
$(if $(wildcard $(item)),, $(warning Cannot find $(1): $(item))))
endef
ifeq ($(PASS_INCLUDE_PATHS_VIA_FILE),1)
INC_PATHS = #$($#_INC)
GENERATE_INC_FILE := 1
else
INC_PATHS = $(call target_specific, INC_PATHS, $($#_TGT))
GENERATE_INC_FILE :=
endif
# $1 object file
# $2 source file
# $3 include paths container file
# $4 target name
define bind_obj_with_src
$(eval $(1) := $(2)) \
$(eval $(1)_INC := $(3)) \
$(eval $(1)_TGT := $(4)) \
$(eval $(1): Makefile | $(dir $(1)).) \
$(if $(GENERATE_INC_FILE), $(eval $(1): $(3)))
endef
# $1 target name
# $2 source file name
# Note: this additional .o for .s files is a workaround for issues with make 4.1
# from MinGW (it does nothing to remake .s.o files when a rule for .S.o
# files is defined as well).
define get_object_file_name
$(OUTPUT_DIRECTORY)/$(strip $(1))/$(notdir $(2:%.s=%.s.o)).o
endef
# $1 target name
# $2 include paths container file
# $3 list of source files
define get_object_files
$(call ensure_exists_each,source file, $(3)) \
$(foreach src_file, $(3), \
$(eval obj_file := $(call get_object_file_name, $(1), $(src_file))) \
$(eval DEPENDENCIES += $(obj_file:.o=.d)) \
$(call bind_obj_with_src, $(obj_file), $(src_file), $(2), $(1)) \
$(obj_file))
endef
# $1 variable name
# $2 target name
define target_specific
$($(addsuffix _$(strip $(2)), $(1)))
endef
ifeq ($(ABSOLUTE_PATHS),1)
get_path = $(call quote,$(abspath $1))
else
get_path = $1
endif
# $1 list of include folders
define get_inc_paths
$(call ensure_exists_each,include folder,$(1)) \
$(foreach folder,$(1),-I$(call get_path,$(folder)))
endef
# $1 target name
# $2 include paths container file
# $3 build goal name
define prepare_build
$(eval DEPENDENCIES :=) \
$(eval $(3): \
$(call get_object_files, $(1), $(2), \
$(SRC_FILES) $(call target_specific, SRC_FILES, $(1)))) \
$(eval -include $(DEPENDENCIES)) \
$(eval INC_PATHS_$(strip $(1)) := \
$(call get_inc_paths, \
$(INC_FOLDERS) $(call target_specific, INC_FOLDERS, $(1))))
endef
# $1 target name
define define_target
$(eval OUTPUT_FILE := $(OUTPUT_DIRECTORY)/$(strip $(1))) \
$(eval $(1): $(OUTPUT_FILE).out $(OUTPUT_FILE).hex $(OUTPUT_FILE).bin \
; #echo DONE $(strip $(1))) \
$(call prepare_build, $(1), $(OUTPUT_FILE).inc, $(OUTPUT_FILE).out)
endef
# $1 target name
# $2 library file name
define define_library
$(eval OUTPUT_FILE := $(OUTPUT_DIRECTORY)/$(strip $(1))) \
$(eval $(1) := $(2)) \
$(call prepare_build, $(1), $(OUTPUT_FILE).inc, $(1))
endef
# $1 content to be dumped
# Invokes another instance of MAKE to dump the specified content to stdout,
# which may be then redirected in shell to a file and this way stored there.
# MAKE in version prior to 4.0 does not provide the $(file ...) function.
define dump
$(eval CONTENT_TO_DUMP := $(1)) \
"$(MAKE)" -s --no-print-directory \
-f "$(TEMPLATE_PATH)/dump.mk" VARIABLE=CONTENT_TO_DUMP
endef
export CONTENT_TO_DUMP
.PHONY: $(TARGETS) all
all: $(TARGETS)
# Create build directories
$(OUTPUT_DIRECTORY):
$(MK) $#
$(OUTPUT_DIRECTORY)/%/.: | $(OUTPUT_DIRECTORY)
cd $(OUTPUT_DIRECTORY) && $(MK) $*
$(OUTPUT_DIRECTORY)/%.inc: Makefile | $(OUTPUT_DIRECTORY)
$(info Generating $#)
$(NO_ECHO)$(call dump, $(call target_specific, INC_PATHS, $*)) > $#
# $1 command
# $2 flags
# $3 message
define run
$(info $(call PROGRESS,$(3) file: $(notdir $($#)))) \
$(NO_ECHO)$(1) -MP -MD -c -o $# $(call get_path,$($#)) $(2) $(INC_PATHS)
endef
# Create object files from C source files
%.c.o:
$(call run,$(CC) -std=c99,$(CFLAGS),Compiling)
# Create object files from C++ source files
%.cpp.o:
$(call run,$(CXX),$(CFLAGS) $(CXXFLAGS),Compiling)
# Create object files from assembly source files
%.S.o %.s.o.o:
$(call run,$(CC) -x assembler-with-cpp,$(ASMFLAGS),Assembling)
ifeq ($(PASS_LINKER_INPUT_VIA_FILE),1)
GENERATE_LD_INPUT_FILE = $(call dump, $^ $(LIB_FILES)) > $(#:.out=.in)
LD_INPUT = #$(#:.out=.in)
else
GENERATE_LD_INPUT_FILE =
LD_INPUT = $^ $(LIB_FILES)
endif
# Link object files
%.out:
$(info $(call PROGRESS,Linking target: $#))
$(NO_ECHO)$(GENERATE_LD_INPUT_FILE)
$(NO_ECHO)$(CC) $(LDFLAGS) $(LD_INPUT) -Wl,-Map=$(#:.out=.map) -o $#
$(NO_ECHO)$(SIZE) $#
# Create binary .bin file from the .out file
%.bin: %.out
$(info Preparing: $#)
$(NO_ECHO)$(OBJCOPY) -O binary $< $#
# Create binary .hex file from the .out file
%.hex: %.out
$(info Preparing: $#)
$(NO_ECHO)$(OBJCOPY) -O ihex $< $#
endif # ifneq (,$(filter clean, $(MAKECMDGOALS)))
This is almost certainly not right:
flash: clean default
This tells make that both the clean and default targets need to complete before the recipe for the flash target can be invoked.
However, it says absolutely nothing about any relationship between the clean and default targets themselves. Since that's true, make will be free to run the recipes for both targets (and their prerequisites) in parallel, if you invoke it with the -j option.
It's highly unlikely it will work reliably for your clean target to be running in parallel with other, build targets.
ETA
There is only one way to tell make that one target must be built before another is started, and that's to define a prerequisite relationship. So if you want to require that clean must complete before default, the only way to tell make about that is to use:
default: clean
However you probably don't want to do this because it will mean that every time you run the default target it will first run the clean target.
There are some complicated things you can do but the simplest one is to use recursive make invocations. That would look something like this:
flash: clean
$(MAKE) default
#echo Flashing: $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex
nrfjprog -f nrf52 --program $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex --sectorerase
nrfjprog -f nrf52 --reset
This forces clean to run first before the recipe for flash, then the first line in the flash recipe invokes a recursive make that builds the default target.

How to fix GNU/Make "Too many open files. Stop." errors without increasing the open file limit?

I am currently trying to compile a project for an nRF52 board. When using make clean, I get the error message Makefile.common:12: *** Too many open files. Stop. (Line 12 of Makefile.common just says include $(TEMPLATE_PATH)Makefile.posix).
Every solution I can find online to this problem involves increasing the number of files the system can open at once. Unfortunately, I tried increasing it all the way to 20000 (which is apparently enough to overload the memory on my computer), and it still gave the same error message. So I don't think this is a practical solution in my case, and that this problem indicates something wrong with the makefile itself. Is there a culprit that would cause this to happen?
In case it's important, I'm using Ubuntu 18.04. The makefile is pasted below.
TARGETS := nrf52832_xxaa
OUTPUT_DIRECTORY := _build
SDK_ROOT := $(realpath ../../../../../..)
PROJ_DIR := ../../..
$(OUTPUT_DIRECTORY)/nrf52832_xxaa.out: \
LINKER_SCRIPT := ble_app_hrs_gcc_nrf52.ld
# Source files common to all targets
SRC_FILES += \
$(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52.S \
$(SDK_ROOT)/components/libraries/button/app_button.c \
$(SDK_ROOT)/components/libraries/util/app_error.c \
$(SDK_ROOT)/components/libraries/util/app_error_weak.c \
$(SDK_ROOT)/components/libraries/scheduler/app_scheduler.c \
$(SDK_ROOT)/components/libraries/timer/app_timer.c \
$(SDK_ROOT)/components/libraries/util/app_util_platform.c \
$(SDK_ROOT)/components/libraries/crc16/crc16.c \
$(SDK_ROOT)/components/libraries/fds/fds.c \
$(SDK_ROOT)/components/libraries/hardfault/hardfault_implementation.c \
$(SDK_ROOT)/components/libraries/util/nrf_assert.c \
$(SDK_ROOT)/components/libraries/fstorage/fstorage.c \
$(SDK_ROOT)/components/libraries/experimental_memobj/nrf_memobj.c \
$(SDK_ROOT)/components/libraries/pwr_mgmt/nrf_pwr_mgmt.c \
$(SDK_ROOT)/components/libraries/sensorsim/sensorsim.c \
$(SDK_ROOT)/components/drivers_nrf/nrf_drv_clock.c \
$(SDK_ROOT)/components/drivers_nrf/nrfx_drv_gpiote.c \
$(SDK_ROOT)/components/drivers_nrf/nrfx_uart.c \
$(PROJ_DIR)/main.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \
$(SDK_ROOT)/components/ble/common/ble_advdata.c \
$(SDK_ROOT)/components/ble/ble_advertising/ble_advertising.c \
$(SDK_ROOT)/components/ble/common/ble_conn_params.c \
$(SDK_ROOT)/components/ble/common/ble_conn_state.c \
$(SDK_ROOT)/components/ble/common/ble_srv_common.c \
$(SDK_ROOT)/components/ble/peer_manager/gatt_cache_manager.c \
$(SDK_ROOT)/components/ble/peer_manager/gatts_cache_manager.c \
$(SDK_ROOT)/components/ble/peer_manager/id_manager.c \
$(SDK_ROOT)/components/ble/peer_manager/peer_data_storage.c \
$(SDK_ROOT)/components/ble/peer_manager/peer_database.c \
$(SDK_ROOT)/components/ble/peer_manager/peer_id.c \
$(SDK_ROOT)/components/ble/peer_manager/peer_manager.c \
$(SDK_ROOT)/components/ble/peer_manager/pm_buffer.c \
$(SDK_ROOT)/components/ble/peer_manager/pm_mutex.c \
$(SDK_ROOT)/components/ble/peer_manager/security_dispatcher.c \
$(SDK_ROOT)/components/ble/peer_manager/security_manager.c \
$(SDK_ROOT)/components/ble/ble_services/ble_bas/ble_bas.c \
$(SDK_ROOT)/components/ble/ble_services/ble_dis/ble_dis.c \
$(SDK_ROOT)/components/ble/ble_services/ble_hrs/ble_hrs.c \
$(SDK_ROOT)/components/softdevice/common/softdevice_handler/softdevice_handler.c \
$(SDK_ROOT)/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.c \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/nfc_ble_pair_msg.c \
# Include folders common to all targets
INC_FOLDERS += \
$(SDK_ROOT)/components/nfc/ndef/generic/message \
$(SDK_ROOT)/components/nfc/t2t_lib \
$(SDK_ROOT)/components/ble/ble_services/ble_ancs_c \
$(SDK_ROOT)/components/ble/ble_services/ble_ias_c \
$(SDK_ROOT)/components/libraries/pwm \
$(SDK_ROOT)/components/softdevice/s132/headers/nrf52 \
$(SDK_ROOT)/components/drivers_nrf/hal \
$(SDK_ROOT)/components/ble/ble_services/ble_gls \
$(SDK_ROOT)/components/libraries/fstorage \
$(SDK_ROOT)/components/nfc/ndef/text \
$(SDK_ROOT)/components/libraries/gpiote \
$(SDK_ROOT)/components/libraries/bootloader_dfu \
$(SDK_ROOT)/components/nfc/ndef/connection_handover \
$(SDK_ROOT)/components/nfc/ndef/generic/record \
$(SDK_ROOT)/components/ble/ble_advertising \
$(SDK_ROOT)/components/ble/ble_services/ble_bas_c \
$(SDK_ROOT)/modules/nrfx/drivers/include \
$(SDK_ROOT)/components/libraries/experimental_task_manager \
$(SDK_ROOT)/components/ble/ble_services/ble_hrs_c \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/le_oob_rec \
$(SDK_ROOT)/components/libraries/queue \
$(SDK_ROOT)/components/libraries/pwr_mgmt \
$(SDK_ROOT)/components/ble/ble_dtm \
$(SDK_ROOT)/components/toolchain/CMSIS/include \
$(SDK_ROOT)/components/ble/ble_services/ble_rscs_c \
$(SDK_ROOT)/components/ble/common \
$(SDK_ROOT)/components/ble/ble_services/ble_lls \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/ac_rec \
$(SDK_ROOT)/components/ble/ble_services/ble_bas \
$(SDK_ROOT)/components/libraries/experimental_section_vars \
$(SDK_ROOT)/components/softdevice/s132/headers \
$(SDK_ROOT)/components/ble/ble_services/ble_ans_c \
$(SDK_ROOT)/components/libraries/slip \
$(SDK_ROOT)/components/drivers_nrf/delay \
$(SDK_ROOT)/components/libraries/mem_manager \
$(SDK_ROOT)/components/ble/ble_services/ble_nus_c \
$(SDK_ROOT)/components/softdevice/common \
$(SDK_ROOT)/components/ble/ble_services/ble_ias \
$(SDK_ROOT)/components/libraries/low_power_pwm \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/ep_oob_rec \
$(SDK_ROOT)/components/nfc/ndef/parser/message \
$(SDK_ROOT)/components/nfc/ndef/parser/record \
$(SDK_ROOT)/components/ble/ble_services/ble_dfu \
$(SDK_ROOT)/components \
$(SDK_ROOT)/components/libraries/scheduler \
$(SDK_ROOT)/components/ble/ble_services/ble_lbs \
$(SDK_ROOT)/components/ble/ble_services/ble_hts \
$(SDK_ROOT)/components/libraries/crc16 \
$(SDK_ROOT)/components/nfc/t2t_parser \
$(SDK_ROOT)/components/libraries/util \
../config \
$(SDK_ROOT)/components/libraries/ecc \
$(SDK_ROOT)/components/libraries/hardfault \
$(SDK_ROOT)/components/ble/ble_services/ble_cscs \
$(SDK_ROOT)/components/libraries/hci \
$(SDK_ROOT)/components/libraries/timer \
$(SDK_ROOT)/components/libraries/led_softblink \
$(SDK_ROOT)/components/nfc/ndef/parser \
$(SDK_ROOT)/components/nfc/ndef/connection_handover \
$(SDK_ROOT)/components/ble/ble_services/ble_cts_c \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/le_oob_rec \
$(SDK_ROOT)/components/ble/ble_services/ble_nus \
$(SDK_ROOT)/components/libraries/twi_mngr \
$(SDK_ROOT)/components/ble/ble_services/ble_hids \
$(SDK_ROOT)/components/libraries/strerror \
$(SDK_ROOT)/components/libraries/crc32 \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/ble_oob_advdata \
$(SDK_ROOT)/components/libraries/usbd/class/audio \
$(SDK_ROOT)/components/libraries/sensorsim \
$(SDK_ROOT)/components/nfc/t2t_lib \
$(SDK_ROOT)/components/ble/peer_manager \
$(SDK_ROOT)/components/ble/ble_services/ble_tps \
$(SDK_ROOT)/components/ble/ble_services/ble_dis \
$(SDK_ROOT)/components/nfc/ndef/uri \
$(SDK_ROOT)/components/libraries/button \
$(SDK_ROOT)/components/libraries/twi \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/ep_oob_rec \
$(SDK_ROOT)/external/segger_rtt \
$(SDK_ROOT)/components/ble/ble_services/ble_lbs_c \
$(SDK_ROOT)/components/libraries/sha256 \
$(SDK_ROOT)/components/ble/ble_racp \
$(SDK_ROOT)/components/libraries/fds \
$(SDK_ROOT)/components/nfc/ndef/launchapp \
$(SDK_ROOT)/components/ble/ble_services/ble_rscs \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/hs_rec \
$(SDK_ROOT)/components/nfc/t2t_lib/hal_t2t \
$(SDK_ROOT)/components/nfc/ndef/connection_handover/ac_rec \
$(SDK_ROOT)/components/ble/ble_services/ble_hrs \
# Libraries common to all targets
LIB_FILES += \
# Optimization flags
OPT = -O3 -g3
# Uncomment the line below to enable link time optimization
#OPT += -flto
# C flags common to all targets
CFLAGS += $(OPT)
CFLAGS += -DBLE_STACK_SUPPORT_REQD
CFLAGS += -DBOARD_PCA10040
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
CFLAGS += -DFLOAT_ABI_HARD
CFLAGS += -DNRF52
CFLAGS += -DNRF52832_XXAA
CFLAGS += -DNRF52_PAN_74
CFLAGS += -DNRF_SD_BLE_API_VERSION=6
CFLAGS += -DS132
CFLAGS += -DSOFTDEVICE_PRESENT
CFLAGS += -DSWI_DISABLE0
CFLAGS += -mcpu=cortex-m4
CFLAGS += -mthumb -mabi=aapcs
CFLAGS += -Wall -Werror
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# keep every function in a separate section, this allows linker to discard unused ones
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin -fshort-enums
# C++ flags common to all targets
CXXFLAGS += $(OPT)
# Assembler flags common to all targets
ASMFLAGS += -g3
ASMFLAGS += -mcpu=cortex-m4
ASMFLAGS += -mthumb -mabi=aapcs
ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
ASMFLAGS += -DBLE_STACK_SUPPORT_REQD
ASMFLAGS += -DBOARD_PCA10040
ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
ASMFLAGS += -DFLOAT_ABI_HARD
ASMFLAGS += -DNRF52
ASMFLAGS += -DNRF52832_XXAA
ASMFLAGS += -DNRF52_PAN_74
ASMFLAGS += -DNRF_SD_BLE_API_VERSION=6
ASMFLAGS += -DS132
ASMFLAGS += -DSOFTDEVICE_PRESENT
ASMFLAGS += -DSWI_DISABLE0
# Linker flags
LDFLAGS += $(OPT)
LDFLAGS += -mthumb -mabi=aapcs -L$(SDK_ROOT)/modules/nrfx/mdk -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m4
LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# let linker dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs
nrf52832_xxaa: CFLAGS += -D__HEAP_SIZE=8192
nrf52832_xxaa: CFLAGS += -D__STACK_SIZE=8192
nrf52832_xxaa: ASMFLAGS += -D__HEAP_SIZE=8192
nrf52832_xxaa: ASMFLAGS += -D__STACK_SIZE=8192
# Add standard libraries at the very end of the linker input, after all objects
# that may need symbols provided by these libraries.
LIB_FILES += -lc -lnosys -lm
.PHONY: default help
# Default target - first one defined
default: nrf52832_xxaa
# Print all targets that can be built
help:
#echo following targets are available:
#echo nrf52832_xxaa
#echo flash_softdevice
#echo sdk_config - starting external tool for editing sdk_config.h
#echo flash - flashing binary
TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc/Makefile.common
#echo $(TEMPLATE_PATH)
include $(TEMPLATE_PATH) # /Makefile.common
$(foreach target, $(TARGETS), $(call define_target, $(target)))
.PHONY: flash flash_softdevice erase
# Flash the program
flash: $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex
#echo Flashing: $<
nrfjprog -f nrf52 --program $< --sectorerase
nrfjprog -f nrf52 --reset
# Flash softdevice
flash_softdevice:
#echo Flashing: s132_nrf52_6.0.0_softdevice.hex
nrfjprog -f nrf52 --program $(SDK_ROOT)/components/softdevice/s132/hex/s132_nrf52_6.0.0_softdevice.hex --sectorerase
nrfjprog -f nrf52 --reset
erase:
nrfjprog -f nrf52 --eraseall
SDK_CONFIG_FILE := ../config/sdk_config.h
CMSIS_CONFIG_TOOL := $(SDK_ROOT)/external_tools/cmsisconfig/CMSIS_Configuration_Wizard.jar
sdk_config:
java -jar $(CMSIS_CONFIG_TOOL) $(SDK_CONFIG_FILE)
The only way I can imagine you getting that error is if you have an include loop in your makefile. That is, either a makefile includes itself, or makefile A has include B and makefile B has include A.
You don't show the content of Makefile.posix but if it includes Makefile.common you could have the latter problem.
Another alternative is based on this in your example which looks wrong:
TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc/Makefile.common
include $(TEMPLATE_PATH)
then you say in Makefile.common you have:
include $(TEMPLATE_PATH)Makefile.posix
This is wrong since TEMPLATE_PATH is not a directory, it's a file; this would expand to:
include /sdk/root/components/toolchain/gcc/Makefile.commonMakefile.posix
which is clearly wrong.
But consider this: what if you have a trailing space in TEMPLATE_PATH, so it's like this:
TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc/Makefile.common #<-space here
Note you don't need the comment; make always preserves trailing spaces even if there's nothing else at the end of the line. Then, the include in Makefile.common would expand to this:
include /sdk/root/components/toolchain/gcc/Makefile.common Makefile.posix
which has a makefile including itself, recursively. Eventually you'll run out of open files.

What does this make rule do?

I am writing makefile by example of another and have stumbled upon this target rule:
ifeq ($(MAKECMDGOALS),build_executable)
$(firstword $(dependency_files)): $(application_path)/config/gcc/app.mk
#rm -rf $(object_output_path)
-include $(dependency_files)
endif
This is placed between other rules. This makefile runs recursively reinvoking itself with different goals.
All variables pretty much explains themself. Prerequisite app.mk contains just configuration by some variables set which are used in this make file. Dependency files variable constructed like this:
dependency_files := $(object_files:%.o=%.d)
My question is what "common practice" this rule corresponds to, what does it do and why it is like that. If my understanding is correct (please correct me if I am wrong), I do understand that first of all it includes all dependency files if they exist. Then this rule may be ran by "makeflow". What I do not understand is the intention of doing this. Also, what is the trigger of running this rule on that one (basically the random one) dependency file since .d files are generated with GCC -MMD -MP options.
Thanks in advance.
EDIT:
###############################################################################
#
# #brief This file is part of the TouchGFX 4.8.0 evaluation distribution.
#
# #author Draupner Graphics A/S <http://www.touchgfx.com>
#
###############################################################################
#
# #section Copyright
#
# This file is free software and is provided for example purposes. You may
# use, copy, and modify within the terms and conditions of the license
# agreement.
#
# This is licensed software for evaluation use, any use must strictly comply
# with the evaluation license agreement provided with delivery of the
# TouchGFX software.
#
# The evaluation license agreement can be seen on www.touchgfx.com
#
# #section Disclaimer
#
# DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Draupner Graphics A/S has
# no obligation to support this software. Draupner Graphics A/S is providing
# the software "AS IS", with no express or implied warranties of any kind,
# including, but not limited to, any implied warranties of merchantability
# or fitness for any particular purpose or warranties against infringement
# of any proprietary rights of a third party.
#
# Draupner Graphics A/S can not be held liable for any consequential,
# incidental, or special damages, or any other relief, or for any claim by
# any third party, arising from your use of this software.
#
###############################################################################
# Get name of this Makefile
makefile_name := $(lastword $(MAKEFILE_LIST))
# Get path of this Makefile
makefile_path := $(dir $(abspath $(makefile_name)))
# Get path where the Application is
application_path := $(abspath $(makefile_path)/../..)
# Change makefile_name to a relative path
makefile_name := $(patsubst $(application_path)/%,%,$(abspath $(makefile_name)))
# Get relative path to makefile
makefile_path_relative = $(patsubst $(application_path)/%,%,$(makefile_path))
# Get path to bsp
bsp_path := $(patsubst $(application_path)/%,%,$(abspath $(makefile_path_relative)../bsp))
# Get OS path
os_path := $(patsubst $(application_path)/%,%, $(abspath $(makefile_path_relative)../CMSIS-RTOS2))
# Get target path
cmsis_core_path := $(patsubst $(application_path)/%,%, $(abspath $(makefile_path_relative)../CMSIS-COREM))
# Get identification of this system
ifeq ($(OS),Windows_NT)
UNAME := MINGW32_NT-6.2
else
UNAME := $(shell uname -s)
endif
board_name := NONE
platform := cortex_m4f
.PHONY: all clean assets flash intflash
ifneq ($(words $(makefile_path))$(words $(MAKEFILE_LIST)),11)
all: $(filter clean,$(MAKECMDGOALS))
all clean assets flash intflash:
$(error Spaces not allowed in path)
else
all: $(filter clean,$(MAKECMDGOALS))
all clean assets:
#cd $(application_path) && $(MAKE) -r -f $(makefile_name) -s $(MFLAGS) _$#_
flash intflash: all
#cd $(application_path) && $(MAKE) -r -f $(makefile_name) -s $(MFLAGS) _$#_
# Directories containing application-specific source and header files.
# Additional components can be added to this list. make will look for
# source files recursively in comp_name/src and setup an include directive
# for comp_name/include.
components := gui target generated/gui_generated
# Location of folder containing bmp/png files.
asset_images_input := assets/images
# Location of folder to search for ttf font files
asset_fonts_input := assets/fonts
# Location of folder where the texts.xlsx is placed
asset_texts_input := assets/texts
build_root_path := build
object_output_path := $(build_root_path)/$(board_name)
binary_output_path := $(build_root_path)/bin
# Location of output folders where autogenerated code from assets is placed
asset_root_path := generated
asset_images_output := $(asset_root_path)/images
asset_fonts_output := $(asset_root_path)/fonts
asset_texts_output := $(asset_root_path)/texts
#include application specific configuration
include $(application_path)/config/gcc/app.mk
os_source_files := $(os_path)/RTX/Config/RTX_Config.c \
$(os_path)/RTX/Source/rtx_lib.c
os_include_paths := $(os_path)/Include \
$(os_path)/RTX/Config \
$(os_path)/RTX/Include
#$(os_path)/RTX/Source \
os_wrapper := $(os_path)/OSWrappers_cmsis.cpp
### END OF USER SECTION. THE FOLLOWING SHOULD NOT BE MODIFIED ###
ifeq ($(UNAME), Linux)
imageconvert_executable := $(touchgfx_path)/framework/tools/imageconvert/build/linux/imageconvert.out
fontconvert_executable := $(touchgfx_path)/framework/tools/fontconvert/build/linux/fontconvert.out
else
imageconvert_executable := $(touchgfx_path)/framework/tools/imageconvert/build/win/imageconvert.out
fontconvert_executable := $(touchgfx_path)/framework/tools/fontconvert/build/win/fontconvert.out
st_link_executable := "$(PROGRAMFILES)\\STMicroelectronics\\STM32 ST-LINK Utility\\ST-LINK Utility\\ST-LINK_CLI.exe"
st_link_external_loader := "$(PROGRAMFILES)\\STMicroelectronics\\STM32 ST-LINK Utility\\ST-LINK Utility\\ExternalLoader\\N25Q128A_STM32469I-DISCO.stldr"
endif
target_executable := target.elf
target_hex := target.hex
########### include $(touchgfx_path)/config/toolchain-arm-none-eabi-gcc.mk #################
# Defines the assembler binary and options. These are optional and only
# of relevance if the component includes source files with an
# extension of .asm.
# Consider adding -Wall to c_compiler_options and cpp_compiler_options
#no_libs := -nostdlib -nodefaultlibs For now, include everything.
assembler := arm-none-eabi-gcc
assembler_options += -g \
-nostartfiles -fno-exceptions\
$(no_libs) -mthumb -mno-thumb-interwork \
-Wall
assembler_options += $(float_options)
c_compiler := arm-none-eabi-gcc
c_compiler_options += -g \
-nostartfiles -mthumb -fno-exceptions \
-mno-thumb-interwork -std=c99 \
$(no_libs) \
-Os -fno-strict-aliasing -fdata-sections -ffunction-sections
c_compiler_options += $(float_options)
cpp_compiler := arm-none-eabi-g++
cpp_compiler_options += -g -mthumb \
-nostartfiles $(no_libs) \
-mno-thumb-interwork -fno-rtti -fno-exceptions \
-Os -fno-strict-aliasing -fdata-sections -ffunction-sections
cpp_compiler_options += $(float_options)
linker := arm-none-eabi-g++
linker_options += -g -Wl,-static -nostartfiles -mthumb $(no_libs) -mno-thumb-interwork \
-fno-exceptions -fno-rtti \
-Os -fno-strict-aliasing -Wl,--gc-sections
objcopy := arm-none-eabi-objcopy
archiver := arm-none-eabi-ar
strip := arm-none-eabi-strip
####################### Additional toolchain configuration for Cortex-M4f targets.##########################
float_abi := hard
float_options := -mfpu=fpv4-sp-d16
ifneq ("$(float_abi)","hard")
float_options += -mfloat-abi=softfp
else
float_options += -mfloat-abi=hard
endif
assembler_options += -mcpu=cortex-m4 -march=armv7e-m -Wno-psabi $(float_options) -DCORE_M4 -D__irq=""
c_compiler_options += -mcpu=cortex-m4 -march=armv7e-m -Wno-psabi $(float_options) -DCORE_M4 -D__irq=""
cpp_compiler_options += -mcpu=cortex-m4 -march=armv7e-m -Wno-psabi $(float_options) -DCORE_M4 -D__irq=""
linker_options += -mcpu=cortex-m4 -march=armv7e-m -Wno-psabi $(float_options)
############################################################################################################
#include everything + specific vendor folders
framework_includes := $(touchgfx_path)/framework/include
#this needs to change when assset include folder changes.
all_components := $(components) \
$(asset_fonts_output) \
$(asset_images_output) \
$(asset_texts_output)
#keep framework include and source out of this mess! :)
include_paths := $(library_includes) $(foreach comp, $(all_components), $(comp)/include) $(framework_includes) $(source_bsp_paths)
source_paths = $(foreach comp, $(all_components), $(comp)/src)
# Finds files that matches the specified pattern. The directory list
# is searched recursively. It is safe to invoke this function with an
# empty list of directories.
#
# Param $(1): List of directories to search
# Param $(2): The file pattern to search for
define find
$(foreach dir,$(1),$(foreach d,$(wildcard $(dir)/*),\
$(call find,$(d),$(2))) $(wildcard $(dir)/$(strip $(2))))
endef
unexport find
fontconvert_ttf_lower_files := $(call find, $(asset_fonts_input), *.ttf)
fontconvert_ttf_upper_files := $(call find, $(asset_fonts_input), *.TTF)
fontconvert_otf_lower_files := $(call find, $(asset_fonts_input), *.otf)
fontconvert_otf_upper_files := $(call find, $(asset_fonts_input), *.OTF)
fontconvert_bdf_lower_files := $(call find, $(asset_fonts_input), *.bdf)
fontconvert_bdf_upper_files := $(call find, $(asset_fonts_input), *.BDF)
fontconvert_font_files := $(fontconvert_ttf_lower_files) \
$(fontconvert_ttf_upper_files) \
$(fontconvert_otf_lower_files) \
$(fontconvert_otf_upper_files) \
$(fontconvert_bdf_lower_files) \
$(fontconvert_bdf_upper_files)
source_files := $(call find, $(source_paths),*.cpp)
gcc_source_files := $(touchgfx_path)/framework/config/gcc/stdio.c \
$(touchgfx_path)/framework/config/gcc/stdlib.c \
$(touchgfx_path)/framework/config/gcc/string.c
# bsp files
board_c_files := \
$(bsp_path)/src/main.c \
$(bsp_path)/src/debug.c
board_cpp_files := \
$(bsp_path)/src/leds.cpp \
$(bsp_path)/src/KeySampler.cpp \
$(bsp_path)/src/app_gpio.cpp
# bsp include
board_include_paths := \
$(bsp_path)/inc \
gui/include \
generated/gui_generated/include
# Compiler options
c_compiler_options += -DST -DSTM32F469xx -DUSE_OS_SYSTICK -DUSE_FLOATING_POINT -g -gdwarf-2
cpp_compiler_options += -DST -DSTM32F469xx -DUSE_OS_SYSTICK -DUSE_FLOATING_POINT -g -gdwarf-2
include_paths += $(application_path)/platform/os $(board_include_paths) $(os_include_paths)
c_source_files := $(call find, $(source_paths),*.c) $(os_source_files) $(makefile_path_relative)/isr.c $(board_c_files)
source_files += $(os_wrapper) target/gcc/gccstubs.cpp target/main.cpp \
$(board_cpp_files) \
$(bsp_path)/src/BoardConfiguration.cpp \
$(bsp_path)/src/GPIO.cpp
object_files := $(source_files:$(touchgfx_path)/%.cpp=$(object_output_path)/touchgfx/%.o) $(c_source_files:$(touchgfx_path)/%.c=$(object_output_path)/touchgfx/%.o)
object_files := $(object_files:%.cpp=$(object_output_path)/%.o)
object_files := $(object_files:%.c=$(object_output_path)/%.o)
dependency_files := $(object_files:%.o=%.d)
textconvert_script_path := $(touchgfx_path)/framework/tools/textconvert
textconvert_executable := $(call find, $(textconvert_script_path), *.rb)
text_database := $(asset_texts_input)/texts.xlsx
libraries := touchgfx-float-abi-hard RTX_CM4F
library_include_paths := $(touchgfx_path)/lib/core/$(platform)/gcc
library_include_paths += $(os_path)/RTX/Library/GCC
.PHONY: _all_ _clean_ _assets_ _flash_ _intflash_ generate_assets build_executable
# Force linking each time
.PHONY: $(binary_output_path)/$(target_executable)
_all_: generate_assets
ifeq ($(shell find $(application_path) -wholename "$(application_path)/$(binary_output_path)/extflash.bin" -size +0c | wc -l | xargs echo),1)
_flash_: _extflash_
else
_flash_: _intflash_
endif
_extflash_:
#$(st_link_executable) -c -P $(binary_output_path)/target.hex 0x90000000 -Rst -EL $(st_link_external_loader)
_intflash_:
#$(st_link_executable) -c -P $(binary_output_path)/intflash.hex 0x08000000 -Rst
generate_assets: _assets_
#$(MAKE) -f $(makefile_name) -r -s $(MFLAGS) build_executable
build_executable: $(binary_output_path)/$(target_executable)
$(binary_output_path)/$(target_executable): $(object_files)
#echo Linking $(#)
#mkdir -p $(#D)
#mkdir -p $(object_output_path)
#$(file >$(build_root_path)/objects.tmp) $(foreach F,$(object_files),$(file >>$(build_root_path)/objects.tmp,$F))
#$(linker) \
$(linker_options) -T $(makefile_path_relative)/application.ld -Wl,-Map=$(#D)/application.map $(linker_options_local) \
$(patsubst %,-L%,$(library_include_paths)) \
#$(build_root_path)/objects.tmp -o $# \
-Wl,--start-group $(patsubst %,-l%,$(libraries)) -Wl,--end-group
#rm -f $(build_root_path)/objects.tmp
#echo "Producing additional output formats..."
#echo " target.hex - Combined internal+external hex"
#$(objcopy) -O ihex $# $(#D)/target.hex
#echo " intflash.elf - Internal flash, elf debug"
#$(objcopy) --remove-section=ExtFlashSection $# $(#D)/intflash.elf 2>/dev/null
#echo " intflash.hex - Internal flash, hex"
#$(objcopy) -O ihex --remove-section=ExtFlashSection $# $(#D)/intflash.hex
#echo " extflash.bin - External flash, binary"
#$(objcopy) -O binary --only-section=ExtFlashSection $# $(#D)/extflash.bin
$(object_output_path)/touchgfx/%.o: $(touchgfx_path)/%.cpp $(application_path)/config/gcc/app.mk
#echo Compiling $<
#mkdir -p $(#D)
#$(cpp_compiler) \
-MMD -MP $(cpp_compiler_options) $(cpp_compiler_options_local) $(user_cflags) \
$(patsubst %,-I%,$(include_paths)) \
-c $< -o $#
$(object_output_path)/%.o: %.cpp $(application_path)/config/gcc/app.mk
#echo Compiling $<
#mkdir -p $(#D)
#$(cpp_compiler) \
-MMD -MP $(cpp_compiler_options) $(cpp_compiler_options_local) $(user_cflags) \
$(patsubst %,-I%,$(include_paths)) \
-c $< -o $#
$(object_output_path)/%.o: %.c $(application_path)/config/gcc/app.mk
#echo Compiling $<
#mkdir -p $(#D)
#$(c_compiler) \
-MMD -MP $(c_compiler_options) $(c_compiler_options_local) $(user_cflags) \
$(patsubst %,-I%,$(include_paths)) \
-c $< -o $#
ifeq ($(MAKECMDGOALS),build_executable)
$(firstword $(dependency_files)): $(application_path)/config/gcc/app.mk
#rm -rf $(object_output_path)
-include $(dependency_files)
endif
_assets_: BitmapDatabase $(asset_texts_output)/include/texts/TextKeysAndLanguages.hpp
alpha_dither ?= no
dither_algorith ?= 2
remap_identical_texts ?= yes
.PHONY: BitmapDatabase
BitmapDatabase:
#echo Converting images
#$(imageconvert_executable) -dither $(dither_algorithm) -alpha_dither $(alpha_dither) -opaque_image_format $(opaque_image_format) -non_opaque_image_format $(non_opaque_image_format) $(screen_orientation) -r $(asset_images_input) -w $(asset_images_output)
$(asset_texts_output)/include/texts/TextKeysAndLanguages.hpp: $(text_database) $(application_path)/config/gcc/app.mk $(textconvert_executable) $(fontconvert_executable) $(fontconvert_font_files)
#rm -f $(asset_fonts_output)/src/*
#rm -f $(asset_fonts_output)/include/fonts/*
#rm -f $(asset_fonts_output)/UnicodeList*.txt
#rm -f $(asset_fonts_output)/CharSizes*.csv
#mkdir -p $(asset_texts_output)/include/texts
#ruby $(textconvert_script_path)/main.rb $(text_database) $(fontconvert_executable) $(asset_fonts_output) $(asset_texts_output) $(asset_fonts_input) . $(remap_identical_texts) $(text_data_format)
_clean_:
#echo Cleaning
#rm -rf $(build_root_path)
# Do not remove gui_generated
#rm -rf $(asset_images_output)
#rm -rf $(asset_fonts_output)
#rm -rf $(asset_texts_output)
# Create directory to avoid error if it does not exist
#mkdir -p $(asset_root_path)
# Remove assets folder if it is empty (i.e. no gui_generated folder)
#rmdir --ignore-fail-on-non-empty $(asset_root_path)
endif
Changing the app.mk file might make the dependency files obsolete. What this rule does is forcing the re-building of the dependency files by deleting their directory.
For instance the dependencies may change because preprocessor symboles where added or modified. Let's assume that in the provided example the c_compiler_options has been modified to add the -DUSE_FLOATING_POINT option:
c_compiler_options += -DST -DSTM32F469xx -DUSE_OS_SYSTICK -DUSE_FLOATING_POINT -g -gdwarf-2
In a source file this may add or remove include file directives:
#ifdef USE_FLOATING_POINT
#include <some_file.h>
#else
#incude <anotherfile.h>
#endif
Hence the need for running the dependendy evaluation again.

Resources