version.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. exit
  41. }
  42. #*** main code *********************************************************
  43. if [ -z "$1" ]
  44. then
  45. echo "usage: $0 <toplevel-source-dir>"
  46. exit 1
  47. fi
  48. src_top_dir="$1"
  49. VERSION_FILE="${src_top_dir}/version.h"
  50. PREV_MC_VERSION="unknown"
  51. CURR_MC_VERSION="${PREV_MC_VERSION}"
  52. if [ -r "${VERSION_FILE}" ]
  53. then
  54. PREV_MC_VERSION=`sed -n 's/^#define MC_CURRENT_VERSION "\(.*\)"$/\1/p' "${VERSION_FILE}"`
  55. CURR_MC_VERSION="${PREV_MC_VERSION}"
  56. fi
  57. git_head=`git --git-dir "${src_top_dir}/.git" rev-parse --verify HEAD 2>/dev/null`
  58. [ -z "${git_head}" ] && mc_print_version
  59. # try to store sha1
  60. CURR_MC_VERSION="${git_head}"
  61. new_version=`git --git-dir "${src_top_dir}/.git" describe 2>/dev/null`
  62. [ -z "${new_version}" ] && mc_print_version
  63. # store pretty tagged version
  64. CURR_MC_VERSION="${new_version}"
  65. mc_print_version