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