check.mak: Make number of torture iterations configurable
[platform/upstream/gst-common.git] / gst-autogen.sh
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_get ()
24 # based on the command's version output, set variables
25 # _MAJOR, _MINOR, _MICRO, _VERSION, using the given prefix as variable prefix
26 #
27 # arg 1: command binary name
28 # arg 2: (uppercased) variable name prefix
29 {
30   COMMAND=$1
31   VARPREFIX=`echo $2 | tr .,- _`
32
33   # strip everything that's not a digit, then use cut to get the first field
34   pkg_version=`$COMMAND --version|head -n 1|sed 's/^.*)[^0-9]*//'|cut -d' ' -f1`
35   debug "pkg_version $pkg_version"
36   # remove any non-digit characters from the version numbers to permit numeric
37   # comparison
38   pkg_major=`echo $pkg_version | cut -d. -f1 | sed s/[a-zA-Z\-].*//g`
39   pkg_minor=`echo $pkg_version | cut -d. -f2 | sed s/[a-zA-Z\-].*//g`
40   pkg_micro=`echo $pkg_version | cut -d. -f3 | sed s/[a-zA-Z\-].*//g`
41   test -z "$pkg_major" && pkg_major=0
42   test -z "$pkg_minor" && pkg_minor=0
43   test -z "$pkg_micro" && pkg_micro=0
44   debug "found major $pkg_major minor $pkg_minor micro $pkg_micro"
45   eval ${VARPREFIX}_MAJOR=$pkg_major
46   eval ${VARPREFIX}_MINOR=$pkg_minor
47   eval ${VARPREFIX}_MICRO=$pkg_micro
48   eval ${VARPREFIX}_VERSION=$pkg_version
49 }
50
51 version_compare ()
52 # Checks whether the version of VARPREFIX is equal to or
53 # newer than the requested version
54 # arg1: VARPREFIX
55 # arg2: MAJOR
56 # arg3: MINOR
57 # arg4: MICRO
58 {
59   VARPREFIX=`echo $1 | tr .,- _`
60   MAJOR=$2
61   MINOR=$3
62   MICRO=$4
63
64   eval pkg_major=\$${VARPREFIX}_MAJOR;
65   eval pkg_minor=\$${VARPREFIX}_MINOR;
66   eval pkg_micro=\$${VARPREFIX}_MICRO;
67
68   #start checking the version
69   debug "version_compare: $VARPREFIX against $MAJOR.$MINOR.$MICRO"
70
71     # reset check
72     WRONG=
73
74     if [ ! "$pkg_major" -gt "$MAJOR" ]; then
75       debug "major: $pkg_major <= $MAJOR"
76       if [ "$pkg_major" -lt "$MAJOR" ]; then
77         debug "major: $pkg_major < $MAJOR"
78         WRONG=1
79       elif [ ! "$pkg_minor" -gt "$MINOR" ]; then
80         debug "minor: $pkg_minor <= $MINOR"
81         if [ "$pkg_minor" -lt "$MINOR" ]; then
82           debug "minor: $pkg_minor < $MINOR"
83           WRONG=1
84         elif [ "$pkg_micro" -lt "$MICRO" ]; then
85           debug "micro: $pkg_micro < $MICRO"
86           WRONG=1
87         fi
88       fi
89     fi
90     if test ! -z "$WRONG"; then
91       debug "version_compare: $VARPREFIX older than $MAJOR.$MINOR.$MICRO"
92       return 1
93     fi
94     debug "version_compare: $VARPREFIX equal to/newer than $MAJOR.$MINOR.$MICRO"
95     return 0
96 }
97
98
99 version_check ()
100 # check the version of a package
101 # first argument : package name (executable)
102 # second argument : optional path where to look for it instead
103 # third argument : source download url
104 # rest of arguments : major, minor, micro version
105 # all consecutive ones : suggestions for binaries to use
106 # (if not specified in second argument)
107 {
108   PACKAGE=$1
109   PKG_PATH=$2
110   URL=$3
111   MAJOR=$4
112   MINOR=$5
113   MICRO=$6
114
115   # for backwards compatibility, we let PKG_PATH=PACKAGE when PKG_PATH null
116   if test -z "$PKG_PATH"; then PKG_PATH=$PACKAGE; fi
117   debug "major $MAJOR minor $MINOR micro $MICRO"
118   VERSION=$MAJOR
119   if test ! -z "$MINOR"; then VERSION=$VERSION.$MINOR; else MINOR=0; fi
120   if test ! -z "$MICRO"; then VERSION=$VERSION.$MICRO; else MICRO=0; fi
121
122   debug "major $MAJOR minor $MINOR micro $MICRO"
123
124   for SUGGESTION in $PKG_PATH; do
125     COMMAND="$SUGGESTION"
126
127     # don't check if asked not to
128     test -z "$NOCHECK" && {
129       printf "  checking for $COMMAND >= $VERSION ... "
130     } || {
131       # we set a var with the same name as the package, but stripped of
132       # unwanted chars
133       VAR=`echo $PACKAGE | sed 's/-//g'`
134       debug "setting $VAR"
135       eval $VAR="$COMMAND"
136       return 0
137     }
138
139     which $COMMAND > /dev/null 2>&1
140     if test $? -eq 1;
141     then 
142       debug "$COMMAND not found"
143       continue
144     fi
145
146     VARPREFIX=`echo $COMMAND | sed 's/-//g' | tr [:lower:] [:upper:]`
147     version_get $COMMAND $VARPREFIX
148
149     version_compare $VARPREFIX $MAJOR $MINOR $MICRO
150     if test $? -ne 0; then
151       echo "found $pkg_version, not ok !"
152       continue
153     else
154       echo "found $pkg_version, ok."
155       # we set a var with the same name as the package, but stripped of
156       # unwanted chars
157       VAR=`echo $PACKAGE | sed 's/-//g'`
158       debug "setting $VAR"
159       eval $VAR="$COMMAND"
160       return 0
161     fi
162   done
163
164   echo "$PACKAGE not found !"
165   echo "You must have $PACKAGE installed to compile $package."
166   echo "Download the appropriate package for your distribution,"
167   echo "or get the source tarball at $URL"
168   return 1;
169 }
170
171 aclocal_check ()
172 {
173   # normally aclocal is part of automake
174   # so we expect it to be in the same place as automake
175   # so if a different automake is supplied, we need to adapt as well
176   # so how's about replacing automake with aclocal in the set var,
177   # and saving that in $aclocal ?
178   # note, this will fail if the actual automake isn't called automake*
179   # or if part of the path before it contains it
180   if [ -z "$automake" ]; then
181     echo "Error: no automake variable set !"
182     return 1
183   else
184     aclocal=`echo $automake | sed s/automake/aclocal/`
185     debug "aclocal: $aclocal"
186     if [ "$aclocal" != "aclocal" ];
187     then
188       CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-aclocal=$aclocal"
189     fi
190     if [ ! -x `which $aclocal` ]; then
191       echo "Error: cannot execute $aclocal !"
192       return 1
193     fi
194   fi
195 }
196
197 autoheader_check ()
198 {
199   # same here - autoheader is part of autoconf
200   # use the same voodoo
201   if [ -z "$autoconf" ]; then
202     echo "Error: no autoconf variable set !"
203     return 1
204   else
205     autoheader=`echo $autoconf | sed s/autoconf/autoheader/`
206     debug "autoheader: $autoheader"
207     if [ "$autoheader" != "autoheader" ];
208     then
209       CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-autoheader=$autoheader"
210     fi
211     if [ ! -x `which $autoheader` ]; then
212       echo "Error: cannot execute $autoheader !"
213       return 1
214     fi
215   fi
216
217 }
218
219 die_check ()
220 {
221   # call with $DIE
222   # if set to 1, we need to print something helpful then die
223   DIE=$1
224   if test "x$DIE" = "x1";
225   then
226     echo
227     echo "- Please get the right tools before proceeding."
228     echo "- Alternatively, if you're sure we're wrong, run with --nocheck."
229     exit 1
230   fi
231 }
232
233 autogen_options ()
234 {
235   if test "x$1" = "x"; then
236     return 0
237   fi
238
239   while test "x$1" != "x" ; do
240     optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
241     case "$1" in
242       --noconfigure)
243           NOCONFIGURE=defined
244           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --noconfigure"
245           echo "+ configure run disabled"
246           shift
247           ;;
248       --nocheck)
249           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --nocheck"
250           NOCHECK=defined
251           echo "+ autotools version check disabled"
252           shift
253           ;;
254       -d|--debug)
255           DEBUG=defined
256           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --debug"
257           echo "+ debug output enabled"
258           shift
259           ;;
260       -h|--help)
261           echo "autogen.sh (autogen options) -- (configure options)"
262           echo "autogen.sh help options: "
263           echo " --noconfigure            don't run the configure script"
264           echo " --nocheck                don't do version checks"
265           echo " --debug                  debug the autogen process"
266           echo
267           echo " --with-autoconf PATH     use autoconf in PATH"
268           echo " --with-automake PATH     use automake in PATH"
269           echo
270           echo "Any argument either not in the above list or after a '--' will be "
271           echo "passed to ./configure."
272           exit 1
273           ;;
274       --with-automake=*)
275           AUTOMAKE=$optarg
276           echo "+ using alternate automake in $optarg"
277           CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-automake=$AUTOMAKE"
278           shift
279           ;;
280       --with-autoconf=*)
281           AUTOCONF=$optarg
282           echo "+ using alternate autoconf in $optarg"
283           CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-autoconf=$AUTOCONF"
284           shift
285           ;;
286       --) shift ; break ;;
287       *)
288           echo "+ passing argument $1 to configure"
289           CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $1"
290           shift
291           ;;
292     esac
293   done
294
295   for arg do CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $arg"; done
296   if test ! -z "$CONFIGURE_EXT_OPT"
297   then
298     echo "+ options passed to configure: $CONFIGURE_EXT_OPT"
299   fi
300 }
301
302 toplevel_check ()
303 {
304   srcfile=$1
305   test -f $srcfile || {
306         echo "You must run this script in the top-level $package directory"
307         exit 1
308   }
309 }
310
311 tool_run ()
312 {
313   tool=$1
314   options=$2
315   run_if_fail=$3
316   echo "+ running $tool $options..."
317   $tool $options || {
318     echo
319     echo $tool failed
320     eval $run_if_fail
321     exit 1
322   }
323 }
324
325 install_git_hooks ()
326 {
327   if test -d .git; then
328     # install pre-commit hook for doing clean commits
329     for hook in pre-commit; do
330       if test ! \( -x .git/hooks/$hook -a -L .git/hooks/$hook \); then
331         echo "+ Installing git $hook hook"
332         rm -f .git/hooks/$hook
333         ln -s ../../common/hooks/$hook.hook .git/hooks/$hook || {
334           # if we couldn't create a symbolic link, try doing a plain cp
335           if cp common/hooks/pre-commit.hook .git/hooks/pre-commit; then
336             chmod +x .git/hooks/pre-commit;
337           else
338             echo "********** Couldn't install git $hook hook **********";
339           fi
340         }
341       fi
342     done
343   fi
344 }