Implement version 3 of virConnectListAllDomains.
[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.4.4.2)
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 libvirt >= 0.2.1 (our minimum supported version).
71 dnl See: http://libvirt.org/hvsupport.html
72 AC_CHECK_FUNC(virConnectGetCapabilities,
73         [],
74         AC_MSG_ERROR([You must have libvirt >= 0.2.1]))
75
76 dnl Check for optional libvirt functions added since 0.2.1.
77 dnl See: http://libvirt.org/hvsupport.html
78 AC_CHECK_FUNCS([virConnectGetHostname \
79                 virConnectGetURI \
80                 virDomainBlockStats \
81                 virDomainGetSchedulerParameters \
82                 virDomainGetSchedulerType \
83                 virDomainInterfaceStats \
84                 virDomainMigrate \
85                 virDomainSetSchedulerParameters \
86                 virNodeGetFreeMemory \
87                 virNodeGetCellsFreeMemory \
88                 virStoragePoolGetConnect \
89                 virConnectNumOfStoragePools \
90                 virConnectListStoragePools \
91                 virConnectNumOfDefinedStoragePools \
92                 virConnectListDefinedStoragePools \
93                 virStoragePoolLookupByName \
94                 virStoragePoolLookupByUUID \
95                 virStoragePoolLookupByUUIDString \
96                 virStoragePoolLookupByVolume \
97                 virStoragePoolCreateXML \
98                 virStoragePoolDefineXML \
99                 virStoragePoolBuild \
100                 virStoragePoolUndefine \
101                 virStoragePoolCreate \
102                 virStoragePoolDestroy \
103                 virStoragePoolDelete \
104                 virStoragePoolFree \
105                 virStoragePoolRefresh \
106                 virStoragePoolGetName \
107                 virStoragePoolGetUUID \
108                 virStoragePoolGetUUIDString \
109                 virStoragePoolGetInfo \
110                 virStoragePoolGetXMLDesc \
111                 virStoragePoolGetAutostart \
112                 virStoragePoolSetAutostart \
113                 virStoragePoolNumOfVolumes \
114                 virStoragePoolListVolumes \
115                 virStorageVolLookupByName \
116                 virStorageVolLookupByKey \
117                 virStorageVolLookupByPath \
118                 virStorageVolGetName \
119                 virStorageVolGetKey \
120                 virStorageVolCreateXML \
121                 virStorageVolDelete \
122                 virStorageVolFree \
123                 virStorageVolGetInfo \
124                 virStorageVolGetXMLDesc \
125                 virStorageVolGetPath \
126                 virDomainBlockPeek \
127                 virDomainMemoryPeek \
128                 virConnectListAllDomains \
129 ])
130
131 # This jobs API was never published and is due to get overhauled
132 # in the near future:
133 #               virJobGetInfo
134 #               virJobGetDomain
135 #               virJobGetNetwork
136 #               virJobCancel
137 #               virJobFree
138 #               virDomainCreateLinuxJob
139 #               virDomainSaveJob
140 #               virDomainRestoreJob
141 #               virDomainCoreDumpJob
142 #               virDomainCreateJob
143 #               virNetworkCreateXMLJob
144 #               virNetworkCreateJob
145
146 dnl Check for optional types added since 0.2.1.
147 AC_CHECK_TYPES([virJobPtr, virStoragePoolPtr, virStorageVolPtr],,,
148                [#include <libvirt/libvirt.h>])
149
150 dnl Check for basic OCaml environment & findlib.
151 AC_PROG_OCAML
152 AC_PROG_FINDLIB
153
154 if test "x$OCAMLFIND" = "x"; then
155     AC_MSG_ERROR([OCaml findlib is required])
156 fi
157
158 dnl Use ocamlfind to find the required packages ...
159
160 dnl Check for required OCaml packages.
161 AC_CHECK_OCAML_PKG(unix)
162 if test "x$pkg_unix" != "xyes"; then
163     AC_MSG_ERROR([Cannot find required OCaml package 'unix'])
164 fi
165
166 dnl Check for optional OCaml packages.
167 AC_CHECK_OCAML_PKG(gettext)
168
169 AC_SUBST(pkg_gettext)
170
171 dnl Check for recommended ocaml-gettext tool.
172 AC_CHECK_PROG(OCAML_GETTEXT,ocaml-gettext,ocaml-gettext)
173
174 dnl Check for optional NSIS (for building a Windows installer).
175 dnl XXX This probably doesn't work at the moment XXX
176 AC_ARG_WITH([nsis],
177         [AS_HELP_STRING([--with-nsis],
178             [use NSIS to build a Windows installer])],
179         [],
180         [with_nsis=no])
181
182 MAKENSIS=
183 LIBVIRT_DLL_PATH=
184 LIBXDR_DLL_PATH=
185 LIBXML2_DLL_PATH=
186 GNUTLS_DLL_PATH=
187 GTK_PATH=
188 GTK_DLL_PATH=
189
190 [
191 msys_to_win_dir () {
192     eval pushd "\$$1" > /dev/null
193     eval $1=`pwd -W`
194     popd > /dev/null
195 }
196 ]
197
198 if test "x$with_nsis" != "xno"; then
199     AC_PATH_PROG(MAKENSIS,makensis,[],[$with_nsis:$PATH])
200     if test "x$MAKENSIS" = "x"; then
201         AC_MSG_FAILURE([--with-nsis was given, but could not find MAKENSIS.EXE])
202     fi
203
204     # MAKENSIS is set so we will build a rule for making a Windows
205     # installer.  To support this, generate wininstaller.nsis.
206     saved_IFS=$IFS
207     IFS=$PATH_SEPARATOR
208     for d in $PATH; do
209         IFS=$saved_IFS
210         echo Checking $d for DLLs ... >&5
211         if test -f "$d/libvirt-0.dll"; then
212             LIBVIRT_DLL_PATH="$d"
213         fi
214         if test -f "$d/libxdr.dll"; then
215             LIBXDR_DLL_PATH="$d"
216         fi
217         if test -f "$d/libxml2-2.dll"; then
218             LIBXML2_DLL_PATH="$d"
219         fi
220         if test -f "$d/libgpg-error-0.dll"; then
221             GNUTLS_DLL_PATH="$d"
222         fi
223         if test -f "$d/libgtk-win32-2.0-0.dll"; then
224             GTK_DLL_PATH="$d"
225             GTK_PATH="$d/.."
226         fi
227     done
228     IFS=$saved_IFS
229
230     if test "x$LIBVIRT_DLL_PATH" = "x"; then
231         AC_MSG_FAILURE([cannot find libvirt-0.dll in PATH])
232     fi
233     if test "x$LIBXDR_DLL_PATH" = "x"; then
234         AC_MSG_FAILURE([cannot find libxdr.dll in PATH])
235     fi
236     if test "x$LIBXML2_DLL_PATH" = "x"; then
237         AC_MSG_FAILURE([cannot find libxml2-2.dll in PATH])
238     fi
239     if test "x$GNUTLS_DLL_PATH" = "x"; then
240         AC_MSG_FAILURE([cannot find GnuTLS DLLs in PATH])
241     fi
242     if test "x$GTK_DLL_PATH" = "x"; then
243         AC_MSG_WARN([cannot find GTK DLLs in PATH])
244     fi
245
246     # Change the paths to Windows paths.
247     msys_to_win_dir LIBVIRT_DLL_PATH
248     msys_to_win_dir LIBXDR_DLL_PATH
249     msys_to_win_dir LIBXML2_DLL_PATH
250     msys_to_win_dir GNUTLS_DLL_PATH
251     if test "x$GTK_DLL_PATH" != "x"; then
252         msys_to_win_dir GTK_DLL_PATH
253         msys_to_win_dir GTK_PATH
254     fi
255 fi
256 AC_SUBST(MAKENSIS)
257 AC_SUBST(LIBVIRT_DLL_PATH)
258 AC_SUBST(LIBXDR_DLL_PATH)
259 AC_SUBST(LIBXML2_DLL_PATH)
260 AC_SUBST(GNUTLS_DLL_PATH)
261 AC_SUBST(GTK_DLL_PATH)
262 AC_SUBST(GTK_PATH)
263
264 dnl Write gettext modules for the programs.
265 dnl http://www.le-gall.net/sylvain+violaine/documentation/ocaml-gettext/html/reference-manual/ch03s04.html
266 for d in mlvirsh; do
267     f=`echo $d | tr - _`_gettext.ml
268     AC_MSG_NOTICE([creating $d/$f])
269     rm -f $d/$f
270     echo "(* This file is generated automatically by ./configure. *)" > $d/$f
271     if test "x$pkg_gettext" != "xno"; then
272         # Gettext module is available, so use it.
273         cat <<EOT >>$d/$f
274 module Gettext = Gettext.Program (
275   struct
276     let textdomain = "$d"
277     let codeset = None
278     let dir = None
279     let dependencies = [[]]
280   end
281 ) (GettextStub.Native)
282 EOT
283     else
284         # No gettext module is available, so fake the translation functions.
285         cat <<EOT >>$d/$f
286 module Gettext = struct
287   external s_ : string -> string = "%identity"
288   external f_ : ('a -> 'b, 'c, 'd) format -> ('a -> 'b, 'c, 'd) format
289     = "%identity"
290   let sn_ : string -> string -> int -> string
291     = fun s p n -> if n = 1 then s else p
292   let fn_ : ('a -> 'b, 'c, 'd) format -> ('a -> 'b, 'c, 'd) format -> int
293       -> ('a -> 'b, 'c, 'd) format
294     = fun s p n -> if n = 1 then s else p
295 end
296 EOT
297     fi
298 done
299
300 dnl Summary.
301 echo "------------------------------------------------------------"
302 echo "Thanks for downloading" $PACKAGE_STRING
303 echo "------------------------------------------------------------"
304
305 dnl Produce output files.
306 AC_CONFIG_HEADERS([config.h])
307 AC_CONFIG_FILES([META
308         libvirt/libvirt_version.ml
309         Makefile
310         Make.rules
311         po/Makefile
312         libvirt/Makefile
313         examples/Makefile
314         mlvirsh/Makefile
315         ])
316 if test "x$MAKENSIS" != "x"; then
317         AC_CONFIG_FILES([wininstaller.nsis])
318 fi
319 AC_OUTPUT