2
0

get-version.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/sh
  2. #
  3. # extract version numbers from a header file
  4. #
  5. # USAGE: get-version.sh CMD VERSION_HEADER PREFIX
  6. # where CMD is one of: all, major, libtool
  7. # where PREFIX is the prefix to {MAJOR|MINOR|PATCH}_VERSION defines
  8. #
  9. # get-version.sh all returns a dotted version number
  10. # get-version.sh major returns just the major version number
  11. # get-version.sh libtool returns a version "libtool -version-info" format
  12. #
  13. if test $# != 3; then
  14. echo "USAGE: $0 CMD VERSION_HEADER PREFIX"
  15. echo " where CMD is one of: all, major, libtool"
  16. exit 1
  17. fi
  18. major_sed="/#define.*$3_MAJOR_VERSION/s/^[^0-9]*\([0-9]*\).*$/\1/p"
  19. minor_sed="/#define.*$3_MINOR_VERSION/s/^[^0-9]*\([0-9]*\).*$/\1/p"
  20. patch_sed="/#define.*$3_PATCH_VERSION/s/^[^0-9]*\([0-9]*\).*$/\1/p"
  21. major="`sed -n $major_sed $2`"
  22. minor="`sed -n $minor_sed $2`"
  23. patch="`sed -n $patch_sed $2`"
  24. if test "$1" = "all"; then
  25. echo ${major}.${minor}.${patch}
  26. elif test "$1" = "major"; then
  27. echo ${major}
  28. elif test "$1" = "libtool"; then
  29. # Yes, ${minor}:${patch}:${minor} is correct due to libtool idiocy.
  30. echo ${minor}:${patch}:${minor}
  31. else
  32. echo "ERROR: unknown version CMD ($1)"
  33. exit 1
  34. fi