1AC_PREREQ([2.57])
2
3# Follow the libtool manual for the so version:
4# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
5# - If the library source code has changed at all since the last update,
6#   then increment revision (‘c:r:a’ becomes ‘c:r+1:a’).
7# - If any interfaces have been added, removed, or changed since the last update,
8#   increment current, and set revision to 0.
9# - If any interfaces have been added since the last public release,
10#   then increment age.
11# - If any interfaces have been removed or changed since the last public release,
12#   then set age to 0.
13#
14dnl TODO see server/spice-char.h TODO comment for API breakage
15m4_define([SPICE_CURRENT], [15])
16m4_define([SPICE_REVISION], [1])
17m4_define([SPICE_AGE], [14])
18
19AC_INIT(spice, [m4_esyscmd(build-aux/git-version-gen .tarball-version)],
20        [spice-devel@lists.freedesktop.org], spice)
21
22major=`echo $PACKAGE_VERSION | cut -d. -f1`
23minor=`echo $PACKAGE_VERSION | cut -d. -f2`
24micro=`echo $PACKAGE_VERSION | cut -d. -f3`
25git=`echo $PACKAGE_VERSION | cut -d. -f4`
26if test x"$git" != x ; then
27    micro=$(($micro+1))
28fi
29SPICE_SERVER_VERSION=`printf "0x%02x%02x%02x" $major $minor $micro`
30AC_SUBST(SPICE_SERVER_VERSION)
31
32AC_CONFIG_MACRO_DIR([m4])
33AM_CONFIG_HEADER([config.h])
34AC_CONFIG_AUX_DIR(.)
35
36AM_INIT_AUTOMAKE([dist-bzip2 no-dist-gzip subdir-objects foreign])
37AM_MAINTAINER_MODE
38
39AC_PROG_CC
40AC_PROG_CC_C99
41if test x"$ac_cv_prog_cc_c99" = xno; then
42    AC_MSG_ERROR([C99 compiler is required.])
43fi
44AC_PROG_INSTALL
45AC_CANONICAL_HOST
46LT_INIT([disable-static])
47AM_PROG_CC_C_O
48AC_C_BIGENDIAN
49PKG_PROG_PKG_CONFIG
50
51AC_PROG_CXX
52AC_LANG_PUSH([C++])
53m4_ifndef([AX_CXX_COMPILE_STDCXX_11], [m4_fatal([Missing AX_CXX_COMPILE_STDCXX_11, install autoconf-archive])])
54AX_CXX_COMPILE_STDCXX_11
55AX_APPEND_COMPILE_FLAGS([-fno-exceptions -fno-check-new])
56AC_LANG_POP([C++])
57
58AC_CHECK_HEADERS([sys/time.h execinfo.h linux/sockios.h pthread_np.h])
59AC_CHECK_DECL([TCP_KEEPIDLE], [have_tcp_keepidle="yes"],,
60              [#include <netinet/tcp.h>])
61AS_IF([test "x$have_tcp_keepidle" = "xyes"],
62      [AC_DEFINE([HAVE_TCP_KEEPIDLE],1,[Define to 1 if <netinet/tcp.h> has a TCP_KEEPIDLE definition])],
63)
64AC_FUNC_ALLOCA
65
66SPICE_LT_VERSION=m4_format("%d:%d:%d", SPICE_CURRENT, SPICE_REVISION, SPICE_AGE)
67AC_SUBST(SPICE_LT_VERSION)
68
69# Check for the CPU we are using
70case $host_cpu in
71  x86_64)
72        ;;
73  *)
74        SPICE_WARNING([spice-server on non-x86_64 architectures has not been extensively tested])
75esac
76
77AC_MSG_CHECKING([for native Win32])
78case "$host_os" in
79     *mingw*|*cygwin*)
80        os_win32=yes
81        dnl AI_ADDRCONFIG and possibly some other code require at least Vista
82        AC_DEFINE([_WIN32_WINNT], [0x600], [Minimal Win32 version])
83        ;;
84     *)
85        os_win32=no
86        ;;
87esac
88AC_MSG_RESULT([$os_win32])
89AM_CONDITIONAL([OS_WIN32],[test "$os_win32" = "yes"])
90
91dnl =========================================================================
92dnl Check optional features
93SPICE_CHECK_SMARTCARD
94
95AC_ARG_ENABLE(gstreamer,
96              AS_HELP_STRING([--enable-gstreamer=@<:@auto/0.10/1.0/yes/no@:>@],
97                             [Enable GStreamer support]),,
98              [enable_gstreamer="auto"])
99
100if test "x$enable_gstreamer" != "xno" && test "x$enable_gstreamer" != "x0.10"; then
101    SPICE_CHECK_GSTREAMER(GSTREAMER_1_0, 1.0, [gstreamer-1.0 gstreamer-base-1.0 gstreamer-app-1.0 gstreamer-video-1.0],
102        [enable_gstreamer="1.0"
103         SPICE_CHECK_GSTREAMER_ELEMENTS($GST_INSPECT_1_0, [gst-plugins-base 1.0], [appsrc videoconvert appsink])
104         SPICE_CHECK_GSTREAMER_ELEMENTS($GST_INSPECT_1_0, [gstreamer-libav 1.0], [avenc_mjpeg])
105         SPICE_CHECK_GSTREAMER_ELEMENTS($GST_INSPECT_1_0, [gst-plugins-good 1.0], [vp8enc vp9enc])
106         SPICE_CHECK_GSTREAMER_ELEMENTS($GST_INSPECT_1_0, [gst-plugins-ugly 1.0], [x264enc])
107         ],
108         [if test "x$enable_gstreamer" = "x1.0"; then
109              AC_MSG_ERROR([GStreamer 1.0 support requested but not found. You may set GSTREAMER_1_0_CFLAGS and GSTREAMER_1_0_LIBS to avoid the need to call pkg-config.])
110          fi
111    ])
112fi
113
114if test "x$enable_gstreamer" != "xno" && test "x$enable_gstreamer" != "x1.0"; then
115    SPICE_CHECK_GSTREAMER(GSTREAMER_0_10, 0.10, [gstreamer-0.10 gstreamer-base-0.10 gstreamer-app-0.10 gstreamer-video-0.10],
116        [enable_gstreamer="0.10"
117         SPICE_CHECK_GSTREAMER_ELEMENTS($GST_INSPECT_0_10, [gst-plugins-base 0.10], [appsrc appsink])
118         SPICE_CHECK_GSTREAMER_ELEMENTS($GST_INSPECT_0_10, [gstreamer-ffmpeg 0.10], [ffmpegcolorspace ffenc_mjpeg])
119         SPICE_CHECK_GSTREAMER_ELEMENTS($GST_INSPECT_0_10, [gst-plugins-bad 0.10], [vp8enc])
120         SPICE_CHECK_GSTREAMER_ELEMENTS($GST_INSPECT_0_10, [gst-plugins-ugly 0.10], [x264enc])
121        ],
122        [if test "x$enable_gstreamer" = "x0.10"; then
123             AC_MSG_ERROR([GStreamer 0.10 support requested but not found. You may set GSTREAMER_0_10_CFLAGS and GSTREAMER_0_10_LIBS to avoid the need to call pkg-config.])
124         fi
125    ])
126fi
127AM_CONDITIONAL(HAVE_GSTREAMER, test "x$have_gstreamer_0_10" = "xyes" || test "x$have_gstreamer_1_0" = "xyes")
128AM_CONDITIONAL(HAVE_GSTREAMER_1_0, test "x$have_gstreamer_1_0" = "xyes")
129
130AS_IF([test "x$enable_gstreamer" = "xyes"],
131      [AC_MSG_ERROR("GStreamer support requested but not found")],
132      [test "x$enable_gstreamer" = "xauto"],
133      [enable_gstreamer="no"
134])
135AS_IF([test x"$missing_gstreamer_elements" = xyes],
136    [SPICE_WARNING([The GStreamer video encoder can be built but may not work.])
137])
138
139if test "x$have_gstreamer_0_10" = "xyes" || test "x$have_gstreamer_1_0" = "xyes"; then
140    PKG_CHECK_MODULES(ORC, orc-0.4)
141    AC_SUBST(ORC_CFLAGS)
142    AC_SUBST(ORC_LIBS)
143fi
144
145AC_ARG_ENABLE([tests],
146  AS_HELP_STRING([--enable-tests],
147                 [Enable tests @<:@default=yes@:>@]),
148  [],
149  enable_tests="yes")
150AM_CONDITIONAL(ENABLE_TESTS, test "x$enable_tests" = "xyes")
151
152dnl Check for the presence of Valgrind and do the plumbing to allow
153dnl the running of "make check-valgrind".
154AX_VALGRIND_DFLT(memcheck, on)
155AX_VALGRIND_DFLT(helgrind, off)
156AX_VALGRIND_DFLT(drd, off)
157AX_VALGRIND_DFLT(sgcheck, off)
158
159AX_VALGRIND_CHECK
160
161SPICE_CHECK_LZ4
162SPICE_CHECK_SASL
163AM_CONDITIONAL(HAVE_SASL, test "x$have_sasl" = "xyes")
164
165dnl =========================================================================
166dnl Check deps
167m4_define([SPICE_PROTOCOL_MIN_VER],[0.14.3])
168m4_include([subprojects/spice-common/m4/common.m4])
169
170AC_CHECK_LIBM
171AC_SUBST(LIBM)
172
173AC_CHECK_LIB(rt, clock_gettime, LIBRT="-lrt")
174AC_SUBST(LIBRT)
175
176AS_VAR_APPEND([SPICE_NONPKGCONFIG_LIBS], [" -pthread $LIBM $LIBRT"])
177AS_IF([test "x$os_win32" = "xyes"], [
178    AS_VAR_APPEND([SPICE_NONPKGCONFIG_LIBS], [" -lws2_32"])
179])
180
181SPICE_REQUIRES=""
182
183AS_IF([test x"$have_smartcard" = "xyes"], [
184    AS_VAR_APPEND([SPICE_REQUIRES], [" libcacard >= 2.5.1"])
185])
186
187GLIB2_REQUIRED=2.38
188GLIB2_ENCODED_VERSION="GLIB_VERSION_2_38"
189PKG_CHECK_MODULES([GLIB2], [glib-2.0 >= $GLIB2_REQUIRED])
190GLIB2_CFLAGS="$GLIB2_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=$GLIB2_ENCODED_VERSION \
191  -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_60"
192AS_VAR_APPEND([SPICE_REQUIRES], [" glib-2.0 >= $GLIB2_REQUIRED"])
193
194#used only by tests
195AS_IF([test "x$os_win32" != "xyes"],
196      [PKG_CHECK_MODULES([GIO_UNIX], [gio-unix-2.0 >= $GLIB2_REQUIRED])])
197
198PIXMAN_REQUIRED=0.17.7
199PKG_CHECK_MODULES(PIXMAN, pixman-1 >= $PIXMAN_REQUIRED)
200AC_SUBST(PIXMAN_CFLAGS)
201AC_SUBST(PIXMAN_LIBS)
202AS_VAR_APPEND([SPICE_REQUIRES], [" pixman-1 >= $PIXMAN_REQUIRED"])
203
204PKG_CHECK_MODULES(SSL, openssl >= 1.0.0)
205AC_SUBST(SSL_CFLAGS)
206AC_SUBST(SSL_LIBS)
207AS_VAR_APPEND([SPICE_REQUIRES], [" openssl"])
208
209save_CFLAGS="$CFLAGS"
210CFLAGS="$CFLAGS $SSL_CFLAGS"
211AC_CHECK_DECLS([SSL_CTX_set_ecdh_auto], [], [], [
212AC_INCLUDES_DEFAULT
213#include <openssl/err.h>
214#include <openssl/ssl.h>
215])
216CFLAGS="$save_CFLAGS"
217
218AC_CHECK_LIB(jpeg, jpeg_destroy_decompress,
219    AC_MSG_CHECKING([for jpeglib.h])
220    AC_TRY_CPP(
221[#include <stdio.h>
222#undef PACKAGE
223#undef VERSION
224#undef HAVE_STDLIB_H
225#include <jpeglib.h>],
226        JPEG_LIBS='-ljpeg'
227        AC_MSG_RESULT($jpeg_ok),
228	AC_MSG_ERROR([jpeglib.h not found])),
229    AC_MSG_ERROR([libjpeg not found]))
230AC_SUBST(JPEG_LIBS)
231
232AC_CHECK_LIB(z, deflate, Z_LIBS='-lz', AC_MSG_ERROR([zlib not found]))
233AC_SUBST(Z_LIBS)
234
235
236AC_ARG_ENABLE([manual],
237               AS_HELP_STRING([--enable-manual=@<:@auto/yes/no@:>@],
238                              [Build SPICE manual]),
239               [],
240               [enable_manual="auto"])
241if test "x$enable_manual" != "xno"; then
242    AC_PATH_PROG([ASCIIDOC], [asciidoc])
243    AS_IF([test -z "$ASCIIDOC" && test "x$enable_manual" = "xyes"],
244          [AC_MSG_ERROR([asciidoc is missing and build of manual was requested])])
245    AC_PATH_PROG([A2X], [a2x])
246    AS_IF([test -z "$A2X" && test "x$enable_manual" = "xyes"],
247          [AC_MSG_ERROR([a2x is missing and build of manual was requested])])
248fi
249AS_IF([test -n "$ASCIIDOC"], [have_asciidoc=yes], [have_asciidoc=no])
250AM_CONDITIONAL([BUILD_MANUAL], [test -n "$ASCIIDOC" || test -n "$A2X"])
251AM_CONDITIONAL([BUILD_HTML_MANUAL], [test -n "$ASCIIDOC"])
252AM_CONDITIONAL([BUILD_CHUNKED_MANUAL], [test -n "$A2X"])
253
254AC_ARG_ENABLE([statistics],
255               AS_HELP_STRING([--enable-statistics=@<:@yes/no@:>@],
256                              [Build SPICE with statistic code enabled @<:@default=no@:>@]))
257AS_IF([test "$enable_statistics" = "yes"],
258      [AC_DEFINE([RED_STATISTICS], [1], [Enable SPICE statistics])])
259
260dnl ===========================================================================
261dnl check compiler flags
262
263AC_LANG_PUSH([C++])
264SPICE_COMPILE_WARNINGS
265AC_LANG_POP([C++])
266LIBVIRT_LINKER_RELRO
267LIBVIRT_LINKER_NO_INDIRECT
268
269AC_SUBST(WARN_CFLAGS)
270
271dnl =========================================================================
272dnl -fvisibility stuff
273
274have_gcc4=no
275AC_MSG_CHECKING(for -fvisibility)
276AC_COMPILE_IFELSE([AC_LANG_SOURCE([
277#if defined(__GNUC__) && (__GNUC__ >= 4)
278#else
279error Need GCC 4.0 for visibility
280#endif
281int main () { return 0; }
282])], have_gcc4=yes)
283
284if test "x$have_gcc4" = "xyes" && test ! "$os_win32" = "yes" ; then
285   VISIBILITY_HIDDEN_CFLAGS="-fvisibility=hidden"
286fi
287AC_MSG_RESULT($have_gcc4)
288AC_SUBST(VISIBILITY_HIDDEN_CFLAGS)
289
290dnl ensure linker supports ---version-script option before using it
291AC_CACHE_CHECK([if -Wl,--version-script works], [spice_cv_ld_version_script],
292    [save_LDFLAGS="$LDFLAGS"
293     LDFLAGS="$LDFLAGS -Wl,--version-script=$srcdir/server/spice-server.syms"
294     AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
295        [spice_cv_ld_version_script=yes], [spice_cv_ld_version_script=no])
296     LDFLAGS="$save_LDFLAGS"])
297AM_CONDITIONAL([HAVE_LD_VERSION_SCRIPT],
298    [test x"$spice_cv_ld_version_script" = xyes])
299
300AC_DEFINE([SPICE_USE_SAFER_CONTAINEROF], [1], [Enable more type safe version of SPICE_CONTAINEROF])
301
302AC_SUBST(SPICE_REQUIRES)
303AC_SUBST(SPICE_NONPKGCONFIG_CFLAGS)
304AC_SUBST(SPICE_NONPKGCONFIG_LIBS)
305
306AM_SILENT_RULES([yes])
307
308AC_OUTPUT([
309Makefile
310spice-server.pc
311server/Makefile
312server/spice-version.h
313server/tests/Makefile
314docs/Makefile
315docs/manual/Makefile
316tools/Makefile
317])
318
319dnl ==========================================================================
320AC_MSG_NOTICE([
321
322        Spice $VERSION
323        ==============
324
325        prefix:                   ${prefix}
326        C compiler:               ${CC}
327        C++ compiler:             ${CXX}
328
329        LZ4 support:              ${have_lz4}
330        Smartcard:                ${have_smartcard}
331        GStreamer:                ${enable_gstreamer}
332        SASL support:             ${have_sasl}
333        Manual:                   ${have_asciidoc}
334
335        Now type 'make' to build $PACKAGE
336])
337SPICE_PRINT_MESSAGES
338