2021-08-23 02:09:30 +08:00
|
|
|
project('OpenRC', 'c',
|
2024-09-10 03:57:12 +08:00
|
|
|
version : '0.55',
|
2021-08-23 02:09:30 +08:00
|
|
|
license: 'BSD-2',
|
|
|
|
default_options : [
|
2024-11-02 05:15:39 +08:00
|
|
|
'bindir=/bin',
|
2021-08-23 02:09:30 +08:00
|
|
|
'c_std=c99',
|
2022-01-01 00:56:42 +08:00
|
|
|
'prefix=/usr',
|
2024-11-02 05:15:39 +08:00
|
|
|
'sbindir=/sbin',
|
2021-08-23 02:09:30 +08:00
|
|
|
'warning_level=3',
|
|
|
|
],
|
2024-11-02 05:15:39 +08:00
|
|
|
meson_version : '>=0.62.0'
|
2024-07-16 19:23:28 +08:00
|
|
|
)
|
2021-08-23 02:09:30 +08:00
|
|
|
|
|
|
|
cc = meson.get_compiler('c')
|
2021-11-29 02:35:29 +08:00
|
|
|
fs = import('fs')
|
2021-08-23 02:09:30 +08:00
|
|
|
|
|
|
|
audit_dep = dependency('audit', required : get_option('audit'))
|
|
|
|
if audit_dep.found()
|
|
|
|
cc_audit_flags = '-DHAVE_AUDIT'
|
2021-12-25 02:33:00 +08:00
|
|
|
else
|
2021-08-23 02:09:30 +08:00
|
|
|
cc_audit_flags = []
|
2021-12-25 02:33:00 +08:00
|
|
|
endif
|
2021-08-23 02:09:30 +08:00
|
|
|
|
|
|
|
if get_option('branding') != ''
|
|
|
|
cc_branding_flags = '-DBRANDING=' + get_option('branding')
|
|
|
|
else
|
|
|
|
cc_branding_flags = []
|
|
|
|
endif
|
|
|
|
|
|
|
|
libname = get_option('libdir').split('/')[-1]
|
|
|
|
|
|
|
|
option_local_prefix = get_option('local_prefix')
|
|
|
|
if option_local_prefix == ''
|
|
|
|
local_prefix = get_option('prefix') / 'usr' / 'local'
|
|
|
|
else
|
|
|
|
local_prefix = option_local_prefix
|
|
|
|
endif
|
|
|
|
|
|
|
|
option_os = get_option('os')
|
|
|
|
if option_os == ''
|
|
|
|
uname = find_program('uname')
|
2022-10-23 03:35:29 +08:00
|
|
|
r = run_command(uname, '-s', check: true)
|
2021-08-23 02:09:30 +08:00
|
|
|
os = r.stdout().strip()
|
|
|
|
os = '-'.join(os.split('/'))
|
|
|
|
else
|
|
|
|
os = option_os
|
|
|
|
endif
|
|
|
|
|
2021-12-31 08:45:39 +08:00
|
|
|
if os != 'Linux'
|
2024-09-13 21:37:30 +08:00
|
|
|
cap_dep = []
|
2024-09-14 00:06:11 +08:00
|
|
|
kvm_dep = cc.find_library('kvm')
|
2021-12-31 08:45:39 +08:00
|
|
|
else
|
2024-09-13 21:37:30 +08:00
|
|
|
cap_dep = dependency('libcap', version: '>=2.33')
|
2021-12-31 08:45:39 +08:00
|
|
|
kvm_dep = []
|
|
|
|
endif
|
|
|
|
|
2021-10-09 05:39:21 +08:00
|
|
|
pam_dep = dependency('pam', required: false)
|
2021-10-08 23:46:42 +08:00
|
|
|
if not pam_dep.found()
|
2021-10-09 05:39:21 +08:00
|
|
|
pam_dep = cc.find_library('pam', required: false)
|
2021-10-08 23:46:42 +08:00
|
|
|
endif
|
2021-11-07 08:37:37 +08:00
|
|
|
if pam_dep.found() and get_option('pam')
|
2021-08-23 02:09:30 +08:00
|
|
|
cc_pam_flags = '-DHAVE_PAM'
|
|
|
|
else
|
|
|
|
cc_pam_flags = []
|
|
|
|
endif
|
|
|
|
|
2021-10-09 05:39:21 +08:00
|
|
|
if not pam_dep.found() and get_option('pam')
|
|
|
|
error('Pam was requested but could not be located')
|
2021-12-25 02:33:00 +08:00
|
|
|
endif
|
2021-10-09 05:39:21 +08:00
|
|
|
|
2021-08-23 02:09:30 +08:00
|
|
|
option_pkg_prefix = get_option('pkg_prefix')
|
|
|
|
if option_pkg_prefix == ''
|
|
|
|
if os == 'Dragonfly' or os == 'FreeBSD'
|
|
|
|
pkg_prefix = '/usr/local'
|
|
|
|
elif os == 'GNU' or os == 'GNU-kFreeBSD' or os == 'Linux'
|
|
|
|
pkg_prefix = '/usr'
|
|
|
|
elif os == 'NetBSD'
|
|
|
|
pkg_prefix = '/usr/pkg'
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
pkg_prefix = option_pkg_prefix
|
|
|
|
endif
|
|
|
|
|
2024-09-24 01:53:07 +08:00
|
|
|
bindir = get_option('prefix') / get_option('bindir')
|
|
|
|
libdir = get_option('prefix') / get_option('libdir')
|
|
|
|
pluginsdir = libdir / 'rc/plugins'
|
|
|
|
libexecdir = get_option('prefix') / get_option('libexecdir')
|
2021-08-23 02:09:30 +08:00
|
|
|
rc_libexecdir = libexecdir / 'rc'
|
2021-09-22 01:34:22 +08:00
|
|
|
rc_bindir = rc_libexecdir / 'bin'
|
|
|
|
rc_sbindir = rc_libexecdir / 'sbin'
|
2021-12-30 05:57:04 +08:00
|
|
|
rc_shdir = rc_libexecdir / 'sh'
|
2024-09-24 01:53:07 +08:00
|
|
|
sbindir = get_option('prefix') / get_option('sbindir')
|
2022-01-01 01:01:55 +08:00
|
|
|
pamdir = get_option('sysconfdir') / 'pam.d'
|
2021-08-23 02:09:30 +08:00
|
|
|
|
2021-11-22 18:30:36 +08:00
|
|
|
crypt_dep = []
|
2021-11-20 20:06:37 +08:00
|
|
|
|
2021-08-23 02:09:30 +08:00
|
|
|
selinux_dep = dependency('libselinux', required : get_option('selinux'))
|
2021-11-20 20:05:56 +08:00
|
|
|
pam_misc_dep = []
|
2021-08-23 02:09:30 +08:00
|
|
|
if selinux_dep.found()
|
|
|
|
cc_selinux_flags = '-DHAVE_SELINUX'
|
2021-10-09 05:39:21 +08:00
|
|
|
if pam_dep.found() and get_option('pam')
|
|
|
|
pam_misc_dep = dependency('pam_misc', required: false)
|
2021-10-08 23:46:42 +08:00
|
|
|
if not pam_misc_dep.found()
|
2021-10-09 05:39:21 +08:00
|
|
|
pam_misc_dep = cc.find_library('pam_misc', required: false)
|
|
|
|
endif
|
|
|
|
if not pam_misc_dep.found() and get_option('pam')
|
|
|
|
error('Pam was requested but could not be located')
|
2021-10-08 23:46:42 +08:00
|
|
|
endif
|
2021-11-22 18:30:36 +08:00
|
|
|
else
|
2021-11-25 03:42:01 +08:00
|
|
|
crypt_dep = dependency('libcrypt', required : false)
|
|
|
|
if not crypt_dep.found()
|
|
|
|
crypt_dep = cc.find_library('crypt', required : true)
|
|
|
|
endif
|
2021-10-03 04:46:12 +08:00
|
|
|
endif
|
|
|
|
else
|
2021-08-23 02:09:30 +08:00
|
|
|
cc_selinux_flags = []
|
|
|
|
endif
|
|
|
|
|
|
|
|
if get_option('buildtype').startswith('debug')
|
|
|
|
cc_debug_flags = ['-DRC_DEBUG']
|
|
|
|
else
|
|
|
|
cc_debug_flags = []
|
|
|
|
endif
|
|
|
|
|
|
|
|
if os == 'Linux' or os == 'GNU-kFreeBSD'
|
|
|
|
cc_os_flags = ['-D_DEFAULT_SOURCE']
|
|
|
|
elif os == 'FreeBSD'
|
|
|
|
cc_os_flags = ['-D_BSD_SOURCE']
|
|
|
|
elif os == 'GNU'
|
2024-10-25 23:12:58 +08:00
|
|
|
cc_os_flags = ['-D_DEFAULT_SOURCE', '-DPATH_MAX=4096']
|
2021-12-25 02:33:00 +08:00
|
|
|
endif
|
2021-08-23 02:09:30 +08:00
|
|
|
|
|
|
|
# Try and use some good cc flags if we're building from git. We don't use
|
|
|
|
# -pedantic as it will warn about our perfectly valid use of %m in our logger.
|
|
|
|
# We should be using -Wredundant-decls, but our library hidden proto stuff gives
|
|
|
|
# loads of warnings. I don't fully understand it (the hidden proto, not the
|
|
|
|
# warning) so we just silence the warning.
|
|
|
|
cc_warning_flags_test = [
|
|
|
|
'-Wcast-align',
|
|
|
|
'-Wcast-qual',
|
|
|
|
'-Wdeclaration-after-statement',
|
|
|
|
'-Wformat=2',
|
|
|
|
'-Winline',
|
2024-07-24 03:21:15 +08:00
|
|
|
'-Wmismatched-dealloc',
|
2021-08-23 02:09:30 +08:00
|
|
|
'-Wmissing-declarations',
|
|
|
|
'-Wmissing-format-attribute',
|
|
|
|
'-Wmissing-noreturn',
|
|
|
|
'-Wmissing-prototypes',
|
|
|
|
'-Wnested-externs',
|
|
|
|
'-Wpointer-arith',
|
|
|
|
'-Wsequence-point',
|
|
|
|
'-Wshadow',
|
|
|
|
'-Wwrite-strings',
|
2023-04-19 14:00:42 +08:00
|
|
|
'-Werror=implicit-int',
|
2021-08-23 02:09:30 +08:00
|
|
|
'-Werror=implicit-function-declaration',
|
2023-04-19 14:00:42 +08:00
|
|
|
'-Werror=int-conversion',
|
|
|
|
'-Werror=incompatible-function-pointer-types',
|
2021-08-23 02:09:30 +08:00
|
|
|
]
|
|
|
|
cc_warning_flags = cc.get_supported_arguments(cc_warning_flags_test)
|
|
|
|
cc_flags = [cc_debug_flags, cc_os_flags, cc_warning_flags]
|
|
|
|
add_project_arguments(cc_flags, language : 'c')
|
|
|
|
|
2022-03-31 14:25:35 +08:00
|
|
|
# Meson's has_function_attribute doesn't know about GCC's extended
|
|
|
|
# version (with arguments), so we have to build a test program instead.
|
|
|
|
malloc_attribute_test = '''#include<stdlib.h>
|
|
|
|
__attribute__ ((malloc (free, 1)))
|
|
|
|
int func() { return 0; }
|
|
|
|
'''
|
|
|
|
if cc.compiles(malloc_attribute_test, name : 'malloc attribute with arguments')
|
|
|
|
add_project_arguments('-DHAVE_MALLOC_EXTENDED_ATTRIBUTE', language: 'c')
|
|
|
|
endif
|
|
|
|
|
2023-08-30 17:33:37 +08:00
|
|
|
if cc.has_function('close_range', prefix: '#define _GNU_SOURCE\n#include <unistd.h>')
|
|
|
|
add_project_arguments('-DHAVE_CLOSE_RANGE', language: 'c')
|
2023-08-30 19:34:23 +08:00
|
|
|
elif cc.has_header('linux/close_range.h')
|
|
|
|
add_project_arguments('-DHAVE_LINUX_CLOSE_RANGE_H', language: 'c')
|
2022-08-21 21:10:44 +08:00
|
|
|
endif
|
|
|
|
|
2023-08-30 09:32:13 +08:00
|
|
|
if cc.has_function('strlcpy', prefix: '#define _GNU_SOURCE\n#include <string.h>')
|
|
|
|
add_project_arguments('-DHAVE_STRLCPY', language: 'c')
|
|
|
|
endif
|
|
|
|
|
2022-04-06 23:51:55 +08:00
|
|
|
incdir = include_directories('src/shared')
|
2021-08-23 02:09:30 +08:00
|
|
|
einfo_incdir = include_directories('src/libeinfo')
|
|
|
|
rc_incdir = include_directories('src/librc')
|
|
|
|
|
|
|
|
init_d_conf_data = configuration_data()
|
|
|
|
init_d_conf_data.set('SBINDIR', sbindir)
|
|
|
|
init_d_conf_data.set('PKG_PREFIX', pkg_prefix)
|
|
|
|
init_d_conf_data.set('SYSCONFDIR', get_option('sysconfdir'))
|
|
|
|
|
|
|
|
dl_dep = cc.find_library('dl', required: false)
|
|
|
|
util_dep = cc.find_library('util', required: false)
|
|
|
|
|
2021-12-31 01:49:23 +08:00
|
|
|
subdir('bash-completion')
|
2021-08-23 02:09:30 +08:00
|
|
|
subdir('conf.d')
|
|
|
|
subdir('etc')
|
|
|
|
subdir('init.d')
|
|
|
|
subdir('local.d')
|
|
|
|
subdir('man')
|
|
|
|
subdir('sh')
|
|
|
|
subdir('src')
|
|
|
|
subdir('support')
|
|
|
|
subdir('sysctl.d')
|
2022-04-17 04:13:08 +08:00
|
|
|
subdir('test')
|
2021-12-31 01:49:23 +08:00
|
|
|
subdir('zsh-completion')
|
2021-08-23 02:09:30 +08:00
|
|
|
|
2024-07-16 19:23:28 +08:00
|
|
|
if get_option('pkgconfig')
|
|
|
|
pkg = import('pkgconfig')
|
|
|
|
|
|
|
|
einfo_pkgconf = pkg.generate(
|
|
|
|
name : 'einfo',
|
|
|
|
description : 'Pretty console informational display',
|
|
|
|
version : meson.project_version(),
|
|
|
|
libraries : libeinfo,
|
|
|
|
subdirs : ['einfo'],
|
|
|
|
)
|
|
|
|
|
|
|
|
openrc_pkgconf = pkg.generate(
|
|
|
|
name : 'OpenRC',
|
2024-07-21 17:06:53 +08:00
|
|
|
filebase : 'openrc',
|
2024-07-16 19:23:28 +08:00
|
|
|
description : 'Universal init system',
|
|
|
|
version : meson.project_version(),
|
|
|
|
libraries : librc,
|
|
|
|
subdirs : ['openrc'],
|
|
|
|
variables: {
|
2024-09-24 01:53:07 +08:00
|
|
|
'pluginsdir': pluginsdir,
|
2024-07-16 19:23:28 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
endif
|
|
|
|
|
2021-08-23 02:09:30 +08:00
|
|
|
meson.add_install_script('tools/meson_runlevels.sh',
|
|
|
|
os,
|
|
|
|
get_option('newnet') ? 'yes' : 'no',
|
|
|
|
rc_libexecdir,
|
2021-09-09 00:59:25 +08:00
|
|
|
get_option('sysconfdir'),
|
|
|
|
get_option('sysvinit') ? 'yes' : 'no')
|
2021-08-23 02:09:30 +08:00
|
|
|
meson.add_install_script('tools/meson_final.sh',
|
|
|
|
rc_libexecdir,
|
2024-07-24 01:52:35 +08:00
|
|
|
os)
|