version.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. if [ -z "$1" ]
  3. then
  4. echo "usage: $0 <toplevel-source-dir>"
  5. exit 1
  6. fi
  7. src_top_dir="$1"
  8. VERSION_FILE="${src_top_dir}/version.h"
  9. PREV_MC_VERSION="unknown"
  10. CURR_MC_VERSION="${PREV_MC_VERSION}"
  11. if [ -r "${VERSION_FILE}" ]
  12. then
  13. PREV_MC_VERSION=`sed -n 's/^#define MC_CURRENT_VERSION "\(.*\)"$/\1/p' "${VERSION_FILE}"`
  14. CURR_MC_VERSION="${PREV_MC_VERSION}"
  15. fi
  16. mc_print_version(){
  17. if [ ! -f "${VERSION_FILE}" \
  18. -o "${PREV_MC_VERSION}" != "${CURR_MC_VERSION}" ]
  19. then
  20. cat >"${VERSION_FILE}" <<EOF
  21. #ifndef MC_CURRENT_VERSION
  22. /* This is an autogenerated file. Don't edit! */
  23. #define MC_CURRENT_VERSION "${CURR_MC_VERSION}"
  24. #endif
  25. EOF
  26. fi
  27. exit
  28. }
  29. git_head=`git --git-dir "${src_top_dir}/.git" rev-parse --verify HEAD 2>/dev/null`
  30. [ -z "${git_head}" ] && mc_print_version
  31. # try to store sha1
  32. CURR_MC_VERSION="${git_head}"
  33. new_version=`git --git-dir "${src_top_dir}/.git" describe 2>/dev/null`
  34. [ -z "${new_version}" ] && mc_print_version
  35. # store pretty tagged version
  36. CURR_MC_VERSION="${new_version}"
  37. mc_print_version