~michael-sheldon/gst-opencv/trunk

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