-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
248 lines (214 loc) · 8.34 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
project(
'clr-boot-manager',
['c'],
version: run_command('cat', 'VERSION').stdout().split()[0],
license: [
'LGPL-2.1',
],
default_options: [
'c_std=c11',
'prefix=/usr',
'sysconfdir=/etc',
'datadir=/usr/share',
'with-kernel-conf-dir=/etc/kernel',
'with-kernel-vendor-conf-dir=/usr/share/kernel',
],
)
# Ensure a sane minimum set of flags exists
am_cflags = [
'-fstack-protector',
'-pedantic',
'-Wstrict-prototypes',
'-Wundef',
'-fno-common',
'-Werror-implicit-function-declaration',
'-Wformat',
'-Wformat-security',
'-Werror=format-security',
'-Wconversion',
'-Wunused-variable',
'-Wunreachable-code',
'-Wall',
'-W',
'-D_FORTIFY_SOURCE=2',
'-Wno-missing-field-initializers',
]
add_global_arguments(am_cflags, language: 'c')
# Cache compiler object
ccompiler = meson.get_compiler('c')
# pkgconfig deps
dep_blkid = dependency('blkid')
dep_check = dependency('check', version: '>= 0.9')
# other deps
dep_btrfs = ccompiler.find_library('btrfsutil')
if not ccompiler.has_header('btrfsutil.h')
error('Cannot find btrfsutil.h. Is btrfs-progs-dev(el) installed?')
endif
# Grab necessary paths
path_prefix = get_option('prefix')
path_bindir = join_paths(path_prefix, get_option('bindir'))
path_sysconfdir = join_paths(path_prefix, get_option('sysconfdir'))
path_datadir = join_paths(path_prefix, get_option('datadir'))
# Configure project details
cdata = configuration_data()
cdata.set_quoted('PACKAGE_NAME', meson.project_name())
cdata.set_quoted('PACKAGE_VERSION', meson.project_version())
cdata.set_quoted('SYSCONFDIR', path_sysconfdir)
require_efi = false
# What bootloader are we using?
with_bootloader = get_option('with-bootloader')
if with_bootloader == 'systemd-boot'
cdata.set('HAVE_SYSTEMD_BOOT', 1)
elif with_bootloader == 'shim-systemd-boot'
cdata.set('HAVE_SHIM_SYSTEMD_BOOT', 1)
cdata.set('HAVE_SYSTEMD_BOOT', 1)
require_efi = true
endif
# Let's find gnu-efi / efi-var
if require_efi == true
message('EFI variable support required, looking for headers/libs')
dir_gnu_efi = get_option('with-gnu-efi')
if dir_gnu_efi == ''
dir_gnu_efi = '/usr/include/efi'
endif
dir_efivar = get_option('with-efi-var')
if dir_efivar == ''
dir_efivar = '/usr/include/efivar'
endif
dep_efivar = ccompiler.find_library('efivar')
dep_efiboot = ccompiler.find_library('efiboot')
if not ccompiler.has_header('efiboot.h', args: '-I@0@'.format(dir_efivar))
error('Cannot find efiboot.h. Is efivar-dev(el) installed?')
endif
if not ccompiler.has_header('efivar.h', args: '-I@0@'.format(dir_efivar))
error('Cannot find efivar.h. Is efivar-dev(el) installed?')
endif
if not ccompiler.has_header('efi.h', args: '-I@0@'.format(dir_gnu_efi))
error('Cannot find efi.h. Is gnu-efi-dev(el) installed?')
endif
# Ensure we add to the global cflags so we can compile with efi bits
add_global_arguments(['-isystem', dir_efivar], language: 'c')
add_global_arguments(['-isystem', dir_gnu_efi], language: 'c')
# Require architecture specific bits too
gnu_efi_arch = join_paths(dir_gnu_efi, build_machine.cpu_family())
add_global_arguments(['-isystem', gnu_efi_arch], language: 'c')
message('gnu efi arch: @0@'.format(gnu_efi_arch))
# Required for efivar as they're not defining GNU_SOURCE, etc.
add_global_arguments(['-D_POSIX_C_SOURCE=201112L'], language: 'c')
endif
# Defaults to /usr/lib/kernel
with_kernel_dir = get_option('with-kernel-dir')
if with_kernel_dir == ''
with_kernel_dir = join_paths(path_prefix, 'lib', 'kernel')
endif
# Defaults to /usr/lib/initrd.d
with_initrd_dir = get_option('with-initrd-dir')
if with_initrd_dir == ''
with_initrd_dir = join_paths(path_prefix, 'lib', 'initrd.d')
endif
# Defaults to /etc/kernel/initrd.d
with_user_initrd_dir = get_option('with-user-initrd-dir')
if with_user_initrd_dir == ''
with_user_initrd_dir = join_paths(path_sysconfdir, 'kernel', 'initrd.d')
endif
# Defaults to /etc/kernel
with_kernel_conf_dir = get_option('with-kernel-conf-dir')
if with_kernel_conf_dir == ''
with_kernel_conf_dir = join_paths(path_sysconfdir, 'kernel')
endif
# Defaults to /usr/lib/modules
with_kernel_modules_dir = get_option('with-kernel-modules-dir')
if with_kernel_modules_dir == ''
with_kernel_modules_dir = join_paths(path_prefix, 'lib', 'modules')
endif
# Defaults to /usr/share/kernel
with_kernel_vendor_conf_dir = get_option('with-kernel-vendor-conf-dir')
if with_kernel_vendor_conf_dir == ''
with_kernel_vendor_conf_dir = join_paths(path_datadir, 'kernel')
endif
with_boot_dir = get_option('with-boot-dir')
with_kernel_namespace = get_option('with-kernel-namespace')
with_vendor_prefix = get_option('with-vendor-prefix')
# Systemd configuration
with_systemd_system_unit_dir = get_option('with-systemd-system-unit-dir')
if with_systemd_system_unit_dir == ''
# Automatically discover systemd unit location from pkgconfig
message('Asking pkg-config for systemd\'s system unit directory')
dep_systemd = dependency('systemd')
with_systemd_system_unit_dir = dep_systemd.get_pkgconfig_variable('systemdsystemunitdir')
if with_systemd_system_unit_dir == ''
error('Cannot locate the systemd system unit directory')
endif
endif
# Vendor configuration
with_uefi_entry_label = get_option('with-uefi-entry-label')
if with_uefi_entry_label == ''
with_uefi_entry_label = 'Linux bootloader'
endif
# Set config.h options up for our general directories, etc.
cdata.set_quoted('KERNEL_DIRECTORY', with_kernel_dir)
cdata.set_quoted('INITRD_DIRECTORY', with_initrd_dir)
cdata.set_quoted('USER_INITRD_DIRECTORY', with_user_initrd_dir)
cdata.set_quoted('KERNEL_MODULES_DIRECTORY', with_kernel_modules_dir)
cdata.set_quoted('KERNEL_NAMESPACE', with_kernel_namespace)
cdata.set_quoted('BOOT_DIRECTORY', with_boot_dir)
cdata.set_quoted('VENDOR_PREFIX', with_vendor_prefix)
cdata.set_quoted('KERNEL_CONF_DIRECTORY', with_kernel_conf_dir)
cdata.set_quoted('VENDOR_KERNEL_CONF_DIRECTORY', with_kernel_vendor_conf_dir)
cdata.set_quoted('UEFI_ENTRY_LABEL', with_uefi_entry_label)
with_grub2_backend = get_option('with-grub2-backend')
if with_grub2_backend == true
cdata.set('GRUB2_BACKEND_ENABLED', with_grub2_backend)
endif
# Helps the test suites
test_top_dir = meson.current_source_dir()
# Write config.h now
config_h = configure_file(
configuration: cdata,
output: 'config.h',
)
config_h_dir = include_directories('.')
# Data files (systemd unit + shell completions + manpages)
subdir('data')
subdir('data/completions/bash')
subdir('data/completions/zsh')
subdir('man')
# Aggregate library + binary configuration
subdir('src')
# Now set up tests
subdir('tests')
report = [
' Build configuration:',
' ====================',
'',
' version: @0@'.format(meson.project_version()),
' prefix: @0@'.format(path_prefix),
' datadir: @0@'.format(path_datadir),
' sysconfdir: @0@'.format(path_sysconfdir),
' systemd unit directory: @0@'.format(with_systemd_system_unit_dir),
' uefi entry label: @0@'.format(with_uefi_entry_label),
'',
' Identification:',
' ===============',
'',
' kernel namespace: @0@'.format(with_kernel_namespace),
' vendor prefix: @0@'.format(with_vendor_prefix),
'',
' Directories:',
' ============',
'',
' boot directory: @0@'.format(with_boot_dir),
' kernel directory: @0@'.format(with_kernel_dir),
' kernel modules directory: @0@'.format(with_kernel_modules_dir),
' kernel config directory: @0@'.format(with_kernel_conf_dir),
' kernel vendor config directory: @0@'.format(with_kernel_vendor_conf_dir),
'',
' Booting:',
' ========',
'',
' bootloader: @0@'.format(with_bootloader),
' efi variable support: @0@'.format(require_efi),
' grub backend: @0@'.format(with_grub2_backend),
]
# Output some stuff to validate the build config
message('\n\n\n' + '\n'.join(report) + '\n\n')