forked from managarm/mlibc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
373 lines (327 loc) · 12.8 KB
/
meson.build
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
project('mlibc', default_options: ['warning_level=2', 'cpp_std=c++20'])
fs = import('fs')
rtdl_include_dirs = [
include_directories('options/internal/include'),
include_directories('options/internal' / host_machine.cpu_family() + '-include'),
include_directories('options/rtdl/include'),
]
libc_include_dirs = [
include_directories('options/internal/include'),
include_directories('options/elf/include'),
include_directories('options/lsb/include'),
include_directories('options/rtdl/include'),
include_directories('options/internal' / host_machine.cpu_family() + '-include')
]
rtdl_sources = [ ]
rtdl_dso_sources = [ ]
libc_sources = [ ]
libc_sublibs = [ ]
libc_deps = [ ]
rtdl_deps = [ ]
headers_only = get_option('headers_only')
no_headers = get_option('mlibc_no_headers')
library_type = get_option('default_library')
build_tests = get_option('build_tests')
build_tests_host_libc = get_option('build_tests_host_libc')
disable_ansi_option = get_option('disable_ansi_option')
disable_posix_option = get_option('disable_posix_option')
disable_linux_option = get_option('disable_linux_option')
disable_linux_headers = get_option('disable_linux_headers_option')
disable_iconv_option = get_option('disable_iconv_option')
disable_intl_option = get_option('disable_intl_option')
disable_glibc_option = get_option('disable_glibc_option')
disable_crypt_option = get_option('disable_crypt_option')
disable_bsd_option = get_option('disable_bsd_option')
internal_conf = configuration_data()
mlibc_conf = configuration_data()
if not headers_only
cxxshim_dep = dependency('cxxshim', fallback: ['cxxshim', 'cxxshim_dep'])
libc_deps += cxxshim_dep
rtdl_deps += cxxshim_dep
frigg_dep = dependency(
'frigg',
default_options: ['frigg_no_install=true'],
fallback: ['frigg', 'frigg_dep'],
)
libc_deps += frigg_dep
rtdl_deps += frigg_dep
add_languages('c', 'cpp')
c_compiler = meson.get_compiler('c')
add_project_arguments('-Wno-unused-function', '-D__MLIBC_BUILDING_MLIBC', language: ['c', 'cpp'])
add_project_arguments('-nostdinc', '-fno-builtin', language: ['c', 'cpp'])
add_project_arguments('-fno-rtti', '-fno-exceptions', language: 'cpp')
add_project_link_arguments('-nostdlib', language: ['c', 'cpp'])
searchdirs = run_command(c_compiler.cmd_array(), '-print-search-dirs',
check: true).stdout()
searchdirs_arr = searchdirs.split('\n')
searchline = 'install: '
ccdir = ''
if c_compiler.get_id() == 'clang'
searchline = 'libraries: ='
endif
foreach line : searchdirs_arr
if line.startswith(searchline)
ccdir = line.strip(searchline)
ccdir = ccdir.split(':')[0]
break
endif
endforeach
if ccdir == ''
error('could not find compiler-specific header directory')
endif
if c_compiler.get_id() == 'gcc' and fs.exists(ccdir / 'include-fixed')
rtdl_include_dirs += include_directories(ccdir / 'include-fixed')
libc_include_dirs += include_directories(ccdir / 'include-fixed')
endif
rtdl_include_dirs += include_directories(ccdir / 'include')
libc_include_dirs += include_directories(ccdir / 'include')
endif
internal_conf.set_quoted('MLIBC_SYSTEM_NAME', host_machine.system())
internal_conf.set('MLIBC_MAP_DSO_SEGMENTS', false)
internal_conf.set('MLIBC_MAP_FILE_WINDOWS', false)
internal_conf.set('MLIBC_DEBUG_ALLOCATOR', get_option('debug_allocator'))
#----------------------------------------------------------------------------------------
# Configuration based on sysdeps.
#----------------------------------------------------------------------------------------
# Process sysdeps first, as sysdeps might want to disable unsupported options.
if host_machine.system() == 'linux'
disable_linux_headers = true
rtdl_include_dirs += include_directories('sysdeps/linux/include')
libc_include_dirs += include_directories('sysdeps/linux/include')
subdir('sysdeps/linux')
elif host_machine.system() == 'aero'
rtdl_include_dirs += include_directories('sysdeps/aero/include')
libc_include_dirs += include_directories('sysdeps/aero/include')
subdir('sysdeps/aero')
elif host_machine.system() == 'managarm'
# TODO: Adopt the include_directories() commands from the managarm meson.build.
rtdl_include_dirs += include_directories('sysdeps/managarm/include')
libc_include_dirs += include_directories('sysdeps/managarm/include')
internal_conf.set('MLIBC_MAP_DSO_SEGMENTS', true)
internal_conf.set('MLIBC_MAP_FILE_WINDOWS', true)
subdir('sysdeps/managarm')
elif host_machine.system() == 'ironclad'
# disable_linux_option = true
rtdl_include_dirs += include_directories('sysdeps/ironclad/include')
libc_include_dirs += include_directories('sysdeps/ironclad/include')
subdir('sysdeps/ironclad')
elif host_machine.system() == 'vinix'
rtdl_include_dirs += include_directories('sysdeps/vinix/include')
libc_include_dirs += include_directories('sysdeps/vinix/include')
subdir('sysdeps/vinix')
elif host_machine.system() == 'lemon'
rtdl_include_dirs += include_directories('sysdeps/lemon/include')
libc_include_dirs += include_directories('sysdeps/lemon/include')
subdir('sysdeps/lemon')
elif host_machine.system() == 'dripos'
disable_linux_option = true
rtdl_include_dirs += include_directories('sysdeps/dripos/include')
libc_include_dirs += include_directories('sysdeps/dripos/include')
subdir('sysdeps/dripos')
else
error('No sysdeps defined for OS: ' + host_machine.system())
endif
#----------------------------------------------------------------------------------------
# Configuration based on enabled options.
#----------------------------------------------------------------------------------------
mlibc_conf.set('__MLIBC_ANSI_OPTION', not disable_ansi_option)
mlibc_conf.set('__MLIBC_POSIX_OPTION', not disable_posix_option)
mlibc_conf.set('__MLIBC_LINUX_OPTION', not disable_linux_option)
mlibc_conf.set('__MLIBC_INTL_OPTION', not disable_intl_option)
mlibc_conf.set('__MLIBC_ICONV_OPTION', not disable_iconv_option)
mlibc_conf.set('__MLIBC_GLIBC_OPTION', not disable_glibc_option)
mlibc_conf.set('__MLIBC_CRYPT_OPTION', not disable_crypt_option)
mlibc_conf.set('__MLIBC_BSD_OPTION', not disable_bsd_option)
if not disable_ansi_option
rtdl_include_dirs += include_directories('options/ansi/include')
libc_include_dirs += include_directories('options/ansi/include')
endif
if not disable_posix_option
rtdl_include_dirs += include_directories('options/posix/include')
libc_include_dirs += include_directories('options/posix/include')
endif
if not disable_iconv_option
rtdl_include_dirs += include_directories('options/iconv/include')
libc_include_dirs += include_directories('options/iconv/include')
endif
if not disable_intl_option
libc_include_dirs += include_directories('options/intl/include')
endif
if not disable_linux_option
rtdl_include_dirs += include_directories('options/linux/include')
libc_include_dirs += include_directories('options/linux/include')
endif
if not disable_glibc_option
rtdl_include_dirs += include_directories('options/glibc/include')
libc_include_dirs += include_directories('options/glibc/include')
endif
if not disable_crypt_option
libc_include_dirs += include_directories('options/crypt/include')
endif
if not disable_bsd_option
libc_include_dirs += include_directories('options/bsd/include')
endif
rtdl_include_dirs += include_directories('options/linux-headers/include')
libc_include_dirs += include_directories('options/linux-headers/include')
rtdl_include_dirs += include_directories('options/elf/include')
libc_include_dirs += include_directories('options/elf/include')
libc_include_dirs += include_directories('.')
#----------------------------------------------------------------------------------------
configure_file(input: 'internal-config.h.in',
output: 'internal-config.h',
configuration: internal_conf)
configure_file(input: 'mlibc-config.h.in',
output: 'mlibc-config.h',
configuration: mlibc_conf,
install: not no_headers,
install_dir: get_option('includedir'))
internal_sources = [
'options/internal/generic/allocator.cpp',
'options/internal/generic/charcode.cpp',
'options/internal/generic/charset.cpp',
'options/internal/generic/debug.cpp',
'options/internal/generic/ensure.cpp',
'options/internal/generic/essential.cpp',
'options/internal/generic/frigg.cpp',
'options/internal/generic/global-config.cpp',
'options/internal/generic/inline-emitter.cpp',
'options/internal/generic/locale.cpp',
'options/internal/generic/sigset.cpp',
'options/internal/generic/strings.cpp',
'options/internal/generic/ubsan.cpp',
'options/internal/gcc/stack_protector.cpp',
'options/internal/gcc/guard-abi.cpp',
'options/internal/gcc/initfini.cpp',
'options/internal/gcc-extra/cxxabi.cpp',
'options/internal' / host_machine.cpu_family() / 'setjmp.S',
]
internal_dso_sources = [
'options/internal/gcc-extra/mlibc_crtbegin.S',
'options/internal' / host_machine.cpu_family() / 'mlibc_crtend.S',
]
if not no_headers
install_headers(
'options/internal/include/stdint.h'
)
install_headers(
'options/internal/include/bits/wchar_t.h',
'options/internal/include/bits/wchar.h',
'options/internal/include/bits/wint_t.h',
'options/internal/include/bits/size_t.h',
'options/internal/include/bits/types.h',
'options/internal/include/bits/ensure.h',
'options/internal/include/bits/machine.h',
'options/internal/include/bits/mbstate.h',
'options/internal/include/bits/nl_item.h',
'options/internal/include/bits/null.h',
'options/internal/include/bits/off_t.h',
'options/internal/include/bits/ssize_t.h',
'options/internal/include/bits/sigset_t.h',
'options/internal/include/bits/inline-definition.h',
subdir: 'bits'
)
endif
rtdl_sources += [
'options/internal/gcc/stack_protector.cpp',
'options/internal/gcc/guard-abi.cpp',
'options/internal/generic/allocator.cpp',
'options/internal/generic/debug.cpp',
'options/internal/generic/ensure.cpp',
'options/internal/generic/essential.cpp',
'options/internal/generic/inline-emitter.cpp',
'options/internal/generic/frigg.cpp',
'options/internal/generic/ubsan.cpp',
'options/rtdl/generic/main.cpp',
'options/rtdl/generic/linker.cpp',
'options/rtdl' / host_machine.cpu_family() / 'runtime.S'
]
rtdl_dso_sources += ['options/rtdl' / host_machine.cpu_family() / 'entry.S']
subdir('options/elf')
subdir('options/ansi')
subdir('options/posix')
subdir('options/lsb')
subdir('options/glibc')
subdir('options/linux')
subdir('options/linux-headers')
subdir('options/iconv')
subdir('options/intl')
subdir('options/crypt')
subdir('options/bsd')
rtlib_deps = []
if not headers_only
if host_machine.cpu_family() == 'aarch64' or host_machine.cpu_family() == 'riscv64'
# Some architectures require us to link with libgcc or compiler_rt
libgcc = meson.get_compiler('c').find_library('gcc', required: false)
compiler_rt_name = 'libclang_rt.builtins-' + host_machine.cpu_family()
compiler_rt = meson.get_compiler('c').find_library(compiler_rt_name, required: false)
if libgcc.found()
rtlib_deps += libgcc
elif compiler_rt.found()
rtlib_deps += compiler_rt
else
error('neither libgcc nor ' + compiler_rt_name + ' was found')
endif
endif
ld_cpp_args = [
'-fvisibility=hidden',
'-fno-stack-protector',
'-DMLIBC_BUILDING_RTDL'
]
libc_all_sources = [
libc_sources,
internal_sources,
ansi_sources,
lsb_sources,
]
# Our library have different behaviour when built as static and shared libraries.
# Hence we need to rebuild the object files with a different define for each mode.
if library_type in ['static', 'both']
static_cpp_args = [
'-DMLIBC_STATIC_BUILD',
'-DFRIGG_HAVE_LIBC',
]
ld_static_lib = static_library('ld', rtdl_sources,
name_prefix: '',
cpp_args: ld_cpp_args + static_cpp_args,
include_directories: rtdl_include_dirs,
dependencies: rtdl_deps + rtlib_deps,
install: false
)
libc_static = static_library('c', libc_all_sources,
cpp_args: static_cpp_args + ['-fno-stack-protector'],
include_directories: libc_include_dirs,
dependencies: libc_deps + rtlib_deps,
link_with: [ld_static_lib],
link_whole: [libc_sublibs, ld_static_lib],
install: true
)
endif
if library_type in ['shared', 'both']
ld_shared_lib = shared_library('ld', rtdl_sources + rtdl_dso_sources,
name_prefix: '',
cpp_args: ld_cpp_args,
include_directories: rtdl_include_dirs,
dependencies: rtdl_deps + rtlib_deps,
install: true
)
libc_shared = shared_library('c', libc_all_sources + internal_dso_sources,
include_directories: libc_include_dirs,
dependencies: libc_deps + rtlib_deps,
link_with: [ld_shared_lib],
link_whole: libc_sublibs,
install: true
)
endif
library('pthread', 'dummy-libs/libpthread/src/dummy.cpp', install: true)
library('rt', 'dummy-libs/librt/src/dummy.cpp', install: true)
library('util', 'dummy-libs/libutil/src/dummy.cpp', install: true)
library('m', 'dummy-libs/libm/src/dummy.cpp', install: true)
if not disable_crypt_option
library('crypt', 'dummy-libs/libcrypt/src/dummy.cpp', install: true)
endif
library('resolv', 'dummy-libs/libresolv/src/dummy.cpp', install: true)
library('dl', 'dummy-libs/libdl/src/dummy.cpp', install: true)
endif
if build_tests
subdir('tests/')
endif