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