]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
meson: introduce IN_LIBLXC preprocessor macro
authorAlexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Sat, 17 Feb 2024 15:47:41 +0000 (16:47 +0100)
committerAlexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Sat, 17 Feb 2024 15:47:41 +0000 (16:47 +0100)
The purpose of it is to tell us if we are compiling
liblxc or lxc test/tool/command.

This thing is needed to exclude unnecessary functions
from being compiled-in in the resulting executables
like lxc-start, lxc-attach, etc.

The problem is that lxc tools (lxc-start, lxc-stop, etc)
depend not only on the liblxc as a shared library, but also
require some non-exported symbols or helpers from liblxc
internals. So, we have to link these executables with some liblxc
object files directly which results in the dependency hell,
because linking one .c file from liblxc may end up having to
link with another one (what contains some dependency) and so on.
By using IN_LIBLXC in the liblxc internals we can selectively
omit some functions from being compiled in such cases.

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
src/lxc/meson.build
src/lxc/state.c
src/lxc/utils.c

index f33257c2316a54be67f58104eb481127ef752d9e..f76971c15f538d3c13b1ba53fcc930e82e138150 100644 (file)
@@ -157,7 +157,7 @@ liblxc_static = static_library(
     install: true,
     include_directories: liblxc_includes,
     dependencies: [threads] + liblxc_dependency_headers,
-    c_args: '-fvisibility=default')
+    c_args: ['-fvisibility=default', '-DIN_LIBLXC'])
 
 lxc_functions = configure_file(
     configuration: conf,
index 2633327e75164d8f8d4c9bdad5fec03111c701f3..d487e1dcbfb5c5d1a32f45c01b6f5f5c0c1e9742 100644 (file)
@@ -52,6 +52,8 @@ lxc_state_t lxc_str2state(const char *state)
        return -1;
 }
 
+#ifdef IN_LIBLXC
+
 lxc_state_t lxc_getstate(const char *name, const char *lxcpath, int timeout)
 {
        return lxc_cmd_get_state(name, lxcpath, timeout);
@@ -117,3 +119,5 @@ int lxc_wait(const char *lxcname, const char *states, int timeout,
 
        return 0;
 }
+
+#endif /* IN_LIBLXC */
index f445debd6c9b145eb48f0f9620a8829b3e2654da..65c7d75716e14239d0376fae867bed00cbb9e412 100644 (file)
@@ -61,6 +61,8 @@ lxc_log_define(utils, lxc);
  */
 extern bool btrfs_try_remove_subvol(const char *path);
 
+#ifdef IN_LIBLXC
+
 static int _recursive_rmdir(const char *dirname, dev_t pdev,
                            const char *exclude, int level, bool onedev)
 {
@@ -193,6 +195,8 @@ extern int lxc_rmdir_onedev(const char *path, const char *exclude)
        return _recursive_rmdir(path, mystat.st_dev, exclude, 0, onedev);
 }
 
+#endif /* IN_LIBLXC */
+
 /* borrowed from iproute2 */
 extern int get_u16(unsigned short *val, const char *arg, int base)
 {