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