diff --git a/.gitignore b/.gitignore index a66c59cde..67a20db8d 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ tmpout debug Doxyfile mc.kdevelop +version.h diff --git a/Makefile.am b/Makefile.am index faae10219..73c15d572 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,4 @@ ## Process this file with automake to create Makefile.in. - AUTOMAKE_OPTIONS = 1.5 SUBDIRS = intl po vfs edit src doc syntax contrib misc @@ -8,5 +7,19 @@ EXTRA_DIST = dist_noinst_SCRIPTS = build-glib2.sh +dist_noinst_HEADERS = $(top_srcdir)/version.h + ACLOCAL_AMFLAGS = -I m4 +CONFIG_STATUS_DEPENDENCIES = $(top_srcdir)/version.h + +.PHONY: update-version + +update-version: + @if test -x $(top_srcdir)/maint/version.sh; then \ + $(top_srcdir)/maint/version.sh "$(top_srcdir)" 2>&1 >/dev/null; \ + else \ + echo "File not found: $(top_srcdir)/maint/version.sh"; \ + fi + +$(top_srcdir)/version.h: update-version diff --git a/acinclude.m4 b/acinclude.m4 index 99807716e..146e17237 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -6,3 +6,4 @@ m4_include([m4.include/mc-use-termcap.m4]) m4_include([m4.include/mc-with-screen.m4]) m4_include([m4.include/ac-g-module-supported.m4]) m4_include([m4.include/mc-vfs.m4]) +m4_include([m4.include/mc-version.m4]) diff --git a/configure.ac b/configure.ac index 5431470d6..8ff82701e 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,8 @@ AC_PREREQ(2.60) m4_pattern_forbid(MC_) AC_CONFIG_SRCDIR(src/main.c) AC_CONFIG_AUX_DIR(config) -AM_INIT_AUTOMAKE(mc, 4.6.2) +MC_VERSION +AM_INIT_AUTOMAKE(mc, ${VERSION} ) AM_CONFIG_HEADER(config.h) AM_MAINTAINER_MODE @@ -531,7 +532,7 @@ dnl Libraries used only when building the mc binary AC_SUBST(MCLIBS) dnl Version for the RedHat package, without dashes -RPM_VERSION=`echo $VERSION | sed 's/-//g'` +RPM_VERSION=`echo $VERSION | sed 's/-/./g'` AC_SUBST(RPM_VERSION) if test -n "$use_smbfs"; then diff --git a/m4.include/mc-version.m4 b/m4.include/mc-version.m4 new file mode 100644 index 000000000..73815b1a5 --- /dev/null +++ b/m4.include/mc-version.m4 @@ -0,0 +1,20 @@ +dnl @synopsis MC_VERSION +dnl +dnl get current version of Midnight Commander from git tags +dnl +dnl @author Slava Zanko +dnl @version 2009-06-02 +dnl @license GPL +dnl @copyright Free Software Foundation, Inc. + +AC_DEFUN([MC_VERSION],[ + if test ! -f ${srcdir}/version.h; then + ${srcdir}/maint/version.sh ${srcdir} + fi + if test -f ${srcdir}/version.h; then + VERSION=$(cat ${srcdir}/version.h| grep '^#define MC_CURRENT_VERSION'| sed -r 's/.*"(.*)"$/\1/') + else + VERSION="unknown" + fi + AC_SUBST(VERSION) +]) diff --git a/maint/version.sh b/maint/version.sh new file mode 100755 index 000000000..4df9489b4 --- /dev/null +++ b/maint/version.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +git --version &>/dev/null || exit + +curr_dir=$(pwd) + +src_top_dir= +[ -d ${curr_dir}/.git ] && { + src_top_dir=${curr_dir} +} || { + curr_dir=$(dirname ${curr_dir}) + [ -d ${curr_dir}/.git ] && { + src_top_dir=${curr_dir} + } || { + [ -z "$1" ] && exit + src_top_dir=$1 + } +} +[ -z "${src_top_dir}" ] && exit + + +VERSION_FILE=${src_top_dir}/version.h + +pushd ${src_top_dir} &>/dev/null +git_head=$(git rev-parse --verify HEAD 2>/dev/null) +[ -z "${git_head}" ] && exit + +new_version="$(git describe 2>/dev/null)" +[ -z "${new_version}" ] && exit +popd &>/dev/null + + +saved_version= +[ -r ${VERSION_FILE} ] && { + saved_version=$(grep '^#define MC_CURRENT_VERSION' ${VERSION_FILE}| sed -r 's/.*"(.*)"$/\1/') +} + +[ -z "${saved_version}" -o "${saved_version}" != "${new_version}" ] && { + cat >${VERSION_FILE} <