logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: 48068a36f4ee18e127a24574077ba17cbdd1eda9
parent 06cc72cc97b1c4f4c6a5c9301b5c562ecb9f04c4
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 21 Jan 2025 11:49:16 +0100

configure: generate config.h to properly invalidate after running ./bootstrap.sh

Diffstat:

MMakefile4++--
Mbootstrap-regen.sh2++
Mbootstrap.sh2++
Mcmd/chmod.c1+
Mcmd/chown.c1+
Mcmd/env.c2++
Mcmd/install.c1+
Mcmd/mktemp.c1+
Mcmd/rmdir.c2++
Mcmd/sync.c2++
Mcmd/wc.c1+
Mconfigure25++++++++++++++++++++-----
Mlib/fs.h2++
Mtest-cmd/env.sh4++--
Mtest-cmd/rmdir_long.t2+-
15 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile @@ -82,7 +82,7 @@ lib/sys_signame.c: lib/sys_signame.sh lib/sys_signame.sh >|lib/sys_signame.c LIBUTILS_O = ${LIBUTILS_C:.c=.o} -lib/utils.a: ${LIBUTILS_O} ${LIBUTILS_H} config.mk Makefile +lib/utils.a: ${LIBUTILS_O} ${LIBUTILS_H} config.mk config.h Makefile ${AR} rc ${ARFLAGS} lib/utils.a ${LIBUTILS_O} build/cmd/date.1: cmd/date.1.in lib/iso_parse.mdoc Makefile @@ -105,7 +105,7 @@ cmd/seq: cmd/seq.c Makefile $(CC) -std=c99 $(CFLAGS) -o $@ cmd/seq.c -lm $(LDFLAGS) $(LDSTATIC) # ./bootstrap.sh binaries should be kept simple -lib/fs.o: lib/fs.c lib/fs.h +lib/fs.o: lib/fs.c lib/fs.h config.h lib/err.o: lib/err.c lib/err.h lib/consent.o: lib/consent.c lib/consent.h lib/tr_str.o: lib/tr_str.c lib/tr_str.h diff --git a/bootstrap-regen.sh b/bootstrap-regen.sh @@ -26,6 +26,8 @@ $MAKE clean set -ex +: >config.h + ' $MAKE -n \ CC='$$CC' CFLAGS='$$CFLAGS' \ diff --git a/bootstrap.sh b/bootstrap.sh @@ -9,6 +9,8 @@ set -ex +: >config.h + $CC -std=c99 $CFLAGS -c -o lib/fs.o lib/fs.c $CC -std=c99 $CFLAGS -o cmd/cat cmd/cat.c lib/fs.o $LDFLAGS $LDSTATIC $CC -std=c99 $CFLAGS -o cmd/echo cmd/echo.c $LDFLAGS $LDSTATIC diff --git a/cmd/chmod.c b/cmd/chmod.c @@ -9,6 +9,7 @@ #define _NETBSD_SOURCE #endif +#include "../config.h" // HAS_* #include "../lib/mode.h" #include <dirent.h> // fdopendir, readdir, closedir diff --git a/cmd/chown.c b/cmd/chown.c @@ -9,6 +9,7 @@ #define _NETBSD_SOURCE #endif +#include "../config.h" // HAS_* #include "../lib/fs.h" #include "../lib/user_group_parse.h" diff --git a/cmd/env.c b/cmd/env.c @@ -5,6 +5,8 @@ #define _POSIX_C_SOURCE 200809L #define _XOPEN_SOURCE 800 // wordexp +#include "../config.h" // HAS_* + #include <assert.h> // assert #include <errno.h> // errno #include <stdbool.h> // bool, true, false diff --git a/cmd/install.c b/cmd/install.c @@ -6,6 +6,7 @@ #define _GNU_SOURCE // musl, glibc #define _DEFAULT_SOURCE // FreeBSD +#include "../config.h" // HAS_* #include "../lib/fs.h" #include "../lib/lib_mkdir.h" #include "../lib/mode.h" diff --git a/cmd/mktemp.c b/cmd/mktemp.c @@ -4,6 +4,7 @@ // getentropy got in POSIX.1-2024 but defining _POSIX_C_SOURCE causes too much side-effects #define _DEFAULT_SOURCE // getentropy +#include "../config.h" // HAS_* #include <errno.h> #include <limits.h> // PATH_MAX diff --git a/cmd/rmdir.c b/cmd/rmdir.c @@ -3,6 +3,8 @@ // SPDX-License-Identifier: MPL-2.0 #define _POSIX_C_SOURCE 200809L +#include "../config.h" // HAS_* + #include <errno.h> #include <stdbool.h> #include <stdio.h> // fprintf diff --git a/cmd/sync.c b/cmd/sync.c @@ -6,6 +6,8 @@ #define _GNU_SOURCE // syncfs #define _XOPEN_SOURCE 700 // sync +#include "../config.h" // HAS_* + #include <errno.h> #include <fcntl.h> // open, O_* #include <stdbool.h> diff --git a/cmd/wc.c b/cmd/wc.c @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MPL-2.0 #define _POSIX_C_SOURCE 200809L +#include "../config.h" // HAS_* #include "../lib/bitmasks.h" #include <ctype.h> // isspace diff --git a/configure b/configure @@ -81,6 +81,10 @@ gen_targets() { echo } +cpp_define() { + printf '#define %s\n' "$*" >> config.h +} + check_cmd() { var="$1" full_cmd="$2" @@ -165,6 +169,14 @@ for i; do esac done +printf 'Writing skeleton to config.h ...' +cat >config.h <<EOF +/* Autogenerated by ./configure */ +#ifndef UTILS_STD_CONFIG_H +#define UTILS_STD_CONFIG_H +EOF +is_ok + # Fallback definitions for dirs, based on $PREFIX BINDIR="${BINDIR:-${PREFIX}/bin}" SHELLDIR="${SHELLDIR:-${BINDIR}}" @@ -239,19 +251,19 @@ if ! check_header sys/sysmacros.h; then fi # As seen missing in Haiku beta5 <https://dev.haiku-os.org/ticket/16257> -check_header wordexp.h && CFLAGS="${CFLAGS} -DHAS_WORDEXP" +check_header wordexp.h && cpp_define HAS_WORDEXP -check_conftest configure.d/sendfile_linux.c && CFLAGS="${CFLAGS} -DHAS_SENDFILE" -check_conftest configure.d/copy_file_range.c && CFLAGS="${CFLAGS} -DHAS_COPY_FILE_RANGE" +check_conftest configure.d/sendfile_linux.c && cpp_define HAS_SENDFILE +check_conftest configure.d/copy_file_range.c && cpp_define HAS_COPY_FILE_RANGE if ! check_conftest configure.d/reallocarray.c; then echo 'Disabling cmd/tr cmd/cut' target_filter="${target_filter} -e cmd/tr. -e cmd/cut." fi -check_conftest configure.d/getopt_long.c && CFLAGS="${CFLAGS} -DHAS_GETOPT_LONG" +check_conftest configure.d/getopt_long.c && cpp_define HAS_GETOPT_LONG -check_conftest configure.d/syncfs.c && CFLAGS="${CFLAGS} -DHAS_SYNCFS" +check_conftest configure.d/syncfs.c && cpp_define HAS_SYNCFS if ! check_conftest configure.d/fgetln.c; then echo 'Disabling cmd/join' @@ -295,6 +307,9 @@ is_ok printf 'Adding targets to config.mk ...' gen_targets >> config.mk ; or_die +# Must close header guard +echo '#endif // UTILS_STD_CONFIG_H' >> config.h + echo echo 'Done, you can now run make' diff --git a/lib/fs.h b/lib/fs.h @@ -2,6 +2,8 @@ // SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> // SPDX-License-Identifier: MPL-2.0 +#include "../config.h" // HAS_* + #include <stdbool.h> #include <stddef.h> // size_t #include <stdio.h> // off_t diff --git a/test-cmd/env.sh b/test-cmd/env.sh @@ -21,7 +21,7 @@ t --exit=127 enoent '/var/empty/e/no/ent' "env: error: Failed executing '/var/em t posix_me_harder "-i FOO=BAR sh -c echo" ' ' -if grep -q HAS_WORDEXP "${WD}/config.mk"; then +if grep -q HAS_WORDEXP "${WD}/config.h"; then t_args opt_S 'foo bar baz @@ -38,7 +38,7 @@ then ' t uflag "-i FOOZ=BARZ $target -u FOOZ FOO=BAR" 'FOO=BAR ' - if grep -q HAS_GETOPT_LONG "${WD}/config.mk"; then + if grep -q HAS_GETOPT_LONG "${WD}/config.h"; then t unsetflag "-i FOOZ=BARZ $target --unset=FOOZ FOO=BAR" 'FOO=BAR ' else diff --git a/test-cmd/rmdir_long.t b/test-cmd/rmdir_long.t @@ -6,7 +6,7 @@ $ test "$(command -v rmdir)" = "$TESTDIR/../cmd/rmdir" - $ grep -q HAS_GETOPT_LONG "${TESTDIR}/../config.mk" || return 80 + $ grep -q HAS_GETOPT_LONG "${TESTDIR}/../config.h" || return 80 $ mkdir -p e_not_empty-ign/a/b/c/d empty-ign/a/b/c $ rmdir -p --ignore-fail-on-non-empty e_not_empty-ign/a/b/c empty-ign/a/b/c