adding informative message when we die because of tools problems changed the tr to...
[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   # remove any non-digit characters from the version numbers to permit numeric
51   # comparison
52   pkg_major=`echo $pkg_version | cut -d. -f1 | sed s/[a-zA-Z\-].*//g`
53   pkg_minor=`echo $pkg_version | cut -d. -f2 | sed s/[a-zA-Z\-].*//g`
54   pkg_micro=`echo $pkg_version | cut -d. -f3 | sed s/[a-zA-Z\-].*//g`
55   test -z "$pkg_minor" && pkg_minor=0
56   test -z "$pkg_micro" && pkg_micro=0
57
58   debug "found major $pkg_major minor $pkg_minor micro $pkg_micro"
59
60   #start checking the version
61   debug "version check"
62
63   if [ ! "$pkg_major" -gt "$MAJOR" ]; then
64     debug "$pkg_major <= $MAJOR"
65     if [ "$pkg_major" -lt "$MAJOR" ]; then
66       WRONG=1
67     elif [ ! "$pkg_minor" -gt "$MINOR" ]; then
68       if [ "$pkg_minor" -lt "$MINOR" ]; then
69         WRONG=1
70       elif [ "$pkg_micro" -lt "$MICRO" ]; then
71         WRONG=1
72       fi
73     fi
74   fi
75
76   if test ! -z "$WRONG"; then
77     echo "found $pkg_version, not ok !"
78     echo
79     echo "You must have $PACKAGE $VERSION or greater to compile $package."
80     echo "Get the latest version from $URL"
81     echo
82     return 1
83   else
84     echo "found $pkg_version, ok."
85   fi
86 }
87
88 autoconf_2.52d_check ()
89 {
90   # autoconf 2.52d has a weird issue involving a yes:no error
91   # so don't allow it's use
92   ac_version=`autoconf --version|head -n 1|sed 's/^[a-zA-z\.\ ()]*//;s/ .*$//'`
93   if test "$ac_version" = "2.52d"; then
94     echo "autoconf 2.52d has an issue with our current build."
95     echo "We don't know who's to blame however.  So until we do, get a"
96     echo "regular version.  RPM's of a working version are on the gstreamer site."
97     exit 1
98   fi
99 }
100
101 die_check ()
102 {
103   # call with $DIE
104   # if set to 1, we need to print something helpful then die
105   DIE=$1
106   if test "x$DIE" = "x1";
107   then
108     echo
109     echo "- Please get the right tools before proceeding."
110     echo "- Alternatively, if you're sure we're wrong, run with --autogen-nocheck."
111     exit 1
112   fi
113 }
114
115 autogen_options ()
116 {
117   for i in $@; do
118       if test "$i" = "--autogen-noconfigure"; then
119           NOCONFIGURE=defined
120           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --autogen-noconfigure"
121           echo "+ configure run disabled"
122       elif test "$i" = "--autogen-nocheck"; then
123           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --autogen-nocheck"
124           NOCHECK=defined
125           echo "+ autotools version check disabled"
126       elif test "$i" = "--autogen-debug"; then
127           DEBUG=defined
128           echo "+ debug output enabled"
129           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --autogen-debug"
130       elif test "$i" = "--help"; then
131           echo "autogen.sh help options: "
132           echo " --autogen-noconfigure    don't run the configure script"
133           echo " --autogen-nocheck        don't do version checks"
134           echo " --autogen-debug          debug the autogen process"
135           exit 1
136       else
137           CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $i"
138       fi
139   done
140 }
141
142 toplevel_check ()
143 {
144   srcfile=$1
145   test -f $srcfile || {
146         echo "You must run this script in the top-level $package directory"
147         exit 1
148   }
149 }
150
151
152 tool_run ()
153 {
154   tool=$1
155   options=$2
156   echo "+ running $tool $options..."
157   $tool $options || {
158     echo
159     echo $tool failed
160     exit 1
161   }
162 }