]> Lady’s Gitweb - CGirls/blob - sh/gen-version.sh
Build testing infrastructure
[CGirls] / sh / gen-version.sh
1 #!/bin/sh
2 # SPDX-FileCopyrightText: 2007 Lars Hjemli <hjemli@gmail.com>
3 # SPDX-FileCopyrightText: 2014 Fabien C <t74jgwb88tli9ch@jetable.org>
4 # SPDX-FileCopyrightText: 2025 Lady <https://www.ladys.computer/about/#lady>
5 # SPDX-License-Identifier: GPL-2.0-only
6
7 # This script is based on the one used by `cgit´ (<https://git.zx2c4.com/cgit/tree/gen-version.sh>) as of commit e8cacb5981039e7e74921659ea50e287395ed411.
8 # It writes a line like `CGIRLS_VERSION := {VERSION}´ to a file, which can be included in a make·file to set the `CGIRLS_VERSION´ variable.
9 # The argument gives the file to write.
10 V="$(cat GNUmakefile | sed '/^CGIRLS_VERSION[ :=]/!d;s/^[^=]*= *//')"
11 F="$1"
12
13 # Use `git describe´ to get current version if we¦re inside a git repo.
14 if test "$(git rev-parse --git-dir 2>/dev/null)" = '.git'
15 then
16 V=$(git describe HEAD 2>>/dev/null || git rev-parse --short=7 HEAD 2>>/dev/null || :)
17 fi
18
19 # Make the build directory if it does not exist.
20 if test '!' -d "$(dirname $F)"
21 then
22 mkdir -p "$(dirname $F)"
23 touch $F
24 fi
25
26 new="CGIRLS_VERSION := $V"
27 old="$(cat $F 2>/dev/null)"
28
29 # Exit if version is up·to·date.
30 if test "$old" = "$new"
31 then
32 printf '%s\n' "$old"
33 exit 0
34 fi
35
36 # Update version with new version info.
37 printf '%s\n' "$new" | tee $F
This page took 0.323224 seconds and 5 git commands to generate.