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