rosfran@253: # a silly hack that generates autoregen.sh but it's handy
rosfran@253: echo "#!/bin/sh" > autoregen.sh
rosfran@253: echo "./autogen.sh $@ \$@" >> autoregen.sh
rosfran@253: chmod +x autoregen.sh
rosfran@253: 
rosfran@253: # helper functions for autogen.sh
rosfran@253: 
rosfran@253: debug ()
rosfran@253: # print out a debug message if DEBUG is a defined variable
rosfran@253: {
rosfran@253:   if test ! -z "$DEBUG"
rosfran@253:   then
rosfran@253:     echo "DEBUG: $1"
rosfran@253:   fi
rosfran@253: }
rosfran@253: 
rosfran@253: version_check ()
rosfran@253: # check the version of a package
rosfran@253: # first argument : package name (executable)
rosfran@253: # second argument : optional path where to look for it instead
rosfran@253: # third argument : source download url
rosfran@253: # rest of arguments : major, minor, micro version
rosfran@253: # all consecutive ones : suggestions for binaries to use
rosfran@253: # (if not specified in second argument)
rosfran@253: {
rosfran@253:   PACKAGE=$1
rosfran@253:   PKG_PATH=$2
rosfran@253:   URL=$3
rosfran@253:   MAJOR=$4
rosfran@253:   MINOR=$5
rosfran@253:   MICRO=$6
rosfran@253: 
rosfran@253:   # for backwards compatibility, we let PKG_PATH=PACKAGE when PKG_PATH null
rosfran@253:   if test -z "$PKG_PATH"; then PKG_PATH=$PACKAGE; fi
rosfran@253:   debug "major $MAJOR minor $MINOR micro $MICRO"
rosfran@253:   VERSION=$MAJOR
rosfran@253:   if test ! -z "$MINOR"; then VERSION=$VERSION.$MINOR; else MINOR=0; fi
rosfran@253:   if test ! -z "$MICRO"; then VERSION=$VERSION.$MICRO; else MICRO=0; fi
rosfran@253: 
rosfran@253:   debug "major $MAJOR minor $MINOR micro $MICRO"
rosfran@253:   
rosfran@253:   for SUGGESTION in $PKG_PATH; do 
rosfran@253:     COMMAND="$SUGGESTION"
rosfran@253: 
rosfran@253:     # don't check if asked not to
rosfran@253:     test -z "$NOCHECK" && {
rosfran@253:       echo -n "  checking for $COMMAND >= $VERSION ... "
rosfran@253:     } || {
rosfran@253:       # we set a var with the same name as the package, but stripped of
rosfran@253:       # unwanted chars
rosfran@253:       VAR=`echo $PACKAGE | sed 's/-//g'`
rosfran@253:       debug "setting $VAR"
rosfran@253:       eval $VAR="$COMMAND"
rosfran@253:       return 0
rosfran@253:     }
rosfran@253: 
rosfran@253:     debug "checking version with $COMMAND"
rosfran@253:     ($COMMAND --version) < /dev/null > /dev/null 2>&1 || 
rosfran@253:     {
rosfran@253:       echo "not found."
rosfran@253:       continue
rosfran@253:     }
rosfran@253:     # strip everything that's not a digit, then use cut to get the first field
rosfran@253:     pkg_version=`$COMMAND --version|head -n 1|sed 's/^[^0-9]*//'|cut -d' ' -f1`
rosfran@253:     debug "pkg_version $pkg_version"
rosfran@253:     # remove any non-digit characters from the version numbers to permit numeric
rosfran@253:     # comparison
rosfran@253:     pkg_major=`echo $pkg_version | cut -d. -f1 | sed s/[a-zA-Z\-].*//g`
rosfran@253:     pkg_minor=`echo $pkg_version | cut -d. -f2 | sed s/[a-zA-Z\-].*//g`
rosfran@253:     pkg_micro=`echo $pkg_version | cut -d. -f3 | sed s/[a-zA-Z\-].*//g`
rosfran@253:     test -z "$pkg_major" && pkg_major=0
rosfran@253:     test -z "$pkg_minor" && pkg_minor=0
rosfran@253:     test -z "$pkg_micro" && pkg_micro=0
rosfran@253:     debug "found major $pkg_major minor $pkg_minor micro $pkg_micro"
rosfran@253: 
rosfran@253:     #start checking the version
rosfran@253:     debug "version check"
rosfran@253: 
rosfran@253:     # reset check
rosfran@253:     WRONG=
rosfran@253: 
rosfran@253:     if [ ! "$pkg_major" -gt "$MAJOR" ]; then
rosfran@253:       debug "major: $pkg_major <= $MAJOR"
rosfran@253:       if [ "$pkg_major" -lt "$MAJOR" ]; then
rosfran@253:         debug "major: $pkg_major < $MAJOR"
rosfran@253:         WRONG=1
rosfran@253:       elif [ ! "$pkg_minor" -gt "$MINOR" ]; then
rosfran@253:         debug "minor: $pkg_minor <= $MINOR"
rosfran@253:         if [ "$pkg_minor" -lt "$MINOR" ]; then
rosfran@253:           debug "minor: $pkg_minor < $MINOR"
rosfran@253:           WRONG=1
rosfran@253:         elif [ "$pkg_micro" -lt "$MICRO" ]; then
rosfran@253:           debug "micro: $pkg_micro < $MICRO"
rosfran@253: 	  WRONG=1
rosfran@253:         fi
rosfran@253:       fi
rosfran@253:     fi
rosfran@253: 
rosfran@253:     if test ! -z "$WRONG"; then
rosfran@253:       echo "found $pkg_version, not ok !"
rosfran@253:       continue
rosfran@253:     else
rosfran@253:       echo "found $pkg_version, ok."
rosfran@253:       # we set a var with the same name as the package, but stripped of
rosfran@253:       # unwanted chars
rosfran@253:       VAR=`echo $PACKAGE | sed 's/-//g'`
rosfran@253:       debug "setting $VAR"
rosfran@253:       eval $VAR="$COMMAND"
rosfran@253:       return 0
rosfran@253:     fi
rosfran@253:   done
rosfran@253: 
rosfran@253:   echo "not found !"
rosfran@253:   echo "You must have $PACKAGE installed to compile $package."
rosfran@253:   echo "Download the appropriate package for your distribution,"
rosfran@253:   echo "or get the source tarball at $URL"
rosfran@253:   return 1;
rosfran@253: }
rosfran@253: 
rosfran@253: aclocal_check ()
rosfran@253: {
rosfran@253:   # normally aclocal is part of automake
rosfran@253:   # so we expect it to be in the same place as automake
rosfran@253:   # so if a different automake is supplied, we need to adapt as well
rosfran@253:   # so how's about replacing automake with aclocal in the set var,
rosfran@253:   # and saving that in $aclocal ?
rosfran@253:   # note, this will fail if the actual automake isn't called automake*
rosfran@253:   # or if part of the path before it contains it
rosfran@253:   if [ -z "$automake" ]; then
rosfran@253:     echo "Error: no automake variable set !"
rosfran@253:     return 1
rosfran@253:   else
rosfran@253:     aclocal=`echo $automake | sed s/automake/aclocal/`
rosfran@253:     debug "aclocal: $aclocal"
rosfran@253:     if [ "$aclocal" != "aclocal" ];
rosfran@253:     then
rosfran@253:       CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-aclocal=$aclocal"
rosfran@253:     fi
rosfran@253:     if [ ! -x `which $aclocal` ]; then
rosfran@253:       echo "Error: cannot execute $aclocal !"
rosfran@253:       return 1
rosfran@253:     fi
rosfran@253:   fi
rosfran@253: }
rosfran@253: 
rosfran@253: autoheader_check ()
rosfran@253: {
rosfran@253:   # same here - autoheader is part of autoconf
rosfran@253:   # use the same voodoo
rosfran@253:   if [ -z "$autoconf" ]; then
rosfran@253:     echo "Error: no autoconf variable set !"
rosfran@253:     return 1
rosfran@253:   else
rosfran@253:     autoheader=`echo $autoconf | sed s/autoconf/autoheader/`
rosfran@253:     debug "autoheader: $autoheader"
rosfran@253:     if [ "$autoheader" != "autoheader" ];
rosfran@253:     then
rosfran@253:       CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-autoheader=$autoheader"
rosfran@253:     fi
rosfran@253:     if [ ! -x `which $autoheader` ]; then
rosfran@253:       echo "Error: cannot execute $autoheader !"
rosfran@253:       return 1
rosfran@253:     fi
rosfran@253:   fi
rosfran@253: 
rosfran@253: }
rosfran@253: 
rosfran@253: autoconf_2_52d_check ()
rosfran@253: {
rosfran@253:   # autoconf 2.52d has a weird issue involving a yes:no error
rosfran@253:   # so don't allow it's use
rosfran@253:   test -z "$NOCHECK" && {
rosfran@253:     ac_version=`$autoconf --version|head -n 1|sed 's/^[a-zA-Z\.\ ()]*//;s/ .*$//'`
rosfran@253:     if test "$ac_version" = "2.52d"; then
rosfran@253:       echo "autoconf 2.52d has an issue with our current build."
rosfran@253:       echo "We don't know who's to blame however.  So until we do, get a"
rosfran@253:       echo "regular version.  RPM's of a working version are on the gstreamer site."
rosfran@253:       exit 1
rosfran@253:     fi
rosfran@253:   }
rosfran@253:   return 0
rosfran@253: }
rosfran@253: 
rosfran@253: die_check ()
rosfran@253: {
rosfran@253:   # call with $DIE
rosfran@253:   # if set to 1, we need to print something helpful then die
rosfran@253:   DIE=$1
rosfran@253:   if test "x$DIE" = "x1";
rosfran@253:   then
rosfran@253:     echo
rosfran@253:     echo "- Please get the right tools before proceeding."
rosfran@253:     echo "- Alternatively, if you're sure we're wrong, run with --nocheck."
rosfran@253:     exit 1
rosfran@253:   fi
rosfran@253: }
rosfran@253: 
rosfran@253: autogen_options ()
rosfran@253: {
rosfran@253:   if test "x$1" = "x"; then
rosfran@253:     return 0
rosfran@253:   fi
rosfran@253: 
rosfran@253:   while test "x$1" != "x" ; do
rosfran@253:     optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
rosfran@253:     case "$1" in
rosfran@253:       --noconfigure)
rosfran@253:           NOCONFIGURE=defined
rosfran@253: 	  AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --noconfigure"
rosfran@253:           echo "+ configure run disabled"
rosfran@253:           shift
rosfran@253:           ;;
rosfran@253:       --nocheck)
rosfran@253: 	  AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --nocheck"
rosfran@253:           NOCHECK=defined
rosfran@253:           echo "+ autotools version check disabled"
rosfran@253:           shift
rosfran@253:           ;;
rosfran@253:       --debug)
rosfran@253:           DEBUG=defined
rosfran@253: 	  AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --debug"
rosfran@253:           echo "+ debug output enabled"
rosfran@253:           shift
rosfran@253:           ;;
rosfran@253:       --prefix=*)
rosfran@253: 	  CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT --prefix=$optarg"
rosfran@253: 	  echo "+ passing --prefix=$optarg to configure"
rosfran@253:           shift
rosfran@253:           ;;
rosfran@253:       --prefix)
rosfran@253: 	  shift
rosfran@253: 	  echo "DEBUG: $1"
rosfran@253: 	  CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT --prefix=$1"
rosfran@253: 	  echo "+ passing --prefix=$1 to configure"
rosfran@253:           shift
rosfran@253:           ;;
rosfran@253:       -h|--help)
rosfran@253:           echo "autogen.sh (autogen options) -- (configure options)"
rosfran@253:           echo "autogen.sh help options: "
rosfran@253:           echo " --noconfigure            don't run the configure script"
rosfran@253:           echo " --nocheck                don't do version checks"
rosfran@253:           echo " --debug                  debug the autogen process"
rosfran@253: 	  echo " --prefix		  will be passed on to configure"
rosfran@253:           echo
rosfran@253:           echo " --with-autoconf PATH     use autoconf in PATH"
rosfran@253:           echo " --with-automake PATH     use automake in PATH"
rosfran@253:           echo
rosfran@253:           echo "to pass options to configure, put them as arguments after -- "
rosfran@253: 	  exit 1
rosfran@253:           ;;
rosfran@253:       --with-automake=*)
rosfran@253:           AUTOMAKE=$optarg
rosfran@253:           echo "+ using alternate automake in $optarg"
rosfran@253: 	  CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-automake=$AUTOMAKE"
rosfran@253:           shift
rosfran@253:           ;;
rosfran@253:       --with-autoconf=*)
rosfran@253:           AUTOCONF=$optarg
rosfran@253:           echo "+ using alternate autoconf in $optarg"
rosfran@253: 	  CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-autoconf=$AUTOCONF"
rosfran@253:           shift
rosfran@253:           ;;
rosfran@253:       --disable*|--enable*|--with*)
rosfran@253:           echo "+ passing option $1 to configure"
rosfran@253: 	  CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $1"
rosfran@253:           shift
rosfran@253:           ;;
rosfran@253:        --) shift ; break ;;
rosfran@253:       *) echo "- ignoring unknown autogen.sh argument $1"; shift ;;
rosfran@253:     esac
rosfran@253:   done
rosfran@253: 
rosfran@253:   for arg do CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $arg"; done
rosfran@253:   if test ! -z "$CONFIGURE_EXT_OPT"
rosfran@253:   then
rosfran@253:     echo "+ options passed to configure: $CONFIGURE_EXT_OPT"
rosfran@253:   fi
rosfran@253: }
rosfran@253: 
rosfran@253: toplevel_check ()
rosfran@253: {
rosfran@253:   srcfile=$1
rosfran@253:   test -f $srcfile || {
rosfran@253:         echo "You must run this script in the top-level $package directory"
rosfran@253:         exit 1
rosfran@253:   }
rosfran@253: }
rosfran@253: 
rosfran@253: 
rosfran@253: tool_run ()
rosfran@253: {
rosfran@253:   tool=$1
rosfran@253:   options=$2
rosfran@253:   run_if_fail=$3
rosfran@253:   echo "+ running $tool $options..."
rosfran@253:   $tool $options || {
rosfran@253:     echo
rosfran@253:     echo $tool failed
rosfran@253:     eval $run_if_fail
rosfran@253:     exit 1
rosfran@253:   }
rosfran@253: }