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