do lexical comparison on version parts
[platform/upstream/gstreamer.git] / autogen.sh
1 #!/bin/sh
2 # Run this to generate all the initial makefiles, etc.
3
4 DIE=0
5 package=GStreamer
6 srcfile=gst/gstobject.h
7 #DEBUG=defined
8
9 debug ()
10 # print out a debug message if DEBUG is a defined variable
11 {
12   if test ! -z $DEBUG
13   then
14     echo "DEBUG: $1"
15   fi
16 }
17
18 version_check ()
19 # check the version of a package
20 # first argument : package name (executable)
21 # second argument : source download url
22 # rest of arguments : major, minor, micro version
23 {
24   PACKAGE=$1
25   URL=$2
26   MAJOR=$3
27   MINOR=$4
28   MICRO=$5
29
30
31   debug "major $MAJOR minor $MINOR micro $MICRO"
32   VERSION=$MAJOR
33   if test ! -z $MINOR; then VERSION=$VERSION.$MINOR; else MINOR=0; fi
34   if test ! -z $MICRO; then VERSION=$VERSION.$MICRO; else MICRO=0; fi
35
36   debug "major $MAJOR minor $MINOR micro $MICRO"
37   echo "Checking for $1 > $VERSION ..."
38   ($PACKAGE --version) < /dev/null > /dev/null 2>&1 || 
39   {
40         echo
41         echo "You must have $PACKAGE installed to compile $package."
42         echo "Download the appropriate package for your distribution,"
43         echo "or get the source tarball at $URL"
44         return 1
45   }
46   # the following line is carefully crafted sed magic
47   pkg_version=`$PACKAGE --version|head -n 1|sed 's/^[a-zA-z\.\ ()]*//;s/ .*$//'`
48   debug "pkg_version $pkg_version"
49   pkg_major=`echo $pkg_version | cut -d. -f1`
50   pkg_minor=`echo $pkg_version | cut -d. -f2`
51   pkg_micro=`echo $pkg_version | cut -d. -f3`
52   test -z $pkg_minor && pkg_minor=0
53   test -z $pkg_micro && pkg_micro=0
54
55   debug "found major $pkg_major minor $pkg_minor micro $pkg_micro"
56
57   #start checking the version
58   debug "version check"
59
60   if [ "$pkg_major" \< "$MAJOR -o "$pkg_major" = $MAJOR" ]; then
61     debug "$pkg_major <= $MAJOR"
62     if [ "$pkg_major" \< "$MAJOR" ]; then
63       WRONG=1
64     elif [ "$pkg_minor" \< "$MINOR -o $pkg_minor = $MINOR" ]; then
65       if [ "$pkg_minor" \< "$MINOR" ]; then
66         WRONG=1
67       elif [ "$pkg_micro" \< "$MICRO" ]; then
68         WRONG=1
69       fi
70     fi
71   fi
72
73   if test ! -z $WRONG; then
74     echo
75     echo "You must have $PACKAGE $VERSION or greater to compile $package."
76     echo "Get the latest version from $URL"
77     return 1
78   fi
79 }
80
81 version_check "autoconf" "ftp://ftp.gnu.org/pub/gnu/autoconf/" 2 52 || DIE=1
82 version_check "automake" "ftp://ftp.gnu.org/pub/gnu/automake/" 1 5 || DIE=1
83 version_check "libtool" "ftp://ftp.gnu.org/pub/gnu/libtool/" 1 4 0 || DIE=1
84 version_check "pkg-config" "http://www.freedesktop.org/software/pkgconfig" 0 7 0 || DIE=1
85
86 if test "$DIE" -eq 1; then
87         exit 1
88 fi
89
90 test -f $srcfile || {
91         echo "You must run this script in the top-level $package directory"
92         exit 1
93 }
94
95 if test -z "$*"; then
96         echo "I am going to run ./configure with no arguments - if you wish "
97         echo "to pass any to it, please specify them on the $0 command line."
98 fi
99
100
101 libtoolize --copy --force
102 aclocal $ACLOCAL_FLAGS || {
103         echo
104         echo "aclocal failed - check that all needed development files are present on system"
105         exit 1
106 }
107 autoheader || {
108         echo
109         echo "autoheader failed"
110         exit 1
111 }
112 autoconf || {
113         echo
114         echo "autoconf failed"
115         #exit 1
116 }
117 automake --add-missing || {
118         echo
119         echo "automake failed"
120         #exit 1
121 }
122
123 # now remove the cache, because it can be considered dangerous in this case
124 rm -f config.cache
125
126 CONFIGURE_OPT='--enable-maintainer-mode --enable-plugin-builddir --enable-debug --enable-DEBUG'
127
128 echo
129 echo "./configure default flags: $CONFIGURE_OPT"
130 echo "using: $CONFIGURE_OPT $@"
131 echo
132
133 ./configure $CONFIGURE_OPT "$@" || {
134         echo
135         echo "configure failed"
136         exit 1
137 }
138
139 echo 
140 echo "Now type 'make' to compile $package."