#!/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 git_head=$(git --git-dir "${src_top_dir}" rev-parse --verify HEAD 2>/dev/null) [ -z "${git_head}" ] && exit new_version="$(git --git-dir "${src_top_dir}" describe 2>/dev/null)" [ -z "${new_version}" ] && exit 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} <