get-version.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. #
  3. # USAGE: get-version.sh path/to/expat.h
  4. #
  5. # This script will print Expat's version number on stdout. For example:
  6. #
  7. # $ ./conftools/get-version.sh ./lib/expat.h
  8. # 1.95.3
  9. # $
  10. #
  11. if test $# = 0; then
  12. echo "ERROR: pathname for expat.h was not provided."
  13. echo ""
  14. echo "USAGE: $0 path/to/expat.h"
  15. exit 1
  16. fi
  17. if test $# != 1; then
  18. echo "ERROR: too many arguments were provided."
  19. echo ""
  20. echo "USAGE: $0 path/to/expat.h"
  21. exit 1
  22. fi
  23. hdr="$1"
  24. if test ! -r "$hdr"; then
  25. echo "ERROR: '$hdr' does not exist, or is not readable."
  26. exit 1
  27. fi
  28. MAJOR_VERSION="`sed -n -e '/MAJOR_VERSION/s/[^0-9]*//gp' $hdr`"
  29. MINOR_VERSION="`sed -n -e '/MINOR_VERSION/s/[^0-9]*//gp' $hdr`"
  30. MICRO_VERSION="`sed -n -e '/MICRO_VERSION/s/[^0-9]*//gp' $hdr`"
  31. # Determine how to tell echo not to print the trailing \n. This is
  32. # similar to Autoconf's @ECHO_C@ and @ECHO_N@; however, we don't
  33. # generate this file via autoconf (in fact, get-version.sh is used
  34. # to *create* ./configure), so we just do something similar inline.
  35. case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
  36. *c*,-n*) ECHO_N= ECHO_C='
  37. ' ;;
  38. *c*,* ) ECHO_N=-n ECHO_C= ;;
  39. *) ECHO_N= ECHO_C='\c' ;;
  40. esac
  41. echo $ECHO_N "$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$ECHO_C"