version.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/sh
  2. # Midnight Commander - calculate current version
  3. #
  4. # Copyright (C) 2009, 2010, 2013
  5. # The Free Software Foundation, Inc.
  6. #
  7. # Written by:
  8. # Slava Zanko <slavazanko@gmail.com>, 2009, 2010, 2013
  9. # Stan. S. Krupoderov <pashelper@gmail.com>, 2009
  10. # Sergei Trofimovich <slyfox@inbox.ru>, 2009
  11. # Oswald Buddenhagen <ossi@kde.org>, 2009
  12. #
  13. # This file is part of the Midnight Commander.
  14. #
  15. # The Midnight Commander is free software: you can redistribute it
  16. # and/or modify it under the terms of the GNU General Public License as
  17. # published by the Free Software Foundation, either version 3 of the License,
  18. # or (at your option) any later version.
  19. #
  20. # The Midnight Commander is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. # GNU General Public License for more details.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. #*** include section (source functions, for example) *******************
  28. #*** file scope functions **********************************************
  29. mc_print_version(){
  30. if [ ! -f "${VERSION_FILE}" \
  31. -o "${PREV_MC_VERSION}" != "${CURR_MC_VERSION}" ]
  32. then
  33. cat >"${VERSION_FILE}" <<EOF
  34. #ifndef MC_CURRENT_VERSION
  35. /* This is an autogenerated file. Don't edit! */
  36. #define MC_CURRENT_VERSION "${CURR_MC_VERSION}"
  37. #endif
  38. EOF
  39. fi
  40. echo "${SHOR_MC_VERSION}"
  41. exit
  42. }
  43. #*** main code *********************************************************
  44. if [ -z "$1" ]
  45. then
  46. echo "usage: $0 <toplevel-source-dir>"
  47. exit 1
  48. fi
  49. src_top_dir="$1"
  50. VERSION_FILE="${src_top_dir}/mc-version.h"
  51. PREV_MC_VERSION="unknown"
  52. CURR_MC_VERSION="${PREV_MC_VERSION}"
  53. SHOR_MC_VERSION="${PREV_MC_VERSION}"
  54. if [ -r "${VERSION_FILE}" ]
  55. then
  56. PREV_MC_VERSION=`${SED-sed} -n 's/^#define MC_CURRENT_VERSION "\(.*\)"$/\1/p' "${VERSION_FILE}"`
  57. CURR_MC_VERSION="${PREV_MC_VERSION}"
  58. SHOR_MC_VERSION="${PREV_MC_VERSION}"
  59. fi
  60. git_head=`git --git-dir "${src_top_dir}/.git" rev-parse --verify HEAD 2>/dev/null`
  61. [ -z "${git_head}" ] && mc_print_version
  62. # try to store sha1
  63. CURR_MC_VERSION="${git_head}"
  64. SHOR_MC_VERSION="${CURR_MC_VERSION}"
  65. new_version=`git --git-dir "${src_top_dir}/.git" describe --always 2>/dev/null`
  66. [ -z "${new_version}" ] && mc_print_version
  67. # store pretty tagged version
  68. CURR_MC_VERSION="${new_version}"
  69. SHOR_MC_VERSION="${CURR_MC_VERSION}"
  70. # stop full rebuild by using not-exact git version string in config.h, see #2252, #4266
  71. SHOR_MC_VERSION=`git --git-dir "${src_top_dir}/.git" describe --always --abbrev=0 2>/dev/null`-git
  72. mc_print_version