Ticket #3810: keep panelization while switching panel listing mode.
[midnight-commander.git] / maint / utils / version.sh
blob64405191f6096036d378c06427e0f88383abc216
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 exit
48 #*** main code *********************************************************
50 if [ -z "$1" ]
51 then
52 echo "usage: $0 <toplevel-source-dir>"
53 exit 1
56 src_top_dir="$1"
58 VERSION_FILE="${src_top_dir}/version.h"
59 PREV_MC_VERSION="unknown"
60 CURR_MC_VERSION="${PREV_MC_VERSION}"
62 if [ -r "${VERSION_FILE}" ]
63 then
64 PREV_MC_VERSION=`sed -n 's/^#define MC_CURRENT_VERSION "\(.*\)"$/\1/p' "${VERSION_FILE}"`
65 CURR_MC_VERSION="${PREV_MC_VERSION}"
68 git_head=`git --git-dir "${src_top_dir}/.git" rev-parse --verify HEAD 2>/dev/null`
69 [ -z "${git_head}" ] && mc_print_version
71 # try to store sha1
72 CURR_MC_VERSION="${git_head}"
74 new_version=`git --git-dir "${src_top_dir}/.git" describe --always 2>/dev/null`
75 [ -z "${new_version}" ] && mc_print_version
77 # store pretty tagged version
78 CURR_MC_VERSION="${new_version}"
79 mc_print_version