946466af9431c0f8c7c58e3241432e9b79f9ca4a
[virt-top.git] / configure.ac
1 # virt-top
2 # Copyright (C) 2007-2021 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.9])
21 AM_INIT_AUTOMAKE([foreign])
22 AC_CONFIG_MACRO_DIR([m4])
23
24 AC_PROG_INSTALL
25
26 dnl Enable GNU stuff.
27 AC_USE_SYSTEM_EXTENSIONS
28
29 dnl Check for basic C environment.
30 AC_PROG_CC_STDC
31 AC_PROG_CPP
32 AC_C_PROTOTYPES
33 test "x$U" != "x" && AC_MSG_ERROR([Compiler not ANSI compliant])
34 AM_PROG_CC_C_O
35
36 dnl Check support for 64 bit file offsets.
37 AC_SYS_LARGEFILE
38
39 dnl Check for basic OCaml environment & findlib.
40 AC_PROG_OCAML
41 if test "$OCAMLC" = "no"; then
42     AC_MSG_ERROR([You must install the OCaml compiler])
43 fi
44
45 AM_CONDITIONAL([HAVE_OCAMLOPT],[test "$OCAMLBEST" = "opt"])
46
47 AC_PROG_FINDLIB
48 if test "x$OCAMLFIND" = "xno"; then
49     AC_MSG_ERROR([OCaml findlib is required])
50 fi
51
52 dnl Use ocamlfind to find the required packages ...
53
54 dnl Check for required OCaml packages.
55 AC_CHECK_OCAML_PKG(unix)
56 if test "x$OCAML_PKG_unix" = "xno"; then
57     AC_MSG_ERROR([Cannot find required OCaml package 'unix'])
58 fi
59
60 AC_CHECK_OCAML_PKG(extlib)
61 if test "x$OCAML_PKG_extlib" = "xno"; then
62     AC_MSG_ERROR([Cannot find required OCaml package 'extlib'])
63 fi
64
65 AC_CHECK_OCAML_PKG(libvirt)
66 if test "x$OCAML_PKG_libvirt" = "xno"; then
67     AC_MSG_ERROR([Cannot find required OCaml package 'libvirt'])
68 fi
69
70 AC_CHECK_OCAML_PKG(curses)
71 if test "x$OCAML_PKG_curses" = "xno"; then
72     AC_MSG_ERROR([Cannot find required OCaml package 'curses'])
73 fi
74
75 dnl Check for optional OCaml packages.
76 AC_CHECK_OCAML_PKG(calendar)
77 AC_CHECK_OCAML_PKG(csv)
78 AC_CHECK_OCAML_PKG(gettext)
79 AC_CHECK_OCAML_PKG(xml-light)
80
81 AM_CONDITIONAL([HAVE_PKG_CALENDAR], [test "x$OCAML_PKG_calendar" != "xno"])
82 AM_CONDITIONAL([HAVE_PKG_CSV],      [test "x$OCAML_PKG_csv" != "xno"])
83 AM_CONDITIONAL([HAVE_PKG_GETTEXT],  [test "x$OCAML_PKG_gettext" != "xno"])
84 AM_CONDITIONAL([HAVE_PKG_XML_LIGHT],[test "x$OCAML_PKG_xml_light" != "xno"])
85
86 dnl Check if ocamlc/ocamlopt -runtime-variant _pic works.  It was
87 dnl added in OCaml >= 4.03, but in theory might be disabled by
88 dnl downstream distros.
89 OCAML_RUNTIME_VARIANT_PIC_OPTION=""
90 if test "x$OCAMLC" != "xno"; then
91     AC_MSG_CHECKING([if OCaml ‘-runtime-variant _pic’ works])
92     rm -f conftest.ml contest
93     echo 'print_endline "hello world"' > conftest.ml
94     if $OCAMLOPT conftest.ml -runtime-variant _pic -o conftest >&5 2>&5 ; then
95         AC_MSG_RESULT([yes])
96         OCAML_RUNTIME_VARIANT_PIC_OPTION="-runtime-variant _pic"
97     else
98         AC_MSG_RESULT([no])
99     fi
100     rm -f conftest.ml contest
101 fi
102 AC_SUBST([OCAML_RUNTIME_VARIANT_PIC_OPTION])
103
104 dnl Check for optional perldoc (for building manual pages).
105 AC_CHECK_PROG([HAVE_PERLDOC], perldoc, perldoc)
106 AM_CONDITIONAL([HAVE_PERLDOC], [test "x$HAVE_PERLDOC" = "xperldoc"])
107
108 dnl Check for recommended ocaml-gettext tool.
109 AC_CHECK_PROG([OCAML_GETTEXT], ocaml-gettext, ocaml-gettext)
110 AM_CONDITIONAL([HAVE_OCAML_GETTEXT],[test "x$OCAML_GETTEXT" = "xocaml-gettext"])
111
112 dnl Check for GNU gettext tools (optional).
113 AC_CHECK_PROG([XGETTEXT],[xgettext],[xgettext],[no])
114 AC_CHECK_PROG([MSGCAT],[msgcat],[msgcat],[no])
115 AC_CHECK_PROG([MSGFMT],[msgfmt],[msgfmt],[no])
116 AC_CHECK_PROG([MSGMERGE],[msgmerge],[msgmerge],[no])
117
118 dnl Check they are the GNU gettext tools.
119 AC_MSG_CHECKING([msgfmt is GNU tool])
120 if $MSGFMT --version >/dev/null 2>&1 && $MSGFMT --version | grep -q 'GNU gettext
121 '; then
122     msgfmt_is_gnu=yes
123 else
124     msgfmt_is_gnu=no
125 fi
126 AC_MSG_RESULT([$msgfmt_is_gnu])
127 AM_CONDITIONAL([HAVE_GNU_GETTEXT],
128     [test "x$XGETTEXT" != "xno" && test "x$MSGCAT" != "xno" && test "x$MSGFMT" != "xno" && test "x$MSGMERGE" != "xno" && test "x$msgfmt_is_gnu" != "xno"])
129
130 dnl Check for gettext.
131 AM_GNU_GETTEXT([external])
132
133 dnl Write gettext modules for the programs.
134 dnl http://www.le-gall.net/sylvain+violaine/documentation/ocaml-gettext/html/reference-manual/ch03s04.html
135 AC_MSG_NOTICE([creating src/opt_gettext.ml])
136 rm -f src/opt_gettext.ml
137 echo "(* This file is generated automatically by ./configure. *)" > src/opt_gettext.ml
138 if test "x$OCAML_PKG_gettext" != "xno"; then
139     # Gettext module is available, so use it.
140     cat <<EOT >>src/opt_gettext.ml
141 module Gettext = Gettext.Program (
142   struct
143     let textdomain = "virt-top"
144     let codeset = None
145     let dir = None
146     let dependencies = [[]]
147   end
148 ) (GettextStub.Native)
149 EOT
150 else
151     # No gettext module is available, so fake the translation functions.
152     cat <<EOT >>src/opt_gettext.ml
153 module Gettext = struct
154   external s_ : string -> string = "%identity"
155   external f_ : ('a -> 'b, 'c, 'd) format -> ('a -> 'b, 'c, 'd) format
156     = "%identity"
157   let sn_ : string -> string -> int -> string
158     = fun s p n -> if n = 1 then s else p
159   let fn_ : ('a -> 'b, 'c, 'd) format -> ('a -> 'b, 'c, 'd) format -> int
160       -> ('a -> 'b, 'c, 'd) format
161     = fun s p n -> if n = 1 then s else p
162 end
163 EOT
164 fi
165
166 dnl Summary.
167 echo "------------------------------------------------------------"
168 echo "Thanks for downloading" $PACKAGE_STRING
169 echo "------------------------------------------------------------"
170
171 dnl Produce output files.
172 AC_CONFIG_HEADERS([config.h])
173 AC_CONFIG_FILES([ocaml-dep.sh],  [chmod +x,-w ocaml-dep.sh])
174 AC_CONFIG_FILES([ocaml-link.sh], [chmod +x,-w ocaml-link.sh])
175 AC_CONFIG_FILES([Makefile
176         po/Makefile
177         src/Makefile
178         src/version.ml
179         ])
180 AC_OUTPUT