-
Notifications
You must be signed in to change notification settings - Fork 1
/
meson.build
executable file
·299 lines (242 loc) · 10.1 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
project(
'ymp',
'vala', 'c',
meson_version: '>= 0.58.0',
version : '1.3',
license: ['GplV3']
)
if meson.get_compiler('vala').version().version_compare('<0.54.9')
error('vala compiler version 0.54.9 or newer is required.')
endif
conf = []
compiler = meson.get_compiler('c')
architecture = run_command('uname', '-m', check:true).stdout().strip()
message('\x1b[32;1mGenerate:\x1b[;0m','ctx.vala')
run_command('bash', './tool/mkctx.sh',
'CONFIGDIR=/'+get_option('sysconfdir'),
'STORAGEDIR=/'+get_option('storagedir'),
'DISTRODIR=/'+get_option('distrodir'),
'VERSION='+meson.project_version(),
check:true)
run_command('bash', './tool/check.sh', meson.current_build_dir(), check:true)
cflags = ['-I'+meson.current_source_dir()/'src/include/']
ldflags = ['-L'+meson.current_build_dir(), '-lymp']
if get_option('ansi')
cflags += ['-ansi']
endif
# disable vala related warnings
cflags += ['-Wno-unused', '-Wno-unused-result', '-Wno-incompatible-pointer-types',
'-Wno-discarded-qualifiers', '-Wno-infinite-recursion',
'-Wno-cast-function-type', '-Wno-attributes','-Wno-unknown-warning-option',
]
cflags += ['-DGETTEXT_PACKAGE=ymp']
# some compiler flags from dpkg-buildpackage
cflags += ['-g', '-O2', '-Werror=implicit-function-declaration',
'-ffile-prefix-map=/root/ymp=.', '-fstack-protector-strong',
'-fstack-clash-protection', '-Wformat', '-Werror=format-security'
]
# error on warning
if compiler.get_id() == 'gcc'
cflags += ['-Werror']
endif
# some improvements
cflags += ['-fno-plt', '-flto', '-isystem', '-fvisibility=hidden', '-DVALA_EXTERN=extern', '-pthread']
start_code = []
# do not include glibc or musl stdlib and link with glibc or musl
if run_command('/bin/sh', '-c', 'ldd /proc/self/exe | grep /lib/ld-musl-'+architecture+'.so.1').returncode() == 0
cflags += ['-Dmusl']
else
if not get_option('test')
ldflags += ['-nostdlib', '-lc']
start_code += ['src/start/'+architecture+'.s' ]
endif
endif
deps = []
pkgconfig_dep = []
pkgconfig_arg = ''
if get_option('static')
pkgconfig_arg = '--static'
ldflags += ['--static']
conf += ['STATIC']
else
conf += ['SHARED']
endif
# valac configuration
add_project_arguments(['--disable-assert', '--hide-internal', '--nostdpkg', '--enable-checking', '--abi-stability'], language: 'vala')
add_project_arguments('-D', '_GNU_SOURCE', '--disable-version-header', language: 'vala')
add_project_arguments(['--pkg', 'posix'], language: 'vala')
# vapi directory (valac configunation)
add_project_arguments('--vapidir', meson.current_source_dir() / 'src/vapi/', language: 'vala')
foreach vapi : run_command('find', 'src/vapi','-type','f',check:true).stdout().strip().split('\n')
vapi = vapi.replace('.vapi','')
vapi = vapi.split('/')[-1]
add_project_arguments('--pkg', vapi, language: 'vala')
endforeach
# gio
deps += [dependency('gio-2.0', static: get_option('static'), required:true)]
# glib-2.0
pkgconfig_dep += ['gio-2.0']
#libarchive (no vapi)
if get_option('libarchive')
libarchive = dependency('libarchive', static:get_option('static'), required:false)
if not libarchive.found()
else
conf += ['libarchive']
pkgconfig_dep += ['libarchive']
endif
else
error('libarchive not found')
endif
#libreadline
if get_option('libreadline')
libreadline = dependency('readline', static:get_option('static'), required:false)
if not libreadline.found()
conf += ['no_libreadline']
endif
deps += [libreadline]
endif
#libcurl (no vapi)
if get_option('libcurl')
libcurl = dependency('libcurl', static:get_option('static'), required:false)
if not libcurl.found()
else
conf += ['libcurl']
pkgconfig_dep += ['libcurl']
if get_option('libbrotli')
ldflags += ['-lbrotlicommon']
endif
endif
#libsoup-3.0 (no vapi)
elif get_option('libsoup')
libsoup = dependency('libsoup-3.0', static:get_option('static'), required:false)
if not libsoup.found()
else
conf += ['libsoup']
pkgconfig_dep += ['libsoup-3.0']
endif
else
conf += ['no_fetcher_backend']
endif
# find sources
sources = ['data/ymp-extra.h']
sources += run_command('find', 'src/', '-not', '-path', 'src/cli/*','-type','f', '-iname', '*.vala',check:true).stdout().strip().split('\n')
# find C sources
foreach csource : run_command('find', 'src/', '-not', '-path', 'src/cli/*','-type','f', '-iname', '*.c' ,check:true).stdout().strip().split('\n')
sources += [meson.current_source_dir() / csource]
endforeach
# locale settings
if get_option('locale')
subdir('po')
else
conf += ['no_locale']
endif
# experimental features
if get_option('experimental')
conf += ['experimental']
endif
# debug
if get_option('debug')
add_project_arguments('--debug', language: 'vala')
cflags += ['-g3', '-Wall', '-Wextra', '-grecord-gcc-switches','-fdiagnostics-color=always', '-DDEBUG']
conf += ['DEBUG']
else
cflags += ['-DNDEBUG']
conf += ['NDEBUG']
endif
# colorize options
if not get_option('colorize')
conf += ['NOCOLOR']
endif
# oem check feature
if get_option('check_oem')
conf += ['check_oem']
endif
########### add ldflags and cflags ###########
foreach name: pkgconfig_dep
# Run the pkg-config command and capture its output
ldflags += run_command(
'pkg-config', '--libs', name, pkgconfig_arg, check: true
).stdout().strip().split(' ')
# Run the pkg-config command and capture its output
cflags += run_command(
'pkg-config', '--cflags', name, pkgconfig_arg, check: true
).stdout().strip().split(' ')
endforeach
########### build ymp.pc ###########
run_command('install', 'data/ymp.pc', meson.current_build_dir(), check: true)
run_command('sed', '-i', 's/@version@/'+meson.project_version()+'/g', meson.current_build_dir()+'/ymp.pc', check: true)
foreach c : conf
add_project_arguments('-D', c, language: 'vala')
cflags += '-D'+c
endforeach
########### generate vala sources ###########
generated_sources=[]
foreach valasrc : sources
message('\x1b[32;1mGenerate:\x1b[;0m' ,valasrc)
run_command('bash', 'tool/preprocessor.sh','.generated',valasrc, cflags,check:true)
generated_sources += '.generated'/valasrc
endforeach
if get_option('nolibc_path') != ''
cflags += ['-nostdlib', '-I'+get_option('nolibc_path')]
endif
add_project_arguments('-I'+meson.current_source_dir()+'/src/include/', language : 'c')
add_project_arguments('-fPIC', language : 'c')
generated_sources += ['ctx.vala']
foreach arg : cflags
if arg != ''
add_project_arguments(arg, language : 'c')
endif
endforeach
########### build libymp ###########
if get_option('static')
libymp = static_library('ymp', generated_sources, dependencies: deps, link_args: ldflags)
else
libymp = shared_library('ymp', generated_sources, dependencies: deps, link_args: ldflags)
endif
install_data(meson.current_build_dir() / 'libymp.so', install_dir : get_option('libdir'), rename: 'libymp.so')
########### build tools ###########
if get_option('tools')
# ymp cli
cli = executable('ymp-cli', ['src/cli/main.c'] + start_code, dependencies: deps, link_args: ldflags , link_with: libymp)
install_data(meson.current_build_dir() / 'ymp-cli', install_dir : get_option('bindir'),rename : 'ymp')
# ymp shell
shell = executable('ymp-shell', ['src/cli/shell.c'] + start_code, dependencies: deps, link_args: ldflags, link_with: libymp)
install_data(meson.current_build_dir() / 'ymp-shell', install_dir : get_option('bindir'),rename : 'ympsh')
endif
########### build start code ###########
start_name = 'start-' +architecture + '.o'
run_command(compiler.get_id(), '-c', 'src/start/'+architecture+'.s',
'-nostdlib', '-static', '-o', meson.current_build_dir() / start_name ,
check:true)
install_data(meson.current_build_dir() / start_name, install_dir : get_option('libdir'),rename : start_name)
########### build test ###########
if get_option('test')
executable('ymp-test', ['test/test.vala'] + start_code, dependencies: deps, link_args: ldflags, link_with: libymp)
endif
########### build scripts ###########
if get_option('scripts')
foreach script : run_command('find', 'scripts','-type','f',check:true).stdout().strip().split('\n')
install_data(script, install_dir : get_option('bindir'))
endforeach
endif
########### code runner plugins ###########
foreach plugin : run_command('find', 'data/code-runner-plugins','-type','f',check:true).stdout().strip().split('\n')
install_data(plugin, install_dir : '/lib/code-runner/')
endforeach
########### install files ###########
install_data('data/ymp.yaml', install_dir : get_option('sysconfdir'))
install_data('data/org.turkman.ymp.extract.desktop', install_dir : get_option('prefix') / 'share/applications')
install_data(meson.current_build_dir()+'/ymp.pc', install_dir : get_option('libdir')/ 'pkgconfig')
install_data('data/application-x-ymp.svg', install_dir : get_option('prefix') / 'share/icons/hicolor/scalable/mimetypes/')
install_data('data/fix-turkish.sed', install_dir : get_option('prefix') / 'share/ymp/')
install_data('data/ymp-mime.xml', install_dir : get_option('prefix') / 'share/mime/packages/')
install_data('data/debian-names.yaml', install_dir : get_option('sysconfdir'))
install_data(meson.current_build_dir() / 'obj.o', install_dir : get_option('libdir'), rename : 'empty.o')
install_data('data/bash-completion.sh', install_dir : get_option('prefix')/ 'bash-completion/completions/', rename: 'ymp')
########### install headers ###########
install_data(meson.current_build_dir() / 'ymp.h', install_dir : get_option('includedir')/'ymp/')
install_data(meson.current_source_dir() / 'data/ymp-extra.h', install_dir : get_option('includedir')/'ymp/', rename : 'extra.h')
foreach header : run_command('find', 'src/include','-type','f',check:true).stdout().strip().split('\n')
install_data(meson.current_source_dir() / header, install_dir : get_option('includedir')/'ymp/')
endforeach
install_data(meson.current_build_dir() / 'ymp.vapi', install_dir : get_option('prefix')/'share/vala/vapi/')