mc/maint/version.sh

45 lines
986 B
Bash
Raw Normal View History

#!/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}/.git" rev-parse --verify HEAD 2>/dev/null)
[ -z "${git_head}" ] && exit
new_version="$(git --git-dir "${src_top_dir}/.git" describe 2>/dev/null)"
[ -z "${new_version}" ] && exit
saved_version=
[ -r ${VERSION_FILE} ] && {
saved_version=$(sed -rn 's/^#define MC_CURRENT_VERSION "(.*)"$/\1/p' ${VERSION_FILE})
}
[ -z "${saved_version}" -o "${saved_version}" != "${new_version}" ] && {
cat >${VERSION_FILE} <<EOF
#ifndef MC_CURRENT_VERSION
/* This is an autogenerated file. Don't edit! */
#define MC_CURRENT_VERSION "${new_version}"
#endif
EOF
}
exit 0