summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
Diffstat (limited to 'build')
-rwxr-xr-xbuild/cc.sh30
-rw-r--r--build/config.mk15
-rwxr-xr-xbuild/define-if.sh4
-rw-r--r--build/deps.mk18
-rwxr-xr-xbuild/embed.sh2
-rwxr-xr-xbuild/flags-if.sh28
-rw-r--r--build/flags.mk68
-rw-r--r--build/flags/Wformat.c (renamed from build/has/aligned-alloc.c)5
-rw-r--r--build/flags/Wimplicit-fallthrough.c9
-rw-r--r--build/flags/Wimplicit.c9
-rw-r--r--build/flags/Wmissing-decls.c9
-rw-r--r--build/flags/Wmissing-var-decls.c9
-rw-r--r--build/flags/Wshadow.c9
-rw-r--r--build/flags/Wsign-compare.c9
-rw-r--r--build/flags/Wstrict-prototypes.c9
-rw-r--r--build/flags/Wundef-prefix.c9
-rw-r--r--build/flags/bind-now.c8
-rw-r--r--build/flags/deps.c8
-rw-r--r--build/has/_Fork.c8
-rw-r--r--build/has/io-uring-max-workers.c11
-rw-r--r--build/has/tcgetwinsize.c9
-rw-r--r--build/has/timer-create.c9
-rw-r--r--build/header.mk25
-rwxr-xr-xbuild/pkgconf.sh10
-rw-r--r--build/prelude.mk57
-rwxr-xr-xbuild/version.sh18
26 files changed, 263 insertions, 142 deletions
diff --git a/build/cc.sh b/build/cc.sh
index 45d51ca..e1d2b0b 100755
--- a/build/cc.sh
+++ b/build/cc.sh
@@ -3,14 +3,32 @@
# Copyright © Tavian Barnes <tavianator@tavianator.com>
# SPDX-License-Identifier: 0BSD
-# Run the compiler and check if it succeeded
+# Run the compiler and check if it succeeded. Usage:
+#
+# $ build/cc.sh [-q] path/to/file.c [-flags -Warnings ...]
set -eu
-TMP=$(mktemp)
-trap 'rm -f "$TMP"' EXIT
+QUIET=
+if [ "$1" = "-q" ]; then
+ QUIET=y
+ shift
+fi
-(
+# Source files can specify their own flags with lines like
+#
+# /// _CFLAGS += -Wmissing-variable-declarations
+#
+# which will be added to the makefile on success, or lines like
+#
+# /// -Werror
+#
+# which are just used for the current file.
+EXTRA_FLAGS=$(sed -n '\|^///|{s|^/// ||; s|[^=]*= ||; p;}' "$1")
+
+# Without -q, print the executed command for config.log
+if [ -z "$QUIET" ]; then
set -x
- $XCC $XCPPFLAGS $XCFLAGS $XLDFLAGS "$@" $XLDLIBS -o "$TMP"
-)
+fi
+
+$XCC $XCPPFLAGS $XCFLAGS $XLDFLAGS "$@" $EXTRA_FLAGS $XLDLIBS
diff --git a/build/config.mk b/build/config.mk
index 24873ec..6296168 100644
--- a/build/config.mk
+++ b/build/config.mk
@@ -7,21 +7,20 @@ include build/prelude.mk
include build/exports.mk
# All configuration steps
-config: gen/config.mk gen/config.h
+config: gen/config.mk
.PHONY: config
# Makefile fragments generated by `./configure`
MKS := \
gen/vars.mk \
gen/flags.mk \
- gen/deps.mk \
gen/pkgs.mk
# The main configuration file, which includes the others
-gen/config.mk: ${MKS}
+gen/config.mk: ${MKS} gen/config.h
${MSG} "[ GEN] $@"
@printf '# %s\n' "$@" >$@
- @printf 'include %s\n' ${.ALLSRC} >>$@
+ @printf 'include %s\n' ${MKS} >>$@
${VCAT} gen/config.mk
.PHONY: gen/config.mk
@@ -38,6 +37,7 @@ gen/vars.mk::
@printf 'MKDIR := %s\n' "$$XMKDIR" >>$@
@printf 'PKG_CONFIG := %s\n' "$$XPKG_CONFIG" >>$@
@printf 'RM := %s\n' "$$XRM" >>$@
+ @test -z "$$VERSION" || printf 'export VERSION=%s\n' "$$VERSION" >>$@
${VCAT} $@
# Sets the build flags. This depends on vars.mk and uses a recursive make so
@@ -46,17 +46,12 @@ gen/flags.mk: gen/vars.mk
@+XMAKEFLAGS="$$MAKEFLAGS" ${MAKE} -sf build/flags.mk $@
.PHONY: gen/flags.mk
-# Check for dependency generation support
-gen/deps.mk: gen/flags.mk
- @+XMAKEFLAGS="$$MAKEFLAGS" ${MAKE} -sf build/deps.mk $@
-.PHONY: gen/deps.mk
-
# Auto-detect dependencies and their build flags
gen/pkgs.mk: gen/flags.mk
@+XMAKEFLAGS="$$MAKEFLAGS" ${MAKE} -sf build/pkgs.mk $@
.PHONY: gen/pkgs.mk
# Compile-time feature detection
-gen/config.h: gen/config.mk
+gen/config.h: gen/pkgs.mk
@+XMAKEFLAGS="$$MAKEFLAGS" ${MAKE} -sf build/header.mk $@
.PHONY: gen/config.h
diff --git a/build/define-if.sh b/build/define-if.sh
index 295ead8..204cfa4 100755
--- a/build/define-if.sh
+++ b/build/define-if.sh
@@ -7,9 +7,7 @@
set -eu
-SLUG="${1#build/}"
-SLUG="${SLUG%.c}"
-MACRO="BFS_$(printf '%s' "$SLUG" | tr '/a-z-' '_A-Z_')"
+MACRO=$(printf 'BFS_%s' "$1" | tr '/a-z-' '_A-Z_')
shift
if "$@"; then
diff --git a/build/deps.mk b/build/deps.mk
deleted file mode 100644
index d382f5d..0000000
--- a/build/deps.mk
+++ /dev/null
@@ -1,18 +0,0 @@
-# Copyright © Tavian Barnes <tavianator@tavianator.com>
-# SPDX-License-Identifier: 0BSD
-
-# Makefile that generates gen/deps.mk
-
-include build/prelude.mk
-include gen/vars.mk
-include gen/flags.mk
-include build/exports.mk
-
-gen/deps.mk::
- ${MSG} "[ GEN] $@"
- @printf '# %s\n' "$@" >$@
- @if build/cc.sh -MD -MP -MF /dev/null build/empty.c; then \
- printf '_CPPFLAGS += -MD -MP\n'; \
- fi >>$@ 2>$@.log
- ${VCAT} $@
- @printf -- '-include %s\n' ${OBJS:.o=.d} >>$@
diff --git a/build/embed.sh b/build/embed.sh
index 8d7d0f1..c0744f6 100755
--- a/build/embed.sh
+++ b/build/embed.sh
@@ -9,4 +9,4 @@ set -eu
{ cat; printf '\0'; } \
| od -An -tx1 \
- | sed 's/\([^ ][^ ]*\)/0x\1,/g'
+ | sed 's/[^ ][^ ]*/0x&,/g'
diff --git a/build/flags-if.sh b/build/flags-if.sh
new file mode 100755
index 0000000..81eb345
--- /dev/null
+++ b/build/flags-if.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+# Copyright © Tavian Barnes <tavianator@tavianator.com>
+# SPDX-License-Identifier: 0BSD
+
+# Add flags to a makefile if a build succeeds
+
+set -eu
+
+build/cc.sh "$@" || exit 1
+
+# If the build succeeded, print any lines like
+#
+# /// _CFLAGS += -foo
+#
+# (unless they're already set)
+OLD_FLAGS="$XCC $XCPPFLAGS $XCFLAGS $XLDFLAGS $XLDLIBS"
+
+while IFS="" read -r line; do
+ case "$line" in
+ ///*=*)
+ flag="${line#*= }"
+ if [ "${OLD_FLAGS#*"$flag"}" = "$OLD_FLAGS" ]; then
+ printf '%s\n' "${line#/// }"
+ fi
+ ;;
+ esac
+done <"$1"
diff --git a/build/flags.mk b/build/flags.mk
index c50b077..2562e03 100644
--- a/build/flags.mk
+++ b/build/flags.mk
@@ -7,19 +7,7 @@ include build/prelude.mk
include gen/vars.mk
# Internal flags
-_CPPFLAGS := \
- -Isrc \
- -Igen \
- -D__EXTENSIONS__ \
- -D_ATFILE_SOURCE \
- -D_BSD_SOURCE \
- -D_DARWIN_C_SOURCE \
- -D_DEFAULT_SOURCE \
- -D_GNU_SOURCE \
- -D_POSIX_PTHREAD_SEMANTICS \
- -D_FILE_OFFSET_BITS=64 \
- -D_TIME_BITS=64
-
+_CPPFLAGS := -Isrc -Igen -include src/prelude.h
_CFLAGS := -std=c17 -pthread
_LDFLAGS :=
_LDLIBS :=
@@ -41,10 +29,6 @@ _GCOV := ${TRUTHY,${GCOV}}
_LINT := ${TRUTHY,${LINT}}
_RELEASE := ${TRUTHY,${RELEASE}}
-# https://github.com/google/sanitizers/issues/342
-TSAN_CPPFLAGS,y := -DBFS_USE_TARGET_CLONES=0
-_CPPFLAGS += ${TSAN_CPPFLAGS,${_TSAN}}
-
ASAN_CFLAGS,y := -fsanitize=address
LSAN_CFLAGS,y := -fsanitize=leak
MSAN_CFLAGS,y := -fsanitize=memory -fsanitize-memory-track-origins
@@ -83,16 +67,7 @@ _CPPFLAGS += ${RELEASE_CPPFLAGS,${_RELEASE}}
_CFLAGS += ${RELEASE_CFLAGS,${_RELEASE}}
# Configurable flags
-CFLAGS ?= \
- -g \
- -Wall \
- -Wformat=2 \
- -Werror=implicit \
- -Wimplicit-fallthrough \
- -Wmissing-declarations \
- -Wshadow \
- -Wsign-compare \
- -Wstrict-prototypes
+CFLAGS ?= -g -Wall
# Add the configurable flags last so they can override ours
_CPPFLAGS += ${CPPFLAGS} ${EXTRA_CPPFLAGS}
@@ -103,7 +78,21 @@ _LDLIBS := ${LDLIBS} ${EXTRA_LDLIBS} ${_LDLIBS}
include build/exports.mk
-gen/flags.mk::
+# Conditionally-supported flags
+AUTO_FLAGS := \
+ gen/flags/Wformat.mk \
+ gen/flags/Wimplicit-fallthrough.mk \
+ gen/flags/Wimplicit.mk \
+ gen/flags/Wmissing-decls.mk \
+ gen/flags/Wmissing-var-decls.mk \
+ gen/flags/Wshadow.mk \
+ gen/flags/Wsign-compare.mk \
+ gen/flags/Wstrict-prototypes.mk \
+ gen/flags/Wundef-prefix.mk \
+ gen/flags/bind-now.mk \
+ gen/flags/deps.mk
+
+gen/flags.mk: ${AUTO_FLAGS}
${MSG} "[ GEN] $@"
@printf '# %s\n' "$@" >$@
@printf '_CPPFLAGS := %s\n' "$$XCPPFLAGS" >>$@
@@ -112,4 +101,27 @@ gen/flags.mk::
@printf '_LDLIBS := %s\n' "$$XLDLIBS" >>$@
@printf 'NOLIBS := %s\n' "$$XNOLIBS" >>$@
@test "${OS}-${SAN}" != FreeBSD-y || printf 'POSTLINK = elfctl -e +noaslr $$@\n' >>$@
+ @cat ${.ALLSRC} >>$@
+ @cat ${.ALLSRC:%=%.log} >gen/flags.log
${VCAT} $@
+.PHONY: gen/flags.mk
+
+# Check that the C compiler works at all
+cc::
+ @build/cc.sh -q build/empty.c -o gen/.cc.out; \
+ ret=$$?; \
+ build/msg-if.sh "[ CC ] build/empty.c" test $$ret -eq 0; \
+ exit $$ret
+
+# The short name of the config test
+SLUG = ${@:gen/%.mk=%}
+# The source file to build
+CSRC = build/${SLUG}.c
+# The hidden output file name
+OUT = ${SLUG:flags/%=gen/flags/.%.out}
+
+${AUTO_FLAGS}: cc
+ @${MKDIR} ${@D}
+ @build/flags-if.sh ${CSRC} -o ${OUT} >$@ 2>$@.log; \
+ build/msg-if.sh "[ CC ] ${SLUG}.c" test $$? -eq 0
+.PHONY: ${AUTO_FLAGS}
diff --git a/build/has/aligned-alloc.c b/build/flags/Wformat.c
index 4460038..287b209 100644
--- a/build/has/aligned-alloc.c
+++ b/build/flags/Wformat.c
@@ -1,8 +1,9 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include <stdlib.h>
+/// _CFLAGS += -Wformat=2
+/// -Werror
int main(void) {
- return !aligned_alloc(_Alignof(void *), sizeof(void *));
+ return 0;
}
diff --git a/build/flags/Wimplicit-fallthrough.c b/build/flags/Wimplicit-fallthrough.c
new file mode 100644
index 0000000..c32058d
--- /dev/null
+++ b/build/flags/Wimplicit-fallthrough.c
@@ -0,0 +1,9 @@
+// Copyright © Tavian Barnes <tavianator@tavianator.com>
+// SPDX-License-Identifier: 0BSD
+
+/// _CFLAGS += -Wimplicit-fallthrough
+/// -Werror
+
+int main(void) {
+ return 0;
+}
diff --git a/build/flags/Wimplicit.c b/build/flags/Wimplicit.c
new file mode 100644
index 0000000..3ea2b90
--- /dev/null
+++ b/build/flags/Wimplicit.c
@@ -0,0 +1,9 @@
+// Copyright © Tavian Barnes <tavianator@tavianator.com>
+// SPDX-License-Identifier: 0BSD
+
+/// _CFLAGS += -Werror=implicit
+/// -Werror
+
+int main(void) {
+ return 0;
+}
diff --git a/build/flags/Wmissing-decls.c b/build/flags/Wmissing-decls.c
new file mode 100644
index 0000000..5ef3e96
--- /dev/null
+++ b/build/flags/Wmissing-decls.c
@@ -0,0 +1,9 @@
+// Copyright © Tavian Barnes <tavianator@tavianator.com>
+// SPDX-License-Identifier: 0BSD
+
+/// _CFLAGS += -Wmissing-declarations
+/// -Werror
+
+int main(void) {
+ return 0;
+}
diff --git a/build/flags/Wmissing-var-decls.c b/build/flags/Wmissing-var-decls.c
new file mode 100644
index 0000000..5c20cc6
--- /dev/null
+++ b/build/flags/Wmissing-var-decls.c
@@ -0,0 +1,9 @@
+// Copyright © Tavian Barnes <tavianator@tavianator.com>
+// SPDX-License-Identifier: 0BSD
+
+/// _CFLAGS += -Wmissing-variable-declarations
+/// -Werror
+
+int main(void) {
+ return 0;
+}
diff --git a/build/flags/Wshadow.c b/build/flags/Wshadow.c
new file mode 100644
index 0000000..28f6ef3
--- /dev/null
+++ b/build/flags/Wshadow.c
@@ -0,0 +1,9 @@
+// Copyright © Tavian Barnes <tavianator@tavianator.com>
+// SPDX-License-Identifier: 0BSD
+
+/// _CFLAGS += -Wshadow
+/// -Werror
+
+int main(void) {
+ return 0;
+}
diff --git a/build/flags/Wsign-compare.c b/build/flags/Wsign-compare.c
new file mode 100644
index 0000000..f083083
--- /dev/null
+++ b/build/flags/Wsign-compare.c
@@ -0,0 +1,9 @@
+// Copyright © Tavian Barnes <tavianator@tavianator.com>
+// SPDX-License-Identifier: 0BSD
+
+/// _CFLAGS += -Wsign-compare
+/// -Werror
+
+int main(void) {
+ return 0;
+}
diff --git a/build/flags/Wstrict-prototypes.c b/build/flags/Wstrict-prototypes.c
new file mode 100644
index 0000000..9614bee
--- /dev/null
+++ b/build/flags/Wstrict-prototypes.c
@@ -0,0 +1,9 @@
+// Copyright © Tavian Barnes <tavianator@tavianator.com>
+// SPDX-License-Identifier: 0BSD
+
+/// _CFLAGS += -Wstrict-prototypes
+/// -Werror
+
+int main(void) {
+ return 0;
+}
diff --git a/build/flags/Wundef-prefix.c b/build/flags/Wundef-prefix.c
new file mode 100644
index 0000000..3eaf82b
--- /dev/null
+++ b/build/flags/Wundef-prefix.c
@@ -0,0 +1,9 @@
+// Copyright © Tavian Barnes <tavianator@tavianator.com>
+// SPDX-License-Identifier: 0BSD
+
+/// _CPPFLAGS += -Wundef-prefix=BFS_
+/// -Werror
+
+int main(void) {
+ return 0;
+}
diff --git a/build/flags/bind-now.c b/build/flags/bind-now.c
new file mode 100644
index 0000000..08bb4f2
--- /dev/null
+++ b/build/flags/bind-now.c
@@ -0,0 +1,8 @@
+// Copyright © Tavian Barnes <tavianator@tavianator.com>
+// SPDX-License-Identifier: 0BSD
+
+/// _LDFLAGS += -Wl,-z,now
+
+int main(void) {
+ return 0;
+}
diff --git a/build/flags/deps.c b/build/flags/deps.c
new file mode 100644
index 0000000..1c8c309
--- /dev/null
+++ b/build/flags/deps.c
@@ -0,0 +1,8 @@
+// Copyright © Tavian Barnes <tavianator@tavianator.com>
+// SPDX-License-Identifier: 0BSD
+
+/// _CPPFLAGS += -MD -MP
+
+int main(void) {
+ return 0;
+}
diff --git a/build/has/_Fork.c b/build/has/_Fork.c
new file mode 100644
index 0000000..4d7fbd3
--- /dev/null
+++ b/build/has/_Fork.c
@@ -0,0 +1,8 @@
+// Copyright © Tavian Barnes <tavianator@tavianator.com>
+// SPDX-License-Identifier: 0BSD
+
+#include <unistd.h>
+
+int main(void) {
+ return _Fork();
+}
diff --git a/build/has/io-uring-max-workers.c b/build/has/io-uring-max-workers.c
new file mode 100644
index 0000000..34ab5b7
--- /dev/null
+++ b/build/has/io-uring-max-workers.c
@@ -0,0 +1,11 @@
+// Copyright © Tavian Barnes <tavianator@tavianator.com>
+// SPDX-License-Identifier: 0BSD
+
+#include <liburing.h>
+
+int main(void) {
+ struct io_uring ring;
+ io_uring_queue_init(1, &ring, 0);
+ unsigned int values[] = {0, 0};
+ return io_uring_register_iowq_max_workers(&ring, values);
+}
diff --git a/build/has/tcgetwinsize.c b/build/has/tcgetwinsize.c
new file mode 100644
index 0000000..d25d12b
--- /dev/null
+++ b/build/has/tcgetwinsize.c
@@ -0,0 +1,9 @@
+// Copyright © Tavian Barnes <tavianator@tavianator.com>
+// SPDX-License-Identifier: 0BSD
+
+#include <termios.h>
+
+int main(void) {
+ struct winsize ws;
+ return tcgetwinsize(0, &ws);
+}
diff --git a/build/has/timer-create.c b/build/has/timer-create.c
new file mode 100644
index 0000000..d5354c3
--- /dev/null
+++ b/build/has/timer-create.c
@@ -0,0 +1,9 @@
+// Copyright © Tavian Barnes <tavianator@tavianator.com>
+// SPDX-License-Identifier: 0BSD
+
+#include <time.h>
+
+int main(void) {
+ timer_t timer;
+ return timer_create(CLOCK_REALTIME, NULL, &timer);
+}
diff --git a/build/header.mk b/build/header.mk
index 632afb6..f940e52 100644
--- a/build/header.mk
+++ b/build/header.mk
@@ -4,18 +4,20 @@
# Makefile that generates gen/config.h
include build/prelude.mk
-include gen/config.mk
+include gen/vars.mk
+include gen/flags.mk
+include gen/pkgs.mk
include build/exports.mk
# All header fragments we generate
HEADERS := \
gen/has/--st-birthtim.h \
+ gen/has/_Fork.h \
gen/has/acl-get-entry.h \
gen/has/acl-get-file.h \
gen/has/acl-get-tag-type.h \
gen/has/acl-is-trivial-np.h \
gen/has/acl-trivial.h \
- gen/has/aligned-alloc.h \
gen/has/builtin-riscv-pause.h \
gen/has/confstr.h \
gen/has/extattr-get-file.h \
@@ -31,6 +33,7 @@ HEADERS := \
gen/has/getmntinfo.h \
gen/has/getprogname-gnu.h \
gen/has/getprogname.h \
+ gen/has/io-uring-max-workers.h \
gen/has/pipe2.h \
gen/has/posix-getdents.h \
gen/has/posix-spawn-addfchdir-np.h \
@@ -47,7 +50,9 @@ HEADERS := \
gen/has/strerror-r-posix.h \
gen/has/string-to-flags.h \
gen/has/strtofflags.h \
+ gen/has/tcgetwinsize.h \
gen/has/timegm.h \
+ gen/has/timer-create.h \
gen/has/tm-gmtoff.h \
gen/has/uselocale.h
@@ -61,7 +66,7 @@ gen/config.h: ${PKG_HEADERS} ${HEADERS}
@printf '#define BFS_CONFIG_H\n' >>$@
@cat ${.ALLSRC} >>$@
@printf '#endif // BFS_CONFIG_H\n' >>$@
- @cat gen/cc.log ${.ALLSRC:%=%.log} >gen/config.log
+ @cat gen/flags.log ${.ALLSRC:%=%.log} >gen/config.log
${VCAT} $@
@printf '%s' "$$CONFFLAGS" | build/embed.sh >gen/confflags.i
@printf '%s' "$$XCC" | build/embed.sh >gen/cc.i
@@ -73,16 +78,10 @@ gen/config.h: ${PKG_HEADERS} ${HEADERS}
# The short name of the config test
SLUG = ${@:gen/%.h=%}
+# The hidden output file name
+OUT = ${SLUG:has/%=gen/has/.%.out}
-${HEADERS}: cc
+${HEADERS}::
@${MKDIR} ${@D}
- @build/define-if.sh ${SLUG} build/cc.sh build/${SLUG}.c >$@ 2>$@.log; \
+ @build/define-if.sh ${SLUG} build/cc.sh build/${SLUG}.c -o ${OUT} >$@ 2>$@.log; \
build/msg-if.sh "[ CC ] ${SLUG}.c" test $$? -eq 0
-.PHONY: ${HEADERS}
-
-# Check that the C compiler works at all
-cc::
- @build/cc.sh build/empty.c 2>gen/cc.log; \
- ret=$$?; \
- build/msg-if.sh "[ CC ] build/empty.c" test $$ret -eq 0; \
- exit $$ret
diff --git a/build/pkgconf.sh b/build/pkgconf.sh
index 244c95d..decf706 100755
--- a/build/pkgconf.sh
+++ b/build/pkgconf.sh
@@ -34,10 +34,10 @@ if [ -z "$MODE" ]; then
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/with/$LIB.c $LDLIBS || exit 1
+ XCFLAGS="$XCFLAGS $("$0" --cflags "$LIB")" || exit 1
+ XLDFLAGS="$XLDFLAGS $("$0" --ldflags "$LIB")" || exit 1
+ XLDLIBS="$("$0" --ldlibs "$LIB") $XLDLIBS" || exit 1
+ build/cc.sh "build/with/$LIB.c" -o "gen/with/.$LIB.out" || exit 1
done
fi
@@ -92,5 +92,5 @@ done
case "$MODE" in
--ldlibs)
printf '%s\n' "$LDLIBS"
- ;;
+ ;;
esac
diff --git a/build/prelude.mk b/build/prelude.mk
index 76fbce8..c25dea4 100644
--- a/build/prelude.mk
+++ b/build/prelude.mk
@@ -37,7 +37,7 @@ RM ?= rm -f
# VAR=1 ${TRUTHY,${VAR}} => ${TRUTHY,1} => y
# VAR=n ${TRUTHY,${VAR}} => ${TRUTHY,n} => [empty]
# VAR=other ${TRUTHY,${VAR}} => ${TRUTHY,other} => [empty]
-# VAR= ${TRUTHY,${VAR}} => ${TRUTHY,} => [emtpy]
+# VAR= ${TRUTHY,${VAR}} => ${TRUTHY,} => [empty]
#
# Inspired by https://github.com/wahern/autoguess
TRUTHY,y := y
@@ -68,58 +68,3 @@ ALL_PKGS := \
libselinux \
liburing \
oniguruma
-
-# List all object files here, as they're needed by both `./configure` and `make`
-
-# All object files except the entry point
-LIBBFS := \
- obj/src/alloc.o \
- obj/src/bar.o \
- obj/src/bfstd.o \
- obj/src/bftw.o \
- obj/src/color.o \
- obj/src/ctx.o \
- obj/src/diag.o \
- obj/src/dir.o \
- obj/src/dstring.o \
- obj/src/eval.o \
- obj/src/exec.o \
- obj/src/expr.o \
- obj/src/fsade.o \
- obj/src/ioq.o \
- obj/src/mtab.o \
- obj/src/opt.o \
- obj/src/parse.o \
- obj/src/printf.o \
- obj/src/pwcache.o \
- obj/src/sighook.o \
- obj/src/stat.o \
- obj/src/thread.o \
- obj/src/trie.o \
- obj/src/typo.o \
- obj/src/version.o \
- obj/src/xregex.o \
- obj/src/xspawn.o \
- obj/src/xtime.o \
-
-# Unit test objects
-UNIT_OBJS := \
- obj/tests/alloc.o \
- obj/tests/bfstd.o \
- obj/tests/bit.o \
- obj/tests/ioq.o \
- obj/tests/list.o \
- obj/tests/main.o \
- obj/tests/sighook.o \
- obj/tests/trie.o \
- obj/tests/xspawn.o \
- obj/tests/xtime.o
-
-# All object files
-OBJS := \
- obj/src/main.o \
- obj/tests/mksock.o \
- obj/tests/xspawnee.o \
- obj/tests/xtouch.o \
- ${LIBBFS} \
- ${UNIT_OBJS}
diff --git a/build/version.sh b/build/version.sh
new file mode 100755
index 0000000..ba5447f
--- /dev/null
+++ b/build/version.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+# Copyright © Tavian Barnes <tavianator@tavianator.com>
+# SPDX-License-Identifier: 0BSD
+
+# Print the version number
+
+set -eu
+
+DIR="$(dirname -- "$0")/.."
+
+if [ "${VERSION-}" ]; then
+ printf '%s' "$VERSION"
+elif [ -e "$DIR/.git" ] && command -v git >/dev/null 2>&1; then
+ git -C "$DIR" describe --always --dirty
+else
+ echo "4.0.4"
+fi