From 34e133bd0e2d5bb4eed5d5091d14d9e6fce1ff2b Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 29 May 2024 13:19:20 -0400 Subject: Embed more configuration info in bfs --version --- Makefile | 12 +++++------- build/embed.sh | 12 ++++++++++++ build/header.mk | 5 +++++ build/prelude.mk | 2 +- configure | 3 +++ src/main.c | 1 + src/parse.c | 11 ++++++++++- src/prelude.h | 6 ++++++ src/version.c | 28 ++++++++++++++++++++++++++++ 9 files changed, 71 insertions(+), 9 deletions(-) create mode 100755 build/embed.sh create mode 100644 src/version.c diff --git a/Makefile b/Makefile index e256ac7..2679c85 100644 --- a/Makefile +++ b/Makefile @@ -66,22 +66,20 @@ ${OBJS}: gen/config.mk ${MSG} "[ CC ] ${CSRC}" ${CC} ${_CPPFLAGS} ${_CFLAGS} -c ${CSRC} -o $@ # Save the version number to this file, but only update version.c if it changes -gen/version.c.new:: +gen/version.i.new:: @${MKDIR} ${@D} - @printf 'const char bfs_version[] = "' >$@ @if [ "$$VERSION" ]; then \ printf '%s' "$$VERSION"; \ elif test -e src/../.git && command -v git >/dev/null 2>&1; then \ git -C src/.. describe --always --dirty; \ else \ echo "3.3.1"; \ - fi | tr -d '\n' >>$@ - @printf '";\n' >>$@ + fi | tr -d '\n' | build/embed.sh >$@ -gen/version.c: gen/version.c.new - @test -e $@ && cmp -s $@ ${.ALLSRC} && rm ${.ALLSRC} || mv ${.ALLSRC} $@ +gen/version.i: gen/version.i.new + @test -e $@ && cmp -s $@ ${.ALLSRC} && ${RM} ${.ALLSRC} || mv ${.ALLSRC} $@ -obj/gen/version.o: gen/version.c +obj/src/version.o: gen/version.i ## Test phase (`make check`) diff --git a/build/embed.sh b/build/embed.sh new file mode 100755 index 0000000..8d7d0f1 --- /dev/null +++ b/build/embed.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# Copyright © Tavian Barnes +# SPDX-License-Identifier: 0BSD + +# Convert data into a C array like #embed + +set -eu + +{ cat; printf '\0'; } \ + | od -An -tx1 \ + | sed 's/\([^ ][^ ]*\)/0x\1,/g' diff --git a/build/header.mk b/build/header.mk index 76e9562..8b28346 100644 --- a/build/header.mk +++ b/build/header.mk @@ -63,6 +63,11 @@ gen/config.h: ${PKG_HEADERS} ${HEADERS} @printf '#endif // BFS_CONFIG_H\n' >>$@ @cat ${.ALLSRC:%=%.log} >gen/config.log ${VCAT} $@ + @printf '%s' "$$CONFIG" | build/embed.sh >gen/config.i + @printf '%s' "$$XCPPFLAGS" | build/embed.sh >gen/cppflags.i + @printf '%s' "$$XCFLAGS" | build/embed.sh >gen/cflags.i + @printf '%s' "$$XLDFLAGS" | build/embed.sh >gen/ldflags.i + @printf '%s' "$$XLDLIBS" | build/embed.sh >gen/ldlibs.i .PHONY: gen/config.h # The short name of the config test diff --git a/build/prelude.mk b/build/prelude.mk index 38e432c..76fbce8 100644 --- a/build/prelude.mk +++ b/build/prelude.mk @@ -97,10 +97,10 @@ LIBBFS := \ 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 \ - obj/gen/version.o # Unit test objects UNIT_OBJS := \ diff --git a/configure b/configure index 60d7a92..40eb313 100755 --- a/configure +++ b/configure @@ -7,6 +7,9 @@ set -eu +# Save the ./configure command line for bfs --version +export CONFIG="$0 $*" + # Default to `make` MAKE="${MAKE:-make}" diff --git a/src/main.c b/src/main.c index 5dd88e4..6f23034 100644 --- a/src/main.c +++ b/src/main.c @@ -41,6 +41,7 @@ * - thread.h (multi-threading) * - trie.[ch] (a trie set/map implementation) * - typo.[ch] (fuzzy matching for typos) + * - version.c (embeds version information) * - xregex.[ch] (regular expression support) * - xspawn.[ch] (spawns processes) * - xtime.[ch] (date/time handling utilities) diff --git a/src/parse.c b/src/parse.c index 8e454e4..a626391 100644 --- a/src/parse.c +++ b/src/parse.c @@ -2958,7 +2958,16 @@ static struct bfs_expr *parse_help(struct bfs_parser *parser, int arg1, int arg2 static struct bfs_expr *parse_version(struct bfs_parser *parser, int arg1, int arg2) { cfprintf(parser->ctx->cout, "${ex}%s${rs} ${bld}%s${rs}\n\n", BFS_COMMAND, bfs_version); - printf("%s\n", BFS_HOMEPAGE); + printf("Copyright © Tavian Barnes and the bfs contributors\n"); + printf("No rights reserved (https://opensource.org/license/0BSD)\n\n"); + + printf("CONFIG := %s\n", bfs_config); + printf("CPPFLAGS := %s\n", bfs_cppflags); + printf("CFLAGS := %s\n", bfs_cflags); + printf("LDFLAGS := %s\n", bfs_ldflags); + printf("LDLIBS := %s\n", bfs_ldlibs); + + printf("\n%s\n", BFS_HOMEPAGE); parser->just_info = true; return NULL; diff --git a/src/prelude.h b/src/prelude.h index 0944df1..faa84ec 100644 --- a/src/prelude.h +++ b/src/prelude.h @@ -40,6 +40,12 @@ // when the version number changes extern const char bfs_version[]; +extern const char bfs_config[]; +extern const char bfs_cppflags[]; +extern const char bfs_cflags[]; +extern const char bfs_ldflags[]; +extern const char bfs_ldlibs[]; + // Check for system headers #ifdef __has_include diff --git a/src/version.c b/src/version.c new file mode 100644 index 0000000..e2d4c87 --- /dev/null +++ b/src/version.c @@ -0,0 +1,28 @@ +// Copyright © Tavian Barnes +// SPDX-License-Identifier: 0BSD + +#include "prelude.h" + +const char bfs_version[] = { +#include "version.i" +}; + +const char bfs_config[] = { +#include "config.i" +}; + +const char bfs_cppflags[] = { +#include "cppflags.i" +}; + +const char bfs_cflags[] = { +#include "cflags.i" +}; + +const char bfs_ldflags[] = { +#include "ldflags.i" +}; + +const char bfs_ldlibs[] = { +#include "ldlibs.i" +}; -- cgit v1.2.3