diff options
-rw-r--r-- | build/header.mk | 2 | ||||
-rwxr-xr-x | build/msg-if.sh | 4 | ||||
-rwxr-xr-x | build/pkgconf.sh | 18 | ||||
-rw-r--r-- | build/pkgs.mk | 10 | ||||
-rw-r--r-- | build/with/libacl.c (renamed from build/use/libacl.c) | 0 | ||||
-rw-r--r-- | build/with/libcap.c (renamed from build/use/libcap.c) | 0 | ||||
-rw-r--r-- | build/with/libselinux.c (renamed from build/use/libselinux.c) | 0 | ||||
-rw-r--r-- | build/with/liburing.c (renamed from build/use/liburing.c) | 0 | ||||
-rw-r--r-- | build/with/oniguruma.c (renamed from build/use/oniguruma.c) | 0 | ||||
-rwxr-xr-x | configure | 111 | ||||
-rw-r--r-- | docs/BUILDING.md | 14 | ||||
-rw-r--r-- | src/bftw.c | 2 | ||||
-rw-r--r-- | src/fsade.h | 4 | ||||
-rw-r--r-- | src/ioq.c | 26 | ||||
-rw-r--r-- | src/parse.c | 4 | ||||
-rw-r--r-- | src/xregex.c | 14 |
16 files changed, 128 insertions, 81 deletions
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/with/libacl.c index de1fe50..de1fe50 100644 --- a/build/use/libacl.c +++ b/build/with/libacl.c diff --git a/build/use/libcap.c b/build/with/libcap.c index 58e832c..58e832c 100644 --- a/build/use/libcap.c +++ b/build/with/libcap.c diff --git a/build/use/libselinux.c b/build/with/libselinux.c index bca409d..bca409d 100644 --- a/build/use/libselinux.c +++ b/build/with/libselinux.c diff --git a/build/use/liburing.c b/build/with/liburing.c index bea499a..bea499a 100644 --- a/build/use/liburing.c +++ b/build/with/liburing.c diff --git a/build/use/oniguruma.c b/build/with/oniguruma.c index cb17596..cb17596 100644 --- a/build/use/oniguruma.c +++ b/build/with/oniguruma.c @@ -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 <<EOF Usage: - \$ $0 [--enable-*|--disable-*] [CC=...] [CFLAGS=...] [...] + \$ $0 [--enable-*|--disable-*] [--with-*|--without-*] [CC=...] [...] \$ $MAKE $j Variables set in the environment or on the command line will be picked up: @@ -53,14 +110,14 @@ The default flags result in a plain debug build. Other build profiles include: --enable-gcov Enable code coverage instrumentation -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 Packaging: @@ -78,46 +135,42 @@ EOF ;; --enable-*|--disable-*) - case "$arg" in - --enable-*) yn=y ;; - --disable-*) yn=n ;; + case "$name" in + release|asan|lsan|msan|tsan|ubsan|lint|gcov) + shift + set -- "$@" "$NAME=$yn" + ;; + *) + invalid "$arg" + ;; esac + ;; - name="${arg#--*able-}" - NAME=$(printf '%s' "$name" | tr 'a-z-' 'A-Z_') + --with-*|--without-*) case "$name" in libacl|libcap|libselinux|liburing|oniguruma) shift - set -- "$@" "USE_$NAME=$yn" - ;; - release|asan|lsan|msan|tsan|ubsan|lint|gcov) - shift - set -- "$@" "$NAME=$yn" + set -- "$@" "WITH_$NAME=$yn" ;; *) - printf 'error: Unrecognized option "%s"\n\n' "$arg" >&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: <pre> ---enable-<a href="https://savannah.nongnu.org/projects/acl">libacl</a> --disable-libacl ---enable-<a href="https://sites.google.com/site/fullycapable/">libcap</a> --disable-libcap ---enable-<a href="https://github.com/SELinuxProject/selinux">libselinux</a> --disable-libselinux ---enable-<a href="https://github.com/axboe/liburing">liburing</a> --disable-liburing ---enable-<a href="https://github.com/kkos/oniguruma">oniguruma</a> --disable-oniguruma +--with-<a href="https://savannah.nongnu.org/projects/acl">libacl</a> --without-libacl +--with-<a href="https://sites.google.com/site/fullycapable/">libcap</a> --without-libcap +--with-<a href="https://github.com/SELinuxProject/selinux">libselinux</a> --without-libselinux +--with-<a href="https://github.com/axboe/liburing">liburing</a> --without-liburing +--with-<a href="https://github.com/kkos/oniguruma">oniguruma</a> --without-oniguruma </pre> [`pkg-config`] is used, if available, to detect these libraries and any additional build flags they may require. @@ -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) @@ -135,7 +135,7 @@ #include <stdlib.h> #include <sys/stat.h> -#if BFS_USE_LIBURING +#if BFS_WITH_LIBURING # include <liburing.h> #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 <stdlib.h> #include <string.h> -#if BFS_USE_ONIGURUMA +#if BFS_WITH_ONIGURUMA # include <langinfo.h> # include <oniguruma.h> #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); |