0002-add-git-version-get.patch 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. Makefile: ship also git-version-gen
  2. Without git-version-gen, the tarball autogen.sh fails.
  3. This patch is equivalent to upstream pending merge request:
  4. https://gitlab.com/psmisc/psmisc/merge_requests/13
  5. Signed-off-by: Baruch Siach <baruch@tkos.co.il>
  6. ---
  7. diff --git psmisc-23.1/misc/git-version-gen psmisc-23.1/misc/git-version-gen
  8. new file mode 100755
  9. index 000000000000..171767f0d7a3
  10. --- /dev/null
  11. +++ psmisc-23.1/misc/git-version-gen
  12. @@ -0,0 +1,181 @@
  13. +#!/bin/sh
  14. +# Print a version string.
  15. +scriptversion=2011-02-19.19; # UTC
  16. +
  17. +# Copyright (C) 2007-2011 Free Software Foundation, Inc.
  18. +#
  19. +# This program is free software: you can redistribute it and/or modify
  20. +# it under the terms of the GNU General Public License as published by
  21. +# the Free Software Foundation; either version 3 of the License, or
  22. +# (at your option) any later version.
  23. +#
  24. +# This program is distributed in the hope that it will be useful,
  25. +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. +# GNU General Public License for more details.
  28. +#
  29. +# You should have received a copy of the GNU General Public License
  30. +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. +
  32. +# This script is derived from GIT-VERSION-GEN from GIT: http://git.or.cz/.
  33. +# It may be run two ways:
  34. +# - from a git repository in which the "git describe" command below
  35. +# produces useful output (thus requiring at least one signed tag)
  36. +# - from a non-git-repo directory containing a .tarball-version file, which
  37. +# presumes this script is invoked like "./git-version-gen .tarball-version".
  38. +
  39. +# In order to use intra-version strings in your project, you will need two
  40. +# separate generated version string files:
  41. +#
  42. +# .tarball-version - present only in a distribution tarball, and not in
  43. +# a checked-out repository. Created with contents that were learned at
  44. +# the last time autoconf was run, and used by git-version-gen. Must not
  45. +# be present in either $(srcdir) or $(builddir) for git-version-gen to
  46. +# give accurate answers during normal development with a checked out tree,
  47. +# but must be present in a tarball when there is no version control system.
  48. +# Therefore, it cannot be used in any dependencies. GNUmakefile has
  49. +# hooks to force a reconfigure at distribution time to get the value
  50. +# correct, without penalizing normal development with extra reconfigures.
  51. +#
  52. +# .version - present in a checked-out repository and in a distribution
  53. +# tarball. Usable in dependencies, particularly for files that don't
  54. +# want to depend on config.h but do want to track version changes.
  55. +# Delete this file prior to any autoconf run where you want to rebuild
  56. +# files to pick up a version string change; and leave it stale to
  57. +# minimize rebuild time after unrelated changes to configure sources.
  58. +#
  59. +# It is probably wise to add these two files to .gitignore, so that you
  60. +# don't accidentally commit either generated file.
  61. +#
  62. +# Use the following line in your configure.ac, so that $(VERSION) will
  63. +# automatically be up-to-date each time configure is run (and note that
  64. +# since configure.ac no longer includes a version string, Makefile rules
  65. +# should not depend on configure.ac for version updates).
  66. +#
  67. +# AC_INIT([GNU project],
  68. +# m4_esyscmd([build-aux/git-version-gen .tarball-version]),
  69. +# [bug-project@example])
  70. +#
  71. +# Then use the following lines in your Makefile.am, so that .version
  72. +# will be present for dependencies, and so that .tarball-version will
  73. +# exist in distribution tarballs.
  74. +#
  75. +# BUILT_SOURCES = $(top_srcdir)/.version
  76. +# $(top_srcdir)/.version:
  77. +# echo $(VERSION) > $@-t && mv $@-t $@
  78. +# dist-hook:
  79. +# echo $(VERSION) > $(distdir)/.tarball-version
  80. +
  81. +case $# in
  82. + 1|2) ;;
  83. + *) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version" \
  84. + '[TAG-NORMALIZATION-SED-SCRIPT]'
  85. + exit 1;;
  86. +esac
  87. +
  88. +tarball_version_file=$1
  89. +tag_sed_script="${2:-s/x/x/}"
  90. +nl='
  91. +'
  92. +
  93. +# Avoid meddling by environment variable of the same name.
  94. +v=
  95. +v_from_git=
  96. +
  97. +# First see if there is a tarball-only version file.
  98. +# then try "git describe", then default.
  99. +if test -f $tarball_version_file
  100. +then
  101. + v=`cat $tarball_version_file` || v=
  102. + case $v in
  103. + *$nl*) v= ;; # reject multi-line output
  104. + [0-9]*) ;;
  105. + *) v= ;;
  106. + esac
  107. + test -z "$v" \
  108. + && echo "$0: WARNING: $tarball_version_file is missing or damaged" 1>&2
  109. +fi
  110. +
  111. +if test -n "$v"
  112. +then
  113. + : # use $v
  114. +# Otherwise, if there is at least one git commit involving the working
  115. +# directory, and "git describe" output looks sensible, use that to
  116. +# derive a version string.
  117. +elif test "`git log -1 --pretty=format:x . 2>&1`" = x \
  118. + && v=`git describe --abbrev=4 --match='v*' HEAD 2>/dev/null \
  119. + || git describe --abbrev=4 HEAD 2>/dev/null` \
  120. + && v=`printf '%s\n' "$v" | sed "$tag_sed_script"` \
  121. + && case $v in
  122. + v[0-9]*) ;;
  123. + *) (exit 1) ;;
  124. + esac
  125. +then
  126. + # Is this a new git that lists number of commits since the last
  127. + # tag or the previous older version that did not?
  128. + # Newer: v6.10-77-g0f8faeb
  129. + # Older: v6.10-g0f8faeb
  130. + case $v in
  131. + *-rc[0-9]) ;; # release candidate
  132. + *-*-*) : git describe is okay three part flavor ;;
  133. + *-*)
  134. + : git describe is older two part flavor
  135. + # Recreate the number of commits and rewrite such that the
  136. + # result is the same as if we were using the newer version
  137. + # of git describe.
  138. + vtag=`echo "$v" | sed 's/-.*//'`
  139. + commit_list=`git rev-list "$vtag"..HEAD 2>/dev/null` \
  140. + || { commit_list=failed;
  141. + echo "$0: WARNING: git rev-list failed" 1>&2; }
  142. + numcommits=`echo "$commit_list" | wc -l`
  143. + v=`echo "$v" | sed "s/\(.*\)-\(.*\)/\1-$numcommits-\2/"`;
  144. + test "$commit_list" = failed && v=UNKNOWN
  145. + ;;
  146. + esac
  147. +
  148. + case $v in
  149. + *-rc[0-9])
  150. + # Remove the "g" in git describe's output string, to save a byte.
  151. + v=`echo "$v" | sed 's/\(.*\)-g/\1-/'`;
  152. + ;;
  153. + *)
  154. + # Change the first '-' to a '.', so version-comparing tools work properly.
  155. + # Remove the "g" in git describe's output string, to save a byte.
  156. + v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`;
  157. + ;;
  158. + esac
  159. + v_from_git=1
  160. +else
  161. + v=UNKNOWN
  162. +fi
  163. +
  164. +v=`echo "$v" |sed 's/^v//'`
  165. +
  166. +# Test whether to append the "-dirty" suffix only if the version
  167. +# string we're using came from git. I.e., skip the test if it's "UNKNOWN"
  168. +# or if it came from .tarball-version.
  169. +if test -n "$v_from_git"; then
  170. + # Don't declare a version "dirty" merely because a time stamp has changed.
  171. + git update-index --refresh > /dev/null 2>&1
  172. +
  173. + dirty=`exec 2>/dev/null;git diff-index --name-only HEAD` || dirty=
  174. + case "$dirty" in
  175. + '') ;;
  176. + *) # Append the suffix only if there isn't one already.
  177. + case $v in
  178. + *-dirty) ;;
  179. + *) v="$v-dirty" ;;
  180. + esac ;;
  181. + esac
  182. +fi
  183. +
  184. +# Omit the trailing newline, so that m4_esyscmd can use the result directly.
  185. +echo "$v" | tr -d "$nl"
  186. +
  187. +# Local variables:
  188. +# eval: (add-hook 'write-file-hooks 'time-stamp)
  189. +# time-stamp-start: "scriptversion="
  190. +# time-stamp-format: "%:y-%02m-%02d.%02H"
  191. +# time-stamp-time-zone: "UTC"
  192. +# time-stamp-end: "; # UTC"
  193. +# End: