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