]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
meson: Only build libmount when required
authorJordan Williams <jordan@jwillikers.com>
Fri, 5 Apr 2024 14:49:17 +0000 (07:49 -0700)
committerJordan Williams <jordan@jwillikers.com>
Mon, 15 Apr 2024 13:02:21 +0000 (08:02 -0500)
It is not currently possible to build any part of util-linux without
building libmount when using Meson.
The libuuid library is commonly used on macOS, where it is not possible
to build libmount.
To address this, this PR makes it possible to build without libmount and
 libblkid.

Options have been added to allow toggling whether to build targets that
require libmount.
This makes it possible to fully disable building libmount.

The python object had to be defined outside of the meson.build file in
libmount/python since this may no longer be included.
The python object is used for tests.

Signed-off-by: Jordan Williams <jordan@jwillikers.com>
(cherry picked from commit b6799ccbc08aea69a26cdaa97ab436bfae2ae27f)

libblkid/meson.build
libmount/meson.build
libmount/python/meson.build
meson.build
meson_options.txt

index b2161c6214144ada86fad0bc1007bafc34663b0c..8d1d880aa1d45842eaf423584fb945650b3cc2d8 100644 (file)
@@ -1,4 +1,9 @@
 dir_libblkid = include_directories('.', 'src')
+if not build_libblkid
+  blkid_dep = disabler()
+  blkid_static_dep = disabler()
+  subdir_done()
+endif
 
 defs = configuration_data()
 defs.set('LIBBLKID_DATE', libblkid_date)
@@ -147,12 +152,10 @@ blkid_dep = declare_dependency(link_with: lib_blkid, include_directories: '.')
 lib_blkid_static = lib_blkid.get_static_lib()
 blkid_static_dep = declare_dependency(link_with: lib_blkid_static, include_directories: '.')
 
-if build_libblkid
-  pkgconfig.generate(lib_blkid,
-                     description : 'Block device id library',
-                     subdirs : 'blkid',
-                     version : pc_version)
-  if meson.version().version_compare('>=0.54.0')
-    meson.override_dependency('blkid', blkid_dep)
-  endif
+pkgconfig.generate(lib_blkid,
+                    description : 'Block device id library',
+                    subdirs : 'blkid',
+                    version : pc_version)
+if meson.version().version_compare('>=0.54.0')
+  meson.override_dependency('blkid', blkid_dep)
 endif
index 2534191faf90c25299e19f07aba6992435493cd8..6b16aab94dc036a06a4716d71af7ab0487bacfe1 100644 (file)
@@ -1,3 +1,9 @@
+if not build_libmount
+  mount_dep = disabler()
+  mount_static_dep = disabler()
+  subdir_done()
+endif
+
 dir_libmount = include_directories('.', 'src')
 
 defs = configuration_data()
@@ -99,14 +105,12 @@ lib_mount = library(
   install : build_libmount)
 mount_dep = declare_dependency(link_with: lib_mount, include_directories: '.')
 
-if build_libmount
-  pkgconfig.generate(lib_mount,
-                     description : 'mount library',
-                     subdirs : 'libmount',
-                     version : pc_version)
-  if meson.version().version_compare('>=0.54.0')
-    meson.override_dependency('mount', mount_dep)
-  endif
+pkgconfig.generate(lib_mount,
+                    description : 'mount library',
+                    subdirs : 'libmount',
+                    version : pc_version)
+if meson.version().version_compare('>=0.54.0')
+  meson.override_dependency('mount', mount_dep)
 endif
 
 libmount_tests = [
index 702ca8f378ab9045138ade856ea2cd63c637dd90..0957bca06b01111598ee8326c9bf68216c838882 100644 (file)
@@ -1,9 +1,3 @@
-python_module = import('python')
-
-python = python_module.find_installation(
-    get_option('python'),
-    required : get_option('build-python'),
-    disabler : true)
 build_python = python.found()
 
 pylibmount_sources = '''
index 00d0d3290bdc6ad9e5196a4b3f9463449b09f8a0..f2383834384ac1be302986c3776b9cde3603f6ac 100644 (file)
@@ -78,7 +78,7 @@ conf.set_quoted('ADJTIME_PATH', '/etc/adjtime') # yes, both are used :(
 conf.set_quoted('_PATH_VENDORDIR', vendordir)
 conf.set('USE_VENDORDIR', vendordir == '' ? false : 1)
 
-build_libblkid = not get_option('build-libblkid').disabled()
+build_libblkid = not get_option('build-libblkid').require(get_option('build-libmount').allowed()).disabled()
 conf.set('HAVE_LIBBLKID', build_libblkid ? 1 : false)
 summary('libblkid', build_libblkid ? 'enabled' : 'disabled', section : 'components')
 
@@ -97,7 +97,8 @@ conf.set('HAVE_MOUNTFD_API', have_mountfd_api ? 1 : false)
 have_struct_statx = cc.sizeof('struct statx', prefix : '#include <sys/stat.h>') > 0
 conf.set('HAVE_STRUCT_STATX', have_struct_statx ? 1 : false)
 
-build_libmount = not get_option('build-libmount').disabled()
+build_libmount = get_option('build-libmount').require(get_option('build-libblkid').allowed()).allowed()
+
 conf.set('HAVE_LIBMOUNT', build_libmount ? 1 : false)
 conf.set('USE_LIBMOUNT_SUPPORT_NAMESPACES', 1)
 conf.set('USE_LIBMOUNT_MOUNTFD_SUPPORT', have_mountfd_api ? 1 : false)
@@ -107,7 +108,7 @@ build_libsmartcols = not get_option('build-libsmartcols').disabled()
 conf.set('HAVE_LIBSMARTCOLS', build_libsmartcols ? 1 : false)
 summary('libsmartcols', build_libsmartcols ? 'enabled' : 'disabled', section : 'components')
 
-build_libfdisk = not get_option('build-libfdisk').disabled()
+build_libfdisk = not get_option('build-libfdisk').require(get_option('build-libblkid').allowed()).disabled()
 conf.set('HAVE_LIBFDISK', build_libfdisk ? 1 : false)
 summary('libfdisk', build_libfdisk ? 'enabled' : 'disabled', section : 'components')
 
@@ -901,6 +902,12 @@ bison_gen = generator(
   output : ['@BASENAME@.tab.c', '@BASENAME@.tab.h'],
   arguments : ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@'])
 
+python_module = import('python')
+python = python_module.find_installation(
+    get_option('python'),
+    required : true,
+    disabler : true)
+
 meson_make_symlink = meson.current_source_dir() + '/tools/meson-make-symlink.sh'
 meson_make_manpage_stub = meson.current_source_dir() + '/tools/meson-make-manpage-stub.sh'
 
@@ -1492,6 +1499,7 @@ if opt and not is_disabler(exe)
   bashcompletions += ['tunelp']
 endif
 
+opt = not get_option('build-fstrim').disabled()
 exe = executable(
   'fstrim',
   fstrim_sources,
@@ -1499,8 +1507,9 @@ exe = executable(
   link_with : [lib_common],
   dependencies : [mount_dep],
   install_dir : sbindir,
-  install : true)
-if not is_disabler(exe)
+  install : opt,
+  build_by_default : opt)
+if opt and not is_disabler(exe)
   exes += exe
   manadocs += ['sys-utils/fstrim.8.adoc']
   bashcompletions += ['fstrim']
@@ -1719,6 +1728,7 @@ if not is_disabler(exe)
   bashcompletions += ['prlimit']
 endif
 
+opt = not get_option('build-lsns').disabled()
 exe = executable(
   'lsns',
   lsns_sources,
@@ -1727,8 +1737,9 @@ exe = executable(
                lib_smartcols],
   dependencies : [mount_dep],
   install_dir : usrbin_exec_dir,
-  install : true)
-if not is_disabler(exe)
+  install : opt,
+  build_by_default : opt)
+if opt and not is_disabler(exe)
   exes += exe
   manadocs += ['sys-utils/lsns.8.adoc']
   bashcompletions += ['lsns']
@@ -1793,6 +1804,7 @@ endif
 
 # setuid?
 
+opt = not get_option('build-swapon').disabled()
 exe = executable(
   'swapon',
   swapon_sources,
@@ -1801,13 +1813,15 @@ exe = executable(
                lib_smartcols],
   dependencies : [blkid_dep, mount_dep],
   install_dir : sbindir,
-  install : true)
-if not is_disabler(exe)
+  install : opt,
+  build_by_default : opt)
+if opt and not is_disabler(exe)
   exes += exe
   manadocs += ['sys-utils/swapon.8.adoc']
   bashcompletions += ['swapon']
 endif
 
+opt = not get_option('build-swapoff').disabled()
 exe = executable(
   'swapoff',
   swapoff_sources,
@@ -1815,8 +1829,9 @@ exe = executable(
   link_with : [lib_common],
   dependencies : [blkid_dep, mount_dep],
   install_dir : sbindir,
-  install : true)
-if not is_disabler(exe)
+  install : opt,
+  build_by_default : opt)
+if opt and not is_disabler(exe)
   exes += exe
   manlinks += {'swapoff.8': 'swapon.8'}
   bashcompletions += ['swapoff']
@@ -2671,6 +2686,7 @@ exes += exe
 manadocs += ['misc-utils/whereis.1.adoc']
 bashcompletions += ['whereis']
 
+opt = not get_option('build-lslocks').disabled()
 exe = executable(
   'lslocks',
   lslocks_sources,
@@ -2679,13 +2695,15 @@ exe = executable(
                lib_smartcols],
   dependencies : [mount_dep],
   install_dir : usrbin_exec_dir,
-  install : true)
-if not is_disabler(exe)
+  install : opt,
+  build_by_default : opt)
+if opt and not is_disabler(exe)
   exes += exe
   manadocs += ['misc-utils/lslocks.8.adoc']
   bashcompletions += ['lslocks']
 endif
 
+opt = not get_option('build-lsblk').disabled()
 exe = executable(
   'lsblk',
   lsblk_sources,
@@ -2694,8 +2712,9 @@ exe = executable(
                lib_tcolors,
                lib_smartcols],
   dependencies : [blkid_dep, lib_udev, mount_dep],
-  install : true)
-if not is_disabler(exe)
+  install : opt,
+  build_by_default : opt)
+if opt and not is_disabler(exe)
   exes += exe
   manadocs += ['misc-utils/lsblk.8.adoc']
   bashcompletions += ['lsblk']
@@ -2881,6 +2900,7 @@ if not is_disabler(exe)
   bashcompletions += ['wipefs']
 endif
 
+opt = not get_option('build-findmnt').disabled()
 exe = executable(
   'findmnt',
   findmnt_sources,
@@ -2888,8 +2908,9 @@ exe = executable(
   link_with : [lib_common,
                lib_smartcols],
   dependencies : [blkid_dep, lib_udev, mount_dep],
-  install : true)
-if not is_disabler(exe)
+  install : opt,
+  build_by_default : opt)
+if opt and not is_disabler(exe)
   exes += exe
   manadocs += ['misc-utils/findmnt.8.adoc']
   bashcompletions += ['findmnt']
index 5cc8b4f6133fbac8c3dbdecd3f134636c1d1e37a..e4862ad4a9f01b945cd2187f3c66b1657b2d3fd2 100644 (file)
@@ -53,10 +53,16 @@ option('build-fdisks', type : 'feature',
        description : 'build fdisk(8), sfdisk(8) and cfdisk(8)')
 option('build-mount', type : 'feature',
        description : 'build mount(8) and umount(8)')
+option('build-swapon', type : 'feature',
+       description : 'build swapon')
+option('build-swapoff', type : 'feature',
+       description : 'build swapoff')
 option('build-losetup', type : 'feature',
        description : 'build losetup')
 option('build-zramctl', type : 'feature',
        description : 'build zramctl')
+option('build-lsns', type : 'feature',
+       description : 'build lsns')
 option('build-fsck', type : 'feature',
        description : 'build fsck')
 option('build-partx', type : 'feature',
@@ -101,6 +107,12 @@ option('build-cal', type : 'feature',
        description : 'build cal')
 option('build-logger', type : 'feature',
        description : 'build logger')
+option('build-lsblk', type : 'feature',
+       description : 'build lsblk')
+option('build-lslocks', type : 'feature',
+       description : 'build lslocks')
+option('build-findmnt', type : 'feature',
+       description : 'build findmnt')
 option('build-lsfd', type : 'feature',
        description : 'build lsfd')
 option('build-switch_root', type : 'feature',
@@ -123,6 +135,8 @@ option('build-rfkill', type : 'feature',
        description : 'build rfkill')
 option('build-tunelp', type : 'feature',
        description : 'build tunelp')
+option('build-fstrim', type : 'feature',
+       description : 'build fstrim')
 option('build-kill', type : 'feature',
        description : 'build kill')
 option('build-last', type : 'feature',