]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
build: add meson skeleton
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 3 Sep 2021 07:26:52 +0000 (09:26 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 3 Sep 2021 17:06:09 +0000 (19:06 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
meson.build [new file with mode: 0644]
meson_options.txt [new file with mode: 0644]
src/include/meson.build [new file with mode: 0644]
src/lxc/meson.build [new file with mode: 0644]

diff --git a/meson.build b/meson.build
new file mode 100644 (file)
index 0000000..8d898e7
--- /dev/null
@@ -0,0 +1,325 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+project('lxc', 'c',
+        version : '4.0.0',
+        license : 'LGPLv2+',
+        default_options: [
+                'c_std=gnu11',
+                'warning_level=2',
+        ],
+        meson_version : '>= 0.45',
+       )
+
+liblxc_version = '4.0.0'
+
+conf = configuration_data()
+conf.set_quoted('PROJECT_URL', 'https://linuxcontainers.org/lxc/introduction/')
+conf.set('PROJECT_VERSION',    meson.project_version(),
+         description : 'Numerical project version (used where a simple number is expected)')
+
+version_data = configuration_data()
+version_data.set('LXC_VERSION_MAJOR', '4')
+version_data.set('LXC_VERSION_MINOR', '0')
+version_data.set('LXC_VERSION_MICRO', '7')
+version_data.set('LXC_ABI', '4.0.7')
+version_data.set('LXC_DEVEL', '1')
+version_data.set('LXC_VERSION', '4.0.7-devel')
+
+project_source_root = meson.current_source_dir()
+project_build_root = meson.current_build_dir()
+
+# 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
+datadir = join_paths(prefixdir, get_option('datadir'))
+bindir = join_paths(prefixdir, get_option('bindir'))
+sbindir = join_paths(prefixdir, get_option('sbindir'))
+includedir = join_paths(prefixdir, get_option('includedir'))
+libdir = join_paths(prefixdir, get_option('libdir'))
+libexecdir = join_paths(prefixdir, get_option('libexecdir'))
+sysconfdir = join_paths(prefixdir, get_option('sysconfdir'))
+runtimepath = join_paths(prefixdir, get_option('runtime-path'))
+localstatedir = join_paths('/', get_option('localstatedir'))
+apparmorcachedir = get_option('apparmor-cache-dir')
+rootfsmount = get_option('rootfs-mount-dir')
+cgrouppattern = get_option('cgroup-pattern')
+logpath = get_option('log-path')
+lxcpath = get_option('config-path')
+globalconfig = get_option('global-config')
+
+conf.set_quoted('BINDIR',                      bindir)
+conf.set_quoted('SBINDIR',                     sbindir)
+conf.set_quoted('INCLUDEDIR',                  includedir)
+conf.set_quoted('LIBDIR',                      libdir)
+conf.set_quoted('LIBEXECDIR',                  libexecdir)
+conf.set_quoted('SYSCONFDIR',                  sysconfdir)
+conf.set_quoted('LXC_DEFAULT_CONFIG',          join_paths(sysconfdir, 'lxc/default.conf'))
+conf.set_quoted('APPARMOR_CACHE_DIR',          join_paths(localstatedir, apparmorcachedir))
+conf.set_quoted('LXCROOTFSMOUNT',              join_paths(prefixdir, rootfsmount))
+conf.set_quoted('DEFAULT_CGROUP_PATTERN',      cgrouppattern)
+conf.set_quoted('RUNTIME_PATH',                        runtimepath)
+conf.set_quoted('LOGPATH',                     join_paths(localstatedir, logpath))
+conf.set_quoted('LXCPATH',                     join_paths(localstatedir, lxcpath))
+conf.set_quoted('LXC_GLOBAL_CONF',             join_paths(sysconfdir, globalconfig))
+conf.set_quoted('DATADIR',                     datadir)
+conf.set_quoted('LXCTEMPLATECONFIG',           join_paths(datadir, 'lxc/config'))
+conf.set_quoted('LXCTEMPLATEDIR',              join_paths(datadir, 'lxc/templates'))
+conf.set_quoted('LXCINITDIR',                  libexecdir)
+
+# AS_AC_EXPAND(DATADIR, "$datadir")
+# AS_AC_EXPAND(LOCALSTATEDIR, "$localstatedir")
+# AS_AC_EXPAND(DOCDIR, "$docdir")
+# AS_AC_EXPAND(LXC_GENERATE_DATE, "$(date --utc --date=@${SOURCE_DATE_EPOCH:-$(date +%s)} '+%Y-%m-%d')")
+# AS_AC_EXPAND(LXCPATH, "$with_config_path")
+# AS_AC_EXPAND(LXC_GLOBAL_CONF, "$with_global_conf")
+# AS_AC_EXPAND(LXC_USERNIC_CONF, "$with_usernic_conf")
+# AS_AC_EXPAND(LXC_USERNIC_DB, "$with_usernic_db")
+# AS_AC_EXPAND(LXC_DISTRO_SYSCONF, "$distrosysconf")
+# AS_AC_EXPAND(LXCHOOKDIR, "$datadir/lxc/hooks")
+# AS_AC_EXPAND(LXCBINHOOKDIR, "$libexecdir/lxc/hooks")
+# AS_AC_EXPAND(LXCINITDIR, "$libexecdir")
+# 
+# # We need the install path so criu knows where to reference the hook scripts.
+# AC_DEFINE_UNQUOTED([DATADIR], "$DATADIR", ["Prefix for shared files."])
+
+cc = meson.get_compiler('c')
+pkgconfig = import('pkgconfig')
+
+possible_cc_flags = [
+       '-fPIE',
+       '-Wvla',
+       '-fdiagnostics-color',
+       '-Wimplicit-fallthrough=5',
+       '-Wcast-align',
+       '-Wstrict-prototypes',
+       '-fno-strict-aliasing',
+       '-fstack-clash-protection',
+       '-fstack-protector-strong',
+       '--param=ssp-buffer-size=4',
+       '--mcet -fcf-protection',
+       '-Werror=implicit-function-declaration',
+       '-Wlogical-op',
+       '-Wmissing-include-dirs',
+       '-Wold-style-definition',
+       '-Winit-self',
+       '-Wunused-but-set-variable',
+       '-Wno-unused-parameter',
+       '-Wfloat-equal',
+       '-Wsuggest-attribute=noreturn',
+       '-Werror=return-type',
+       '-Werror=incompatible-pointer-types',
+       '-Wformat=2',
+       '-Wshadow',
+       '-Wendif-labels',
+       '-Werror=overflow',
+       '-fdiagnostics-show-option',
+       '-Werror=shift-count-overflow',
+       '-Werror=shift-overflow=2',
+       '-Wdate-time',
+       '-Wnested-externs',
+       '-fasynchronous-unwind-tables',
+       '-fexceptions',
+       '-Warray-bounds',
+       '-Wrestrict',
+       '-Wreturn-local-addr',
+       '-fsanitize=cfi',
+       '-Wstringop-overflow',
+]
+
+possible_link_flags = [
+       '-Wl,--as-needed',
+       '-Wl,--gc-sections',
+       '-Wl,-z,relro',
+       '-Wl,-z,now',
+       '-pie',
+       '-Wl,-fuse-ld=gold',
+]
+
+if meson.version().version_compare('>=0.46')
+       add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language : 'c')
+else
+       add_project_link_arguments(possible_link_flags, language : 'c')
+endif
+
+add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'c')
+
+foreach header : ['sys/resource.h',
+                  'sys/memfd.h',
+                  'sys/personality.h',
+                  'sys/signalfd.h',
+                  'sys/timerfd.h',
+                  'pty.h',
+                  'utmpx.h',
+                 ]
+
+        conf.set10('HAVE_' + header.underscorify().to_upper(),
+                   cc.has_header(header))
+endforeach
+
+decl_headers = '''
+#include <uchar.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <linux/fs.h>
+#include <linux/types.h>
+#include <linux/openat2.h>
+#include <linux/sched.h>
+'''
+
+foreach decl : [
+                '__aligned_u64',
+                'struct mount_attr',
+                'struct open_how',
+                'struct clone_args',
+               ]
+
+        # We get -1 if the size cannot be determined
+        have = cc.sizeof(decl, prefix : decl_headers, args : '-D_GNU_SOURCE') > 0
+
+       if have == true
+               conf.set10('HAVE_' + decl.underscorify().to_upper(), have)
+       endif
+endforeach
+
+foreach ident : [
+        ['memfd_create',      '''#include <sys/mman.h>'''],
+        ['gettid',            '''#include <sys/types.h>
+                                 #include <unistd.h>'''],
+        ['pivot_root',        '''#include <stdlib.h>
+                                 #include <unistd.h>'''],     # no known header declares pivot_root
+        ['setns',             '''#include <sched.h>'''],
+        ['renameat2',         '''#include <stdio.h>
+                                 #include <fcntl.h>'''],
+        ['kcmp',              '''#include <linux/kcmp.h>'''],
+        ['keyctl',            '''#include <sys/types.h>
+                                 #include <keyutils.h>'''],
+        ['bpf',               '''#include <sys/syscall.h>
+                                 #include <unistd.h>'''],
+        ['statx',             '''#include <sys/types.h>
+                                 #include <sys/stat.h>
+                                 #include <unistd.h>'''],
+        ['pidfd_send_signal', '''#include <stdlib.h>
+                                 #include <unistd.h>
+                                 #include <signal.h>
+                                 #include <sys/wait.h>'''],
+        ['pidfd_open',        '''#include <stdlib.h>
+                                 #include <unistd.h>
+                                 #include <signal.h>
+                                 #include <sys/wait.h>'''],
+        ['execveat',          '''#include <unistd.h>'''],
+        ['close_range',       '''#include <unistd.h>'''],
+        ['mount_setattr',     '''#include <sys/mount.h>'''],
+        ['move_mount',        '''#include <sys/mount.h>'''],
+        ['open_tree',         '''#include <sys/mount.h>'''],
+        ['strlcpy',          '''#include <string.h>'''],
+        ['strlcat',          '''#include <string.h>'''],
+        ['sethostname',              '''#include <unistd.h>'''],
+        ['faccessat',         '''#include <fcntl.h>
+                                 #include <unistd.h>'''],
+        ['unshare',          '''#include <sched.h>'''],
+        ['prlimit',          '''#include <sys/time.h>
+                               #include <sys/resource.h>'''],
+        ['prlimit64',        '''#include <sys/time.h>
+                               #include <sys/resource.h>'''],
+]
+
+        have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE')
+       if have == true
+               conf.set10('HAVE_' + ident[0].to_upper(), have)
+       endif
+endforeach
+
+threads = dependency('threads')
+libseccomp = cc.find_library('seccomp', required : false)
+if libseccomp.found()
+       conf.set10('HAVE_SECCOMP', libseccomp.found())
+
+       seccomp_headers = '''
+       #include <seccomp.h>
+       '''
+
+       if cc.has_function('seccomp_notify_fd', prefix : seccomp_headers, args : '-D_GNU_SOURCE', dependencies: libseccomp)
+               conf.set10('HAVE_DECL_SECCOMP_NOTIFY_FD', true)
+       endif
+
+       if cc.has_function('seccomp_syscall_resolve_name_arch', prefix : seccomp_headers, args : '-D_GNU_SOURCE', dependencies: libseccomp)
+               conf.set10('HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH', true)
+       endif
+
+       foreach decl : [
+                       'scmp_filter_ctx',
+                       'struct seccomp_notif_sizes',
+                       'struct clone_args',
+                      ]
+
+               # We get -1 if the size cannot be determined
+               have = cc.sizeof(decl, prefix : seccomp_headers, args : '-D_GNU_SOURCE') > 0
+
+               if have == true
+                       conf.set10('HAVE_' + decl.underscorify().to_upper(), have)
+               endif
+       endforeach
+endif
+
+libselinux = cc.find_library('selinux', required : false)
+if libselinux.found()
+       conf.set10('HAVE_SELINUX', libselinux.found())
+endif
+
+libapparmor = cc.find_library('apparmor', required : false)
+if libapparmor.found()
+       conf.set10('HAVE_APPARMOR', libapparmor.found())
+endif
+
+libopenssl = dependency('openssl', required : false)
+if libopenssl.found()
+       conf.set10('HAVE_OPENSSL', libopenssl.found())
+endif
+
+libcap = dependency('libcap', required : false)
+if not libcap.found()
+        # Compat with Ubuntu 14.04 which ships libcap w/o .pc file
+        libcap = cc.find_library('cap')
+endif
+
+if libcap.found()
+       conf.set10('HAVE_LIBCAP', libcap.found())
+endif
+
+basic_includes = include_directories(
+       'src',
+       'src/include',
+       '.')
+
+liblxc_includes = [basic_includes, include_directories(
+        'src/lxc/cgroups',
+        'src/lxc/lsm',
+        'src/lxc/storage')]
+
+add_project_arguments('-include', 'config.h', language : 'c')
+
+subdir('src/include')
+subdir('src/lxc')
+
+config_h = configure_file(
+        output : 'config.h',
+        configuration : conf)
+
+liblxc = shared_library(
+        'lxc',
+        version : liblxc_version,
+        include_directories : liblxc_includes,
+        link_args : ['-shared', '-fPIC', '-DPIC'],
+        link_whole : [liblxc_static],
+        dependencies : [threads,
+                       libseccomp,
+                       libcap,
+                       libopenssl,
+                       libselinux,
+                       libapparmor],
+        install : true,
+        install_dir : libdir)
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644 (file)
index 0000000..874516e
--- /dev/null
@@ -0,0 +1,29 @@
+# -*- mode: meson -*-
+
+option('tests', type : 'boolean', value: 'false',
+       description : 'enable tests')
+
+option('runtime-path', type : 'string', value : '/run',
+       description : 'the runtime directory')
+
+option('init-script', type : 'combo',
+       choices : ['systemd', 'sysvinit', 'openrc', 'upstart'], value : 'systemd',
+       description : 'init script')
+
+option('apparmor-cache-dir', type : 'string', value : 'cache/lxc/apparmor',
+       description : 'the AppArmor cache directory')
+
+option('rootfs-mount-dir', type : 'string', value : 'lib/x86_64-linux-gnu/lxc',
+       description : 'the rootfs mount directory')
+
+option('cgroup-pattern', type : 'string', value : '',
+       description : 'the rootfs mount directory')
+
+option('log-path', type : 'string', value : 'log/lxc',
+       description : 'the rootfs mount directory')
+
+option('config-path', type : 'string', value : 'lib/lxc',
+       description : 'the rootfs mount directory')
+
+option('global-config', type : 'string', value : 'lxc/lxc.conf',
+       description : 'the rootfs mount directory')
diff --git a/src/include/meson.build b/src/include/meson.build
new file mode 100644 (file)
index 0000000..85292e2
--- /dev/null
@@ -0,0 +1,95 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+include_sources = files(
+       'bpf.h',
+       'bpf_common.h',
+       'netns_ifaddrs.c',
+       'netns_ifaddrs.h')
+
+if cc.has_function('getline', prefix : '#include <stdio.h>', args : '-D_GNU_SOURCE')
+       conf.set10('HAVE_GETLINE', have)
+else
+       include_sources += files(
+               'getline.c',
+               'getline.h')
+endif
+
+if cc.has_function('fexecve', prefix : '#include <unistd.h>', args : '-D_GNU_SOURCE')
+       conf.set10('HAVE_FEXECVE', have)
+else
+       include_sources += files(
+               'fexecve.c',
+               'fexecve.h')
+endif
+
+
+getgr_headers = '''
+#include <sys/types.h>
+#include <grp.h>
+'''
+
+if cc.has_function('getgrgid_r', prefix : getgr_headers, args : '-D_GNU_SOURCE')
+       conf.set10('HAVE_GETGRGID_R', have)
+else
+       include_sources += files(
+               'getgrgid_r.c',
+               'getgrgid_r.h')
+endif
+
+mntent_headers = '''
+#include <stdio.h>
+#include <mntent.h>
+'''
+
+have_hasmntopt = cc.has_function('hasmntopt', prefix : mntent_headers, args : '-D_GNU_SOURCE')
+if have_hasmntopt
+       conf.set10('HAVE_HASMNTOPT', have)
+endif
+
+have_setmntent = cc.has_function('setmntent', prefix : mntent_headers, args : '-D_GNU_SOURCE')
+if have_setmntent
+       conf.set10('HAVE_SETMNTENT', have)
+endif
+
+have_endmntent = cc.has_function('endmntent', prefix : mntent_headers, args : '-D_GNU_SOURCE')
+if have_endmntent
+       conf.set10('HAVE_ENDMNTENT', have)
+endif
+
+if have_hasmntopt == false or have_setmntent == false or have_endmntent == false
+       include_sources += files(
+               'lxcmntent.c',
+               'lxcmntent.h')
+endif
+
+if cc.has_function('strlcpy', prefix : '#include <string.h>', args : '-D_GNU_SOURCE')
+       conf.set10('HAVE_STRLCPY', have)
+else
+       include_sources += files(
+               'strlcpy.c',
+               'strlcpy.h')
+endif
+
+if cc.has_function('strlcat', prefix : '#include <string.h>', args : '-D_GNU_SOURCE')
+       conf.set10('HAVE_STRLCAT', have)
+else
+       include_sources += files(
+               'strlcat.c',
+               'strlcat.h')
+endif
+
+if cc.has_function('strchrnul', prefix : '#include <string.h>', args : '-D_GNU_SOURCE')
+       conf.set10('HAVE_STRCHRNUL', have)
+else
+       include_sources += files(
+               'strchrnul.c',
+               'strchrnul.h')
+endif
+
+if cc.has_function('openpty', prefix : '#include <pty.h>', args : '-D_GNU_SOURCE')
+       conf.set10('HAVE_OPENPTY', have)
+else
+       include_sources += files(
+               'openpty.c',
+               'openpty.h')
+endif
diff --git a/src/lxc/meson.build b/src/lxc/meson.build
new file mode 100644 (file)
index 0000000..faf3a93
--- /dev/null
@@ -0,0 +1,133 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+liblxcfs_version_file = configure_file(
+                       configuration : version_data,
+                        input : 'version.h.in',
+                        output : 'version.h')
+
+liblxc_sources = files(
+       'cgroups/cgfsng.c',
+       'cgroups/cgroup.c',
+       'cgroups/cgroup.h',
+       'cgroups/cgroup2_devices.c',
+       'cgroups/cgroup2_devices.h',
+       'cgroups/cgroup_utils.c',
+       'cgroups/cgroup_utils.h',
+       'lsm/apparmor.c',
+       'lsm/lsm.c',
+       'lsm/lsm.h',
+       'lsm/nop.c',
+       'lsm/selinux.c',
+       'storage/btrfs.c',
+       'storage/btrfs.h',
+       'storage/dir.c',
+       'storage/dir.h',
+       'storage/loop.c',
+       'storage/loop.h',
+       'storage/lvm.c',
+       'storage/lvm.h',
+       'storage/nbd.c',
+       'storage/nbd.h',
+       'storage/overlay.c',
+       'storage/overlay.h',
+       'storage/rbd.c',
+       'storage/rbd.h',
+       'storage/rsync.c',
+       'storage/rsync.h',
+       'storage/storage.c',
+       'storage/storage.h',
+       'storage/storage_utils.c',
+       'storage/storage_utils.h',
+       'storage/zfs.c',
+       'storage/zfs.h',
+       'af_unix.c',
+       'af_unix.h',
+       'api_extensions.h',
+       'attach.c',
+       'attach.h',
+       'attach_options.h',
+       'caps.c',
+       'caps.h',
+       'commands.c',
+       'commands.h',
+       'commands_utils.c',
+       'commands_utils.h',
+       'compiler.h',
+       'conf.c',
+       'conf.h',
+       'confile.c',
+       'confile.h',
+       'confile_utils.c',
+       'confile_utils.h',
+       'criu.c',
+       'criu.h',
+       'error.c',
+       'error.h',
+       'error_utils.h',
+       'execute.c',
+       'file_utils.c',
+       'file_utils.h',
+       'freezer.c',
+       'hlist.h',
+       'initutils.c',
+       'initutils.h',
+       'list.h',
+       'log.c',
+       'log.h',
+       'lxc.h',
+       'lxccontainer.c',
+       'lxccontainer.h',
+       'lxclock.c',
+       'lxclock.h',
+       'lxcseccomp.h',
+       'macro.h',
+       'mainloop.c',
+       'mainloop.h',
+       'memory_utils.h',
+       'monitor.c',
+       'monitor.h',
+       'mount_utils.c',
+       'mount_utils.h',
+       'namespace.c',
+       'namespace.h',
+       'network.c',
+       'network.h',
+       'nl.c',
+       'nl.h',
+       'parse.c',
+       'parse.h',
+       'process_utils.c',
+       'process_utils.h',
+       'rexec.c',
+       'rexec.h',
+       'ringbuf.c',
+       'ringbuf.h',
+       'rtnl.c',
+       'rtnl.h',
+       'seccomp.c',
+       'start.c',
+       'start.h',
+       'state.c',
+       'state.h',
+       'string_utils.c',
+       'string_utils.h',
+       'sync.c',
+       'sync.h',
+       'syscall_numbers.h',
+       'syscall_wrappers.h',
+       'terminal.c',
+       'terminal.h',
+       'utils.c',
+       'utils.h',
+       'uuid.c',
+       'uuid.h')
+
+liblxc_c_args = ['-fvisibility=default']
+
+liblxc_static = static_library(
+        'lxc_static',
+        liblxc_sources + include_sources,
+        install : false,
+        include_directories : liblxc_includes,
+        dependencies : [threads],
+        c_args : liblxc_c_args)