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 :)
Related
I run macOS Big Sur (v. 11.4) and I am trying to do Fisher analysis by using fishchips (https://github.com/xzackli/fishchips-public.git). In order to do so, I need to use CLASS (https://github.com/lesgourg/class_public.git). Following the instructions here, Class requires using make to allow us to use classy. When I initially run make, I get the error: clang: error: unsupported option '-fopenmp'. After reading here, I changed the OMPFLAG in my makefile from OMPFLAG = -fopenmp to OMPFLAG = -Xpreprocessor -fopenmp and now I get the error:
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
make: *** [class] Error 1.
I am confused about how to solve this. Here is a copy of my current makefile if it helps:
#Some Makefile for CLASS.
#Julien Lesgourgues, 28.11.2011
#Nils Schöneberg, Matteo Lucca, 27.02.2019
MDIR := $(shell pwd)
WRKDIR = $(MDIR)/build
.base:
if ! [ -e $(WRKDIR) ]; then mkdir $(WRKDIR) ; mkdir $(WRKDIR)/lib; fi;
touch build/.base
vpath %.c source:tools:main:test
vpath %.o build
vpath .base build
########################################################
###### LINES TO ADAPT TO YOUR PLATEFORM ################
########################################################
# your C compiler:
CC = gcc
#CC = icc
#CC = pgcc
# your tool for creating static libraries:
AR = ar rv
# Your python interpreter.
# In order to use Python 3, you can manually
# substitute python3 to python in the line below, or you can simply
# add a compilation option on the terminal command line:
# "PYTHON=python3 make all" (Thanks to Marius Millea for python3 compatibility)
PYTHON ?= python
# your optimization flag
OPTFLAG = -O3
#OPTFLAG = -Ofast -ffast-math #-march=native
#OPTFLAG = -fast
# your openmp flag (comment for compiling without openmp)
OMPFLAG = -Xpreprocessor -fopenmp
#OMPFLAG = -mp -mp=nonuma -mp=allcores -g
#OMPFLAG = -openmp
# all other compilation flags
CCFLAG = -g -fPIC
LDFLAG = -g -fPIC
# leave blank to compile without HyRec, or put path to HyRec directory
# (with no slash at the end: e.g. "external/RecfastCLASS")
HYREC = external/HyRec2020
RECFAST = external/RecfastCLASS
HEATING = external/heating
########################################################
###### IN PRINCIPLE THE REST SHOULD BE LEFT UNCHANGED ##
########################################################
# pass current working directory to the code
CCFLAG += -D__CLASSDIR__='"$(MDIR)"'
# where to find include files *.h
INCLUDES = -I../include
HEADERFILES = $(wildcard ./include/*.h)
# automatically add external programs if needed. First, initialize to blank.
EXTERNAL =
vpath %.c $(RECFAST)
#CCFLAG += -DRECFAST
INCLUDES += -I../$(RECFAST)
EXTERNAL += wrap_recfast.o
HEADERFILES += $(wildcard ./$(RECFAST)/*.h)
vpath %.c $(HEATING)
#CCFLAG += -DHEATING
INCLUDES += -I../$(HEATING)
EXTERNAL += injection.o noninjection.o
HEADERFILES += $(wildcard ./$(HEATING)/*.h)
# update flags for including HyRec
ifneq ($(HYREC),)
vpath %.c $(HYREC)
CCFLAG += -DHYREC
#LDFLAGS += -DHYREC
INCLUDES += -I../$(HYREC)
EXTERNAL += hyrectools.o helium.o hydrogen.o history.o wrap_hyrec.o energy_injection.o
HEADERFILES += $(wildcard ./$(HYREC)/*.h)
endif
%.o: %.c .base $(HEADERFILES)
cd $(WRKDIR);$(CC) $(OPTFLAG) $(OMPFLAG) $(CCFLAG) $(INCLUDES) -c ../$< -o $*.o
TOOLS = growTable.o dei_rkck.o sparse.o evolver_rkck.o evolver_ndf15.o arrays.o parser.o quadrature.o hyperspherical.o common.o trigonometric_integrals.o
SOURCE = input.o background.o thermodynamics.o perturbations.o primordial.o fourier.o transfer.o harmonic.o lensing.o distortions.o
INPUT = input.o
PRECISION = precision.o
BACKGROUND = background.o
THERMO = thermodynamics.o
PERTURBATIONS = perturbations.o
TRANSFER = transfer.o
PRIMORDIAL = primordial.o
HARMONIC = harmonic.o
FOURIER = fourier.o
LENSING = lensing.o
DISTORTIONS = distortions.o
OUTPUT = output.o
CLASS = class.o
TEST_LOOPS = test_loops.o
TEST_LOOPS_OMP = test_loops_omp.o
TEST_HARMONIC = test_harmonic.o
TEST_TRANSFER = test_transfer.o
TEST_FOURIER = test_fourier.o
TEST_PERTURBATIONS = test_perturbations.o
TEST_THERMODYNAMICS = test_thermodynamics.o
TEST_BACKGROUND = test_background.o
TEST_HYPERSPHERICAL = test_hyperspherical.o
C_TOOLS = $(addprefix tools/, $(addsuffix .c,$(basename $(TOOLS))))
C_SOURCE = $(addprefix source/, $(addsuffix .c,$(basename $(SOURCE) $(OUTPUT))))
C_TEST = $(addprefix test/, $(addsuffix .c,$(basename $(TEST_DEGENERACY) $(TEST_LOOPS) $(TEST_TRANSFER) $(TEST_FOURIER) $(TEST_PERTURBATIONS) $(TEST_THERMODYNAMICS))))
C_MAIN = $(addprefix main/, $(addsuffix .c,$(basename $(CLASS))))
C_ALL = $(C_MAIN) $(C_TOOLS) $(C_SOURCE)
H_ALL = $(addprefix include/, common.h svnversion.h $(addsuffix .h, $(basename $(notdir $(C_ALL)))))
PRE_ALL = cl_ref.pre clt_permille.pre
INI_ALL = explanatory.ini lcdm.ini
MISC_FILES = Makefile CPU psd_FD_single.dat myselection.dat myevolution.dat README bbn/sBBN.dat external_Pk/* cpp
PYTHON_FILES = python/classy.pyx python/setup.py python/cclassy.pxd python/test_class.py
all: class libclass.a classy
libclass.a: $(TOOLS) $(SOURCE) $(EXTERNAL)
$(AR) $# $(addprefix build/, $(TOOLS) $(SOURCE) $(EXTERNAL))
class: $(TOOLS) $(SOURCE) $(EXTERNAL) $(OUTPUT) $(CLASS)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o class $(addprefix build/,$(notdir $^)) -lm
test_loops: $(TOOLS) $(SOURCE) $(EXTERNAL) $(OUTPUT) $(TEST_LOOPS)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_loops_omp: $(TOOLS) $(SOURCE) $(EXTERNAL) $(OUTPUT) $(TEST_LOOPS_OMP)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_harmonic: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_HARMONIC)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_transfer: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_TRANSFER)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_fourier: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_FOURIER)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_perturbations: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_PERTURBATIONS)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_thermodynamics: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_THERMODYNAMICS)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_background: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_BACKGROUND)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_hyperspherical: $(TOOLS) $(TEST_HYPERSPHERICAL)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o test_hyperspherical $(addprefix build/,$(notdir $^)) -lm
tar: $(C_ALL) $(C_TEST) $(H_ALL) $(PRE_ALL) $(INI_ALL) $(MISC_FILES) $(HYREC) $(PYTHON_FILES)
tar czvf class.tar.gz $(C_ALL) $(H_ALL) $(PRE_ALL) $(INI_ALL) $(MISC_FILES) $(HYREC) $(PYTHON_FILES)
classy: libclass.a python/classy.pyx python/cclassy.pxd
ifdef OMPFLAG
cp python/setup.py python/autosetup.py
else
grep -v "lgomp" python/setup.py > python/autosetup.py
endif
cd python; export CC=$(CC); $(PYTHON) autosetup.py install || $(PYTHON) autosetup.py install --user
rm python/autosetup.py
clean: .base
rm -rf $(WRKDIR);
rm -f libclass.a
rm -f $(MDIR)/python/classy.c
rm -rf $(MDIR)/python/build
rm -f python/autosetup.py
I believe I found the solution fix. It seems as if deleting OMPFLAG was all that was needed to run.
CC = g++49
#General Flags
CFLAGS =
#debug flags
CFLAGS +=
#Target Liker Flags
CFLAGS +=
TARGET = ../game
INCDIR += -I
LIBDIR += -L
LIBS += -l
##############################################
INCDIR += -I
LIBDIR += -L
LIBS += -l
##############################################
CPP_FILE =
OBJDIR =../../Object's
CPPOBJS = $(CPP_FILE:%.cpp=$(OBJDIR)/%.o)
default: $(TARGET)
$(OBJDIR)/%.o: %.cpp
#echo compile $<
#$(CC) $(CFLAGS) $(INCDIR) -c $< -o $#
$(TARGET): $(CPPOBJS)
#echo linking....
#$(CC) $(CFLAGS) $(LIBDIR) $(CPPOBJS) $(LIBS) -o $(TARGET)
Soo this si my makefile .
I want to find all .cpp files and compile.
Without their full name specified in CPP_FILE
Example :
CPP_FILE : test.cpp main.cpp slow.cpp scan.cpp
I want something like CPP_FILE = *.cpp
It is this possible?
Make provides a wildcard function for this very purpose.
CPP_FILE = $(wildcard my_dir/*.cpp)
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.
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.
I have to create different *.o files from a same set of *.c using various CFLAGS. I wanted to use patsubst to generate different *.o files from same *.c. I am doing something wrong the following statement, please help (I want to generate one set of object files having ($<)_O0.o and the other ($<)_O2.o from the same set of c source files):
$(CC) $(CFLAGS_02) -c $< -o $(patsubst %.c,%_O2.o,$<)
Thanks
Use patsubst to make lists of the objects that you want to build, and then use separate rules for each type of build.
Something like this:
SRC_FILES = source1.c source2.c
OBJ_FILES_O0 = $(patsubst %.c,%_O0.o,$(SRC_FILES))
OBJ_FILES_O2 = $(patsubst %.c,%_O2.o,$(SRC_FILES))
CFLAGS_O0 := -O0
CFLAGS_O2 := -O2
all: $(OBJ_FILES_O0) $(OBJ_FILES_O2)
$(OBJ_FILES_O0): %_O0.o: %.c
$(CC) $(CFLAGS_O0) -c $< -o $#
$(OBJ_FILES_O2): %_O2.o: %.c
$(CC) $(CFLAGS_O2) -c $< -o $#
You can also use wild cards to specify all files in the directory.
eg:
#Generic Makefile.
CC := g++
LD := g++
CFLAGS := -c
LDFLAGS := -L<path to lib> -l<libname> \
-L<path to lib> -l>libname> \
......................
ifeq (${TARGETARCH}, debug)
CFLAGS += -g -O0
elif
CFLAGS += -O4 -DNDEBUG
SRCFILES := $(wildcard *.cpp)
OBJFILES := $(patsubst %.cpp, %.o, ${SRCFILES})
all: main
main: ${OBJFILES}
#echo "[Linking]"$#
${LD} ${LDFLAGS} ${OBJFILES}
%.o: %.cpp
#echo "[Compiling]"$#
${CC} ${CFLAGS} $^ -o $#