gst-autogen.sh: only update autoregen.sh on actual runs
[platform/upstream/gst-common.git] / gst-autogen.sh
1 # helper functions for autogen.sh
2
3 debug ()
4 # print out a debug message if DEBUG is a defined variable
5 {
6   if test ! -z "$DEBUG"
7   then
8     echo "DEBUG: $1"
9   fi
10 }
11
12 version_check ()
13 # check the version of a package
14 # first argument : package name (executable)
15 # second argument : optional path where to look for it instead
16 # third argument : source download url
17 # rest of arguments : major, minor, micro version
18 # all consecutive ones : suggestions for binaries to use
19 # (if not specified in second argument)
20 {
21   PACKAGE=$1
22   PKG_PATH=$2
23   URL=$3
24   MAJOR=$4
25   MINOR=$5
26   MICRO=$6
27
28   # for backwards compatibility, we let PKG_PATH=PACKAGE when PKG_PATH null
29   if test -z "$PKG_PATH"; then PKG_PATH=$PACKAGE; fi
30   debug "major $MAJOR minor $MINOR micro $MICRO"
31   VERSION=$MAJOR
32   if test ! -z "$MINOR"; then VERSION=$VERSION.$MINOR; else MINOR=0; fi
33   if test ! -z "$MICRO"; then VERSION=$VERSION.$MICRO; else MICRO=0; fi
34
35   debug "major $MAJOR minor $MINOR micro $MICRO"
36   
37   for SUGGESTION in $PKG_PATH; do 
38     COMMAND="$SUGGESTION"
39
40     # don't check if asked not to
41     test -z "$NOCHECK" && {
42       echo -n "  checking for $COMMAND >= $VERSION ... "
43     } || {
44       # we set a var with the same name as the package, but stripped of
45       # unwanted chars
46       VAR=`echo $PACKAGE | sed 's/-//g'`
47       debug "setting $VAR"
48       eval $VAR="$COMMAND"
49       return 0
50     }
51
52     debug "checking version with $COMMAND"
53     ($COMMAND --version) < /dev/null > /dev/null 2>&1 || 
54     {
55       echo "not found."
56       continue
57     }
58     # strip everything that's not a digit, then use cut to get the first field
59     pkg_version=`$COMMAND --version|head -n 1|sed 's/^[^0-9]*//'|cut -d' ' -f1`
60     debug "pkg_version $pkg_version"
61     # remove any non-digit characters from the version numbers to permit numeric
62     # comparison
63     pkg_major=`echo $pkg_version | cut -d. -f1 | sed s/[a-zA-Z\-].*//g`
64     pkg_minor=`echo $pkg_version | cut -d. -f2 | sed s/[a-zA-Z\-].*//g`
65     pkg_micro=`echo $pkg_version | cut -d. -f3 | sed s/[a-zA-Z\-].*//g`
66     test -z "$pkg_major" && pkg_major=0
67     test -z "$pkg_minor" && pkg_minor=0
68     test -z "$pkg_micro" && pkg_micro=0
69     debug "found major $pkg_major minor $pkg_minor micro $pkg_micro"
70
71     #start checking the version
72     debug "version check"
73
74     # reset check
75     WRONG=
76
77     if [ ! "$pkg_major" -gt "$MAJOR" ]; then
78       debug "major: $pkg_major <= $MAJOR"
79       if [ "$pkg_major" -lt "$MAJOR" ]; then
80         debug "major: $pkg_major < $MAJOR"
81         WRONG=1
82       elif [ ! "$pkg_minor" -gt "$MINOR" ]; then
83         debug "minor: $pkg_minor <= $MINOR"
84         if [ "$pkg_minor" -lt "$MINOR" ]; then
85           debug "minor: $pkg_minor < $MINOR"
86           WRONG=1
87         elif [ "$pkg_micro" -lt "$MICRO" ]; then
88           debug "micro: $pkg_micro < $MICRO"
89           WRONG=1
90         fi
91       fi
92     fi
93
94     if test ! -z "$WRONG"; then
95       echo "found $pkg_version, not ok !"
96       continue
97     else
98       echo "found $pkg_version, ok."
99       # we set a var with the same name as the package, but stripped of
100       # unwanted chars
101       VAR=`echo $PACKAGE | sed 's/-//g'`
102       debug "setting $VAR"
103       eval $VAR="$COMMAND"
104       return 0
105     fi
106   done
107
108   echo "not found !"
109   echo "You must have $PACKAGE installed to compile $package."
110   echo "Download the appropriate package for your distribution,"
111   echo "or get the source tarball at $URL"
112   return 1;
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 `which $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 `which $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 "x$1" = "x"; then
195     return 0
196   fi
197
198   while test "x$1" != "x" ; do
199     optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
200     case "$1" in
201       --noconfigure)
202           NOCONFIGURE=defined
203           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --noconfigure"
204           echo "+ configure run disabled"
205           shift
206           ;;
207       --nocheck)
208           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --nocheck"
209           NOCHECK=defined
210           echo "+ autotools version check disabled"
211           shift
212           ;;
213       --debug)
214           DEBUG=defined
215           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --debug"
216           echo "+ debug output enabled"
217           shift
218           ;;
219       --prefix=*)
220           CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT --prefix=$optarg"
221           echo "+ passing --prefix=$optarg to configure"
222           shift
223           ;;
224       --prefix)
225           shift
226           echo "DEBUG: $1"
227           CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT --prefix=$1"
228           echo "+ passing --prefix=$1 to configure"
229           shift
230           ;;
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=$optarg
248           echo "+ using alternate automake in $optarg"
249           CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-automake=$AUTOMAKE"
250           shift
251           ;;
252       --with-autoconf=*)
253           AUTOCONF=$optarg
254           echo "+ using alternate autoconf in $optarg"
255           CONFIGURE_DEF_OPT="$CONFIGURE_DEF_OPT --with-autoconf=$AUTOCONF"
256           shift
257           ;;
258       --disable*|--enable*|--with*)
259           echo "+ passing option $1 to configure"
260           CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $1"
261           shift
262           ;;
263        --) shift ; break ;;
264       *) echo "- ignoring unknown autogen.sh argument $1"; shift ;;
265     esac
266   done
267
268   # a silly hack that generates autoregen.sh but it's handy
269   echo "#!/bin/sh" > autoregen.sh
270   echo "./autogen.sh $@ \$@" >> autoregen.sh
271   chmod +x autoregen.sh
272
273
274   for arg do CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $arg"; done
275   if test ! -z "$CONFIGURE_EXT_OPT"
276   then
277     echo "+ options passed to configure: $CONFIGURE_EXT_OPT"
278   fi
279 }
280
281 toplevel_check ()
282 {
283   srcfile=$1
284   test -f $srcfile || {
285         echo "You must run this script in the top-level $package directory"
286         exit 1
287   }
288 }
289
290
291 tool_run ()
292 {
293   tool=$1
294   options=$2
295   run_if_fail=$3
296   echo "+ running $tool $options..."
297   $tool $options || {
298     echo
299     echo $tool failed
300     eval $run_if_fail
301     exit 1
302   }
303 }