extract_version 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #! /bin/sh
  2. set -eu
  3. ARG="${1:-}"
  4. # Source directory. In out-of-tree builds, Automake sets this for us.
  5. srcdir=${srcdir:-.}
  6. # Print usage information.
  7. usage() {
  8. cat <<EOF
  9. Print libpqxx version information based on the source tree's VERSION file.
  10. Usage: $0 [option]
  11. Version strings look like: <major>.<minor>.<revision>.
  12. Acceptable option values are:
  13. -h, --help Print this message, and exit.
  14. -a, --abi Show libpqxx ABI version; leave out revision number.
  15. -f, --full Show full libpqxx version string (the default).
  16. -M, --major Show major libpqxx version.
  17. -m, --minor Show minor libpqxx version (between major and revision).
  18. EOF
  19. }
  20. # Print "unknown argument" error.
  21. unknown_arg() {
  22. cat <<EOF >&2
  23. Unknown argument: $1.
  24. Try
  25. $0 --help
  26. for usage information.
  27. EOF
  28. }
  29. case "$ARG" in
  30. ''|-f|--full)
  31. # Default: Print full version.
  32. cat $srcdir/VERSION
  33. ;;
  34. -h|--help)
  35. # Print usage information, and exit.
  36. usage
  37. exit
  38. ;;
  39. -a|--abi)
  40. # Print just the ABI version (major & minor).
  41. sed -e 's/^\([^.]*\.[^.]*\)\..*/\1/' $srcdir/VERSION
  42. ;;
  43. -M|--major)
  44. # Print the major version number.
  45. sed -e 's/^\([^.]*\)\..*/\1/' $srcdir/VERSION
  46. ;;
  47. -m|--minor)
  48. # Print the minor version number.
  49. sed -e 's/^[^.]*\.\([^.]*\)\..*/\1/' $srcdir/VERSION
  50. ;;
  51. *)
  52. unknown_arg $ARG
  53. exit 1
  54. ;;
  55. esac