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