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