#!/usr/bin/env sh # Copyright 2007-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # Author: Michael Haubenwallner set -e versioning_done=no while [ "x$1" != x ]; do arg=$1 shift case "x${arg}" in x--version=*) echo "x${arg}" | sed -e 's,^x--version=,,' > version versioning_done=yes ;; esac done svnurl='$HeadURL$' mainversion=`grep 'AC_INIT(toolchain-prefix-wrapper,[0-9\.]*svnversion)' configure.ac | sed -e 's/.*([^,]*,\([^),]*\)\.svnversion\>.*)/\1/'` if [ "x${mainversion}" != x ]; then # configure.ac indicates to define the package-version automagically if [ "x${versioning_done}" != xyes ] && svn info >& /dev/null ; then svnversion=`svn --version 2>/dev/null | head -n 1` case ${svnversion} in *" version 1."[6-7]"."*) revisionrange="20-27" ;; *" version 1."[0-5]"."*) revisionrange="19-26" ;; *) echo "don't know how to work with ${svnversion}" >&2; exit 1 ;; esac # we are in an svn sandbox: # then we need to determine the version out of svn keyword 'HeadURL'. case "${svnurl}" in *'/trunk/'*) # is snapshot from trunk: # version is mainversion + '.' + [last-committed] svn revision svn status -v | cut -c${revisionrange} | sort -rn | { read v ; echo "${mainversion}.${v}" ;} > version versioning_done=yes ;; *'/branches/'*) # is snapshot from branch: # version is branch-number + '.' + [last-committed] svn revision ( echo -n "${svnurl}" \ | sed -e "s,-branch/bootstrap \\\$,,; s,.*/,," -e "s,^.*-,," svn status -v | cut -c${revisionrange} | sort -rn | { read v ; echo ".${v}" ;} ) > version versioning_done=yes ;; esac fi if [ "x${versioning_done}" != xyes ]; then case "${svnurl}" in *'/tags/'*) # is tag: version is tag number ( echo "${svnurl}" \ | sed -e "s,/bootstrap \\\$,,; s,.*-,," ) > version versioning_done=yes ;; *) if [ -r version ]; then # we reuse the 'version' determined during packaging from svn. versioning_done=yes fi ;; esac fi if [ "x${versioning_done}" != xyes ]; then echo "error: no 'version' file and unknown svnurl '${svnurl}'" >&2 echo "error: cannot determine package version" >&2 exit 1 fi else # configure.ac defines the version, keep 'version' empty. : > version fi set +x echo "mkdir -p build-aux" mkdir -p build-aux echo "aclocal" aclocal echo "autoheader" autoheader echo "automake --add-missing --copy --foreign" automake --add-missing --copy --foreign echo "autoconf" autoconf if [ -s version ]; then version=`cat version` eval `grep '^PACKAGE_VERSION=' configure | head -n 1` if [ "${version}" != "${PACKAGE_VERSION}" ]; then ( echo '--- configure' echo '+++ configure' grep "\<${PACKAGE_VERSION}\>" configure \ | awk '{print "@@ -1,1 +1,1 @@"; print "-" $0; print "+" $0}' \ | sed -e "s|\(^+.*\)\<${PACKAGE_VERSION}\>|\1${version}|" ) | patch --no-backup-if-mismatch configure - fi fi