
#
# this script writes a build tag into file buildtag.hh
#
PACKAGE_NAME=$1
PACKAGE_VERSION=$2

SVNINFO=`svnversion`

ARCHIVE_SVNINFO=`svn info Archive.cc | grep "Last Changed Rev" \
                                     | awk -F : '{print $2;}'`
CONFIGURE_OPTS="unknown ./configure options (no config.status)"
if [ -x ../config.status ]
then
    CONFIGURE_OPTS=`../config.status -V | \
                    grep "with options" | \
                    awk -F\" '{print $2;}'`
    if [ "$CONFIGURE_OPTS" == "" ]
    then
        CONFIGURE_OPTS="default ./configure options"
    fi
fi

if [ -n "$SOURCE_DATE_EPOCH" ]
then
    BUILD_DATE=`date -u "+%F %R:%S %Z" --date=@$SOURCE_DATE_EPOCH`
    BUILD_OS=""
else
    BUILD_DATE=`date -u "+%F %R:%S %Z"`
    BUILD_OS=`uname -s -r -m`
fi

BUILD_TAG="\" / $SVNINFO\", \"$BUILD_DATE\", \"$BUILD_OS\", \"$CONFIGURE_OPTS\""

# write buildtag.hh
#
echo "#include \"Common.hh\""                                     > buildtag.hh
echo "#define BUILDTAG PACKAGE_NAME, PACKAGE_VERSION $BUILD_TAG" >> buildtag.hh
echo "#define ARCHIVE_SVN \"$ARCHIVE_SVNINFO\""                  >> buildtag.hh

# write makefile.h
#
echo "// some strings exported from Makefile"             > makefile.h
echo "//"                                                >> makefile.h
echo "#define Makefile__bindir     \"$bindir\""          >> makefile.h
echo "#define Makefile__docdir     \"$docdir\""          >> makefile.h
echo "#define Makefile__sysconfdir \"$sysconfdir\""      >> makefile.h
echo "#define Makefile__pkglibdir  \"$libdir/$PACKAGE\n" >> makefile.h
echo "#define Makefile__localedir  \"$localedir\""       >> makefile.h
echo "#define Makefile__srcdir     \"$abs_srcdir\""      >> makefile.h
echo                                                     >> makefile.h

