commit: fa9cdab9fbaca679e8d35e007dc3746f2771ccd9
parent 5715c3daa058561d7abf8b486e743b149736bc85
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 18 Dec 2025 18:12:02 +0100
configure: adjust to avoid grep/sed/tr dependency
Now all the commands required for ./configure are present
and always available.
Diffstat:
3 files changed, 48 insertions(+), 33 deletions(-)
diff --git a/Makefile b/Makefile
@@ -7,6 +7,7 @@ include config.mk
SCRIPTS=
# Commands linking to another executable
SYMLINKS=cmd/'[' cmd/chgrp cmd/readlink cmd/uuencode
+MAN1 += cmd/readlink.1 cmd/uuencode.1
RM=rm
diff --git a/bootstrap.mk b/bootstrap.mk
@@ -10,7 +10,6 @@ CC ?= cc
# Can be checked with:
# $ strace -o configure.strace -f -e execve ./configure
# $ grep -F -e 'execve(' configure.strace | cut -f2 -d '"' | xargs -n1 basename | sort -u
-#all: cmd/cat cmd/echo cmd/grep cmd/printf cmd/rm cmd/sed cmd/test cmd/tr
all: cmd/cat cmd/echo cmd/printf cmd/rm cmd/test cmd/tr
@./cmd/printf '%s\n' 'Done, you should now be able to run PATH=cmd/:$$PATH ./configure && make clean && make'
diff --git a/configure b/configure
@@ -2,8 +2,6 @@
# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
# SPDX-License-Identifier: MPL-2.0
-target_filter='-e cmd/expr.tab'
-
usage() {
cat <<END
Usage: [variables] configure [variables]
@@ -56,19 +54,20 @@ or_die() {
}
gen_targets() {
- printf 'EXE = '
- printf '%s\n ' cmd/*.c cmd/*.y | grep -v -F ${target_filter} | sed -e 's;\.c$;;' -e 's;\.y$;;' | tr -d '\n'
+ printf 'EXE ='
+ printf ' cmd/%s' ${commands}
echo
- printf 'MAN1SO = '
- printf '%s\n' cmd/*.1.in \
- | grep -v -F ${target_filter} \
- | sed -e 's;\.in$;;' -e 's;^cmd/;build/cmd/;' \
- | tr '\n' ' '
+ printf 'MAN1SO ='
+ for cmd in ${commands}; do
+ test -f "cmd/${cmd}.1.in" && printf ' %s' "build/cmd/${cmd}.1"
+ done
echo
- printf 'MAN1 = ${MAN1SO} '
- printf '%s\n ' cmd/*.1 | grep -v -F ${target_filter} | tr -d '\n'
+ printf 'MAN1 = ${MAN1SO}'
+ for cmd in ${commands}; do
+ test -f "cmd/${cmd}.1.in" || printf ' %s' "cmd/${cmd}.1"
+ done
echo
printf 'LIBUTILS_C = '
@@ -124,6 +123,11 @@ check_cflag() {
is_ok
}
+add_commands() {
+ echo "Adding commands: $*"
+ commands="${commands} $*"
+}
+
set -o pipefail
## User configuration
@@ -139,6 +143,21 @@ M4="${M4:-m4}"
MANDOC="${MANDOC:-mandoc}"
CRAM="${CRAM:-cram}"
+# when there's 3+ commands starting with the same letter, put them on a new line
+commands="
+ arch base64 basename
+ cat chmod chown chroot cksum cmp date dirname
+ echo env expr false getconf head id install link logname
+ mesg mkdir mkfifo mktemp mv
+ nice nohup nproc
+ paste pathchk printf pwd
+ realpath renice rm rmdir
+ seq sha1sum sha256sum sha512sum shuf sleep split strings sync
+ tee test time timeout touch true truncate tty
+ uname uniq unlink
+ wc which whoami yes
+"
+
# Also allow variables through arguments
for i; do
case "$i" in
@@ -151,7 +170,7 @@ for i; do
usage
exit 1
;;
- *=*)
+ [A-Z]*=*)
# shellcheck disable=SC2163
export "$i"
shift
@@ -235,15 +254,10 @@ done
echo
-if ! check_header mntent.h; then
- echo 'Disabling cmd/df'
- target_filter="${target_filter} -e cmd/df"
-fi
+check_header mntent.h
+has_mntent_h=$?
-if ! check_header sys/sysmacros.h; then
- echo 'Disabling cmd/mknod'
- target_filter="${target_filter} -e cmd/mknod"
-fi
+check_header sys/sysmacros.h && add_commands mknod
# As seen missing in Haiku beta5 <https://dev.haiku-os.org/ticket/16257>
check_header wordexp.h && cpp_define HAS_WORDEXP
@@ -251,27 +265,21 @@ check_header wordexp.h && cpp_define HAS_WORDEXP
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/df cmd/tr cmd/cut cmd/join'
- target_filter="${target_filter} -e cmd/df. -e cmd/tr. -e cmd/cut. -e cmd/join."
-fi
+check_conftest configure.d/reallocarray.c
+has_reallocarray=$?
+test 0 -eq $has_reallocarray && add_commands tr cut
check_conftest configure.d/getopt_long.c && cpp_define HAS_GETOPT_LONG
check_conftest configure.d/syncfs.c && cpp_define HAS_SYNCFS
-if ! check_conftest configure.d/fgetln.c; then
- echo 'Disabling cmd/join'
- target_filter="${target_filter} -e cmd/join."
-fi
+check_conftest configure.d/fgetln.c
+has_fgetln=$?
check_conftest configure.d/mkstemps.c && cpp_define HAS_MKSTEMPS
check_conftest configure.d/mkdtemps.c && cpp_define HAS_MKDTEMPS
-if ! check_conftest configure.d/o_path.c; then
- echo 'Disabling cmd/ln'
- target_filter="${target_filter} -e cmd/ln."
-fi
+check_conftest configure.d/o_path.c && add_commands ln
# OpenBSD lacks posix_fadvise
check_conftest configure.d/posix_fadvise.c || cpp_define 'posix_fadvise(fd, off, len, adv) 0'
@@ -280,6 +288,13 @@ rm -f configure.d/*.bin
echo
+if test 0 -eq $has_reallocarray; then
+ test 0 -eq $has_mntent_h && add_commands df
+ test 0 -eq $has_fgetln && add_commands join
+fi
+
+echo
+
## Configuration write
printf 'Writing to config.mk ...'