From 3a6c1f049bb3643c86eb87f6c69cf7c3d3c95c86 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 24 May 2024 09:37:57 -0400 Subject: configure: Use --with/--without for libraries --- build/header.mk | 2 +- build/msg-if.sh | 4 +- build/pkgconf.sh | 18 +++----- build/pkgs.mk | 10 ++--- build/use/libacl.c | 9 ---- build/use/libcap.c | 9 ---- build/use/libselinux.c | 9 ---- build/use/liburing.c | 9 ---- build/use/oniguruma.c | 9 ---- build/with/libacl.c | 9 ++++ build/with/libcap.c | 9 ++++ build/with/libselinux.c | 9 ++++ build/with/liburing.c | 9 ++++ build/with/oniguruma.c | 9 ++++ configure | 111 +++++++++++++++++++++++++++++++++++------------- docs/BUILDING.md | 14 +++--- src/bftw.c | 2 +- src/fsade.h | 4 +- src/ioq.c | 26 ++++++------ src/parse.c | 4 +- src/xregex.c | 14 +++--- 21 files changed, 173 insertions(+), 126 deletions(-) delete mode 100644 build/use/libacl.c delete mode 100644 build/use/libcap.c delete mode 100644 build/use/libselinux.c delete mode 100644 build/use/liburing.c delete mode 100644 build/use/oniguruma.c create mode 100644 build/with/libacl.c create mode 100644 build/with/libcap.c create mode 100644 build/with/libselinux.c create mode 100644 build/with/liburing.c create mode 100644 build/with/oniguruma.c diff --git a/build/header.mk b/build/header.mk index fb8246d..09454c5 100644 --- a/build/header.mk +++ b/build/header.mk @@ -51,7 +51,7 @@ HEADERS := \ gen/has/uselocale.h # Previously generated by pkgs.mk -PKG_HEADERS := ${ALL_PKGS:%=gen/use/%.h} +PKG_HEADERS := ${ALL_PKGS:%=gen/with/%.h} gen/config.h: ${PKG_HEADERS} ${HEADERS} ${MSG} "[ GEN] $@" diff --git a/build/msg-if.sh b/build/msg-if.sh index 8112aea..e0d0957 100755 --- a/build/msg-if.sh +++ b/build/msg-if.sh @@ -6,8 +6,8 @@ # Print a success/failure indicator from a makefile: # # $ ./configure -# [ CC ] use/liburing.c ✘ -# [ CC ] use/oniguruma.c ✔ +# [ CC ] with/liburing.c ✘ +# [ CC ] with/oniguruma.c ✔ set -eu diff --git a/build/pkgconf.sh b/build/pkgconf.sh index 96e4bf1..244c95d 100755 --- a/build/pkgconf.sh +++ b/build/pkgconf.sh @@ -26,22 +26,18 @@ esac if [ -z "$MODE" ]; then # Check whether the libraries exist at all for LIB; do - # Check ${USE_$LIB} - USE_LIB="USE_$(printf '%s' "$LIB" | tr 'a-z-' 'A-Z_')" - eval "USE=\"\${$USE_LIB:-}\"" - case "$USE" in - y|1) - continue - ;; - n|0) - exit 1 - ;; + # Check ${WITH_$LIB} + WITH_LIB="WITH_$(printf '%s' "$LIB" | tr 'a-z-' 'A-Z_')" + eval "WITH=\"\${$WITH_LIB:-}\"" + case "$WITH" in + y|1) continue ;; + n|0) exit 1 ;; esac CFLAGS=$("$0" --cflags "$LIB") || exit 1 LDFLAGS=$("$0" --ldflags "$LIB") || exit 1 LDLIBS=$("$0" --ldlibs "$LIB") || exit 1 - build/cc.sh $CFLAGS $LDFLAGS build/use/$LIB.c $LDLIBS || exit 1 + build/cc.sh $CFLAGS $LDFLAGS build/with/$LIB.c $LDLIBS || exit 1 done fi diff --git a/build/pkgs.mk b/build/pkgs.mk index 5a26548..5de9ac2 100644 --- a/build/pkgs.mk +++ b/build/pkgs.mk @@ -8,7 +8,7 @@ include gen/vars.mk include gen/flags.mk include build/exports.mk -HEADERS := ${ALL_PKGS:%=gen/use/%.h} +HEADERS := ${ALL_PKGS:%=gen/with/%.h} gen/pkgs.mk: ${HEADERS} ${MSG} "[ GEN] $@" @@ -24,10 +24,10 @@ gen/pkgs.mk: ${HEADERS} .PHONY: gen/pkgs.mk -# Convert gen/use/foo.h to foo -PKG = ${@:gen/use/%.h=%} +# Convert gen/with/foo.h to foo +PKG = ${@:gen/with/%.h=%} ${HEADERS}:: @${MKDIR} ${@D} - @build/define-if.sh use/${PKG} build/pkgconf.sh ${PKG} >$@ 2>$@.log; \ - build/msg-if.sh "[ CC ] use/${PKG}.c" test $$? -eq 0; + @build/define-if.sh with/${PKG} build/pkgconf.sh ${PKG} >$@ 2>$@.log; \ + build/msg-if.sh "[ CC ] with/${PKG}.c" test $$? -eq 0; diff --git a/build/use/libacl.c b/build/use/libacl.c deleted file mode 100644 index de1fe50..0000000 --- a/build/use/libacl.c +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright © Tavian Barnes -// SPDX-License-Identifier: 0BSD - -#include - -int main(void) { - acl_free(0); - return 0; -} diff --git a/build/use/libcap.c b/build/use/libcap.c deleted file mode 100644 index 58e832c..0000000 --- a/build/use/libcap.c +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright © Tavian Barnes -// SPDX-License-Identifier: 0BSD - -#include - -int main(void) { - cap_free(0); - return 0; -} diff --git a/build/use/libselinux.c b/build/use/libselinux.c deleted file mode 100644 index bca409d..0000000 --- a/build/use/libselinux.c +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright © Tavian Barnes -// SPDX-License-Identifier: 0BSD - -#include - -int main(void) { - freecon(0); - return 0; -} diff --git a/build/use/liburing.c b/build/use/liburing.c deleted file mode 100644 index bea499a..0000000 --- a/build/use/liburing.c +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright © Tavian Barnes -// SPDX-License-Identifier: 0BSD - -#include - -int main(void) { - io_uring_free_probe(0); - return 0; -} diff --git a/build/use/oniguruma.c b/build/use/oniguruma.c deleted file mode 100644 index cb17596..0000000 --- a/build/use/oniguruma.c +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright © Tavian Barnes -// SPDX-License-Identifier: 0BSD - -#include - -int main(void) { - onig_free(0); - return 0; -} diff --git a/build/with/libacl.c b/build/with/libacl.c new file mode 100644 index 0000000..de1fe50 --- /dev/null +++ b/build/with/libacl.c @@ -0,0 +1,9 @@ +// Copyright © Tavian Barnes +// SPDX-License-Identifier: 0BSD + +#include + +int main(void) { + acl_free(0); + return 0; +} diff --git a/build/with/libcap.c b/build/with/libcap.c new file mode 100644 index 0000000..58e832c --- /dev/null +++ b/build/with/libcap.c @@ -0,0 +1,9 @@ +// Copyright © Tavian Barnes +// SPDX-License-Identifier: 0BSD + +#include + +int main(void) { + cap_free(0); + return 0; +} diff --git a/build/with/libselinux.c b/build/with/libselinux.c new file mode 100644 index 0000000..bca409d --- /dev/null +++ b/build/with/libselinux.c @@ -0,0 +1,9 @@ +// Copyright © Tavian Barnes +// SPDX-License-Identifier: 0BSD + +#include + +int main(void) { + freecon(0); + return 0; +} diff --git a/build/with/liburing.c b/build/with/liburing.c new file mode 100644 index 0000000..bea499a --- /dev/null +++ b/build/with/liburing.c @@ -0,0 +1,9 @@ +// Copyright © Tavian Barnes +// SPDX-License-Identifier: 0BSD + +#include + +int main(void) { + io_uring_free_probe(0); + return 0; +} diff --git a/build/with/oniguruma.c b/build/with/oniguruma.c new file mode 100644 index 0000000..cb17596 --- /dev/null +++ b/build/with/oniguruma.c @@ -0,0 +1,9 @@ +// Copyright © Tavian Barnes +// SPDX-License-Identifier: 0BSD + +#include + +int main(void) { + onig_free(0); + return 0; +} diff --git a/configure b/configure index 93254fa..60d7a92 100755 --- a/configure +++ b/configure @@ -17,13 +17,70 @@ else j="-j$({ nproc || sysctl -n hw.ncpu || getconf _NPROCESSORS_ONLN || echo 1; } 2>/dev/null)" fi +# Convert kebab-case to UPPER_CASE +toupper() { + printf '%s' "$1" | tr 'a-z-' 'A-Z_' +} + +# Report an argument parsing error +invalid() { + printf 'error: Unrecognized option "%s"\n\n' "$1" >&2 + printf 'Run %s --help for more information.\n' "$0" >&2 + exit 1 +} + for arg; do + # --[(enable|disable|with|without)-]$name[=$value] + value="${arg#*=}" + name="${arg%%=*}" + name="${name#--}" + case "$arg" in + --enable-*|--disable-*|--with-*|--without-*) + name="${name#*-}" + ;; + esac + NAME=$(printf '%s' "$name" | tr 'a-z-' 'A-Z_') + + # y/n modality + case "$arg" in + --enable-*|--with-*) + case "$arg" in + *=y|*=yes) yn=y ;; + *=n|*=no) yn=n ;; + *=*) invalid "$arg" ;; + *) yn=y ;; + esac + ;; + --disable-*|--without-*) + case "$arg" in + *=*) invalid "arg" ;; + *) yn=n ;; + esac + ;; + esac + + # Fix up --enable-lib* to --with-lib* + case "$arg" in + --enable-*|--disable-*) + case "$name" in + libacl|libcap|libselinux|liburing|oniguruma) + old="$arg" + case "$arg" in + --enable-*) arg="--with-${arg#--*-}" ;; + --disable-*) arg="--without-${arg#--*-}" ;; + esac + printf 'warning: Treating "%s" like "%s"\n' "$old" "$arg" >&2 + ;; + esac + ;; + esac + case "$arg" in -h|--help) cat <&2 - printf 'Run %s --help for more information.\n' "$0" >&2 - exit 1 + invalid "$arg" ;; esac ;; --prefix=*|--mandir=*) shift - name="${arg#--}" - name="${name%%=*}" - NAME=$(printf '%s' "$name" | tr 'a-z-' 'A-Z_') - set -- "$@" "$NAME=${arg#*=}" + set -- "$@" "$NAME=$value" ;; --infodir=*|--build=*|--host=*|--target=*) shift - printf 'warning: Ignoring option "%s"\n' "${arg%%=*}" >&2 + printf 'warning: Ignoring option "%s"\n' "$arg" >&2 ;; MAKE=*) - MAKE="${arg#*=}" shift + MAKE="$value" ;; # make flag (-j2) or variable (CC=clang) @@ -126,9 +179,7 @@ EOF ;; *) - printf 'error: Unrecognized option "%s"\n\n' "$arg" >&2 - printf 'Run %s --help for more information.\n' "$0" >&2 - exit 1 + invalid "$arg" ;; esac done diff --git a/docs/BUILDING.md b/docs/BUILDING.md index cb33c51..025dadf 100644 --- a/docs/BUILDING.md +++ b/docs/BUILDING.md @@ -16,7 +16,7 @@ Configuration $ ./configure --help Usage: - $ ./configure [--enable-*|--disable-*] [CC=...] [CFLAGS=...] [...] + $ ./configure [--enable-*|--disable-*] [--with-*|--without-*] [CC=...] [...] $ make ... @@ -82,14 +82,14 @@ You can combine multiple profiles (e.g. `./configure --enable-asan --enable-ubsa ### Dependencies `bfs` depends on some system libraries for some of its features. -External dependencies are auto-detected by default, but you can `--enable` or `--disable` them manually: +External dependencies are auto-detected by default, but you can build `--with` or `--without` them explicitly:
---enable-libacl      --disable-libacl
---enable-libcap      --disable-libcap
---enable-libselinux  --disable-libselinux
---enable-liburing    --disable-liburing
---enable-oniguruma   --disable-oniguruma
+--with-libacl      --without-libacl
+--with-libcap      --without-libcap
+--with-libselinux  --without-libselinux
+--with-liburing    --without-liburing
+--with-oniguruma   --without-oniguruma
 
[`pkg-config`] is used, if available, to detect these libraries and any additional build flags they may require. diff --git a/src/bftw.c b/src/bftw.c index 5322181..c80ac74 100644 --- a/src/bftw.c +++ b/src/bftw.c @@ -913,7 +913,7 @@ static int bftw_state_init(struct bftw_state *state, const struct bftw_args *arg size_t qdepth = 4096; size_t nthreads = args->nthreads; -#if BFS_USE_LIBURING +#if BFS_WITH_LIBURING // io_uring uses one fd per ring, ioq uses one ring per thread if (nthreads >= nopenfd - 1) { nthreads = nopenfd - 2; diff --git a/src/fsade.h b/src/fsade.h index eefef9f..4465017 100644 --- a/src/fsade.h +++ b/src/fsade.h @@ -13,9 +13,9 @@ #define BFS_CAN_CHECK_ACL (BFS_HAS_ACL_GET_FILE || BFS_HAS_ACL_TRIVIAL) -#define BFS_CAN_CHECK_CAPABILITIES BFS_USE_LIBCAP +#define BFS_CAN_CHECK_CAPABILITIES BFS_WITH_LIBCAP -#define BFS_CAN_CHECK_CONTEXT BFS_USE_LIBSELINUX +#define BFS_CAN_CHECK_CONTEXT BFS_WITH_LIBSELINUX #define BFS_CAN_CHECK_XATTRS (BFS_USE_SYS_EXTATTR_H || BFS_USE_SYS_XATTR_H) diff --git a/src/ioq.c b/src/ioq.c index 43a1b35..4057a5e 100644 --- a/src/ioq.c +++ b/src/ioq.c @@ -135,7 +135,7 @@ #include #include -#if BFS_USE_LIBURING +#if BFS_WITH_LIBURING # include #endif @@ -459,7 +459,7 @@ static void ioq_batch_push(struct ioqq *ioqq, struct ioq_batch *batch, struct io /** Sentinel stop command. */ static struct ioq_ent IOQ_STOP; -#if BFS_USE_LIBURING +#if BFS_WITH_LIBURING /** * Supported io_uring operations. */ @@ -477,7 +477,7 @@ struct ioq_thread { /** Pointer back to the I/O queue. */ struct ioq *parent; -#if BFS_USE_LIBURING +#if BFS_WITH_LIBURING /** io_uring instance. */ struct io_uring ring; /** Any error that occurred initializing the ring. */ @@ -497,7 +497,7 @@ struct ioq { /** ioq_ent arena. */ struct arena ents; -#if BFS_USE_LIBURING && BFS_USE_STATX +#if BFS_WITH_LIBURING && BFS_USE_STATX /** struct statx arena. */ struct arena xbufs; #endif @@ -559,7 +559,7 @@ static void ioq_dispatch_sync(struct ioq *ioq, struct ioq_ent *ent) { ent->result = -ENOSYS; } -#if BFS_USE_LIBURING +#if BFS_WITH_LIBURING /** io_uring worker state. */ struct ioq_ring_state { @@ -775,7 +775,7 @@ static void ioq_ring_work(struct ioq_thread *thread) { } } -#endif // BFS_USE_LIBURING +#endif // BFS_WITH_LIBURING /** Synchronous syscall loop. */ static void ioq_sync_work(struct ioq_thread *thread) { @@ -811,7 +811,7 @@ static void ioq_sync_work(struct ioq_thread *thread) { static void *ioq_work(void *ptr) { struct ioq_thread *thread = ptr; -#if BFS_USE_LIBURING +#if BFS_WITH_LIBURING if (thread->ring_err == 0) { ioq_ring_work(thread); return NULL; @@ -824,7 +824,7 @@ static void *ioq_work(void *ptr) { /** Initialize io_uring thread state. */ static int ioq_ring_init(struct ioq *ioq, struct ioq_thread *thread) { -#if BFS_USE_LIBURING +#if BFS_WITH_LIBURING struct ioq_thread *prev = NULL; if (thread > ioq->threads) { prev = thread - 1; @@ -890,7 +890,7 @@ static int ioq_ring_init(struct ioq *ioq, struct ioq_thread *thread) { /** Destroy an io_uring. */ static void ioq_ring_exit(struct ioq_thread *thread) { -#if BFS_USE_LIBURING +#if BFS_WITH_LIBURING if (thread->ring_err == 0) { io_uring_queue_exit(&thread->ring); } @@ -926,7 +926,7 @@ struct ioq *ioq_create(size_t depth, size_t nthreads) { ioq->depth = depth; ARENA_INIT(&ioq->ents, struct ioq_ent); -#if BFS_USE_LIBURING && BFS_USE_STATX +#if BFS_WITH_LIBURING && BFS_USE_STATX ARENA_INIT(&ioq->xbufs, struct statx); #endif @@ -1036,7 +1036,7 @@ int ioq_stat(struct ioq *ioq, int dfd, const char *path, enum bfs_stat_flags fla args->flags = flags; args->buf = buf; -#if BFS_USE_LIBURING && BFS_USE_STATX +#if BFS_WITH_LIBURING && BFS_USE_STATX args->xbuf = arena_alloc(&ioq->xbufs); if (!args->xbuf) { ioq_free(ioq, ent); @@ -1060,7 +1060,7 @@ void ioq_free(struct ioq *ioq, struct ioq_ent *ent) { bfs_assert(ioq->size > 0); --ioq->size; -#if BFS_USE_LIBURING && BFS_USE_STATX +#if BFS_WITH_LIBURING && BFS_USE_STATX if (ent->op == IOQ_STAT && ent->stat.xbuf) { arena_free(&ioq->xbufs, ent->stat.xbuf); } @@ -1091,7 +1091,7 @@ void ioq_destroy(struct ioq *ioq) { ioqq_destroy(ioq->ready); ioqq_destroy(ioq->pending); -#if BFS_USE_LIBURING && BFS_USE_STATX +#if BFS_WITH_LIBURING && BFS_USE_STATX arena_destroy(&ioq->xbufs); #endif arena_destroy(&ioq->ents); diff --git a/src/parse.c b/src/parse.c index 5dd85de..539aa05 100644 --- a/src/parse.c +++ b/src/parse.c @@ -2258,7 +2258,7 @@ static struct bfs_expr *parse_regextype(struct bfs_parser *parser, int arg1, int parser->regex_type = BFS_REGEX_POSIX_BASIC; } else if (strcmp(type, "posix-extended") == 0) { parser->regex_type = BFS_REGEX_POSIX_EXTENDED; -#if BFS_USE_ONIGURUMA +#if BFS_WITH_ONIGURUMA } else if (strcmp(type, "emacs") == 0) { parser->regex_type = BFS_REGEX_EMACS; } else if (strcmp(type, "grep") == 0) { @@ -2280,7 +2280,7 @@ list_types: cfprintf(cfile, " ${bld}posix-basic${rs}: POSIX basic regular expressions (BRE)\n"); cfprintf(cfile, " ${bld}posix-extended${rs}: POSIX extended regular expressions (ERE)\n"); cfprintf(cfile, " ${bld}ed${rs}: Like ${grn}ed${rs} (same as ${bld}posix-basic${rs})\n"); -#if BFS_USE_ONIGURUMA +#if BFS_WITH_ONIGURUMA cfprintf(cfile, " ${bld}emacs${rs}: Like ${grn}emacs${rs}\n"); cfprintf(cfile, " ${bld}grep${rs}: Like ${grn}grep${rs}\n"); #endif diff --git a/src/xregex.c b/src/xregex.c index c2711bc..484f099 100644 --- a/src/xregex.c +++ b/src/xregex.c @@ -13,7 +13,7 @@ #include #include -#if BFS_USE_ONIGURUMA +#if BFS_WITH_ONIGURUMA # include # include #else @@ -21,7 +21,7 @@ #endif struct bfs_regex { -#if BFS_USE_ONIGURUMA +#if BFS_WITH_ONIGURUMA unsigned char *pattern; OnigRegex impl; int err; @@ -32,7 +32,7 @@ struct bfs_regex { #endif }; -#if BFS_USE_ONIGURUMA +#if BFS_WITH_ONIGURUMA static int bfs_onig_status; static OnigEncoding bfs_onig_enc; @@ -121,7 +121,7 @@ int bfs_regcomp(struct bfs_regex **preg, const char *pattern, enum bfs_regex_typ return -1; } -#if BFS_USE_ONIGURUMA +#if BFS_WITH_ONIGURUMA // onig_error_code_to_str() says // // don't call this after the pattern argument of onig_new() is freed @@ -204,7 +204,7 @@ fail: int bfs_regexec(struct bfs_regex *regex, const char *str, enum bfs_regexec_flags flags) { size_t len = strlen(str); -#if BFS_USE_ONIGURUMA +#if BFS_WITH_ONIGURUMA const unsigned char *ustr = (const unsigned char *)str; const unsigned char *end = ustr + len; @@ -263,7 +263,7 @@ int bfs_regexec(struct bfs_regex *regex, const char *str, enum bfs_regexec_flags void bfs_regfree(struct bfs_regex *regex) { if (regex) { -#if BFS_USE_ONIGURUMA +#if BFS_WITH_ONIGURUMA onig_free(regex->impl); free(regex->pattern); #else @@ -278,7 +278,7 @@ char *bfs_regerror(const struct bfs_regex *regex) { return strdup(xstrerror(ENOMEM)); } -#if BFS_USE_ONIGURUMA +#if BFS_WITH_ONIGURUMA unsigned char *str = malloc(ONIG_MAX_ERROR_MESSAGE_LEN); if (str) { onig_error_code_to_str(str, regex->err, ®ex->einfo); -- cgit v1.2.3