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