version.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "${CURR_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. if [ -r "${VERSION_FILE}" ]
  54. then
  55. PREV_MC_VERSION=`sed -n 's/^#define MC_CURRENT_VERSION "\(.*\)"$/\1/p' "${VERSION_FILE}"`
  56. CURR_MC_VERSION="${PREV_MC_VERSION}"
  57. fi
  58. git_head=`git --git-dir "${src_top_dir}/.git" rev-parse --verify HEAD 2>/dev/null`
  59. [ -z "${git_head}" ] && mc_print_version
  60. # try to store sha1
  61. CURR_MC_VERSION="${git_head}"
  62. new_version=`git --git-dir "${src_top_dir}/.git" describe --always 2>/dev/null`
  63. [ -z "${new_version}" ] && mc_print_version
  64. # store pretty tagged version
  65. CURR_MC_VERSION="${new_version}"
  66. mc_print_version