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