aboutsummaryrefslogtreecommitdiff
path: root/meson.build
blob: 3ac018ecbe8000d640bf6e3d313f5195a182c291 (plain)
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
project('OpenRC', 'c',
  version : '0.43',
  license: 'BSD-2',
  default_options : [
    'c_std=c99',
	'prefix=/usr',
    'warning_level=3',
    ],
  meson_version : '>=0.49.0')

cc = meson.get_compiler('c')

audit_dep = dependency('audit', required : get_option('audit'))
if audit_dep.found()
  cc_audit_flags = '-DHAVE_AUDIT'
  else
  cc_audit_flags = []
  endif

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')
  r = run_command(uname, '-s')
  os = r.stdout().strip()
  os = '-'.join(os.split('/'))
else
  os = option_os
endif

pam = get_option('pam')
if pam
  libpam = cc.find_library('pam')
  libpam_misc = cc.find_library('pam_misc')
  cc_pam_flags = '-DHAVE_PAM'
else
  libpam = []
  libpam_misc = []
  cc_pam_flags = []
endif

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

if get_option('split-usr') == 'auto'
  split_usr = run_command('test', '-L', '/bin').returncode() != 0
else
  split_usr = get_option('split-usr') == 'true'
endif

rootprefix_default = split_usr ? '/' : '/usr'
rootprefix_path = get_option('rootprefix')
rootprefix = rootprefix_path != '' ? rootprefix_path : rootprefix_default

bindir = rootprefix / get_option('bindir')
libdir = rootprefix / get_option('libdir')
if os == 'Linux' and split_usr
  libexecpath = 'lib'
else
  libexecpath = get_option('libexecdir')
endif
libexecdir = split_usr ? rootprefix / libexecpath :
  get_option('prefix') / libexecpath
rc_libexecdir = libexecdir / 'rc'
sbindir = rootprefix / get_option('sbindir')

selinux_dep = dependency('libselinux', required : get_option('selinux'))
if selinux_dep.found()
  cc_selinux_flags = '-DHAVE_SELINUX'
  else
  cc_selinux_flags = []
endif

termcap = get_option('termcap')
if termcap != ''
  termcap_dep = dependency(termcap)
  termcap_flags = '-DHAVE_TERMCAP'
  else
  termcap_dep = []
  termcap_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'
  cc_os_flags = ['-D_DEFAULT_SOURCE', '-DMAXPATHLEN=4096', '-DPATH_MAX=4096']
  endif

# 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',
  '-Wmissing-declarations',
  '-Wmissing-format-attribute',
  '-Wmissing-noreturn',
  '-Wmissing-prototypes',
  '-Wnested-externs',
  '-Wpointer-arith',
  '-Wsequence-point',
  '-Wshadow',
  '-Wwrite-strings',
  '-Werror=implicit-function-declaration',
  ]
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')

incdir = include_directories('src/includes')
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)

if get_option('bash-completions')
  subdir('bash-completion')
endif
subdir('conf.d')
subdir('etc')
subdir('init.d')
subdir('local.d')
subdir('man')
if get_option('pkgconfig')
subdir('pkgconfig')
  endif
subdir('scripts')
subdir('sh')
subdir('src')
subdir('support')
subdir('sysctl.d')
if get_option('zsh-completions')
  subdir('zsh-completion')
endif

meson.add_install_script('tools/meson_runlevels.sh',
  os,
  get_option('newnet') ? 'yes' : 'no',
  rc_libexecdir,
  get_option('sysconfdir'))
meson.add_install_script('tools/meson_final.sh',
  rc_libexecdir,
  os)