gmyth-stream/libgnomevfs2/common/autogen-helper.sh
author rosfran
Wed May 16 19:46:20 2007 +0100 (2007-05-16)
branchtrunk
changeset 675 4c7f6a9bfded
permissions -rw-r--r--
[svn r681] Added configuration file parser (name/value pair list).
     1 # a silly hack that generates autoregen.sh but it's handy
     2 echo "#!/bin/sh" > autoregen.sh
     3 echo "./autogen.sh $@ \$@" >> autoregen.sh
     4 chmod +x autoregen.sh
     5 
     6 # helper functions for autogen.sh
     7 
     8 debug ()
     9 # print out a debug message if DEBUG is a defined variable
    10 {
    11   if test ! -z "$DEBUG"
    12   then
    13     echo "DEBUG: $1"
    14   fi
    15 }
    16 
    17 version_check ()
    18 # check the version of a package
    19 # first argument : package name (executable)
    20 # second argument : optional path where to look for it instead
    21 # third argument : source download url
    22 # rest of arguments : major, minor, micro version
    23 # all consecutive ones : suggestions for binaries to use
    24 # (if not specified in second argument)
    25 {
    26   PACKAGE=$1
    27   PKG_PATH=$2
    28   URL=$3
    29   MAJOR=$4
    30   MINOR=$5
    31   MICRO=$6
    32 
    33   # for backwards compatibility, we let PKG_PATH=PACKAGE when PKG_PATH null
    34   if test -z "$PKG_PATH"; then PKG_PATH=$PACKAGE; fi
    35   debug "major $MAJOR minor $MINOR micro $MICRO"
    36   VERSION=$MAJOR
    37   if test ! -z "$MINOR"; then VERSION=$VERSION.$MINOR; else MINOR=0; fi
    38   if test ! -z "$MICRO"; then VERSION=$VERSION.$MICRO; else MICRO=0; fi
    39 
    40   debug "major $MAJOR minor $MINOR micro $MICRO"
    41   
    42   for SUGGESTION in $PKG_PATH; do 
    43     COMMAND="$SUGGESTION"
    44 
    45     # don't check if asked not to
    46     test -z "$NOCHECK" && {
    47       echo -n "  checking for $COMMAND >= $VERSION ... "
    48     } || {
    49       # we set a var with the same name as the package, but stripped of
    50       # unwanted chars
    51       VAR=`echo $PACKAGE | sed 's/-//g'`
    52       debug "setting $VAR"
    53       eval $VAR="$COMMAND"
    54       return 0
    55     }
    56 
    57     debug "checking version with $COMMAND"
    58     ($COMMAND --version) < /dev/null > /dev/null 2>&1 || 
    59     {
    60       echo "not found."
    61       continue
    62     }
    63     # strip everything that's not a digit, then use cut to get the first field
    64     pkg_version=`$COMMAND --version|head -n 1|sed 's/^[^0-9]*//'|cut -d' ' -f1`
    65     debug "pkg_version $pkg_version"
    66     # remove any non-digit characters from the version numbers to permit numeric
    67     # comparison
    68     pkg_major=`echo $pkg_version | cut -d. -f1 | sed s/[a-zA-Z\-].*//g`
    69     pkg_minor=`echo $pkg_version | cut -d. -f2 | sed s/[a-zA-Z\-].*//g`
    70     pkg_micro=`echo $pkg_version | cut -d. -f3 | sed s/[a-zA-Z\-].*//g`
    71     test -z "$pkg_major" && pkg_major=0
    72     test -z "$pkg_minor" && pkg_minor=0
    73     test -z "$pkg_micro" && pkg_micro=0
    74     debug "found major $pkg_major minor $pkg_minor micro $pkg_micro"
    75 
    76     #start checking the version
    77     debug "version check"
    78 
    79     # reset check
    80     WRONG=
    81 
    82     if [ ! "$pkg_major" -gt "$MAJOR" ]; then
    83       debug "major: $pkg_major <= $MAJOR"
    84       if [ "$pkg_major" -lt "$MAJOR" ]; then
    85         debug "major: $pkg_major < $MAJOR"
    86         WRONG=1
    87       elif [ ! "$pkg_minor" -gt "$MINOR" ]; then
    88         debug "minor: $pkg_minor <= $MINOR"
    89         if [ "$pkg_minor" -lt "$MINOR" ]; then
    90           debug "minor: $pkg_minor < $MINOR"
    91           WRONG=1
    92         elif [ "$pkg_micro" -lt "$MICRO" ]; then
    93           debug "micro: $pkg_micro < $MICRO"
    94 	  WRONG=1
    95         fi
    96       fi
    97     fi
    98 
    99     if test ! -z "$WRONG"; then
   100       echo "found $pkg_version, not ok !"
   101       continue
   102     else
   103       echo "found $pkg_version, ok."
   104       # we set a var with the same name as the package, but stripped of
   105       # unwanted chars
   106       VAR=`echo $PACKAGE | sed 's/-//g'`
   107       debug "setting $VAR"
   108       eval $VAR="$COMMAND"
   109       return 0
   110     fi
   111   done
   112 
   113   echo "not found !"
   114   echo "You must have $PACKAGE installed to compile $package."
   115   echo "Download the appropriate package for your distribution,"
   116   echo "or get the source tarball at $URL"
   117   return 1;
   118 }
   119 
   120 aclocal_check ()
   121 {
   122   # normally aclocal is part of automake
   123   # so we expect it to be in the same place as automake
   124   # so if a different automake is supplied, we need to adapt as well
   125   # so how's about replacing automake with aclocal in the set var,
   126   # and saving that in $aclocal ?
   127   # note, this will fail if the actual automake isn't called automake*
   128   # or if part of the path before it contains it
   129   if [ -z "$automake" ]; then
   130     echo "Error: no automake variable set !"
   131     return 1
   132   else
   133     aclocal=`echo $automake | sed s/automake/aclocal/`
   134     debug "aclocal: $aclocal"
   135     if [ "$aclocal" != "aclocal" ];
   136     then
   137       CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-aclocal=$aclocal"
   138     fi
   139     if [ ! -x `which $aclocal` ]; then
   140       echo "Error: cannot execute $aclocal !"
   141       return 1
   142     fi
   143   fi
   144 }
   145 
   146 autoheader_check ()
   147 {
   148   # same here - autoheader is part of autoconf
   149   # use the same voodoo
   150   if [ -z "$autoconf" ]; then
   151     echo "Error: no autoconf variable set !"
   152     return 1
   153   else
   154     autoheader=`echo $autoconf | sed s/autoconf/autoheader/`
   155     debug "autoheader: $autoheader"
   156     if [ "$autoheader" != "autoheader" ];
   157     then
   158       CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-autoheader=$autoheader"
   159     fi
   160     if [ ! -x `which $autoheader` ]; then
   161       echo "Error: cannot execute $autoheader !"
   162       return 1
   163     fi
   164   fi
   165 
   166 }
   167 
   168 autoconf_2_52d_check ()
   169 {
   170   # autoconf 2.52d has a weird issue involving a yes:no error
   171   # so don't allow it's use
   172   test -z "$NOCHECK" && {
   173     ac_version=`$autoconf --version|head -n 1|sed 's/^[a-zA-Z\.\ ()]*//;s/ .*$//'`
   174     if test "$ac_version" = "2.52d"; then
   175       echo "autoconf 2.52d has an issue with our current build."
   176       echo "We don't know who's to blame however.  So until we do, get a"
   177       echo "regular version.  RPM's of a working version are on the gstreamer site."
   178       exit 1
   179     fi
   180   }
   181   return 0
   182 }
   183 
   184 die_check ()
   185 {
   186   # call with $DIE
   187   # if set to 1, we need to print something helpful then die
   188   DIE=$1
   189   if test "x$DIE" = "x1";
   190   then
   191     echo
   192     echo "- Please get the right tools before proceeding."
   193     echo "- Alternatively, if you're sure we're wrong, run with --nocheck."
   194     exit 1
   195   fi
   196 }
   197 
   198 autogen_options ()
   199 {
   200   if test "x$1" = "x"; then
   201     return 0
   202   fi
   203 
   204   while test "x$1" != "x" ; do
   205     optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
   206     case "$1" in
   207       --noconfigure)
   208           NOCONFIGURE=defined
   209 	  AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --noconfigure"
   210           echo "+ configure run disabled"
   211           shift
   212           ;;
   213       --nocheck)
   214 	  AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --nocheck"
   215           NOCHECK=defined
   216           echo "+ autotools version check disabled"
   217           shift
   218           ;;
   219       --debug)
   220           DEBUG=defined
   221 	  AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --debug"
   222           echo "+ debug output enabled"
   223           shift
   224           ;;
   225       --prefix=*)
   226 	  CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT --prefix=$optarg"
   227 	  echo "+ passing --prefix=$optarg to configure"
   228           shift
   229           ;;
   230       --prefix)
   231 	  shift
   232 	  echo "DEBUG: $1"
   233 	  CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT --prefix=$1"
   234 	  echo "+ passing --prefix=$1 to configure"
   235           shift
   236           ;;
   237       -h|--help)
   238           echo "autogen.sh (autogen options) -- (configure options)"
   239           echo "autogen.sh help options: "
   240           echo " --noconfigure            don't run the configure script"
   241           echo " --nocheck                don't do version checks"
   242           echo " --debug                  debug the autogen process"
   243 	  echo " --prefix		  will be passed on to configure"
   244           echo
   245           echo " --with-autoconf PATH     use autoconf in PATH"
   246           echo " --with-automake PATH     use automake in PATH"
   247           echo
   248           echo "to pass options to configure, put them as arguments after -- "
   249 	  exit 1
   250           ;;
   251       --with-automake=*)
   252           AUTOMAKE=$optarg
   253           echo "+ using alternate automake in $optarg"
   254 	  CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-automake=$AUTOMAKE"
   255           shift
   256           ;;
   257       --with-autoconf=*)
   258           AUTOCONF=$optarg
   259           echo "+ using alternate autoconf in $optarg"
   260 	  CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-autoconf=$AUTOCONF"
   261           shift
   262           ;;
   263       --disable*|--enable*|--with*)
   264           echo "+ passing option $1 to configure"
   265 	  CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $1"
   266           shift
   267           ;;
   268        --) shift ; break ;;
   269       *) echo "- ignoring unknown autogen.sh argument $1"; shift ;;
   270     esac
   271   done
   272 
   273   for arg do CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $arg"; done
   274   if test ! -z "$CONFIGURE_EXT_OPT"
   275   then
   276     echo "+ options passed to configure: $CONFIGURE_EXT_OPT"
   277   fi
   278 }
   279 
   280 toplevel_check ()
   281 {
   282   srcfile=$1
   283   test -f $srcfile || {
   284         echo "You must run this script in the top-level $package directory"
   285         exit 1
   286   }
   287 }
   288 
   289 
   290 tool_run ()
   291 {
   292   tool=$1
   293   options=$2
   294   run_if_fail=$3
   295   echo "+ running $tool $options..."
   296   $tool $options || {
   297     echo
   298     echo $tool failed
   299     eval $run_if_fail
   300     exit 1
   301   }
   302 }