f359cca83afd6eddeeca3da05058b91a35e8dcab
[ocaml-libvirt.git] / configure.ac
1 # ocaml-libvirt
2 # Copyright (C) 2007-2008 Red Hat Inc., Richard W.M. Jones
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
18 dnl Process this file with autoconf to produce a configure script.
19
20 AC_INIT(ocaml-libvirt,0.6.1.3)
21
22 dnl Check for basic C environment.
23 AC_PROG_CC
24 AC_PROG_INSTALL
25 AC_PROG_CPP
26
27 AC_C_PROTOTYPES
28 test "x$U" != "x" && AC_MSG_ERROR(Compiler not ANSI compliant)
29
30 AC_PROG_CC_C_O
31
32 dnl Select some C flags based on the host type.
33 AC_CANONICAL_HOST
34
35 DEBUG="-g"
36 WARNINGS="-Wall -Werror"
37 CFLAGS_FPIC="-fPIC"
38 WIN32=no
39 case "$host" in
40   *-*-mingw*)
41     WARNINGS="$WARNINGS -Wno-unused"
42     CFLAGS_FPIC=""
43     WIN32=yes
44 esac
45 AC_SUBST(DEBUG)
46 AC_SUBST(WARNINGS)
47 AC_SUBST(CFLAGS_FPIC)
48 AC_SUBST(WIN32)
49
50 dnl Check for libvirt development environment.
51 AC_ARG_WITH(libvirt,
52         AC_HELP_STRING([--with-libvirt=PATH],[Set path to installed libvirt]),
53         [if test "x$withval" != "x"; then
54            CFLAGS="$CFLAGS -I$withval/include"
55            LDFLAGS="$LDFLAGS -L$withval/lib"
56          fi
57         ])
58 AC_CHECK_LIB(virt,virConnectOpen,
59         [],
60         AC_MSG_ERROR([You must install libvirt library]))
61 AC_CHECK_HEADER([libvirt/libvirt.h],
62         [],
63         AC_MSG_ERROR([You must install libvirt development package]))
64
65 dnl We also use <libvirt/virterror.h>
66 AC_CHECK_HEADER([libvirt/virterror.h],
67         [],
68         AC_MSG_ERROR([You must install libvirt development package]))
69
70 dnl Check for basic OCaml environment & findlib.
71 AC_PROG_OCAML
72 AC_PROG_FINDLIB
73
74 if test "x$OCAMLFIND" = "x"; then
75     AC_MSG_ERROR([OCaml findlib is required])
76 fi
77
78 dnl Use ocamlfind to find the required packages ...
79
80 dnl Check for required OCaml packages.
81 AC_CHECK_OCAML_PKG(unix)
82 if test "x$pkg_unix" != "xyes"; then
83     AC_MSG_ERROR([Cannot find required OCaml package 'unix'])
84 fi
85
86 dnl Check for optional NSIS (for building a Windows installer).
87 dnl XXX This probably doesn't work at the moment XXX
88 AC_ARG_WITH([nsis],
89         [AS_HELP_STRING([--with-nsis],
90             [use NSIS to build a Windows installer])],
91         [],
92         [with_nsis=no])
93
94 MAKENSIS=
95 LIBVIRT_DLL_PATH=
96 LIBXDR_DLL_PATH=
97 LIBXML2_DLL_PATH=
98 GNUTLS_DLL_PATH=
99 GTK_PATH=
100 GTK_DLL_PATH=
101
102 [
103 msys_to_win_dir () {
104     eval pushd "\$$1" > /dev/null
105     eval $1=`pwd -W`
106     popd > /dev/null
107 }
108 ]
109
110 if test "x$with_nsis" != "xno"; then
111     AC_PATH_PROG(MAKENSIS,makensis,[],[$with_nsis:$PATH])
112     if test "x$MAKENSIS" = "x"; then
113         AC_MSG_FAILURE([--with-nsis was given, but could not find MAKENSIS.EXE])
114     fi
115
116     # MAKENSIS is set so we will build a rule for making a Windows
117     # installer.  To support this, generate wininstaller.nsis.
118     saved_IFS=$IFS
119     IFS=$PATH_SEPARATOR
120     for d in $PATH; do
121         IFS=$saved_IFS
122         echo Checking $d for DLLs ... >&5
123         if test -f "$d/libvirt-0.dll"; then
124             LIBVIRT_DLL_PATH="$d"
125         fi
126         if test -f "$d/libxdr.dll"; then
127             LIBXDR_DLL_PATH="$d"
128         fi
129         if test -f "$d/libxml2-2.dll"; then
130             LIBXML2_DLL_PATH="$d"
131         fi
132         if test -f "$d/libgpg-error-0.dll"; then
133             GNUTLS_DLL_PATH="$d"
134         fi
135         if test -f "$d/libgtk-win32-2.0-0.dll"; then
136             GTK_DLL_PATH="$d"
137             GTK_PATH="$d/.."
138         fi
139     done
140     IFS=$saved_IFS
141
142     if test "x$LIBVIRT_DLL_PATH" = "x"; then
143         AC_MSG_FAILURE([cannot find libvirt-0.dll in PATH])
144     fi
145     if test "x$LIBXDR_DLL_PATH" = "x"; then
146         AC_MSG_FAILURE([cannot find libxdr.dll in PATH])
147     fi
148     if test "x$LIBXML2_DLL_PATH" = "x"; then
149         AC_MSG_FAILURE([cannot find libxml2-2.dll in PATH])
150     fi
151     if test "x$GNUTLS_DLL_PATH" = "x"; then
152         AC_MSG_FAILURE([cannot find GnuTLS DLLs in PATH])
153     fi
154     if test "x$GTK_DLL_PATH" = "x"; then
155         AC_MSG_WARN([cannot find GTK DLLs in PATH])
156     fi
157
158     # Change the paths to Windows paths.
159     msys_to_win_dir LIBVIRT_DLL_PATH
160     msys_to_win_dir LIBXDR_DLL_PATH
161     msys_to_win_dir LIBXML2_DLL_PATH
162     msys_to_win_dir GNUTLS_DLL_PATH
163     if test "x$GTK_DLL_PATH" != "x"; then
164         msys_to_win_dir GTK_DLL_PATH
165         msys_to_win_dir GTK_PATH
166     fi
167 fi
168 AC_SUBST(MAKENSIS)
169 AC_SUBST(LIBVIRT_DLL_PATH)
170 AC_SUBST(LIBXDR_DLL_PATH)
171 AC_SUBST(LIBXML2_DLL_PATH)
172 AC_SUBST(GNUTLS_DLL_PATH)
173 AC_SUBST(GTK_DLL_PATH)
174 AC_SUBST(GTK_PATH)
175
176 dnl Summary.
177 echo "------------------------------------------------------------"
178 echo "Thanks for downloading" $PACKAGE_STRING
179 echo "------------------------------------------------------------"
180
181 dnl Produce output files.
182 AC_CONFIG_HEADERS([config.h])
183 AC_CONFIG_FILES([META
184         libvirt/libvirt_version.ml
185         Makefile
186         Make.rules
187         libvirt/Makefile
188         examples/Makefile
189         ])
190 if test "x$MAKENSIS" != "x"; then
191         AC_CONFIG_FILES([wininstaller.nsis])
192 fi
193 AC_OUTPUT