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