Fixed to build virt-ctrl.
[virt-ctrl.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(virt-ctrl,1.0.0)
21
22 AC_PROG_INSTALL
23
24 dnl Check for optional GNOME icons (from gnome-icon-theme package).
25 AC_ARG_WITH(icons,
26         AC_HELP_STRING([--with-icons=PATH],
27                 [Set path to installed icons @<:@default=/usr/share/icons@:>@]),
28         [],[with_icons=/usr/share/icons])
29 icons=""
30 if test "x$with_icons" != "xno"; then
31     for size in 16 24 32 48; do
32         for f in devices/computer.png; do
33             fname="${with_icons}/gnome/${size}x${size}/${f}"
34             AC_MSG_CHECKING([checking for icon $fname])
35             if test -f "$fname"; then
36                 AC_MSG_RESULT([yes])
37                 icons="$size $f $fname $icons"
38             else
39                 AC_MSG_RESULT([no])
40             fi
41         done
42     done
43 fi
44 AC_SUBST(with_icons)
45 AC_SUBST(icons)
46
47 dnl Check for basic OCaml environment & findlib.
48 AC_PROG_OCAML
49 AC_PROG_FINDLIB
50
51 if test "x$OCAMLFIND" = "x"; then
52     AC_MSG_ERROR([OCaml findlib is required])
53 fi
54
55 dnl Use ocamlfind to find the required packages ...
56
57 dnl Check for required OCaml packages.
58 AC_CHECK_OCAML_PKG(unix)
59 if test "x$pkg_unix" != "xyes"; then
60     AC_MSG_ERROR([Cannot find required OCaml package 'unix'])
61 fi
62
63 AC_CHECK_OCAML_PKG(libvirt)
64 if test "x$pkg_libvirt" != "xyes"; then
65     AC_MSG_ERROR([Cannot find required OCaml package 'libvirt'])
66 fi
67
68 AC_CHECK_OCAML_PKG(lablgtk2)
69 if test "x$pkg_lablgtk2" != "xyes"; then
70     AC_MSG_ERROR([Cannot find required OCaml package 'lablgtk2'])
71 fi
72
73 dnl Check for optional OCaml packages.
74 AC_CHECK_OCAML_PKG(gettext)
75 AC_CHECK_OCAML_PKG(dbus)
76
77 AC_SUBST(pkg_unix)
78 AC_SUBST(pkg_lablgtk2)
79 AC_SUBST(pkg_gettext)
80 AC_SUBST(pkg_dbus)
81
82 dnl Check for optional gdk-pixbuf-mlsource (for icons).
83 AC_CHECK_PROG(HAVE_GDK_PIXBUF_MLSOURCE,gdk-pixbuf-mlsource,gdk-pixbuf-mlsource)
84
85 dnl Check for recommended ocaml-gettext tool.
86 AC_CHECK_PROG(OCAML_GETTEXT,ocaml-gettext,ocaml-gettext)
87
88 dnl Check for optional NSIS (for building a Windows installer).
89 dnl XXX This probably needs some attention XXX
90 AC_ARG_WITH([nsis],
91         [AS_HELP_STRING([--with-nsis],
92             [use NSIS to build a Windows installer])],
93         [],
94         [with_nsis=no])
95
96 MAKENSIS=
97 LIBVIRT_DLL_PATH=
98 LIBXDR_DLL_PATH=
99 LIBXML2_DLL_PATH=
100 GNUTLS_DLL_PATH=
101 GTK_PATH=
102 GTK_DLL_PATH=
103
104 [
105 msys_to_win_dir () {
106     eval pushd "\$$1" > /dev/null
107     eval $1=`pwd -W`
108     popd > /dev/null
109 }
110 ]
111
112 if test "x$with_nsis" != "xno"; then
113     AC_PATH_PROG(MAKENSIS,makensis,[],[$with_nsis:$PATH])
114     if test "x$MAKENSIS" = "x"; then
115         AC_MSG_FAILURE([--with-nsis was given, but could not find MAKENSIS.EXE])
116     fi
117
118     # MAKENSIS is set so we will build a rule for making a Windows
119     # installer.  To support this, generate wininstaller.nsis.
120     saved_IFS=$IFS
121     IFS=$PATH_SEPARATOR
122     for d in $PATH; do
123         IFS=$saved_IFS
124         echo Checking $d for DLLs ... >&5
125         if test -f "$d/libvirt-0.dll"; then
126             LIBVIRT_DLL_PATH="$d"
127         fi
128         if test -f "$d/libxdr.dll"; then
129             LIBXDR_DLL_PATH="$d"
130         fi
131         if test -f "$d/libxml2-2.dll"; then
132             LIBXML2_DLL_PATH="$d"
133         fi
134         if test -f "$d/libgpg-error-0.dll"; then
135             GNUTLS_DLL_PATH="$d"
136         fi
137         if test -f "$d/libgtk-win32-2.0-0.dll"; then
138             GTK_DLL_PATH="$d"
139             GTK_PATH="$d/.."
140         fi
141     done
142     IFS=$saved_IFS
143
144     if test "x$LIBVIRT_DLL_PATH" = "x"; then
145         AC_MSG_FAILURE([cannot find libvirt-0.dll in PATH])
146     fi
147     if test "x$LIBXDR_DLL_PATH" = "x"; then
148         AC_MSG_FAILURE([cannot find libxdr.dll in PATH])
149     fi
150     if test "x$LIBXML2_DLL_PATH" = "x"; then
151         AC_MSG_FAILURE([cannot find libxml2-2.dll in PATH])
152     fi
153     if test "x$GNUTLS_DLL_PATH" = "x"; then
154         AC_MSG_FAILURE([cannot find GnuTLS DLLs in PATH])
155     fi
156     if test "x$GTK_DLL_PATH" = "x"; then
157         AC_MSG_WARN([cannot find GTK DLLs in PATH])
158     fi
159
160     # Change the paths to Windows paths.
161     msys_to_win_dir LIBVIRT_DLL_PATH
162     msys_to_win_dir LIBXDR_DLL_PATH
163     msys_to_win_dir LIBXML2_DLL_PATH
164     msys_to_win_dir GNUTLS_DLL_PATH
165     if test "x$GTK_DLL_PATH" != "x"; then
166         msys_to_win_dir GTK_DLL_PATH
167         msys_to_win_dir GTK_PATH
168     fi
169 fi
170 AC_SUBST(MAKENSIS)
171 AC_SUBST(LIBVIRT_DLL_PATH)
172 AC_SUBST(LIBXDR_DLL_PATH)
173 AC_SUBST(LIBXML2_DLL_PATH)
174 AC_SUBST(GNUTLS_DLL_PATH)
175 AC_SUBST(GTK_DLL_PATH)
176 AC_SUBST(GTK_PATH)
177
178 dnl Write gettext modules for the programs.
179 dnl http://www.le-gall.net/sylvain+violaine/documentation/ocaml-gettext/html/reference-manual/ch03s04.html
180 for d in virt-ctrl; do
181     f=`echo $d | tr - _`_gettext.ml
182     AC_MSG_NOTICE([creating $d/$f])
183     rm -f $d/$f
184     echo "(* This file is generated automatically by ./configure. *)" > $d/$f
185     if test "x$pkg_gettext" != "xno"; then
186         # Gettext module is available, so use it.
187         cat <<EOT >>$d/$f
188 module Gettext = Gettext.Program (
189   struct
190     let textdomain = "$d"
191     let codeset = None
192     let dir = None
193     let dependencies = [[]]
194   end
195 ) (GettextStub.Native)
196 EOT
197     else
198         # No gettext module is available, so fake the translation functions.
199         cat <<EOT >>$d/$f
200 module Gettext = struct
201   external s_ : string -> string = "%identity"
202   external f_ : ('a -> 'b, 'c, 'd) format -> ('a -> 'b, 'c, 'd) format
203     = "%identity"
204   let sn_ : string -> string -> int -> string
205     = fun s p n -> if n = 1 then s else p
206   let fn_ : ('a -> 'b, 'c, 'd) format -> ('a -> 'b, 'c, 'd) format -> int
207       -> ('a -> 'b, 'c, 'd) format
208     = fun s p n -> if n = 1 then s else p
209 end
210 EOT
211     fi
212 done
213
214 dnl Summary.
215 echo "------------------------------------------------------------"
216 echo "Thanks for downloading" $PACKAGE_STRING
217 echo "------------------------------------------------------------"
218
219 dnl Produce output files.
220 AC_CONFIG_HEADERS([config.h])
221 AC_CONFIG_FILES([Makefile
222         Make.rules
223         po/Makefile
224         virt-ctrl/Makefile
225         ])
226 if test "x$MAKENSIS" != "x"; then
227         AC_CONFIG_FILES([wininstaller.nsis])
228 fi
229 AC_OUTPUT