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