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