Fix compilation if readline library is not present.
[libguestfs.git] / autogen.sh
1 #!/bin/bash -
2 # libguestfs
3 # Copyright (C) 2009 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #
19 # Rebuild the autotools environment.
20
21 set -e
22 set -v
23
24 # Ensure that whenever we pull in a gnulib update or otherwise change to a
25 # different version (i.e., when switching branches), we also rerun ./bootstrap.
26 curr_status=.git-module-status
27 t=$(git submodule status)
28 if test "$t" = "$(cat $curr_status 2>/dev/null)"; then
29     : # good, it's up to date
30 else
31     echo running bootstrap...
32     ./bootstrap && echo "$t" > $curr_status
33 fi
34
35 CONFIGUREDIR=.
36
37 # Run configure in BUILDDIR if it's set
38 if [ ! -z "$BUILDDIR" ]; then
39     mkdir -p $BUILDDIR
40     cd $BUILDDIR
41
42     CONFIGUREDIR=..
43 fi
44
45 # Ensure that an ocaml package is present for build-from sources.
46 # This is *not* for anything that is required at configure-time
47 # when configure is run from a distribution tarball.  From those,
48 # nothing ocaml-related is required.
49 require_ocaml_pkg()
50 {
51   pkg=$1
52   test -d .git || return 1
53   url=$(git config remote.origin.url) || return 1
54   case $url in
55     *git.et.redhat.com/libguestfs.git) ;;
56     *) return 1;;
57   esac
58   ocamlfind query "$pkg" || return 1
59   return 0
60 }
61
62 require_ocaml_pkg xml-light \
63   || { echo "you must have ocaml, ocamlfind and ocaml-xml-light"; exit 1; }
64
65 # If no arguments were specified and configure has run before, use the previous
66 # arguments
67 if [ $# == 0 -a -x ./config.status ]; then
68     ./config.status --recheck
69 else
70     $CONFIGUREDIR/configure "$@"
71 fi