From c13d4bf616bbe682a59358a037a10cb1acb21419 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Thu, 29 Oct 2026 15:43:47 -1000 Subject: Fold the version script into its make recipe gen-version.sh was only ever run by this one recipe, so tools/ now holds just the scripts a person runs. --- source/cgit.mk | 25 +++++++++++++++++-------- tools/gen-version.sh | 28 ---------------------------- 2 files changed, 17 insertions(+), 36 deletions(-) delete mode 100755 tools/gen-version.sh diff --git a/source/cgit.mk b/source/cgit.mk index a4b9758..d0c9e68 100644 --- a/source/cgit.mk +++ b/source/cgit.mk @@ -9,13 +9,11 @@ # ../../build. include Makefile -# TOOLSDIR and BUILDDIR are named relative to the project root because the -# version recipe changes into the root before using them. CGIT_SRC and -# CGIT_BUILD lead to the sources and the output from vendor/git, where -# everything else here runs. +# BUILDDIR is named relative to the project root because the version recipe +# changes into the root before using it. CGIT_SRC and CGIT_BUILD lead to the +# sources and the output from vendor/git, where everything else here runs. CGIT_ROOT = ../.. SRCDIR = source -TOOLSDIR = tools BUILDDIR = build CGIT_SRC = $(CGIT_ROOT)/$(SRCDIR) CGIT_BUILD = $(CGIT_ROOT)/$(BUILDDIR) @@ -24,11 +22,22 @@ CGIT_BUILD = $(CGIT_ROOT)/$(BUILDDIR) # Makefile exports, which leaves out the build options this file reads. -include $(CGIT_ROOT)/cgit.conf -# The CGIT_ values used below are exported by the top level Makefile. +# The CGIT_ values used below are exported by the top level Makefile. git +# describe names the version when it runs at the top of the cgit working tree, +# rather than in the bundled git, and CGIT_VERSION stands in for a tarball or +# a clone with no tags. The file is left alone when its line is unchanged, +# since everything that includes it would otherwise rebuild. $(CGIT_BUILD)/VERSION: force-version @mkdir -p $(CGIT_BUILD)/ - @cd $(CGIT_ROOT) && \ - '$(SHELL_PATH_SQ)' $(TOOLSDIR)/gen-version.sh "$(CGIT_VERSION)" $(BUILDDIR)/VERSION + @cd $(CGIT_ROOT) && version='$(CGIT_VERSION)' && \ + if test "$$(git rev-parse --git-dir 2>/dev/null)" = .git && \ + described=$$(git describe --abbrev=4 HEAD 2>/dev/null); then \ + version=$$described; \ + fi && \ + line="CGIT_VERSION = $$version" && \ + if test "$$(cat $(BUILDDIR)/VERSION 2>/dev/null)" != "$$line"; then \ + echo "$$line" >$(BUILDDIR)/VERSION && echo "$$line"; \ + fi -include $(CGIT_BUILD)/VERSION .PHONY: force-version diff --git a/tools/gen-version.sh b/tools/gen-version.sh deleted file mode 100755 index ca8ea65..0000000 --- a/tools/gen-version.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -# Writes a "CGIT_VERSION = ..." line into the output file, which the build -# then includes. Run it from the project root, as gen-version.sh -# [output], so that git describe reports cgit rather than the bundled git -# submodule. The output file defaults to VERSION. - -version=$1 -output=${2:-VERSION} - -# Prefer what git describe reports, but only at the top of the cgit working -# tree, and keep the fallback when it has nothing to say, as in a shallow or -# tagless clone. -if test "$(git rev-parse --git-dir 2>/dev/null)" = '.git' -then - described=$(git describe --abbrev=4 HEAD 2>/dev/null) - test -n "$described" && version=$described -fi - -new="CGIT_VERSION = $version" -old=$(cat "$output" 2>/dev/null) - -# Leaving the file untouched when nothing changed keeps make from rebuilding -# everything that depends on it. -test "$old" = "$new" && exit 0 - -echo "$new" > "$output" -cat "$output" -- cgit