Repository navigation
Expand file tree
/
Copy pathmeson.build
More file actions
352 lines (285 loc) · 9.3 KB
/
Copy pathmeson.build
File metadata and controls
352 lines (285 loc) · 9.3 KB
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
project('aes', 'c',
version : '0.0.1',
default_options : [
'warning_level=3',
'werror=true',
'optimization=2',
'debug=false',
'strip=false',
'b_pie=true',
'b_staticpic=true',
'c_std=c18',
'buildtype=custom'
])
fs = import('fs')
#############################
#
# INCLUDES
#
#############################
INC_DIR = ['inc']
#############################
#
# SOURCES
#
#############################
SRCS_RC = ['src/rc/rc.c']
SRCS_PKCS = ['src/pkcs/pkcs.c']
SRCS_EXPANSION = ['src/expansion/aes_128_expansion.c', 'src/expansion/aes_192_expansion.c', 'src/expansion/aes_256_expansion.c']
SRCS_RANDOM = ['src/random/rdrnd.c', 'src/random/urandom.c']
SRCS_AES = ['src/ecb/aes_ecb.c', 'src/cbc/aes_cbc.c', 'src/cfb/aes_cfb.c', 'src/ofb/aes_ofb.c', 'src/ctr/aes_ctr.c', 'src/gcm/aes_gcm.c']
SRCS_GF = ['src/gf/gf8_mul.c', 'src/gf/gf128_mul.c', 'src/gcm/gfmul.c']
SRCS_UTILS = ['src/utils/aes_block.c']
SRCS = [SRCS_PKCS, SRCS_RC, SRCS_EXPANSION, SRCS_RANDOM, SRCS_AES, SRCS_GF, SRCS_UTILS]
SRCS_FILES = files(SRCS)
#############################
#
# GLOBAL FLAGS
#
#############################
CFLAGS = ['-D_FORTIFY_SOURCE=0', '-masm=intel']
#CFLAGS = ['-masm=intel']
LDFLAGS = []
TEST_CFLAGS = ['-ggdb', '-gdwarf', '-fPIC']
TEST_LDFLAGS = []
#LDFLAGS = ['-nostdlib', '-nodefaultlibs']
PIE = true
STACK_PROTECTOR = '-fstack-protector'
#############################
#
# OPTIONS
#
#############################
if (get_option('strip'))
LDFLAGS += '-s'
endif
if (get_option('stack-protector') == 'strong')
STACK_PROTECTOR = '-fstack-protector-strong'
elif (get_option('stack-protector') == 'all')
STACK_PROTECTOR = '-fstack-protector-all'
elif (get_option('stack-protector') == 'no')
STACK_PROTECTOR = '-fno-stack-protector'
endif
if (get_option('no-nx'))
LDFLAGS += ['-z', 'execstack']
endif
#############################
#
# TESTS
#
#############################
TEST_SUBPROJECT = ['tests/rc', 'tests/expansion', 'tests/random', 'tests/aes_ecb', 'tests/aes_cbc', 'tests/aes_cfb', 'tests/pkcs', 'tests/aes_ofb', 'tests/aes_ctr', 'tests/aes_gcm']
#############################
#
# COLORS
#
#############################
C_RST = '\033[00m'
C_R = '\033[31m'
C_G = '\033[32m'
C_Y = '\033[33m'
C_B = '\033[34m'
C_P = '\033[35m'
C_C = '\033[36m'
C_W = '\033[37m'
S_BOLD = '\033[1m'
S_UNDERLINE = '\033[4m'
S_BLINK = '\033[5m'
S_INVERSE = '\033[7m'
#############################
#
# PLATFORM
#
#############################
if (host_machine.system() != 'linux' or host_machine.cpu() != 'x86_64')
error('\033[31m' + meson.project_name() + ' project must be compiled on Linux and use only on Linux !\033[00m')
endif
if get_option('c_std') == 'none'
error('[\033[31m-\033[00m] C Standard not set !\033[00m')
endif
#############################
#
# DISTRO_INFO
#
#############################
dist_info_name = 'undefined'
dist_info_pretty_name = 'undefined'
dist_info_version = 'undefined'
dist_info_version_id = 'undefined'
dist_info_codename = 'undefined'
if fs.is_file('/etc/os-release')
os_release = fs.read('/etc/os-release').split('\n')
foreach line: os_release
if line.startswith('NAME')
dist_info_name = line.split('=')[1].strip('"')
endif
if line.startswith('PRETTY_NAME')
dist_info_pretty_name = line.split('=')[1].strip('"')
endif
if line.startswith('ID')
dist_info_version = line.split('=')[1].strip('"')
endif
if line.startswith('VERSION_ID')
dist_info_version_id = line.split('=')[1].strip('"')
endif
if line.startswith('VERSION_CODENAME')
dist_info_codename = line.split('=')[1].strip('"')
endif
endforeach
endif
#############################
#
# COMPILER OPTIONS
#
#############################
cc = meson.get_compiler('c')
ld = find_program('ld', required: true)
#############################
#
# Header
#
#############################
HEADERS = ['aes.h', 'pkcs.h', 'buf.h', 'rand.h']
foreach header: HEADERS
if cc.has_header(header, include_directories: include_directories('inc'), required: true) == false
error(C_R + header + ' not found !')
endif
endforeach
#############################
#
# Intrinsics
#
#############################
# Check if Intrinsics header of intel is present !
INTRIN_HEADER = ['immintrin.h', 'wmmintrin.h', 'nmmintrin.h', 'emmintrin.h', 'tmmintrin.h', 'x86gprintrin.h', 'smmintrin.h']
if get_option('no-aesni') == false
foreach header: INTRIN_HEADER
if cc.has_header(header) == false and get_option('no-aesni') == false
error('You don\'t have the \'' + header + '\' header required to compile this AES library !\n'
+ 'Maybe your CPU do not support SIMD or AES-NI extension ?')
endif
endforeach
#CFLAGS += ['-msse', '-msse2', # Streaming SIMD Instruction (128 Bits XMM)
# '-mssse3', '-msse4.1',
# '-msse4.2']
CFLAGS += ['-msse2']
CFLAGS += ['-mavx', '-mavx2', '-mavxvnni'] # AVX Instruction (256 Bits (XMM/YMM), 512 Bits (ZMM))
# -mavx512bw
# -mavx512pf
# -mavx512vnl
# -mavxvnni
# -mavx512f
#-mavx512ifma # AVX Instruction (256 Bits, 512 Bits)
CFLAGS += ['-maes'] # AES-NI Instruction
CFLAGS += ['-mrdrnd'] # Read Random Instruction
CFLAGS += ['-mvaes'] # Vectorize AES-NI Instruction
CFLAGS += ['-mgfni'] # Galois Field Instruction
CFLAGS += ['-mpclmul', '-mvpclmulqdq'] # Packer carry less multiplication
endif
#############################
#
# Machine Build Information
#
#############################
summary({
'Meson Version': S_BOLD + C_G + meson.version() + C_RST,
'CPU': build_machine.cpu(),
'Endian': S_BOLD + C_G + build_machine.endian() + C_RST,
'System': build_machine.system(),
'C Compiler': S_BOLD + cc.get_id() + ' ' + C_G + cc.version() + C_RST,
'C Standard Used': S_BOLD + C_G + get_option('c_std') + C_RST,
'Dynamic linker': ld,
'Dynamic Linker version': S_BOLD + C_G + ld.version() + C_RST,
}, section: 'Machine Build Information')
#############################
#
# Project Information
#
#############################
summary({
'Name': S_BOLD + meson.project_name() + C_RST,
'Version': S_BOLD + C_G + meson.project_version() + C_RST,
'Root': meson.project_source_root(),
'Optimization Level': S_BOLD + C_G + '-O' + get_option('optimization') + C_RST,
'Build Type': S_BOLD + C_G + get_option('buildtype') + C_RST,
'Debug mode': get_option('debug') == true ? S_BOLD + C_G + 'True' + C_RST : S_BOLD + C_R + 'False' + C_RST,
'Prefix': S_BOLD + get_option('prefix') + C_RST,
'Include Dir': get_option('prefix') + '/' + S_BOLD + C_G + get_option('includedir') + C_RST,
'Library Dir': get_option('prefix') + '/' + S_BOLD + C_G + get_option('libdir') + C_RST,
'Data Dir': get_option('prefix') + '/' + S_BOLD + C_G + get_option('datadir') + C_RST,
'Bin Dir': get_option('prefix') + '/' + S_BOLD + C_G + get_option('bindir') + C_RST,
}, section: 'Project Overview')
#############################
#
# Distribution Info
#
#############################
summary({
'Name': S_BOLD + C_G + dist_info_name + C_RST,
'Pretty Name': S_BOLD + C_G + dist_info_pretty_name + C_RST,
'Version': S_BOLD + C_G + dist_info_version + C_RST,
'Version ID': S_BOLD + C_G + dist_info_version_id + C_RST,
'Code Name': S_BOLD + C_G + dist_info_codename + C_RST
}, section: 'Distribution Information')
#############################
#
# Kernel Info
#
#############################
k = run_command('uname', '-s', check: true)
r = run_command('uname', '-r', check: true)
v = run_command('uname', '-v', check: true)
summary({
'Kernel': S_BOLD + C_G + k.stdout().strip() + C_RST,
'Release': S_BOLD + C_G + r.stdout().strip() + C_RST,
'Version': S_BOLD + C_G + v.stdout().strip() + C_RST,
}, section: 'Kernel Information')
#############################
#
# GLOBAL FLAGS
#
#############################
foreach args: CFLAGS
add_project_arguments(args, language: 'c')
endforeach
foreach args: LDFLAGS
add_project_link_arguments(args, language: 'c')
endforeach
#############################
#
# BUILD
# STATIC/SHARED LIBRARY
#
#############################
lib = both_libraries(meson.project_name(),
SRCS_FILES,
install: true,
name_prefix: 'lib',
gnu_symbol_visibility: 'default',
install_dir: 'dist',
pic: PIE,
soversion: build_machine.cpu_family() + '_' + meson.project_version(),
include_directories: INC_DIR)
#############################
#
# Library Summary
#
#############################
summary({
'Dynamic Linked Library': S_BOLD + C_G + 'lib' + lib.get_shared_lib().name() + '.so' + C_RST,
'Static Linked Library': S_BOLD + C_G + 'lib' + lib.get_static_lib().name() + '.a' + C_RST,
'Architecture': S_BOLD + C_G + build_machine.cpu_family() + C_RST,
'Version': S_BOLD + C_G + meson.project_version() + C_RST,
'CFLAGS': S_BOLD + C_G + ' '.join(CFLAGS) + C_RST,
'LDFLAGS': S_BOLD + C_G + ' '.join(LDFLAGS) + C_RST,
'PIE (Position Independent Executable)': S_BOLD + C_G + PIE.to_string() + C_RST,
}, section: 'Library Information')
#############################
#
# TESTS
#
#############################
foreach TEST: TEST_SUBPROJECT
subdir(TEST)
endforeach
subdir_done()