# ${R_HOME}/tools/GETVERSION

TOOLS_DIR=`echo ${0} | sed 's%/[^/][^/]*$%%'`
(
  maj=`sed 's/\([^ .]*\).\([^ ]*\) *\(.*\)/\1/' < ${TOOLS_DIR}/../VERSION`
  min=`sed 's/\([^ .]*\).\([^ ]*\) *\(.*\)/\2/' < ${TOOLS_DIR}/../VERSION`
  rev=`sed 's/\([^ .]*\).\([^ ]*\) *\(.*\)/\3/' < ${TOOLS_DIR}/../VERSION`
  nick=`cat ${TOOLS_DIR}/../VERSION-NICK`
  pl=`echo ${min} | sed 's/\..*//'`
  sl=`echo ${min} | sed 's/.*\.//'`
  ver=`expr ${maj} \\* 65536 + ${pl} \\* 256 + ${sl}`
  if test -f ../../SVN-REVISION ; then
    dat=`sed  -e 1d -e 's/^Last Changed Date: //' ../../SVN-REVISION`
    y=`echo ${dat} | cut -d- -f1`
    m=`echo ${dat} | cut -d- -f2`
    d=`echo ${dat} | cut -d- -f3`
    y1=`expr ${y} - 2000`
    svn_rev=`sed -n -e 's/^Revision: //' -e '1p' < ../../SVN-REVISION`
  else
    y=2006
    m=01
    d=01
    y1=6
    svn_rev=unknown
  fi
  echo "/* Rversion.h.  Generated automatically. */"
  echo "#ifndef R_VERSION_H"
  echo "#define R_VERSION_H"
  echo
  echo '#ifdef __cplusplus'
  echo 'extern "C" {'
  echo '#endif'
  echo
  echo "#define R_VERSION ${ver}"
  echo "#define R_NICK \"${nick}\""
  echo "#define R_Version(v,p,s) (((v) * 65536) + ((p) * 256) + (s))"
  echo "#define R_MAJOR  \"${maj}\""
  echo "#define R_MINOR  \"${min}\""
  echo "#define R_STATUS \"${rev}\""
  echo "#define R_YEAR   \"${y}\""
  echo "#define R_MONTH  \"${m}\""
  echo "#define R_DAY    \"${d}\""
  echo "#define R_SVN_REVISION \"${svn_rev}\""
## Using 1-digit year stops problems with leading zeros
#  echo "#define R_FILEVERSION    ${maj},${pl}${sl},${y1}${m}${d},0"
  echo "#define R_FILEVERSION    ${maj},${pl}${sl},${svn_rev},0"
  echo
  echo '#ifdef __cplusplus'
  echo '}'
  echo '#endif'
  echo
  echo "#endif /* not R_VERSION_H */")
    
