maemo-ui/common/autogen-helper.sh
branchtrunk
changeset 46 be7aba49c535
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/maemo-ui/common/autogen-helper.sh	Tue Oct 24 14:30:57 2006 +0100
     1.3 @@ -0,0 +1,302 @@
     1.4 +# a silly hack that generates autoregen.sh but it's handy
     1.5 +echo "#!/bin/sh" > autoregen.sh
     1.6 +echo "./autogen.sh $@ \$@" >> autoregen.sh
     1.7 +chmod +x autoregen.sh
     1.8 +
     1.9 +# helper functions for autogen.sh
    1.10 +
    1.11 +debug ()
    1.12 +# print out a debug message if DEBUG is a defined variable
    1.13 +{
    1.14 +  if test ! -z "$DEBUG"
    1.15 +  then
    1.16 +    echo "DEBUG: $1"
    1.17 +  fi
    1.18 +}
    1.19 +
    1.20 +version_check ()
    1.21 +# check the version of a package
    1.22 +# first argument : package name (executable)
    1.23 +# second argument : optional path where to look for it instead
    1.24 +# third argument : source download url
    1.25 +# rest of arguments : major, minor, micro version
    1.26 +# all consecutive ones : suggestions for binaries to use
    1.27 +# (if not specified in second argument)
    1.28 +{
    1.29 +  PACKAGE=$1
    1.30 +  PKG_PATH=$2
    1.31 +  URL=$3
    1.32 +  MAJOR=$4
    1.33 +  MINOR=$5
    1.34 +  MICRO=$6
    1.35 +
    1.36 +  # for backwards compatibility, we let PKG_PATH=PACKAGE when PKG_PATH null
    1.37 +  if test -z "$PKG_PATH"; then PKG_PATH=$PACKAGE; fi
    1.38 +  debug "major $MAJOR minor $MINOR micro $MICRO"
    1.39 +  VERSION=$MAJOR
    1.40 +  if test ! -z "$MINOR"; then VERSION=$VERSION.$MINOR; else MINOR=0; fi
    1.41 +  if test ! -z "$MICRO"; then VERSION=$VERSION.$MICRO; else MICRO=0; fi
    1.42 +
    1.43 +  debug "major $MAJOR minor $MINOR micro $MICRO"
    1.44 +  
    1.45 +  for SUGGESTION in $PKG_PATH; do 
    1.46 +    COMMAND="$SUGGESTION"
    1.47 +
    1.48 +    # don't check if asked not to
    1.49 +    test -z "$NOCHECK" && {
    1.50 +      echo -n "  checking for $COMMAND >= $VERSION ... "
    1.51 +    } || {
    1.52 +      # we set a var with the same name as the package, but stripped of
    1.53 +      # unwanted chars
    1.54 +      VAR=`echo $PACKAGE | sed 's/-//g'`
    1.55 +      debug "setting $VAR"
    1.56 +      eval $VAR="$COMMAND"
    1.57 +      return 0
    1.58 +    }
    1.59 +
    1.60 +    debug "checking version with $COMMAND"
    1.61 +    ($COMMAND --version) < /dev/null > /dev/null 2>&1 || 
    1.62 +    {
    1.63 +      echo "not found."
    1.64 +      continue
    1.65 +    }
    1.66 +    # strip everything that's not a digit, then use cut to get the first field
    1.67 +    pkg_version=`$COMMAND --version|head -n 1|sed 's/^[^0-9]*//'|cut -d' ' -f1`
    1.68 +    debug "pkg_version $pkg_version"
    1.69 +    # remove any non-digit characters from the version numbers to permit numeric
    1.70 +    # comparison
    1.71 +    pkg_major=`echo $pkg_version | cut -d. -f1 | sed s/[a-zA-Z\-].*//g`
    1.72 +    pkg_minor=`echo $pkg_version | cut -d. -f2 | sed s/[a-zA-Z\-].*//g`
    1.73 +    pkg_micro=`echo $pkg_version | cut -d. -f3 | sed s/[a-zA-Z\-].*//g`
    1.74 +    test -z "$pkg_major" && pkg_major=0
    1.75 +    test -z "$pkg_minor" && pkg_minor=0
    1.76 +    test -z "$pkg_micro" && pkg_micro=0
    1.77 +    debug "found major $pkg_major minor $pkg_minor micro $pkg_micro"
    1.78 +
    1.79 +    #start checking the version
    1.80 +    debug "version check"
    1.81 +
    1.82 +    # reset check
    1.83 +    WRONG=
    1.84 +
    1.85 +    if [ ! "$pkg_major" -gt "$MAJOR" ]; then
    1.86 +      debug "major: $pkg_major <= $MAJOR"
    1.87 +      if [ "$pkg_major" -lt "$MAJOR" ]; then
    1.88 +        debug "major: $pkg_major < $MAJOR"
    1.89 +        WRONG=1
    1.90 +      elif [ ! "$pkg_minor" -gt "$MINOR" ]; then
    1.91 +        debug "minor: $pkg_minor <= $MINOR"
    1.92 +        if [ "$pkg_minor" -lt "$MINOR" ]; then
    1.93 +          debug "minor: $pkg_minor < $MINOR"
    1.94 +          WRONG=1
    1.95 +        elif [ "$pkg_micro" -lt "$MICRO" ]; then
    1.96 +          debug "micro: $pkg_micro < $MICRO"
    1.97 +	  WRONG=1
    1.98 +        fi
    1.99 +      fi
   1.100 +    fi
   1.101 +
   1.102 +    if test ! -z "$WRONG"; then
   1.103 +      echo "found $pkg_version, not ok !"
   1.104 +      continue
   1.105 +    else
   1.106 +      echo "found $pkg_version, ok."
   1.107 +      # we set a var with the same name as the package, but stripped of
   1.108 +      # unwanted chars
   1.109 +      VAR=`echo $PACKAGE | sed 's/-//g'`
   1.110 +      debug "setting $VAR"
   1.111 +      eval $VAR="$COMMAND"
   1.112 +      return 0
   1.113 +    fi
   1.114 +  done
   1.115 +
   1.116 +  echo "not found !"
   1.117 +  echo "You must have $PACKAGE installed to compile $package."
   1.118 +  echo "Download the appropriate package for your distribution,"
   1.119 +  echo "or get the source tarball at $URL"
   1.120 +  return 1;
   1.121 +}
   1.122 +
   1.123 +aclocal_check ()
   1.124 +{
   1.125 +  # normally aclocal is part of automake
   1.126 +  # so we expect it to be in the same place as automake
   1.127 +  # so if a different automake is supplied, we need to adapt as well
   1.128 +  # so how's about replacing automake with aclocal in the set var,
   1.129 +  # and saving that in $aclocal ?
   1.130 +  # note, this will fail if the actual automake isn't called automake*
   1.131 +  # or if part of the path before it contains it
   1.132 +  if [ -z "$automake" ]; then
   1.133 +    echo "Error: no automake variable set !"
   1.134 +    return 1
   1.135 +  else
   1.136 +    aclocal=`echo $automake | sed s/automake/aclocal/`
   1.137 +    debug "aclocal: $aclocal"
   1.138 +    if [ "$aclocal" != "aclocal" ];
   1.139 +    then
   1.140 +      CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-aclocal=$aclocal"
   1.141 +    fi
   1.142 +    if [ ! -x `which $aclocal` ]; then
   1.143 +      echo "Error: cannot execute $aclocal !"
   1.144 +      return 1
   1.145 +    fi
   1.146 +  fi
   1.147 +}
   1.148 +
   1.149 +autoheader_check ()
   1.150 +{
   1.151 +  # same here - autoheader is part of autoconf
   1.152 +  # use the same voodoo
   1.153 +  if [ -z "$autoconf" ]; then
   1.154 +    echo "Error: no autoconf variable set !"
   1.155 +    return 1
   1.156 +  else
   1.157 +    autoheader=`echo $autoconf | sed s/autoconf/autoheader/`
   1.158 +    debug "autoheader: $autoheader"
   1.159 +    if [ "$autoheader" != "autoheader" ];
   1.160 +    then
   1.161 +      CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-autoheader=$autoheader"
   1.162 +    fi
   1.163 +    if [ ! -x `which $autoheader` ]; then
   1.164 +      echo "Error: cannot execute $autoheader !"
   1.165 +      return 1
   1.166 +    fi
   1.167 +  fi
   1.168 +
   1.169 +}
   1.170 +
   1.171 +autoconf_2_52d_check ()
   1.172 +{
   1.173 +  # autoconf 2.52d has a weird issue involving a yes:no error
   1.174 +  # so don't allow it's use
   1.175 +  test -z "$NOCHECK" && {
   1.176 +    ac_version=`$autoconf --version|head -n 1|sed 's/^[a-zA-Z\.\ ()]*//;s/ .*$//'`
   1.177 +    if test "$ac_version" = "2.52d"; then
   1.178 +      echo "autoconf 2.52d has an issue with our current build."
   1.179 +      echo "We don't know who's to blame however.  So until we do, get a"
   1.180 +      echo "regular version.  RPM's of a working version are on the gstreamer site."
   1.181 +      exit 1
   1.182 +    fi
   1.183 +  }
   1.184 +  return 0
   1.185 +}
   1.186 +
   1.187 +die_check ()
   1.188 +{
   1.189 +  # call with $DIE
   1.190 +  # if set to 1, we need to print something helpful then die
   1.191 +  DIE=$1
   1.192 +  if test "x$DIE" = "x1";
   1.193 +  then
   1.194 +    echo
   1.195 +    echo "- Please get the right tools before proceeding."
   1.196 +    echo "- Alternatively, if you're sure we're wrong, run with --nocheck."
   1.197 +    exit 1
   1.198 +  fi
   1.199 +}
   1.200 +
   1.201 +autogen_options ()
   1.202 +{
   1.203 +  if test "x$1" = "x"; then
   1.204 +    return 0
   1.205 +  fi
   1.206 +
   1.207 +  while test "x$1" != "x" ; do
   1.208 +    optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
   1.209 +    case "$1" in
   1.210 +      --noconfigure)
   1.211 +          NOCONFIGURE=defined
   1.212 +	  AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --noconfigure"
   1.213 +          echo "+ configure run disabled"
   1.214 +          shift
   1.215 +          ;;
   1.216 +      --nocheck)
   1.217 +	  AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --nocheck"
   1.218 +          NOCHECK=defined
   1.219 +          echo "+ autotools version check disabled"
   1.220 +          shift
   1.221 +          ;;
   1.222 +      --debug)
   1.223 +          DEBUG=defined
   1.224 +	  AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --debug"
   1.225 +          echo "+ debug output enabled"
   1.226 +          shift
   1.227 +          ;;
   1.228 +      --prefix=*)
   1.229 +	  CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT --prefix=$optarg"
   1.230 +	  echo "+ passing --prefix=$optarg to configure"
   1.231 +          shift
   1.232 +          ;;
   1.233 +      --prefix)
   1.234 +	  shift
   1.235 +	  echo "DEBUG: $1"
   1.236 +	  CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT --prefix=$1"
   1.237 +	  echo "+ passing --prefix=$1 to configure"
   1.238 +          shift
   1.239 +          ;;
   1.240 +      -h|--help)
   1.241 +          echo "autogen.sh (autogen options) -- (configure options)"
   1.242 +          echo "autogen.sh help options: "
   1.243 +          echo " --noconfigure            don't run the configure script"
   1.244 +          echo " --nocheck                don't do version checks"
   1.245 +          echo " --debug                  debug the autogen process"
   1.246 +	  echo " --prefix		  will be passed on to configure"
   1.247 +          echo
   1.248 +          echo " --with-autoconf PATH     use autoconf in PATH"
   1.249 +          echo " --with-automake PATH     use automake in PATH"
   1.250 +          echo
   1.251 +          echo "to pass options to configure, put them as arguments after -- "
   1.252 +	  exit 1
   1.253 +          ;;
   1.254 +      --with-automake=*)
   1.255 +          AUTOMAKE=$optarg
   1.256 +          echo "+ using alternate automake in $optarg"
   1.257 +	  CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-automake=$AUTOMAKE"
   1.258 +          shift
   1.259 +          ;;
   1.260 +      --with-autoconf=*)
   1.261 +          AUTOCONF=$optarg
   1.262 +          echo "+ using alternate autoconf in $optarg"
   1.263 +	  CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-autoconf=$AUTOCONF"
   1.264 +          shift
   1.265 +          ;;
   1.266 +      --disable*|--enable*|--with*)
   1.267 +          echo "+ passing option $1 to configure"
   1.268 +	  CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $1"
   1.269 +          shift
   1.270 +          ;;
   1.271 +       --) shift ; break ;;
   1.272 +      *) echo "- ignoring unknown autogen.sh argument $1"; shift ;;
   1.273 +    esac
   1.274 +  done
   1.275 +
   1.276 +  for arg do CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $arg"; done
   1.277 +  if test ! -z "$CONFIGURE_EXT_OPT"
   1.278 +  then
   1.279 +    echo "+ options passed to configure: $CONFIGURE_EXT_OPT"
   1.280 +  fi
   1.281 +}
   1.282 +
   1.283 +toplevel_check ()
   1.284 +{
   1.285 +  srcfile=$1
   1.286 +  test -f $srcfile || {
   1.287 +        echo "You must run this script in the top-level $package directory"
   1.288 +        exit 1
   1.289 +  }
   1.290 +}
   1.291 +
   1.292 +
   1.293 +tool_run ()
   1.294 +{
   1.295 +  tool=$1
   1.296 +  options=$2
   1.297 +  run_if_fail=$3
   1.298 +  echo "+ running $tool $options..."
   1.299 +  $tool $options || {
   1.300 +    echo
   1.301 +    echo $tool failed
   1.302 +    eval $run_if_fail
   1.303 +    exit 1
   1.304 +  }
   1.305 +}