adding / to ignore
[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   test -z "$NOCHECK" && {
114     ac_version=`$autoconf --version|head -n 1|sed 's/^[a-zA-z\.\ ()]*//;s/ .*$//'`
115     if test "$ac_version" = "2.52d"; then
116       echo "autoconf 2.52d has an issue with our current build."
117       echo "We don't know who's to blame however.  So until we do, get a"
118       echo "regular version.  RPM's of a working version are on the gstreamer site."
119       exit 1
120     fi
121   }
122   return 0
123 }
124
125 die_check ()
126 {
127   # call with $DIE
128   # if set to 1, we need to print something helpful then die
129   DIE=$1
130   if test "x$DIE" = "x1";
131   then
132     echo
133     echo "- Please get the right tools before proceeding."
134     echo "- Alternatively, if you're sure we're wrong, run with --nocheck."
135     exit 1
136   fi
137 }
138
139 autogen_options ()
140 {
141   # we use getopt stuff here, copied things from the example example.bash
142   TEMP=`getopt -o h --long noconfigure,nocheck,debug,help,with-automake:,with-autoconf:,prefix:\
143        -- "$@"`
144
145   eval set -- "$TEMP"
146
147   while true ; do
148     case "$1" in
149       --noconfigure)
150           NOCONFIGURE=defined
151           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --noconfigure"
152           echo "+ configure run disabled"
153           shift
154           ;;
155       --nocheck)
156           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --nocheck"
157           NOCHECK=defined
158           echo "+ autotools version check disabled"
159           shift
160           ;;
161       --debug)
162           DEBUG=defined
163           AUTOGEN_EXT_OPT="$AUTOGEN_EXT_OPT --debug"
164           echo "+ debug output enabled"
165           shift
166           ;;
167       --prefix)
168           CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT --prefix=$2"
169           echo "+ passing --prefix=$2 to configure"
170           shift 2
171           ;;
172       -h|--help)
173           echo "autogen.sh (autogen options) -- (configure options)"
174           echo "autogen.sh help options: "
175           echo " --noconfigure            don't run the configure script"
176           echo " --nocheck                don't do version checks"
177           echo " --debug                  debug the autogen process"
178           echo " --prefix                 will be passed on to configure"
179           echo
180           echo " --with-autoconf PATH     use autoconf in PATH"
181           echo " --with-automake PATH     use automake in PATH"
182           echo
183           echo "to pass options to configure, put them as arguments after -- "
184           exit 1
185           ;;
186       --with-automake)
187           AUTOMAKE=$2
188           echo "+ using alternate automake in $2"
189           shift 2
190           ;;
191       --with-autoconf)
192           AUTOCONF=$2
193           echo "+ using alternate autoconf in $2"
194           shift 2
195           ;;
196        --) shift ; break ;;
197       *) echo "Internal error !" ; exit 1 ;;
198     esac
199   done
200
201   for arg do CONFIGURE_EXT_OPT="$CONFIGURE_EXT_OPT $arg"; done
202   if test ! -z "$CONFIGURE_EXT_OPT"
203   then
204     echo "+ options passed to configure: $CONFIGURE_EXT_OPT"
205   fi
206 }
207
208 toplevel_check ()
209 {
210   srcfile=$1
211   test -f $srcfile || {
212         echo "You must run this script in the top-level $package directory"
213         exit 1
214   }
215 }
216
217
218 tool_run ()
219 {
220   tool=$1
221   options=$2
222   echo "+ running $tool $options..."
223   $tool $options || {
224     echo
225     echo $tool failed
226     exit 1
227   }
228 }