-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathcommon.mk
executable file
·288 lines (251 loc) · 9.07 KB
/
common.mk
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
##
# Common Makefile definitions.
# @version $Format:%h%d$
# Copyright (c) 2013-2016 INSIDE Secure Corporation. All Rights Reserved.
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
## Makefile variables that must be defined in this file
# @param[out] $(BUILD) Set here for release or debug
BUILD:=release ##< Release build strips binary and optimizes
#BUILD:=debug ##< Debug build keeps debug symbols and disables compiler optimizations. Assembly language optimizations remain enabled
#-------------------------------------------------------------------------------
## Makefile variables that are read by this file.
# @param[in] $(MATRIXSSL_ROOT) Must be set to root MatrixSSL directory
# @param[in] $(CC) Used to determine the target platform, which will differ
# from host if cross compiling.
# @param[in] $(CPU) If set, should be the target cpu for the compiler,
# suitable for the '-mcpu=' flag. See 'gcc --help=target' for valid values.
# @param[in] $(SRC) List of source files to be compiled. Used to make $(OBJS),
# the list of object files to build.
#-------------------------------------------------------------------------------
## Makefile variables that are modified by this file
# @param[in,out] $(CFLAGS) Appended with many options as determined by this file, to be passed to compiler
# @param[in,out] $(LDFLAGS) Appended with many options as determined by this file, to be passed to linker
#-------------------------------------------------------------------------------
## Makefile variables that are created by this file
# @param[out] $(OSDEP) Set to platform code directory (./core/$OSDEP/osdep.c), based on $(CC)
# @param[out] $(CCARCH) Set to compiler's target architecture, based on $(CC)
# @param[out] $(STRIP) Set to the executable to use to strip debug symbols from executables
# @param[out] $(STROPS) Human readable description of relevant MatrixSSL compile options.
# @param[out] $(O) Set to the target platform specific object file extension
# @param[out] $(A) Set to the target phatform specific static library (archive) file extension
# @param[out] $(E) Set to the target platform specific executable file extension
# @param[out] $(OBJS) Set to the list of objects that is to be built
#-------------------------------------------------------------------------------
## Auto-detect cross compiler for some platforms based on environment variables
## Based on the value of CC, determine the target, eg.
# x86_64-redhat-linux
# i686-linux-gnu
# x86_64-apple-darwin14.0.0
# arm-linux-gnueabi
# arm-linux-gnueabihf
# arm-none-eabi
# mips-linux-gnu
# mipsisa64-octeon-elf-gcc
# powerpc-linux-gnu
CCARCH:=$(shell $(CC) -v 2>&1 | sed -n '/Target: / s/// p')
CCVER:=$(shell $(CC) --version 2>&1)
STROPTS:="Built for $(CCARCH)"
## uname of the Host environment, eg.
# Linux
# Darwin
# @note Unused
#UNAME:=$(shell uname)
## Standard file extensions for Linux/OS X.
O:=.o
A:=.a
E=
# Check if this version of make supports undefine
ifneq (,$(findstring undefine,$(.FEATURES)))
HAVE_UNDEFINE:=1
endif
#On OS X, Xcode sets CURRENT_VARIANT to normal, debug or profile
ifneq (,$(findstring -apple,$(CCARCH)))
ifneq (,$(findstring ebug,$(CONFIGURATION)))
MATRIX_DEBUG:=1
endif
endif
#Manually enable debug here
#MATRIX_DEBUG:=1
ifdef MATRIX_DEBUG
OPT:=-O0 -g -DDEBUG -Wall
#OPT+=-Wconversion
STRIP:=test # no-op
else
ifneq (,$(findstring -none,$(CCARCH)))
OPT:=-Os -Wall # Compile bare-metal for size
else
OPT:=-O3 -Wall # Compile all others for speed
endif
STRIP:=strip
endif
CFLAGS+=$(OPT)
# Detect multicore and do parallel build. Uncomment if desired:
#> ifneq (,$(findstring -linux,$(CCARCH)))
#> JOBS:=-j$(shell grep -ic processor /proc/cpuinfo)
#> else ifneq (,$(findstring apple,$(CCARCH)))
#> JOBS:=-j$(shell sysctl -n machdep.cpu.thread_count)
#> endif
default: $(BUILD)
debug:
@$(MAKE) compile "MATRIX_DEBUG=1"
release:
@$(MAKE) $(JOBS) compile
# 64 Bit Intel Target
ifneq (,$(findstring x86_64-,$(CCARCH)))
CFLAGS+=-m64
STROPTS+=", 64-bit Intel RSA/ECC ASM"
# Enable AES-NI if the host supports it (assumes Host is Target)
ifneq (,$(findstring -linux,$(CCARCH)))
ifeq ($(shell grep -o -m1 aes /proc/cpuinfo),aes)
CFLAGS+=-maes -mpclmul -msse4.1
STROPTS+=", AES-NI ASM"
endif
else ifneq (,$(findstring apple,$(CCARCH)))
ifeq ($(shell sysctl -n hw.optional.aes),1)
CFLAGS+=-maes -mpclmul -msse4.1
STROPTS+=", AES-NI ASM"
endif
endif
# 32 Bit Intel Edison Target
else ifneq (,$(findstring i586-,$(CCARCH)))
CFLAGS+=-m32
ifneq (,$(findstring edison,$(shell uname -n)))
ifneq (,$(findstring -O3,$(OPT)))
#Edison does not like -O3
OPT:=-O2
endif
CFLAGS+=-DEDISON -maes -mpclmul -msse4.1
STROPTS+=", 32-bit Intel RSA/ECC ASM, AES-NI ASM, Intel Edison"
else
STROPTS+=", 32-bit Intel RSA/ECC ASM"
endif
# 32 Bit Intel Target
else ifneq (,$(findstring i686-,$(CCARCH)))
CFLAGS+=-m32
STROPTS+=", 32-bit Intel RSA/ECC ASM"
# MIPS Target
else ifneq (,$(findstring mips-,$(CCARCH)))
STROPTS+=", 32-bit MIPS RSA/ECC ASM"
# MIPS64 Target
else ifneq (,$(filter mips%64-,$(CCARCH)))
# STROPTS+=", 64-bit MIPS64 RSA/ECC ASM"
# ARM Target
else ifneq (,$(findstring arm,$(CCARCH)))
STROPTS+=", 32-bit ARM RSA/ECC ASM"
ifneq (,$(findstring linux-,$(CCARCH)))
HARDWARE:=$(shell sed -n '/Hardware[ \t]*: / s/// p' /proc/cpuinfo)
# Raspberry Pi Host and Target
ifneq (,$(findstring BCM2708,$(HARDWARE)))
CFLAGS+=-DRASPBERRYPI -mfpu=vfp -mfloat-abi=hard -ffast-math -march=armv6zk -mtune=arm1176jzf-s
STROPTS+=", Raspberry Pi"
endif
# Raspberry Pi 2 Host and Target
ifneq (,$(findstring BCM2709,$(HARDWARE)))
ifneq (,$(findstring 4.6,$(CCVER)))
CFLAGS+=-march=armv7-a
else
# Newer gcc (4.8+ supports this cpu type)
CFLAGS+=-mcpu=cortex-a7
endif
CFLAGS+=-DRASPBERRYPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard
STROPTS+=", Raspberry Pi2"
endif
# Beagleboard/Beaglebone Host and Target
ifneq (,$(findstring AM33XX,$(HARDWARE)))
CFLAGS+=-BEAGLEBOARD -mfpu=neon -mfloat-abi=hard -ffast-math -march=armv7-a -mtune=cortex-a8
STROPTS+=", Beagleboard"
endif
# Samsung Exynos 5 (Can also -mtune=cortex-a15 or a8)
ifneq (,$(findstring EXYNOS5,$(HARDWARE)))
CFLAGS+=-DEXYNOS5 -mfpu=neon -mfloat-abi=hard -ffast-math -march=armv7-a
STROPTS+=", Exynos 5"
endif
ifdef HAVE_UNDEFINE
undefine HARDWARE
endif
endif
endif
ifdef MATRIX_DEBUG
CFLAGS+=-ffunction-sections -fdata-sections
else
CFLAGS+=-ffunction-sections -fdata-sections -fomit-frame-pointer
endif
# If we're using clang (it may be invoked via 'cc' or 'gcc'),
# handle minor differences in compiler behavior vs. gcc
ifneq (,$(findstring clang,$(CCVER)))
CFLAGS+=-Wno-error=unused-variable -Wno-error=\#warnings -Wno-error=\#pragma-messages
endif
# Handle differences between the OS X ld and GNU ld
ifneq (,$(findstring -apple,$(CCARCH)))
LDFLAGS+=-Wl,-dead_strip
else
LDFLAGS+=-Wl,--gc-sections
endif
CFLAGS+=-I$(MATRIXSSL_ROOT)
#USE_OPENSSL_CRYPTO:=1
ifdef USE_OPENSSL_CRYPTO
OPENSSL_ROOT:=/opt/openssl-1.0.2d
ifdef OPENSSL_ROOT
# Statically link against a given openssl tree
CFLAGS+=-I$(OPENSSL_ROOT)/include
LDFLAGS+=$(OPENSSL_ROOT)/libcrypto.a -ldl
else ifneq (,$(findstring -apple,$(CCARCH)))
# Dynamically link against the sytem default openssl tree
# Apple has deprecated the built in openssl, so supress warnings here
CFLAGS+=-Wno-error=deprecated-declarations -Wno-deprecated-declarations
LDFLAGS+=-lcrypto
else ifneq (,$(findstring -linux,$(CCARCH)))
# Dynamically link against the sytem default openssl tree
LDFLAGS+=-lcrypto
else
$(error Please define OPENSSL_ROOT)
endif
CFLAGS+=-DUSE_OPENSSL_CRYPTO
STROPTS+=", USE_OPENSSL_CRYPTO"
endif
#USE_LIBSODIUM_CRYPTO:=1
ifdef USE_LIBSODIUM_CRYPTO
LIBSODIUM_ROOT:=/opt/libsodium-1.0.8/src/libsodium
ifdef LIBSODIUM_ROOT
# Statically link against a given libsodium
CFLAGS+=-I$(LIBSODIUM_ROOT)/include
LDFLAGS+=$(LIBSODIUM_ROOT)/.libs/libsodium.a
else
$(error Please define LIBSODIUM_ROOT)
endif
CFLAGS+=-DUSE_LIBSODIUM_CRYPTO
STROPTS+=", USE_LIBSODIUM_CRYPTO"
endif
# Linux Target
ifneq (,$(findstring -linux,$(CCARCH)))
OSDEP:=POSIX
#For USE_HIGHRES_TIME
LDFLAGS+=-lrt
# OS X Target
else ifneq (,$(findstring -apple,$(CCARCH)))
OSDEP:=POSIX
CFLAGS+=-isystem -I/usr/include
# Bare Metal / RTOS Target
else ifneq (,$(findstring -none,$(CCARCH)))
OSDEP:=METAL
CFLAGS+=-fno-exceptions -fno-unwind-tables -fno-non-call-exceptions -fno-asynchronous-unwind-tables -ffreestanding -fno-builtin -nostartfiles
ifneq (,$(findstring cortex-,$(CPU)))
CFLAGS+=-mthumb -mcpu=$(CPU) -mslow-flash-data
ifeq (cortex-m4,$(CPU))
CFLAGS+=-mcpu=cortex-m4 -mtune=cortex-m4
else ifeq (cortex-m3,$(CPU))
CFLAGS+=-mcpu=cortex-m3 -mtune=cortex-m3 -mfpu=vpf
else ifeq (cortex-m0,$(CPU))
CFLAGS+=-mcpu=cortex-m0 -mtune=cortex-m0 -mfpu=vpf
endif
endif
endif
# This must be defined after OSDEP, because core/Makefile uses OSDEP in SRC
OBJS=$(SRC:.c=.o) $(SRC:.S:*.o)
# Remove extra spaces in CFLAGS
#CFLAGS=$(strip $(CFLAGS))
# Display the precompiler defines for the current build settings
defines:
:| $(CC) $(CFLAGS) -dM -E -x c -