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