Why does my makefile never stop building? - makefile

I am trying to create a makefile to control the build process. I use eclipse and I have a lot of projects some of which are shared libraries. So if I build a project that is using a library, then I would like the library to be built if it is out of date. The seems pretty standard. I just cannot make it work.
I am making the linking dependent on the libraries, and I (try to) provide a rule for building the libraries. But when I do it this way, it seems to be building the library over and over again - and it never finishes. What am I missing?
CPPUTEST_HOME = ...
PROJECTROOT := ...
SDKTARGETSYSROOT := /opt/fsl-imx-fb/4.14-sumo/sysroots/cortexa9hf-neon-poky-linux-gnueabi
COMPONENT_NAME := Jehova
USER_LIB :=
INCLUDE_DIRS := $(PROJECTROOT)/Log/source \
$(PROJECTROOT)/Config/source \
LIBS := $(PROJECTROOT)/Log/bin/libLog.so \
$(PROJECTROOT)/Config/bin/libConfig.so \
# Links to the commands to be used
REMOVE := rm -rf
COMPILER := arm-poky-linux-gnueabi-g++
# All of the sources participating in the build are defined here
SOURCEDIR = source
OBJECTDIR = objects
TEST_DIR = utest
PATH_TO_MAIN = source/main.cpp
SOURCES = $(wildcard $(SOURCEDIR)/*.cpp)
OBJECTS = $(patsubst $(SOURCEDIR)/%.cpp, $(OBJECTDIR)/%.o, $(SOURCES))
DEPENDENCIES = $(patsubst $(SOURCEDIR)/%.cpp, $(OBJECTDIR)/%.d, $(SOURCES))
# Paths to the headerfiles
get_dirs_from_dirspec = $(wildcard $1)
INCLUDE_DIRS += $(USER_LIB) \
$(SDKTARGETSYSROOT)/usr/include/ \
$(SDKTARGETSYSROOT)/usr/include/c++/7.3.0/ \
$(SDKTARGETSYSROOT)/usr/include/c++/7.3.0/arm-poky-linux-gnueabi/
INCLUDE_DIR_EXPANDED = $(call get_dirs_from_dirspec, $(INCLUDE_DIRS))
COMPILE_INCLUDE = $(foreach dir, $(INCLUDE_DIR_EXPANDED), -I$(dir))
LINK_INCLUDE = $(foreach dir, $(INCLUDE_DIR_EXPANDED), -L$(dir))
# Compiler and linkerflags
COMPILER_FLAGS := -Wall -c -fmessage-length=0 -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 -Wno-unknown-pragmas --sysroot=$(SDKTARGETSYSROOT)
LINKER_FLAGS := -mfloat-abi=hard -lpthread
# If main.cpp does not exist the project is assumed to be a shared library
ifeq ("$(wildcard $(PATH_TO_MAIN))","")
COMPILER_FLAGS += -fPIC
LINKER_FLAGS += -shared -o
BIN := ./bin/lib$(COMPONENT_NAME).so
else
LINKER_FLAGS += -o
BIN := ./bin/$(COMPONENT_NAME)
endif
# Optimization and debug levels
ifeq ($(MAKECMDGOALS),release)
COMPILER_FLAGS += -O3
else
COMPILER_FLAGS += -O0 -g3
endif
# Include dependencies
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(DEPENDENCIES)),)
-include $(DEPENDENCIES)
endif
endif
# All Target
all: $(BIN) test
-$(REMOVE) makeenv
# Compile source to create object files
./objects/%.o: ./source/%.cpp
#echo 'Building file: $<'
#echo 'Invoking: Cross G++ Compiler'
-$(COMPILER) $(COMPILE_INCLUDE) $(COMPILER_FLAGS) -MMD -MP -MF"$(#:%.o=%.d)" -MT"$(#)" -o "$#" "$<"
#echo 'Finished building: $<'
#echo ' '
# Link objects to build target
$(BIN): $(OBJECTS) $(LIBS)
#echo 'Building target: $#'
#echo 'Invoking: Cross G++ Linker'
-$(COMPILER) $(LINK_INCLUDE) --sysroot=$(SDKTARGETSYSROOT) $(LINKER_FLAGS) $(BIN) $(OBJECTS) $(LIBS)
#echo 'Finished building target: $#'
#echo ' '
# All Target release build
release: clean $(BIN)
-$(REMOVE) makeenv
# Run the test
test: $(BIN)
make -C $(TEST_DIR)
# Other Targets
clean:
-$(REMOVE) $(OBJECTS)$(DEPENDENCIES) $(BIN)
make -C $(TEST_DIR) clean
-$(REMOVE) makeenv
-#echo ' '
$(LIBS):
-cd $(PROJECTROOT)/Config && $(MAKE) clean all release
-cd $(PROJECTROOT)/Log && $(MAKE) clean all release

Related

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.

Unable to Compile nrf51 SDK example from directory other than SDK

I'm devloping application on nRf51 for that i'm using...
SDK : nRF51_SDK_7.2.0_cf547b5
Tool chain : GNU tools arm Embedded [arm-none-eabi version 4.9.3]
Dev Board : PCA10028(nRF51 DK)
I'm using following example.
C:\nRF51_SDK_7.2.0_cf547b5\examples\peripheral\blinky
When i compile this example using makefile at location C:\nRF51_SDK_7.2.0_cf547b5\examples\peripheral\blinky\pca10028\blank\armgcc
it compiles well and also generate binary/hex.
I want to move this blinky example to D Drive. So now my example is at location D:\blinky.
I'm compiling this example using makefile at location D:\blinky\pca10028\blank\armgcc
I have Modified SDK PATH in makefile as per this
PROJECT_NAME := blinky_blank_pca10028
export OUTPUT_FILENAME
#MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
MAKEFILE_NAME := $(MAKEFILE_LIST)
MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) )
TOOLCHAIN_PATH = C:/nRF51_SDK_7.2.0_cf547b5
TEMPLATE_PATH = $(TOOLCHAIN_PATH)/components/toolchain/gcc
ifeq ($(OS),Windows_NT)
include $(TEMPLATE_PATH)/Makefile.windows
else
include $(TEMPLATE_PATH)/Makefile.posix
endif
MK := mkdir
RM := rm -rf
#echo suspend
ifeq ("$(VERBOSE)","1")
NO_ECHO :=
else
NO_ECHO := #
endif
# Toolchain commands
CC := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc"
AS := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as"
AR := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar" -r
LD := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld"
NM := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-nm"
OBJDUMP := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump"
OBJCOPY := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy"
SIZE := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-size"
#function for removing duplicates in a list
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
#source common to all targets
C_SOURCE_FILES += \
$(TOOLCHAIN_PATH)/components/toolchain/system_nrf51.c \
../../../Main.c \
$(TOOLCHAIN_PATH)/components/drivers_nrf/hal/nrf_delay.c \
#assembly files common to all targets
ASM_SOURCE_FILES = $(TOOLCHAIN_PATH)/components/toolchain/gcc/gcc_startup_nrf51.s
#includes common to all targets
INC_PATHS = -I../../../
INC_PATHS += -I$(TOOLCHAIN_PATH)/components/toolchain/gcc
INC_PATHS += -I$(TOOLCHAIN_PATH)/components/toolchain
INC_PATHS += -I$(TOOLCHAIN_PATH)/components/drivers_nrf/hal
INC_PATHS += -I$(TOOLCHAIN_PATH)/examples/peripheral/bsp
INC_PATHS += -I$(TOOLCHAIN_PATH)/examples/bsp
OBJECT_DIRECTORY = _build
LISTING_DIRECTORY = $(OBJECT_DIRECTORY)
OUTPUT_BINARY_DIRECTORY = $(OBJECT_DIRECTORY)
# Sorting removes duplicates
BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) )
#flags common to all targets
CFLAGS = -DNRF51
CFLAGS += -DBSP_DEFINES_ONLY
CFLAGS += -DBOARD_PCA10028
CFLAGS += -mcpu=cortex-m0
CFLAGS += -mthumb -mabi=aapcs --std=gnu99
CFLAGS += -Wall -Werror -O3
CFLAGS += -mfloat-abi=soft
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -flto -fno-builtin
# keep every function in separate section. This will allow linker to dump unused functions
LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map
LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m0
# let linker to dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs -lc -lnosys
# Assembler flags
ASMFLAGS += -x assembler-with-cpp
ASMFLAGS += -DNRF51
ASMFLAGS += -DBSP_DEFINES_ONLY
ASMFLAGS += -DBOARD_PCA10028
#default target - first one defined
default: clean nrf51422_xxac
#building all targets
all: clean
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e cleanobj
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e nrf51422_xxac
#target for printing all targets
help:
#echo following targets are available:
#echo nrf51422_xxac
C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) )
C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES))
ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) ))
ASM_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(ASM_SOURCE_FILE_NAMES:.s=.o) )
vpath %.c $(C_PATHS)
vpath %.s $(ASM_PATHS)
OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)
nrf51422_xxac: OUTPUT_FILENAME := nrf51422_xxac
nrf51422_xxac: LINKER_SCRIPT=$(TOOLCHAIN_PATH)/components/toolchain/gcc/gcc_nrf51_blank_xxac.ld
nrf51422_xxac: $(BUILD_DIRECTORIES) $(OBJECTS)
#echo Linking target: $(OUTPUT_FILENAME).out
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize
## Create build directories
$(BUILD_DIRECTORIES):
#echo $(MAKEFILE_NAME)
$(MK) $#
# Create objects from C SRC files
$(OBJECTS):
$(OBJECT_DIRECTORY)/%.o: %.c
#echo Compiling file: $(notdir $<)
$(NO_ECHO)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $# $<
# Assemble files
$(OBJECT_DIRECTORY)/%.o: %.s
#echo Compiling file: $(notdir $<)
$(NO_ECHO)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $# $<
# Link
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out: $(BUILD_DIRECTORIES) $(OBJECTS)
#echo Linking target: $(OUTPUT_FILENAME).out
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
## Create binary .bin file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
#echo Preparing: $(OUTPUT_FILENAME).bin
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
## Create binary .hex file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
#echo Preparing: $(OUTPUT_FILENAME).hex
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
finalize: genbin genhex echosize
genbin:
#echo Preparing: $(OUTPUT_FILENAME).bin
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
## Create binary .hex file from the .out file
genhex:
#echo Preparing: $(OUTPUT_FILENAME).hex
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
echosize:
-#echo ""
$(NO_ECHO)$(SIZE) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
-#echo ""
clean:
$(RM) $(BUILD_DIRECTORIES)
cleanobj:
$(RM) $(BUILD_DIRECTORIES)/*.o
flash: $(MAKECMDGOALS)
#echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$<.hex
nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/$<.hex
When i'm compiling this using "make" in cmd.exe then i get
D:\blinky\pca10028\blank\armgcc>make
rm -rf _build
makefile
mkdir _build
Compiling file: Main.c
Linking target: nrf51422_xxac.out
arm-none-eabi-gcc.exe: error: _build/system_nrf51.o: No such file or directory
arm-none-eabi-gcc.exe: error: _build/nrf_delay.o: No such file or directory
arm-none-eabi-gcc.exe: error: _build/gcc_startup_nrf51.o: No such file or directory
make: *** [nrf51422_xxac] Error 1
Any solution on this?
Thank you.
It seems that your absolute source file paths are incorrect :
$(TOOLCHAIN_PATH)/components/toolchain/system_nrf51.c
$(TOOLCHAIN_PATH)/components/drivers_nrf/hal/nrf_delay.c
$(TOOLCHAIN_PATH)/components/toolchain/gcc/gcc_startup_nrf51.s
preventing the corresponding objects from being built.
Please update TOOLCHAIN_PATH - or use another variable - to reflect your new D: location.

Makefile with different source directories than object directory

I'm devloping application on nRf51 for that i'm using:
Compiler: GNU ARM C cross compiler[gcc]
SDK: nRF51_SDK_7.2.0_cf547b5
Tool chain: GNU tools arm Embedded [arm-none-eabi version 4.9.3]
I'm trying to create a makefile in which all source file directories and object directories are different. My makefile needs rules to target *.o files whose source files are on different directories than the project directory. How should I modify the makefile, so that it can compile a C source file from a different directory?
after executing make in cmd.exe, I get:
rm -rf _build
makefile
mkdir _build
make: *** No rule to make target `_build/system_nrf51.o', needed by `nrf51422_xxac'. Stop.
My Makefile looks something like:
`PROJECT_NAME := blinky_blank_pca10028
export OUTPUT_FILENAME
#MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
MAKEFILE_NAME := $(MAKEFILE_LIST)
MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) )
TOOLCHAIN_PATH = C:/nRF51_SDK_7.2.0_cf547b5
TEMPLATE_PATH = $(TOOLCHAIN_PATH)/components/toolchain/gcc
ifeq ($(OS),Windows_NT)
include $(TEMPLATE_PATH)/Makefile.windows
else
include $(TEMPLATE_PATH)/Makefile.posix
endif
MK := mkdir
RM := rm -rf
#echo suspend
ifeq ("$(VERBOSE)","1")
NO_ECHO :=
else
NO_ECHO := #
endif
# Toolchain commands
CC := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc"
AS := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as"
AR := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar" -r
LD := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld"
NM := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-nm"
OBJDUMP := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump"
OBJCOPY := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy"
SIZE := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-size"
#function for removing duplicates in a list
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
#source common to all targets
C_SOURCE_FILES += \
$(TOOLCHAIN_PATH)/components/toolchain/system_nrf51.c \
../../../Main.c \
$(TOOLCHAIN_PATH)/components/drivers_nrf/hal/nrf_delay.c \
#assembly files common to all targets
ASM_SOURCE_FILES = $(TOOLCHAIN_PATH)/components/toolchain/gcc/gcc_startup_nrf51.s
#includes common to all targets
INC_PATHS = -I../../../
INC_PATHS += -I$(TOOLCHAIN_PATH)/components/toolchain/gcc
INC_PATHS += -I$(TOOLCHAIN_PATH)/components/toolchain
INC_PATHS += -I$(TOOLCHAIN_PATH)/components/drivers_nrf/hal
INC_PATHS += -I$(TOOLCHAIN_PATH)/examples/peripheral/bsp
OBJECT_DIRECTORY = _build
LISTING_DIRECTORY = $(OBJECT_DIRECTORY)
OUTPUT_BINARY_DIRECTORY = $(OBJECT_DIRECTORY)
# Sorting removes duplicates
BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) )
#flags common to all targets
CFLAGS = -DNRF51
CFLAGS += -DBSP_DEFINES_ONLY
CFLAGS += -DBOARD_PCA10028
CFLAGS += -mcpu=cortex-m0
CFLAGS += -mthumb -mabi=aapcs --std=gnu99
CFLAGS += -Wall -Werror -O3
CFLAGS += -mfloat-abi=soft
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -flto -fno-builtin
# keep every function in separate section. This will allow linker to dump unused functions
LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map
LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m0
# let linker to dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs -lc -lnosys
# Assembler flags
ASMFLAGS += -x assembler-with-cpp
ASMFLAGS += -DNRF51
ASMFLAGS += -DBSP_DEFINES_ONLY
ASMFLAGS += -DBOARD_PCA10028
#default target - first one defined
default: clean nrf51422_xxac
#building all targets
all: clean
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e cleanobj
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e nrf51422_xxac
#target for printing all targets
help:
#echo following targets are available:
#echo nrf51422_xxac
C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) )
C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES))
ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) ))
ASM_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(ASM_SOURCE_FILE_NAMES:.s=.o) )
vpath %.c $(C_PATHS)
vpath %.s $(ASM_PATHS)
OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)
nrf51422_xxac: OUTPUT_FILENAME := nrf51422_xxac
nrf51422_xxac: LINKER_SCRIPT=$(TOOLCHAIN_PATH)/components/toolchain/gcc/gcc_nrf51_blank_xxac.ld
nrf51422_xxac: $(BUILD_DIRECTORIES) $(OBJECTS)
#echo Linking target: $(OUTPUT_FILENAME).out
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize
## Create build directories
$(BUILD_DIRECTORIES):
#echo $(MAKEFILE_NAME)
$(MK) $#
# Create objects from C SRC files
$(OBJECT_DIRECTORY)/%.o: %.c
#echo Compiling file: $(notdir $<)
$(NO_ECHO)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $# $<
# Assemble files
$(OBJECT_DIRECTORY)/%.o: %.s
#echo Compiling file: $(notdir $<)
$(NO_ECHO)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $# $<
# Link
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out: $(BUILD_DIRECTORIES) $(OBJECTS)
#echo Linking target: $(OUTPUT_FILENAME).out
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
## Create binary .bin file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
#echo Preparing: $(OUTPUT_FILENAME).bin
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
## Create binary .hex file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
#echo Preparing: $(OUTPUT_FILENAME).hex
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
finalize: genbin genhex echosize
genbin:
#echo Preparing: $(OUTPUT_FILENAME).bin
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
## Create binary .hex file from the .out file
genhex:
#echo Preparing: $(OUTPUT_FILENAME).hex
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
echosize:
-#echo ""
$(NO_ECHO)$(SIZE) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
-#echo ""
clean:
$(RM) $(BUILD_DIRECTORIES)
cleanobj:
$(RM) $(BUILD_DIRECTORIES)/*.o
flash: $(MAKECMDGOALS)
#echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$<.hex
nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/$<.hex`
Thank you in advance.

Makefile for nrf51sdk

I am working on programming a nrf51822 evaluation board(This one). I have been looking at this site to program it and have gotten the blinking program to work.
I want to modify the makefile provided on the site previously mentioned, such that when I go along I pretty much only have to add to the list of files to compile. Below is what I have been trying to get to work, but I am not very good with makefiles.
CC := /opt/arm-2012.09/bin/arm-none-eabi-gcc
OBJCOPY := /opt/arm-2012.09/bin/arm-none-eabi-objcopy
NRF51_SDK := /opt/nrf51sdk
NRF51_INCLUDE := $(NRF51_SDK)/Nordic/nrf51822/Include
NRF51_SRC := $(NRF51_SDK)/Nordic/nrf51822/Source
CPU := cortex-m0
BOARD := BOARD_PCA10001
OBJDIR = .
OBJDIR += $(SRC)/templates/
INCLUDEDIRS = $(NRF51_INCLUDE)
INCLUDEDIRS += $(NRF51_INCLUDE)/gcc
DEFINE = BOARD_PCA10001
DEFINE += NRF51
CFLAGS = -mcpu=$(CPU)
CFLAGS +=-mthumb
CFLAGS += $(patsubst %,-D%, $(DEFINE))
CFLAGS += $(patsubst %,-I%, $(INCLUDEDIRS))
CFLAGS += -c
SRC = main.c
SRC += $(NRF51_SRC)/templates/system_nrf51.c
SRC += $(NRF51_SRC)/nrf_delay/nrf_delay.c
ASSEMBLY_SRC += $(NRF51_SRC)/templates/gcc/gcc_startup_nrf51.s
all: main.bin main.hex
%.o : %.c
#echo "Compiling: " $<
$(CC) $(CFLAGS) $<
%.o : %.s
#echo "Compiling: " $<
$(CC) $(CFLAGS) $<
main.out: $(SRC) $(ASSEMBLY_SRC)
$(CC) -L"/opt/arm-2012.09/arm-none-eabi/lib/armv6-m" -L"/opt/arm-2012.09/lib/gcc/arm-none-eabi/4.7.2/armv6-m" -Xlinker -Map=main.map -mcpu=$(CPU) -mthumb -mabi=aapcs -T$(NRF51_SDK)/Nordic/nrf51822/Source/templates/gcc/gcc_linker_script_nrf51.ld main.o system_nrf51.o nrf_delay.o gcc_startup_nrf51.o -o main.out
main.bin: main.out
$(OBJCOPY) -O binary main.out main.bin
main.hex: main.out
$(OBJCOPY) -O ihex main.out main.hex
install: main.bin
sed 's#\[\[--filename--\]\]#$(PWD)/main.bin#' segger/burn-template.seg > burn.seg
./segger/segger.sh $(PWD)/burn.seg
clean:
rm *.o *.out *.hex *.seg *.map *.bin *.hex
When it runs make it just outputs the following:
/opt/arm-2012.09/bin/arm-none-eabi-gcc -L"/opt/arm-2012.09/arm-none-eabi/lib/armv6-m" -L"/opt/arm-2012.09/lib/gcc/arm-none-eabi/4.7.2/armv6-m" -Xlinker -Map=main.map -mcpu=cortex-m0 -mthumb -mabi=aapcs -T/opt/nrf51sdk/Nordic/nrf51822/Source/templates/gcc/gcc_linker_script_nrf51.ld main.o system_nrf51.o nrf_delay.o gcc_startup_nrf51.o -o main.out
arm-none-eabi-gcc: error: main.o: No such file or directory
arm-none-eabi-gcc: error: system_nrf51.o: No such file or directory
arm-none-eabi-gcc: error: nrf_delay.o: No such file or directory
arm-none-eabi-gcc: error: gcc_startup_nrf51.o: No such file or directory
make: *** [main.out] Error 1
Is there anyone around here that can help me with this?
(Copied answer from OP Edit to Solution)
The OP Wrote:
I just figured it out, and am sharing it if anyone wants to know how I did it. Also if anyone would like to comment on how to make it 'better'
CC := /opt/arm-2012.09/bin/arm-none-eabi-gcc
OBJCOPY := /opt/arm-2012.09/bin/arm-none-eabi-objcopy
NRF51_SDK := /opt/nrf51sdk
NRF51_INCLUDE := $(NRF51_SDK)/Nordic/nrf51822/Include
NRF51_SRC := $(NRF51_SDK)/Nordic/nrf51822/Source
CPU := cortex-m0
BOARD := BOARD_PCA10001
INCLUDEDIRS = $(NRF51_INCLUDE)
INCLUDEDIRS += $(NRF51_INCLUDE)/gcc
DEFINE = BOARD_PCA10001
DEFINE += NRF51
# For the compiler stage
CFLAGS = -mcpu=$(CPU)
CFLAGS += -mthumb
CFLAGS += $(patsubst %,-D%, $(DEFINE))
CFLAGS += $(patsubst %,-I%, $(INCLUDEDIRS))
CFLAGS += -Wall
# For the Linker stage
LDIRS = /opt/arm-2012.09/arm-none-eabi/lib/armv6-m
LDIRS += /opt/arm-2012.09/lib/gcc/arm-none-eabi/4.7.2/armv6-m
TDIRS = $(NRF51_SRC)/templates/gcc/gcc_linker_script_nrf51.ld
LFLAGS = -mcpu=$(CPU)
LFLAGS += -mthumb
LFLAGS += -mabi=aapcs
LFLAGS += -Wall
LFLAGS += $(patsubst %, -L%, $(LDIRS))
LFLAGS += $(patsubst %, -T%, $(TDIRS))
# Source files to compile
SRC = main.c
SRC += $(NRF51_SRC)/templates/system_nrf51.c
SRC += $(NRF51_SRC)/nrf_delay/nrf_delay.c
ASSEMBLY_SRC += $(NRF51_SRC)/templates/gcc/gcc_startup_nrf51.s
OBJ = $(SRC:.c=.o) $(ASSEMBLY_SRC:.s=.o)
# Default target
all: begin gcc_version build end
build: main.bin main.hex
main.out: $(OBJ)
#echo
#echo "Linking compiled file. Output will be saved to: " $#
$(CC) $(LFLAGS) $(notdir $(OBJ)) -o $#
main.bin: main.out
#echo
#echo "Making binary file. Output will be saved to: " $#
$(OBJCOPY) -O binary main.out main.bin
main.hex: main.out
#echo
#echo "Making hex file. Output will be saved to: " $#
$(OBJCOPY) -O ihex main.out main.hex
upload: all
#echo
#echo "Uploading file to MCU: "
sed 's#\[\[--filename--\]\]#$(PWD)/main.bin#' segger/burn-template.seg > burn.seg
./segger/segger.sh $(PWD)/burn.seg
clean:
rm *.o *.out *.hex *.seg *.map *.bin *.hex
# Eye Candy
begin:
#echo
#echo "---------- begin ----------"
end:
#echo
#echo "----------- end -----------"
gcc_version:
#echo
#$(CC) --version
# General Rule for compiling C source files
%.o : %.c
#echo
#echo "Compiling: " $(notdir $<)
$(CC) $(CFLAGS) -c $< -o $(notdir $#)
# General Rule for compiling assembly source files
%.o : %.s
#echo
#echo "Compiling: " $(notdir $<)
$(CC) $(CFLAGS) -c $< -o $(notdir $#)
This at least works for now :)

Makefile dependency issue

I'm trying to compile an example code where I added a new file under a new directory but I keep getting a dependency problem.
I have added a file "ipc.c" under "/interface".
I have added the source file to "srcs" and also added the directory with "-I/interface".
The Makefile looks as follows:
#
# ======== Makefile ========
#
include ../products.mak
srcs = main_host.c interface/ipc.c
objs = $(addprefix bin/$(PROFILE)/obj/,$(patsubst %.c,%.o$(SUFFIX),$(srcs)))
libs = $(SYSLINK_INSTALL_DIR)/packages/ti/syslink/lib/syslink.a_$(PROFILE)
MAKEVARS = \
SYSLINK_INSTALL_DIR=$(SYSLINK_INSTALL_DIR) \
PKGPATH=$(PKGPATH)
all:
#$(ECHO) "!"
#$(ECHO) "! Making $# ..."
$(MAKE) $(MAKEVARS) PROFILE=debug SUFFIX=v5T togs2_host
$(MAKE) $(MAKEVARS) PROFILE=release SUFFIX=v5T togs2_host
install:
#$(ECHO) "#"
#$(ECHO) "# Making $# ..."
#$(MKDIR) $(INSTALL_DIR)/debug
$(CP) bin/debug/togs2_host $(INSTALL_DIR)/debug
#$(MKDIR) $(INSTALL_DIR)/release
$(CP) bin/release/togs2_host $(INSTALL_DIR)/release
clean::
$(RMDIR) bin
#
#
# ======== rules ========
#
togs2_host: bin/$(PROFILE)/togs2_host
bin/$(PROFILE)/togs2_host: $(objs) $(libs)
#$(ECHO) "##"
#$(ECHO) "## Making $# ..."
$(LD) $(LDFLAGS) -o $# $^ $(LDLIBS)
bin/$(PROFILE)/obj/%.o$(SUFFIX): %.h
bin/$(PROFILE)/obj/%.o$(SUFFIX): %.c
#$(ECHO) "###"
#$(ECHO) "### Making $# ..."
$(CC) $(CPPFLAGS) $(CFLAGS) -o $# $<
# ======== create output directories ========
ifneq (clean,$(MAKECMDGOALS))
ifneq (,$(PROFILE))
ifeq (,$(wildcard bin/$(PROFILE)))
$(shell $(MKDIR) -p bin/$(PROFILE))
endif
ifeq (,$(wildcard bin/$(PROFILE)/obj))
$(shell $(MKDIR) -p bin/$(PROFILE)/obj)
endif
endif
endif
# ======== install validation ========
ifeq (install,$(MAKECMDGOALS))
ifeq (,$(INSTALL_DIR))
$(error must specify INSTALL_DIR)
endif
endif
# ======== toolchain macros ========
ifeq (v5T,$(SUFFIX))
CC = $(CS_ARM_INSTALL_DIR)gcc -c -MD -MF $#.dep -march=armv5t
AR = $(CS_ARM_INSTALL_DIR)ar cr
LD = $(CS_ARM_INSTALL_DIR)gcc
CPPFLAGS = -D_REENTRANT -Dxdc_target_name__=GCArmv5T \
-Dxdc_target_types__=gnu/targets/arm/std.h
CFLAGS = -Wall -ffloat-store -fPIC -Wunused -Dfar= $(CCPROFILE_$(PROFILE)) \
-I. -I/interface $(addprefix -I,$(subst +, ,$(PKGPATH)))
LDFLAGS = $(LDPROFILE_$(PROFILE)) -Wall -Wl,-Map=$#.map
LDLIBS = -lpthread -lc
CCPROFILE_debug = -ggdb -D DEBUG
CCPROFILE_release = -O3 -D NDEBUG
LDPROFILE_debug = -ggdb
LDPROFILE_release = -O3
endif
I keep getting this error:
fatal error: opening dependency file bin/debug/obj/interface/ipc.ov5T.dep: No such file or directory
This is how the the products.mak looks like:
#
# ======== products.mak ========
#
DEPOT = /opt
BIOS_INSTALL_DIR = $(DEPOT)/bios_6_33_01_25
IPC_INSTALL_DIR = $(DEPOT)/ti/ipc_1_23_05_40
SYSLINK_INSTALL_DIR = $(DEPOT)/syslink_2_10_02_17
TI_C6X_INSTALL_DIR = $(DEPOT)/ti/ccsv5/tools/compiler/c6000
CS_ARM_INSTALL_DIR = $(DEPOT)/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-
XDC_INSTALL_DIR = $(DEPOT)/xdctools_3_23_00_32
PKGPATH := $(SYSLINK_INSTALL_DIR)/packages
PKGPATH := $(PKGPATH)+$(BIOS_INSTALL_DIR)/packages
PKGPATH := $(PKGPATH)+$(IPC_INSTALL_DIR)/packages
PKGPATH := $(PKGPATH)+$(XDC_INSTALL_DIR)/packages
PKGPATH := $(PKGPATH)+$
# Use this goal to print your product variables.
.show-products:
#echo "BIOS_INSTALL_DIR = $(BIOS_INSTALL_DIR)"
#echo "IPC_INSTALL_DIR = $(IPC_INSTALL_DIR)"
#echo "SYSLINK_INSTALL_DIR = $(SYSLINK_INSTALL_DIR)"
#echo "TI_ARM_INSTALL_DIR = $(TI_ARM_INSTALL_DIR)"
#echo "TI_C6X_INSTALL_DIR = $(TI_C6X_INSTALL_DIR)"
#echo "CS_ARM_INSTALL_DIR = $(CS_ARM_INSTALL_DIR)"
#echo "XDC_INSTALL_DIR = $(XDC_INSTALL_DIR)"
# ======== standard macros ========
ifneq (,$(wildcard $(XDC_INSTALL_DIR)/bin/echo.exe))
# use these on Windows
CP = $(XDC_INSTALL_DIR)/bin/cp
ECHO = $(XDC_INSTALL_DIR)/bin/echo
MKDIR = $(XDC_INSTALL_DIR)/bin/mkdir -p
RM = $(XDC_INSTALL_DIR)/bin/rm -f
RMDIR = $(XDC_INSTALL_DIR)/bin/rm -rf
else
# use these on Linux
CP = cp
ECHO = echo
MKDIR = mkdir -p
RM = rm -f
RMDIR = rm -rf
endif
I'm not understanding the Makefile completely as it's a code example I'm simply expanding.
For the record: The error "fatal error: opening dependency file [...]: No such file or directory" can also be caused by a too long path. Happened to me on Cygwin/Windows with a path that was way over 200 characters (didn't check exactly).
Got it working.
Needed to add a rule to create the output directories.
So I added
ifeq (,$(wildcard bin/$(PROFILE)/obj/interface))
$(shell $(MKDIR) -p bin/$(PROFILE)/obj/interface)
endif
This makefile is pretty convoluted, so a certain amount of guesswork is required, but I think the trouble is that it doesn't know how to find interface/ipc.c. Try adding this line at the bottom and see if helps:
vpath %.c interface
If it doesn't, we can try some other things. (And if it does, I can suggest some ways to simplify the makefile.)

Resources