aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/meson.build
blob: aecf461fc9ef076e1bd00527682e8038cf058c2b (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
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
project('ndctl', 'c',
  version : '73',
  license : [
    'GPL-2.0',
    'LGPL-2.1',
    'CC0-1.0',
    'MIT',
  ],
  default_options : [
    'c_std=gnu99',
    'prefix=/usr',
    'sysconfdir=/etc',
    'localstatedir=/var',
  ],
)

# rootprefixdir and rootlibdir setup copied from systemd:
rootprefixdir = get_option('rootprefix')
rootprefix_default = '/usr'
if rootprefixdir == ''
        rootprefixdir = rootprefix_default
endif
rootbindir = join_paths(rootprefixdir, 'bin')

# join_paths ignores the preceding arguments if an absolute component is
# encountered, so this should canonicalize various paths when they are
# absolute or relative.
prefixdir = get_option('prefix')
if not prefixdir.startswith('/')
        error('Prefix is not absolute: "@0@"'.format(prefixdir))
endif
if prefixdir != rootprefixdir and rootprefixdir != '/' and not prefixdir.strip('/').startswith(rootprefixdir.strip('/') + '/')
  error('Prefix is not below root prefix (now rootprefix=@0@ prefix=@1@)'.format(
	rootprefixdir, prefixdir))
endif

libdir = join_paths(prefixdir, get_option('libdir'))
rootlibdir = get_option('rootlibdir')
if rootlibdir == ''
  rootlibdir = join_paths(rootprefixdir, libdir.split('/')[-1])
endif
datadir = prefixdir / get_option('datadir')
includedir = prefixdir / get_option('includedir')

pkgconfiglibdir = get_option('pkgconfiglibdir') != '' ? get_option('pkgconfiglibdir') : libdir / 'pkgconfig'

datadir = prefixdir / get_option('datadir')
includedir = prefixdir / get_option('includedir')
sysconfdir =  get_option('sysconfdir')

pkgconfig_script = '''
sed -e s,@VERSION@,@0@,g
    -e s,@prefix@,@1@,g
    -e s,@exec_prefix@,@1@,g
    -e s,@libdir@,@2@,g
    -e s,@includedir@,@3@,g
'''.format(meson.project_version(), prefixdir, libdir, includedir).split()

cc_flags = [
  '-Wchar-subscripts',
  '-Wformat-security',
  '-Wmissing-declarations',
  '-Wmissing-prototypes',
  '-Wnested-externs ',
  '-Wshadow',
  '-Wsign-compare',
  '-Wstrict-prototypes',
  '-Wtype-limits',
  '-Wmaybe-uninitialized',
  '-Wdeclaration-after-statement',
  '-Wunused-result',
]

if get_option('optimization') != '0'
  cc_flags += [ '-D_FORTIFY_SOURCE=2' ]
endif

cc = meson.get_compiler('c')
add_project_arguments(cc.get_supported_arguments(cc_flags), language : 'c')

project_source_root = meson.current_source_dir()

# Remove this after the conversion to meson has been completed
# Cleanup the leftover config.h files to avoid conflicts with the meson
# generated config.h
git = find_program('git', required : false)
env = find_program('env')
if git.found()
  run_command('clean_config.sh',
    env : 'GIT_DIR=@0@/.git'.format(project_source_root),
  )
endif

version_tag = get_option('version-tag')
if version_tag != ''
  vcs_data = configuration_data()
  vcs_data.set('VCS_TAG', version_tag)
  version_h = configure_file(
    configuration : vcs_data,
    input : 'version.h.in',
    output : 'version.h'
  )
else
  vcs_tagger = [
    project_source_root + '/tools/meson-vcs-tag.sh',
    project_source_root,
    meson.project_version()
  ]

  version_h = vcs_tag(
      input : 'version.h.in',
      output : 'version.h',
      command: vcs_tagger
  )
endif

if git.found()
  all_files = run_command(
    env, '-u', 'GIT_WORK_TREE',
    git, '--git-dir=@0@/.git'.format(project_source_root),
         'ls-files', ':/*.[ch]',
    check : false)
  if all_files.returncode() == 0
    all_files = files(all_files.stdout().split())
    custom_target(
            'tags',
            output : 'tags',
            command : [env, 'etags', '-o', '@0@/TAGS'.format(project_source_root)] + all_files)
    run_target(
            'ctags',
            command : [env, 'ctags', '-o', '@0@/tags'.format(project_source_root)] + all_files)
  endif
endif

versiondep = declare_dependency(
  compile_args: ['-include', 'version.h'],
  sources: version_h
)

kmod = dependency('libkmod')
libudev = dependency('libudev')
uuid = dependency('uuid')
json = dependency('json-c')
if get_option('docs').enabled()
  if get_option('asciidoctor').enabled()
    asciidoc = find_program('asciidoctor', required : true)
  else
    asciidoc = find_program('asciidoc', required : true)
    xmlto = find_program('xmlto', required : true)
  endif
endif

if get_option('systemd').enabled()
  systemd = dependency('systemd', required : true)
  systemdunitdir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
  udev = dependency('udev', required : true)
  udevdir = udev.get_pkgconfig_variable('udevdir')
  udevrulesdir = udevdir / 'rules.d'
endif

cc = meson.get_compiler('c')

# keyutils lacks pkgconfig
keyutils = cc.find_library('keyutils', required : get_option('keyutils'))

# iniparser lacks pkgconfig and its header files are either at '/usr/include' or '/usr/include/iniparser'
# Use the path provided by user via meson configure -Diniparserdir=<somepath>
# if thats not provided then try searching for 'iniparser.h' in default system include path
# and if that not found then as a last resort try looking at '/usr/include/iniparser'
iniparser_headers = ['iniparser.h', 'dictionary.h']

message('Looking for iniparser include headers', iniparser_headers)

iniparserdir = include_directories(includedir / get_option('iniparserdir'), is_system:true)
iniparser = cc.find_library('iniparser', required : (get_option('iniparserdir') != '') ,
	  has_headers :iniparser_headers ,header_include_directories : iniparserdir)

if not iniparser.found()
   iniparserdir = include_directories(includedir / 'iniparser', is_system:true)
   iniparser = cc.find_library('iniparser', required : true, has_headers : iniparser_headers,
	     header_include_directories : iniparserdir)
endif
iniparser = declare_dependency(include_directories: iniparserdir, dependencies:iniparser)

conf = configuration_data()
check_headers = [
  ['HAVE_DLFCN_H', 'dlfcn.h'],
  ['HAVE_INTTYPES_H', 'inttypes.h'],
  ['HAVE_KEYUTILS_H', 'keyutils.h'],
  ['HAVE_LINUX_VERSION_H', 'linux/version.h'],
  ['HAVE_MEMORY_H', 'memory.h'],
  ['HAVE_STDINT_H', 'stdint.h'],
  ['HAVE_STDLIB_H', 'stdlib.h'],
  ['HAVE_STRINGS_H', 'strings.h'],
  ['HAVE_STRING_H', 'string.h'],
  ['HAVE_SYS_STAT_H', 'sys/stat.h'],
  ['HAVE_SYS_TYPES_H', 'sys/types.h'],
  ['HAVE_UNISTD_H', 'unistd.h'],
]

foreach h : check_headers
  if cc.has_header(h.get(1))
    conf.set(h.get(0), 1)
  endif
endforeach

map_sync_symbols = [
  [ 'signal.h', 'BUS_MCEERR_AR' ],
  [ 'linux/mman.h', 'MAP_SHARED_VALIDATE' ],
  [ 'linux/mman.h', 'MAP_SYNC' ],
]

count = 0
foreach symbol : map_sync_symbols
  if cc.has_header_symbol(symbol[0], symbol[1])
    conf.set('HAVE_DECL_@0@'.format(symbol[1].to_upper()), 1)
    count = count + 1
  endif
endforeach

poison_enabled = false
if get_option('poison').enabled() and count == 3
  poison_enabled = true
endif

conf.set('ENABLE_POISON', poison_enabled)
conf.set('ENABLE_KEYUTILS', get_option('keyutils').enabled())
conf.set('ENABLE_TEST', get_option('test').enabled())
conf.set('ENABLE_DESTRUCTIVE', get_option('destructive').enabled())
conf.set('ENABLE_LOGGING', get_option('logging').enabled())
conf.set('ENABLE_DEBUG', get_option('dbg').enabled())

typeof = cc.run('''
  int main() {
    struct {
      char a[16];
    } x;
    typeof(x) y;

    return sizeof(x) == sizeof(y);
  }
  '''
)

if typeof.compiled() and typeof.returncode() == 1
  conf.set('HAVE_TYPEOF', 1)
  conf.set('HAVE_STATEMENT_EXPR', 1)
endif

if target_machine.endian() == 'big'
  conf.set('HAVE_BIG_ENDIAN', 1)
else
  conf.set('HAVE_LITTLE_ENDIAN', 1)
endif

conf.set('_GNU_SOURCE', true)
conf.set_quoted('PREFIX', get_option('prefix'))
conf.set_quoted('NDCTL_MAN_PATH', get_option('mandir'))

foreach ident : ['secure_getenv', '__secure_getenv']
  conf.set10('HAVE_' + ident.to_upper(), cc.has_function(ident))
endforeach

conf.set10('HAVE_JSON_U64',
  cc.has_function('json_object_new_uint64',
    prefix : '''#include <json-c/json.h>''',
    dependencies : json,
  )
)

ndctlconf_dir = sysconfdir / 'ndctl.conf.d'
ndctlconf = ndctlconf_dir / 'monitor.conf'
conf.set_quoted('NDCTL_CONF_FILE', ndctlconf)
conf.set_quoted('NDCTL_CONF_DIR', ndctlconf_dir)

ndctlkeys_dir = sysconfdir / 'ndctl' / 'keys'
conf.set_quoted('NDCTL_KEYS_DIR', ndctlkeys_dir)

daxctlconf_dir = sysconfdir / 'daxctl.conf.d'
daxctlconf = daxctlconf_dir / 'dax.conf'
conf.set_quoted('DAXCTL_CONF_DIR', daxctlconf_dir)

conf.set_quoted('DAXCTL_MODPROBE_DATA', datadir / 'daxctl/daxctl.conf')
conf.set_quoted('DAXCTL_MODPROBE_INSTALL', sysconfdir / 'modprobe.d/daxctl.conf')

config_h = configure_file(
  input : 'config.h.meson',
  output : 'config.h',
  configuration : conf
)
add_project_arguments('-include', 'config.h', language : 'c')

LIBNDCTL_CURRENT=26
LIBNDCTL_REVISION=0
LIBNDCTL_AGE=20

LIBDAXCTL_CURRENT=6
LIBDAXCTL_REVISION=1
LIBDAXCTL_AGE=5

LIBCXL_CURRENT=2
LIBCXL_REVISION=0
LIBCXL_AGE=1

root_inc = include_directories(['.', 'ndctl', ])

ccan = static_library('ccan',
  [ 'ccan/str/str.c', 'ccan/list/list.c' ],
)
ccan_dep = declare_dependency(link_with : ccan)

subdir('daxctl/lib')
subdir('ndctl/lib')
subdir('cxl/lib')
subdir('util')
subdir('ndctl')
subdir('daxctl')
subdir('cxl')
if get_option('docs').enabled()
  subdir('Documentation/ndctl')
  subdir('Documentation/daxctl')
  subdir('Documentation/cxl')
endif
subdir('test')
subdir('contrib')

# only support spec file generation from git builds
if version_tag == ''
  subdir('rhel')
  subdir('sles')
endif