slurp autogen-specific options to AUTOGEN_EXT_OPT for use in autogenning sub-packages...
[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 : source download url
16 # rest of arguments : major, minor, micro version
17 {
18   PACKAGE=$1
19   URL=$2
20   MAJOR=$3
21   MINOR=$4
22   MICRO=$5
23
24   WRONG=
25
26   debug "major $MAJOR minor $MINOR micro $MICRO"
27   VERSION=$MAJOR
28   if test ! -z "$MINOR"; then VERSION=$VERSION.$MINOR; else MINOR=0; fi
29   if test ! -z "$MICRO"; then VERSION=$VERSION.$MICRO; else MICRO=0; fi
30
31   debug "major $MAJOR minor $MINOR micro $MICRO"
32   
33   test -z "$NOCHECK" && {
34       echo -n "  checking for $1 >= $VERSION ... "
35   } || {
36       return 0
37   }
38   
39   ($PACKAGE --version) < /dev/null > /dev/null 2>&1 || 
40   {
41         echo
42         echo "You must have $PACKAGE installed to compile $package."
43         echo "Download the appropriate package for your distribution,"
44         echo "or get the source tarball at $URL"
45         return 1
46   }
47   # the following line is carefully crafted sed magic
48   pkg_version=`$PACKAGE --version|head -n 1|sed 's/^[a-zA-z\.\ ()]*//;s/ .*$//'`
49   debug "pkg_version $pkg_version"
50   pkg_major=`echo $pkg_version | cut -d. -f1`
51   pkg_minor=`echo $pkg_version | cut -d. -f2`
52   pkg_micro=`echo $pkg_version | cut -d. -f3`
53   test -z "$pkg_minor" && pkg_minor=0
54   test -z "$pkg_micro" && pkg_micro=0
55
56   debug "found major $pkg_major minor $pkg_minor micro $pkg_micro"
57
58   #start checking the version
59   debug "version check"
60
61   if [ ! "$pkg_major" -gt "$MAJOR" ]; then
62     debug "$pkg_major <= $MAJOR"
63     if [ "$pkg_major" -lt "$MAJOR" ]; then
64       WRONG=1
65     elif [ ! "$pkg_minor" -gt "$MINOR" ]; then
66       if [ "$pkg_minor" -lt "$MINOR" ]; then
67         WRONG=1
68       elif [ "$pkg_micro" -lt "$MICRO" ]; then
69         WRONG=1
70       fi
71     fi
72   fi
73
74   if test ! -z "$WRONG"; then
75     echo "found $pkg_version, not ok !"
76     echo
77     echo "You must have $PACKAGE $VERSION or greater to compile $package."
78     echo "Get the latest version from $URL"
79     return 1
80   else
81     echo "found $pkg_version, ok."
82   fi
83 }
84
85 autoconf_2.52d_check ()
86 {
87   # autoconf 2.52d has a weird issue involving a yes:no error
88   # so don't allow it's use
89   ac_version=`autoconf --version|head -n 1|sed 's/^[a-zA-z\.\ ()]*//;s/ .*$//'`
90   if test "$ac_version" = "2.52d"; then
91     echo "autoconf 2.52d has an issue with our current build."
92     echo "We don't know who's to blame however.  So until we do, get a"
93     echo "regular version.  RPM's of a working version are on the gstreamer site."
94     exit 1
95   fi
96 }
97
98 autogen_options ()
99 {
100   for i in $@; do
101       if test "$i" = "--autogen-noconfigure"; then
102           NOCONFIGURE=defined
103           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --autogen-noconfigure"
104           echo "+ configure run disabled"
105       elif test "$i" = "--autogen-nocheck"; then
106           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --autogen-nocheck"
107           NOCHECK=defined
108           echo "+ autotools version check disabled"
109       elif test "$i" = "--autogen-debug"; then
110           DEBUG=defined
111           echo "+ debug output enabled"
112           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --autogen-debug"
113       elif test "$i" = "--help"; then
114           echo "autogen.sh help options: "
115           echo " --autogen-noconfigure    don't run the configure script"
116           echo " --autogen-nocheck        don't do version checks"
117           echo " --autogen-debug          debug the autogen process"
118           exit 1
119       else
120           CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $i"
121       fi
122   done
123 }
124
125 toplevel_check ()
126 {
127   srcfile=$1
128   test -f $srcfile || {
129         echo "You must run this script in the top-level $package directory"
130         exit 1
131   }
132 }
133
134
135 tool_run ()
136 {
137   tool=$1
138   options=$2
139   echo "+ running $tool $options..."
140   $tool $options || {
141     echo
142     echo $tool failed
143     exit 1
144   }
145 }