build: misc refactor

EX_DEP():
- Do not generate feature check code if `feat-names` is empty.
- Improve docs.

others:
- Reuse `$host_os` for system type check result.
This commit is contained in:
CismonX 2025-07-12 12:53:16 +08:00
parent 296b85cbe9
commit 602519db12
No known key found for this signature in database
GPG key ID: 3094873E29A482FB
2 changed files with 13 additions and 11 deletions

View file

@ -23,11 +23,11 @@ LT_INIT([disable-static dlopen])
AC_CANONICAL_HOST AC_CANONICAL_HOST
AS_CASE(["${host_os}"], [linux*], [ AS_CASE(["${host_os}"], [linux*], [
AS_VAR_SET([host_os_is_linux], [yes]) AS_VAR_SET([host_os], [linux])
], [freebsd*], [ ], [freebsd*], [
AS_VAR_SET([host_os_is_freebsd], [yes]) AS_VAR_SET([host_os], [freebsd])
], [ ], [
AC_MSG_ERROR(m4_normalize([Unsupported platform "${host_os}".])) AC_MSG_ERROR([Unsupported platform "${host_os}".])
]) ])
# -- Checks for programs -- # -- Checks for programs --
@ -54,7 +54,7 @@ EX_FEAT([bookmarkfs-mount], [NE], [the mount.bookmarkfs program], [
EX_FEAT([sandbox], [YDE], [sandboxing]) EX_FEAT([sandbox], [YDE], [sandboxing])
AS_VAR_IF([host_os_is_linux], [yes], [ AS_VAR_IF([host_os], [linux], [
EX_FEAT([sandbox-landlock], [YD], [using Landlock for sandboxing]) EX_FEAT([sandbox-landlock], [YD], [using Landlock for sandboxing])
]) ])
@ -95,7 +95,7 @@ AX_PTHREAD
EX_DEP([fuse3], [>= 3.5], [fuse3 library], , [bookmarkfs-mount]) EX_DEP([fuse3], [>= 3.5], [fuse3 library], , [bookmarkfs-mount])
AS_VAR_IF([host_os_is_linux], [yes], [ AS_VAR_IF([host_os], [linux], [
EX_DEP([libseccomp], [>= 2.5], [libseccomp library], , [sandbox]) EX_DEP([libseccomp], [>= 2.5], [libseccomp library], , [sandbox])
]) ])

View file

@ -48,33 +48,35 @@ AC_DEFUN([EX_FEAT], [
]) ])
dnl dnl
dnl EX_DEP(pkg-name, version, pkg-desc, [action-if-found], dnl EX_DEP(pkg-name, version, pkg-desc, [action-if-found], [feat-names]...)
dnl [required-by-features]...)
dnl dnl
dnl Check whether a package exists with `pkg-config`, dnl Check whether a package exists with `pkg-config`,
dnl and provide an option to specify the package's custom install location. dnl and provide an option to specify the package's custom install location.
dnl dnl
dnl If at least one feature specified in `feat-names` is enabled,
dnl automatically enable checking the package, and fail if not found.
dnl
AC_DEFUN([EX_DEP], [ AC_DEFUN([EX_DEP], [
AC_ARG_WITH([$1], m4_normalize([ AC_ARG_WITH([$1], m4_normalize([
AS_HELP_STRING([--with-m4_translit([$1], [_], [-])[[=PKGCONFIGDIR]]], AS_HELP_STRING([--with-m4_translit([$1], [_], [-])[[=PKGCONFIGDIR]]],
[pkg-config search path for $3]) [pkg-config search path for $3])
]), , [ ]), , [
AS_VAR_SET([with_$1], [no]) AS_VAR_SET([with_$1], [no])
m4_foreach([feat_name_], [m4_shiftn(4, $@)], [ m4_ifnblank([$5], m4_foreach([feat_name_], [m4_shiftn(4, $@)], [
AS_VAR_IF([enable_]m4_translit(feat_name_, [-], [_]), [yes], [ AS_VAR_IF([enable_]m4_translit(feat_name_, [-], [_]), [yes], [
AS_VAR_SET([with_$1], [yes]) AS_VAR_SET([with_$1], [yes])
]) ])
]) ]))
]) ])
AS_VAR_IF([with_$1], [no], [ AS_VAR_IF([with_$1], [no], [
m4_foreach([feat_name_], [m4_shiftn(4, $@)], [ m4_ifnblank([$5], m4_foreach([feat_name_], [m4_shiftn(4, $@)], [
AS_VAR_IF([enable_]m4_translit(feat_name_, [-], [_]), [yes], [ AS_VAR_IF([enable_]m4_translit(feat_name_, [-], [_]), [yes], [
AC_MSG_ERROR(m4_normalize([ AC_MSG_ERROR(m4_normalize([
Bad option '[--without-]feat_name_'. The $3 is mandatory Bad option '[--without-]feat_name_'. The $3 is mandatory
for AS_VAR_GET([desc_]m4_translit(feat_name_, [-], [_])). for AS_VAR_GET([desc_]m4_translit(feat_name_, [-], [_])).
])) ]))
]) ])
]) ]))
], [ ], [
AS_VAR_SET([old_pkg_config_path_], ["${PKG_CONFIG_PATH}"]) AS_VAR_SET([old_pkg_config_path_], ["${PKG_CONFIG_PATH}"])
AS_VAR_IF([with_$1], [yes], , [ AS_VAR_IF([with_$1], [yes], , [