You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

46 lines
1.2 KiB

  1. #!/bin/sh
  2. set -e
  3. default_version=${1}
  4. src_dir=${2}
  5. out_file=${3}
  6. # echo "default version: ${default_version}"
  7. # echo "source directory: ${src_dir}"
  8. # echo "output file: ${out_file}"
  9. if [ -d "${src_dir}/.git" ] && command -v git > /dev/null; then
  10. workdir=$(pwd)
  11. cd "${src_dir}"
  12. git_version=$(git describe --always --tags)
  13. git_branch=$(git rev-parse --abbrev-ref HEAD)
  14. cd "${workdir}"
  15. new_version="${git_version} ($(env LC_TIME=C date "+%b %d %Y"), branch '${git_branch}')"
  16. else
  17. new_version="${default_version}"
  18. fi
  19. major=$(echo "${new_version}" | sed -r 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1/')
  20. minor=$(echo "${new_version}" | sed -r 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\2/')
  21. patch=$(echo "${new_version}" | sed -r 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\3/')
  22. new_version="#define FOOT_VERSION \"${new_version}\"
  23. #define FOOT_MAJOR ${major}
  24. #define FOOT_MINOR ${minor}
  25. #define FOOT_PATCH ${patch}"
  26. if [ -f "${out_file}" ]; then
  27. old_version=$(cat "${out_file}")
  28. else
  29. old_version=""
  30. fi
  31. # echo "old version: ${old_version}"
  32. # echo "new version: ${new_version}"
  33. if [ "${old_version}" != "${new_version}" ]; then
  34. echo "${new_version}" > "${out_file}"
  35. fi