tizen beta release
[profile/ivi/gst-openmax0.10.git] / build-aux / 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_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
174 autoconf_2_52d_check ()
175 {
176   # autoconf 2.52d has a weird issue involving a yes:no error
177   # so don't allow it's use
178   test -z "$NOCHECK" && {
179     ac_version=`$autoconf --version|head -n 1|sed 's/^[a-zA-Z\.\ ()]*//;s/ .*$//'`
180     if test "$ac_version" = "2.52d"; then
181       echo "autoconf 2.52d has an issue with our current build."
182       echo "We don't know who's to blame however.  So until we do, get a"
183       echo "regular version.  RPM's of a working version are on the gstreamer site."
184       exit 1
185     fi
186   }
187   return 0
188 }
189
190 die_check ()
191 {
192   # call with $DIE
193   # if set to 1, we need to print something helpful then die
194   DIE=$1
195   if test "x$DIE" = "x1";
196   then
197     echo
198     echo "- Please get the right tools before proceeding."
199     echo "- Alternatively, if you're sure we're wrong, run with --nocheck."
200     exit 1
201   fi
202 }
203
204 autogen_options ()
205 {
206   if test "x$1" = "x"; then
207     return 0
208   fi
209
210   while test "x$1" != "x" ; do
211     optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
212     case "$1" in
213       --noconfigure)
214           NOCONFIGURE=defined
215           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --noconfigure"
216           echo "+ configure run disabled"
217           shift
218           ;;
219       --nocheck)
220           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --nocheck"
221           NOCHECK=defined
222           echo "+ autotools version check disabled"
223           shift
224           ;;
225       --debug)
226           DEBUG=defined
227           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --debug"
228           echo "+ debug output enabled"
229           shift
230           ;;
231       -h|--help)
232           echo "autogen.sh (autogen options) -- (configure options)"
233           echo "autogen.sh help options: "
234           echo " --noconfigure            don't run the configure script"
235           echo " --nocheck                don't do version checks"
236           echo " --debug                  debug the autogen process"
237           echo
238           echo " --with-autoconf PATH     use autoconf in PATH"
239           echo " --with-automake PATH     use automake in PATH"
240           echo
241           echo "Any argument either not in the above list or after a '--' will be "
242           echo "passed to ./configure."
243           exit 1
244           ;;
245       --with-automake=*)
246           AUTOMAKE=$optarg
247           echo "+ using alternate automake in $optarg"
248           CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-automake=$AUTOMAKE"
249           shift
250           ;;
251       --with-autoconf=*)
252           AUTOCONF=$optarg
253           echo "+ using alternate autoconf in $optarg"
254           CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-autoconf=$AUTOCONF"
255           shift
256           ;;
257       --) shift ; break ;;
258       *)
259           echo "+ passing argument $1 to configure"
260           CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $1"
261           shift
262           ;;
263     esac
264   done
265
266   for arg do CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $arg"; done
267   if test ! -z "$CONFIGURE_EXT_OPT"
268   then
269     echo "+ options passed to configure: $CONFIGURE_EXT_OPT"
270   fi
271 }
272
273 toplevel_check ()
274 {
275   srcfile=$1
276   test -f $srcfile || {
277         echo "You must run this script in the top-level $package directory"
278         exit 1
279   }
280 }
281
282 tool_run ()
283 {
284   tool=$1
285   options=$2
286   run_if_fail=$3
287   echo "+ running $tool $options..."
288   $tool $options || {
289     echo
290     echo $tool failed
291     eval $run_if_fail
292     exit 1
293   }
294 }