39075f0a0705441bc34fc933b4bda1696fffa371
[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 {
19   PACKAGE=$1
20   PKG_PATH=$2
21   URL=$3
22   MAJOR=$4
23   MINOR=$5
24   MICRO=$6
25
26   WRONG=
27
28   if test ! -z "$PKG_PATH"
29   then
30     COMMAND="$PKG_PATH"
31   else
32     COMMAND="$PACKAGE"  
33   fi
34   debug "major $MAJOR minor $MINOR micro $MICRO"
35   VERSION=$MAJOR
36   if test ! -z "$MINOR"; then VERSION=$VERSION.$MINOR; else MINOR=0; fi
37   if test ! -z "$MICRO"; then VERSION=$VERSION.$MICRO; else MICRO=0; fi
38
39   debug "major $MAJOR minor $MINOR micro $MICRO"
40   
41   test -z "$NOCHECK" && {
42       echo -n "  checking for $1 >= $VERSION"
43       if test ! -z "$PKG_PATH"; then echo -n " (in $PKG_PATH)"; fi
44       echo -n "... "
45   } || {
46     # we set a var with the same name as the package, but stripped of
47     # unwanted chars
48     VAR=`echo $PACKAGE | sed 's/-//g'`
49     debug "setting $VAR"
50     eval $VAR="$COMMAND"
51       return 0
52   }
53
54   debug "checking version with $COMMAND"
55   ($COMMAND --version) < /dev/null > /dev/null 2>&1 || 
56   {
57         echo "not found !"
58         echo "You must have $PACKAGE installed to compile $package."
59         echo "Download the appropriate package for your distribution,"
60         echo "or get the source tarball at $URL"
61         return 1
62   }
63   # the following line is carefully crafted sed magic
64   #pkg_version=`$COMMAND --version|head -n 1|sed 's/^[a-zA-z\.\ ()]*//;s/ .*$//'`
65   pkg_version=`$COMMAND --version|head -n 1|sed 's/^.*) //'|sed 's/ (.*)//'`
66   debug "pkg_version $pkg_version"
67   # remove any non-digit characters from the version numbers to permit numeric
68   # comparison
69   pkg_major=`echo $pkg_version | cut -d. -f1 | sed s/[a-zA-Z\-].*//g`
70   pkg_minor=`echo $pkg_version | cut -d. -f2 | sed s/[a-zA-Z\-].*//g`
71   pkg_micro=`echo $pkg_version | cut -d. -f3 | sed s/[a-zA-Z\-].*//g`
72   test -z "$pkg_minor" && pkg_minor=0
73   test -z "$pkg_micro" && pkg_micro=0
74
75   debug "found major $pkg_major minor $pkg_minor micro $pkg_micro"
76
77   #start checking the version
78   debug "version check"
79
80   if [ ! "$pkg_major" -gt "$MAJOR" ]; then
81     debug "$pkg_major <= $MAJOR"
82     if [ "$pkg_major" -lt "$MAJOR" ]; then
83       WRONG=1
84     elif [ ! "$pkg_minor" -gt "$MINOR" ]; then
85       if [ "$pkg_minor" -lt "$MINOR" ]; then
86         WRONG=1
87       elif [ "$pkg_micro" -lt "$MICRO" ]; then
88         WRONG=1
89       fi
90     fi
91   fi
92
93   if test ! -z "$WRONG"; then
94     echo "found $pkg_version, not ok !"
95     echo
96     echo "You must have $PACKAGE $VERSION or greater to compile $package."
97     echo "Get the latest version from $URL"
98     echo
99     return 1
100   else
101     echo "found $pkg_version, ok."
102     # we set a var with the same name as the package, but stripped of
103     # unwanted chars
104     VAR=`echo $PACKAGE | sed 's/-//g'`
105     debug "setting $VAR"
106     eval $VAR="$COMMAND"
107   fi
108 }
109
110 autoconf_2.52d_check ()
111 {
112   # autoconf 2.52d has a weird issue involving a yes:no error
113   # so don't allow it's use
114   test -z "$NOCHECK" && {
115     ac_version=`$autoconf --version|head -n 1|sed 's/^[a-zA-z\.\ ()]*//;s/ .*$//'`
116     if test "$ac_version" = "2.52d"; then
117       echo "autoconf 2.52d has an issue with our current build."
118       echo "We don't know who's to blame however.  So until we do, get a"
119       echo "regular version.  RPM's of a working version are on the gstreamer site."
120       exit 1
121     fi
122   }
123   return 0
124 }
125
126 die_check ()
127 {
128   # call with $DIE
129   # if set to 1, we need to print something helpful then die
130   DIE=$1
131   if test "x$DIE" = "x1";
132   then
133     echo
134     echo "- Please get the right tools before proceeding."
135     echo "- Alternatively, if you're sure we're wrong, run with --nocheck."
136     exit 1
137   fi
138 }
139
140 autogen_options ()
141 {
142   # we use getopt stuff here, copied things from the example example.bash
143   TEMP=`getopt -o h --long noconfigure,nocheck,debug,help,with-automake:,with-autoconf:,prefix:\
144        -- "$@"`
145
146   eval set -- "$TEMP"
147
148   while true ; do
149     case "$1" in
150       --noconfigure)
151           NOCONFIGURE=defined
152           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --noconfigure"
153           echo "+ configure run disabled"
154           shift
155           ;;
156       --nocheck)
157           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --nocheck"
158           NOCHECK=defined
159           echo "+ autotools version check disabled"
160           shift
161           ;;
162       --debug)
163           DEBUG=defined
164           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --debug"
165           echo "+ debug output enabled"
166           shift
167           ;;
168       --prefix)
169           CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT --prefix=$2"
170           echo "+ passing --prefix=$2 to configure"
171           shift 2
172           ;;
173       -h|--help)
174           echo "autogen.sh (autogen options) -- (configure options)"
175           echo "autogen.sh help options: "
176           echo " --noconfigure            don't run the configure script"
177           echo " --nocheck                don't do version checks"
178           echo " --debug                  debug the autogen process"
179           echo " --prefix                 will be passed on to configure"
180           echo
181           echo " --with-autoconf PATH     use autoconf in PATH"
182           echo " --with-automake PATH     use automake in PATH"
183           echo
184           echo "to pass options to configure, put them as arguments after -- "
185           exit 1
186           ;;
187       --with-automake)
188           AUTOMAKE=$2
189           echo "+ using alternate automake in $2"
190           shift 2
191           ;;
192       --with-autoconf)
193           AUTOCONF=$2
194           echo "+ using alternate autoconf in $2"
195           shift 2
196           ;;
197        --) shift ; break ;;
198       *) echo "Internal error !" ; exit 1 ;;
199     esac
200   done
201
202   for arg do CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $arg"; done
203   if test ! -z "$CONFIGURE_EXT_OPT"
204   then
205     echo "+ options passed to configure: $CONFIGURE_EXT_OPT"
206   fi
207 }
208
209 toplevel_check ()
210 {
211   srcfile=$1
212   test -f $srcfile || {
213         echo "You must run this script in the top-level $package directory"
214         exit 1
215   }
216 }
217
218
219 tool_run ()
220 {
221   tool=$1
222   options=$2
223   echo "+ running $tool $options..."
224   $tool $options || {
225     echo
226     echo $tool failed
227     exit 1
228   }
229 }