showrev.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. #
  3. # Print the current source revision, if available
  4. SDL_ROOT=$(dirname $0)/..
  5. cd $SDL_ROOT
  6. if [ -e ./VERSION.txt ]; then
  7. cat ./VERSION.txt
  8. exit 0
  9. fi
  10. major=$(sed -ne 's/^#define SDL_MAJOR_VERSION *//p' include/SDL3/SDL_version.h)
  11. minor=$(sed -ne 's/^#define SDL_MINOR_VERSION *//p' include/SDL3/SDL_version.h)
  12. micro=$(sed -ne 's/^#define SDL_MICRO_VERSION *//p' include/SDL3/SDL_version.h)
  13. version="${major}.${minor}.${micro}"
  14. if [ -x "$(command -v git)" ]; then
  15. rev="$(git describe --tags --long 2>/dev/null)"
  16. if [ -n "$rev" ]; then
  17. # e.g. release-2.24.0-542-g96361fc47
  18. # or release-2.24.1-5-g36b987dab
  19. # or prerelease-2.23.2-0-gcb46e1b3f
  20. echo "$rev"
  21. exit 0
  22. fi
  23. rev="$(git describe --always --tags --long 2>/dev/null)"
  24. if [ -n "$rev" ]; then
  25. # Just a truncated sha1, e.g. 96361fc47.
  26. # Turn it into e.g. 2.25.0-g96361fc47
  27. echo "${version}-g${rev}"
  28. exit 0
  29. fi
  30. fi
  31. if [ -x "$(command -v p4)" ]; then
  32. rev="$(p4 changes -m1 ./...\#have 2>/dev/null| awk '{print $2}')"
  33. if [ $? = 0 ]; then
  34. # e.g. 2.25.0-p7511446
  35. echo "${version}-p${rev}"
  36. exit 0
  37. fi
  38. fi
  39. # best we can do
  40. echo "${version}-no-vcs"
  41. exit 0