-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
169 lines (136 loc) · 5.87 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Copyright 2023 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
# Native Simulator (NSI) Makefile.
# It builds the simulator runner itself, and produces the final
# Linux executable by linking it to the embedded cpu library
# By default all the build output is placed under the _build folder, but the user can override it
# setting the NSI_BUILD_PATH
#
# The caller can provide an optional configuration file and point to it with NSI_CONFIG_FILE
# See "Configurable/user overridible variables" below.
#
# By default only the core of the runner will be built, but the caller can set NSI_NATIVE
# to also build the components in native/src/
NSI_CONFIG_FILE?=nsi_config
-include ${NSI_CONFIG_FILE}
#If the file does not exist, we don't use it as a build dependency
NSI_CONFIG_FILE:=$(wildcard ${NSI_CONFIG_FILE})
# Configurable/user overridible variables:
# Path to the native_simulator (this folder):
NSI_PATH?=./
# Folder where the build output will be placed
NSI_BUILD_PATH?=$(abspath _build/)
EXE_NAME?=native_simulator.exe
# Final executable path/file_name which will be produced
NSI_EXE?=${NSI_BUILD_PATH}/${EXE_NAME}
# Number of embedded CPUs/MCUs
NSI_N_CPUS?=1
# Path to all CPUs embedded SW which will be linked with the final executable
NSI_EMBEDDED_CPU_SW?=
# Host architecture configuration switch
NSI_ARCH?=-m32
# Coverage switch (GCOV coverage is enabled by default)
NSI_COVERAGE?=--coverage
NSI_LOCALIZE_OPTIONS?=
NSI_BUILD_OPTIONS?=${NSI_ARCH} ${NSI_COVERAGE}
NSI_LINK_OPTIONS?=${NSI_ARCH} ${NSI_COVERAGE}
# Extra source files to be built in the runner context
NSI_EXTRA_SRCS?=
# Extra include directories to be used while building in the runner context
NSI_EXTRA_INCLUDES?=
# Extra libraries to be linked to the final executable
NSI_EXTRA_LIBS?=
SHELL?=bash
# Compiler
NSI_CC?=gcc
# Archive program (it is unlikely you'll need to change this)
NSI_AR?=ar
# Objcopy program (it is unlikely you'll need to change this)
NSI_OBJCOPY?=objcopy
# Build debug switch (by default enabled)
NSI_DEBUG?=-g
# Build optimization level (by default disabled to ease debugging)
NSI_OPT?=-O0
# Warnings switches (for the runner itself)
NSI_WARNINGS?=-Wall -Wpedantic
# Preprocessor flags
NSI_CPPFLAGS?=-D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED
NO_PIE_CO:=-fno-pie -fno-pic
DEPENDFLAGS:=-MMD -MP
CFLAGS:=${NSI_DEBUG} ${NSI_WARNINGS} ${NSI_OPT} ${NO_PIE_CO} -DNSI_N_CPUS=${NSI_N_CPUS} \
-ffunction-sections -fdata-sections ${DEPENDFLAGS} -std=c11 ${NSI_BUILD_OPTIONS}
FINALLINK_FLAGS:=${NO_PIE_CO} -no-pie ${NSI_WARNINGS} \
-Wl,--gc-sections -ldl -pthread \
${NSI_LINK_OPTIONS} -lm
no_default:
@echo "There is no default rule, please specify what you want to build,\
or run make help for more info"
RUNNER_LIB:=runner.a
SRCS:=$(shell ls ${NSI_PATH}common/src/*.c)
ifdef NSI_NATIVE
SRCS+=$(shell ls ${NSI_PATH}native/src/*.c)
endif
INCLUDES:=-I${NSI_PATH}common/src/include/ \
-I${NSI_PATH}common/src \
${NSI_EXTRA_INCLUDES}
ifdef NSI_NATIVE
INCLUDES+=-I${NSI_PATH}native/src/include/
endif
EXTRA_OBJS:=$(abspath $(addprefix $(NSI_BUILD_PATH)/,$(sort ${NSI_EXTRA_SRCS:%.c=%.o})))
OBJS:=$(abspath $(addprefix $(NSI_BUILD_PATH)/,${SRCS:${NSI_PATH}%.c=%.o})) ${EXTRA_OBJS}
DEPENDFILES:=$(addsuffix .d,$(basename ${OBJS}))
-include ${DEPENDFILES}
LOCALIZED_EMBSW:=$(abspath $(addprefix $(NSI_BUILD_PATH)/,$(addsuffix .loc_cpusw.o,${NSI_EMBEDDED_CPU_SW})))
${NSI_BUILD_PATH}:
@if [ ! -d ${NSI_BUILD_PATH} ]; then mkdir -p ${NSI_BUILD_PATH}; fi
#Extra sources build:
${NSI_BUILD_PATH}/%.o: /%.c ${NSI_PATH}Makefile ${NSI_CONFIG_FILE}
@if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
${NSI_CC} ${NSI_CPPFLAGS} ${INCLUDES} ${CFLAGS} -c $< -o $@
${NSI_BUILD_PATH}/%.o: ${NSI_PATH}/%.c ${NSI_PATH}Makefile ${NSI_CONFIG_FILE}
@if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
${NSI_CC} ${NSI_CPPFLAGS} ${INCLUDES} ${CFLAGS} -c $< -o $@
${NSI_BUILD_PATH}/linker_script.ld : ${NSI_PATH}/common/other/linker_script.pre.ld | ${NSI_BUILD_PATH}
${NSI_CC} -x c -E -P $< -o $@ ${DEPENDFLAGS}
${NSI_BUILD_PATH}/${RUNNER_LIB}: ${OBJS}
if [ -f $@ ]; then rm $@ ; fi
${NSI_AR} -cr $@ ${OBJS}
${NSI_BUILD_PATH}/%.loc_cpusw.o: /% ${NSI_CONFIG_FILE}
@if [ -z $< ] || [ ! -f $< ]; then \
echo "Error: Input embedded CPU SW ($<) not found \
(NSI_EMBEDDED_CPU_SW=${NSI_EMBEDDED_CPU_SW} )"; \
false; \
fi
@if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
${NSI_OBJCOPY} --localize-hidden $< $@ -w --localize-symbol=_* ${NSI_LOCALIZE_OPTIONS}
${NSI_EXE}: ${NSI_BUILD_PATH}/${RUNNER_LIB} ${LOCALIZED_EMBSW} ${NSI_EXTRA_LIBS} \
${NSI_BUILD_PATH}/linker_script.ld
${NSI_CC} -Wl,--whole-archive ${LOCALIZED_EMBSW} ${NSI_BUILD_PATH}/${RUNNER_LIB} \
${NSI_EXTRA_LIBS} -Wl,--no-whole-archive \
-o $@ ${FINALLINK_FLAGS} -T ${NSI_BUILD_PATH}/linker_script.ld
Makefile: ;
link_with_esw: ${NSI_EXE};
runner_lib: ${NSI_BUILD_PATH}/${RUNNER_LIB}
all: link_with_esw
clean:
@echo "Deleting intermediate compilation results + libraries + executables (*.d .o .a .exe)"
find $(NSI_BUILD_PATH) -name "*.o" -or -name "*.exe" -or -name "*.a" -or -name "*.d" | xargs rm -f
clean_coverage:
find $(NSI_BUILD_PATH) -name "*.gcda" -or -name "*.gcno" | xargs rm -f ; true
clean_all: clean clean_coverage ;
.PHONY: clean clean_coverage clean_all link_with_esw runner_lib no_default all ${DEPENDFILES}
ifndef NSI_BUILD_VERBOSE
.SILENT:
endif
help:
@echo "*******************************"
@echo "* Native Simulator makefile *"
@echo "*******************************"
@echo "Provided rules:"
@echo " clean : clean all build output"
@echo " clean_coverage : clean all coverage files"
@echo " clean_all : clean + clean_coverage"
@echo " link_with_esw : Link the runner with the CPU embedded sw"
@echo " runner_lib : Build the runner itself (pending the embedded SW)"
@echo " all : link_with_esw"
@echo "Note that you can use TAB to autocomplete rules in the command line in modern OSs"