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