From: Karel Zak Date: Wed, 14 Jul 2021 13:57:00 +0000 (+0200) Subject: tools/git-version-gen: use NEWS as a fallback X-Git-Tag: v2.38-rc1~371 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90a1baf9a72454140a370a35c8dc42bd0dddac24;p=thirdparty%2Futil-linux.git tools/git-version-gen: use NEWS as a fallback * define ".tarball-version" as the default if not specified by $1 * try read the version string from NEWS file as a fallback if the git-repository or .tarball-version is not available Fixes: https://github.com/karelzak/util-linux/issues/1381 Signed-off-by: Karel Zak --- diff --git a/tools/git-version-gen b/tools/git-version-gen index b287cb7940..435f1fa741 100755 --- a/tools/git-version-gen +++ b/tools/git-version-gen @@ -3,6 +3,7 @@ scriptversion=2011-02-19.19; # UTC # Copyright (C) 2007-2011 Free Software Foundation, Inc. +# Copyright (C) 2011-2021 Karel Zak # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,10 +23,9 @@ scriptversion=2011-02-19.19; # UTC # - from a git repository in which the "git describe" command below # produces useful output (thus requiring at least one signed tag) # - from a non-git-repo directory containing a .tarball-version file, which -# presumes this script is invoked like "./git-version-gen .tarball-version". +# presumes this script is invoked like "./git-version-gen [.tarball-version]". -# In order to use intra-version strings in your project, you will need two -# separate generated version string files: +# In order to use intra-version strings in your project, you will need: # # .tarball-version - present only in a distribution tarball, and not in # a checked-out repository. Created with contents that were learned at @@ -44,6 +44,11 @@ scriptversion=2011-02-19.19; # UTC # files to pick up a version string change; and leave it stale to # minimize rebuild time after unrelated changes to configure sources. # +# NEWS - present everywhere. It's used only as a fallback solution for +# 3rd-party tarballs generated by the unofficial way (e.g. GitHub). +# The version string is read from the first line of the file, the expected +# format is "project-name version: date". +# # It is probably wise to add these two files to .gitignore, so that you # don't accidentally commit either generated file. # @@ -67,13 +72,13 @@ scriptversion=2011-02-19.19; # UTC # echo $(VERSION) > $(distdir)/.tarball-version case $# in - 1|2) ;; - *) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version" \ - '[TAG-NORMALIZATION-SED-SCRIPT]' + 0|1|2) ;; + *) echo 1>&2 "Usage: $0 [[\$srcdir/.tarball-version]" \ + '[TAG-NORMALIZATION-SED-SCRIPT]]' exit 1;; esac -tarball_version_file=$1 +tarball_version_file=${1:-".tarball-version"} tag_sed_script="${2:-s/x/x/}" nl=' ' @@ -125,7 +130,12 @@ then esac v_from_git=1 else - v=UNKNOWN + if test -f NEWS + then + v=`sed '1s/.*[[:blank:]]\(.*\):.*/\1/; q;' NEWS` + else + v=UNKNOWN + fi fi v=`echo "$v" |sed 's/^v//'`