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