-
Notifications
You must be signed in to change notification settings - Fork 42
/
meson.build
172 lines (148 loc) · 3.43 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
project(
'libucontext',
'c',
meson_version : '>=0.59.0',
default_options: ['c_std=gnu11', 'default_library=both'],
version : run_command('head', files('VERSION')).stdout()
)
cpu = get_option('cpu')
if cpu == ''
cpu = host_machine.cpu_family()
endif
if cpu == 'sh4'
cpu = 'sh'
endif
project_description = 'Portable implementation of ucontext'
project_headers = [
'include/libucontext/libucontext.h'
]
project_source_files = [
'arch' / cpu / 'getcontext.S',
'arch' / cpu / 'setcontext.S',
'arch' / cpu / 'swapcontext.S',
]
if cpu in ['mips', 'mips64']
project_source_files += [
'arch' / cpu / 'makecontext.S'
]
else
project_source_files += [
'arch' / cpu / 'makecontext.c'
]
endif
if cpu in ['ppc', 'ppc64']
project_source_files += [
'arch' / cpu / 'retfromsyscall.c'
]
endif
if cpu not in ['loongarch64', 'mips', 'mips64', 'ppc', 'ppc64', 's390x', 'x86']
project_source_files += [
'arch' / cpu / 'trampoline.c'
]
else
project_source_files += [
'arch' / cpu / 'startcontext.S'
]
endif
project_includes = [
'include',
'arch/common'
]
build_args = [
'-D_DEFAULT_SOURCE'
]
# ===================================================================
# ======
# Options
# ======
freestanding = get_option('freestanding')
export_unprefixed = get_option('export_unprefixed')
build_posix = true
if freestanding
build_args += '-DFREESTANDING'
build_posix = false
export_unprefixed = false
project_headers += ['arch' / cpu / 'include/libucontext/bits.h']
project_includes += ['arch' / cpu / 'include']
else
project_headers += ['arch/common/include/libucontext/bits.h']
project_includes += ['arch/common/include']
endif
if export_unprefixed
build_args += '-DEXPORT_UNPREFIXED'
endif
# ======
# Target
# ======
headers = include_directories(project_includes)
libucontext_target = library(
'ucontext',
project_source_files,
version: '1',
install : not meson.is_subproject(),
c_args : build_args,
pic: true,
include_directories : headers,
)
libucontext_dep = declare_dependency(
include_directories: headers,
link_with : libucontext_target
)
if build_posix
libucontext_posix_target = library(
'ucontext_posix',
project_source_files + ['libucontext_posix.c'],
version: '1',
install : not meson.is_subproject(),
c_args : build_args,
pic: true,
include_directories : headers,
)
libucontext_posix_dep = declare_dependency(
include_directories: headers,
link_with : libucontext_posix_target
)
endif
# =======
# Project
# =======
if not meson.is_subproject()
# Make this library usable from the system's
# package manager.
install_headers(project_headers, subdir : meson.project_name())
pkg_mod = import('pkgconfig')
pkg_mod.generate(
name : meson.project_name(),
filebase : meson.project_name(),
description : project_description,
subdirs : meson.project_name(),
libraries : libucontext_target,
)
endif
# ====
# Docs
# ====
if not meson.is_subproject() and get_option('docs')
subdir('doc')
endif
# ==========
# Unit Tests
# ==========
test('test_libucontext',
executable(
'test_libucontext',
files('test_libucontext.c'),
dependencies : libucontext_dep,
install : false
)
)
if build_posix
test('test_libucontext_posix',
executable(
'test_libucontext_posix',
files('test_libucontext_posix.c'),
dependencies : [libucontext_dep, libucontext_posix_dep],
install : false
)
)
endif