1 # Macro to check if websockets support was enabled. This macro also
2 # takes care of detecting older versions of libwebsockets (lacking
3 # pkg-config support, no per-context userdata) and propagating this
4 # information to config.h and the compilation process.
7 AC_DEFUN([CHECK_WEBSOCKETS],
10 AC_ARG_ENABLE(websockets,
11 [ --enable-websockets enable websockets support],
12 [enable_websockets=$enableval], [enable_websockets=auto])
14 # Check if we have properly packaged libwebsockets (json-c is now mandatory
15 # and already has been tested for).
16 if test "$enable_websockets" != "no"; then
17 PKG_CHECK_MODULES(WEBSOCKETS, [libwebsockets],
18 [have_websockets=yes], [have_websockets=no])
19 if test "$have_websockets" = "yes"; then
20 WEBSOCKETS_CFLAGS="`pkg-config --cflags libwebsockets`"
21 # Check for a couple of recent features we need to adopt to.
22 saved_CFLAGS="$CFLAGS"
23 saved_LDFLAGS="$LDFLAGS"
25 # Note that (at least with autoconf 2.69 and gcc 4.7.2), setting
26 # LD_AS_NEEDED to 1 breaks AC_LINK_IFELSE. That macro generates
27 # the compilation command so that the libraries are specified
28 # before the generated C source so all referenced/tested symbols
29 # from any of the libraries end up being undefined. This fools
30 # AC_LINK_IFELSE to consider the test a failure and select the
32 # rpmbuild always sets LD_AS_NEEDED to 1. To work around this save
33 # and restore LD_AS_NEEDED for the duration of the AC_LINK_IFELSE
35 saved_LD_AS_NEEDED="$LD_AS_NEEDED"
37 CFLAGS="`pkg-config --cflags libwebsockets`"
38 LIBS="`pkg-config --libs libwebsockets`"
40 # Check for new context creation API.
41 AC_MSG_CHECKING([for WEBSOCKETS new context creation API])
45 #include <libwebsockets.h>]],
46 [[struct libwebsocket_context *ctx;
47 ctx = libwebsocket_create_context(NULL);]])],
50 AC_MSG_RESULT([$websockets_cci])
52 # Check for new libwebsockets_get_internal_extensions.
53 AC_MSG_CHECKING([for WEBSOCKETS internal extension query API])
57 #include <libwebsockets.h>]],
58 [[struct libwebsocket_extension *ext;
59 ext = libwebsocket_get_internal_extensions();]])],
60 [websockets_query_ext=yes],
61 [websockets_query_ext=no])
62 AC_MSG_RESULT([$websockets_query_ext])
64 # Check for newer lws_set_log_level API.
65 # Note that we cheat heavily here: instead of rolling a proper
66 # test, we blindly assume gcc, turn on the -Werror flag (to catch
67 # calls with a mismatching function pointer) and hope that we will
68 # not get false negatives because of other warnings.
69 no_werror_CFLAGS="$CFLAGS"
70 CFLAGS="$CFLAGS -Werror"
71 AC_MSG_CHECKING([for WEBSOCKETS updated logging API.])
75 #include <libwebsockets.h>
76 static void logger(int level, const char *line) {
79 [[lws_set_log_level(LLL_INFO, logger);]])],
80 [websockets_log_with_level=yes],
81 [websockets_log_with_level=no])
82 AC_MSG_RESULT([$websockets_log_with_level])
84 # Check whether we have libwebsocket_close_and_free_session.
85 AC_MSG_CHECKING([for WEBSOCKETS close_and_free_session API])
89 #include <libwebsockets.h>]],
90 [[libwebsocket_close_and_free_session(NULL, NULL, 0);]])],
91 [websockets_close_session=yes],
92 [websockets_close_session=no])
93 AC_MSG_RESULT([$websockets_close_session])
95 # Check for LWS_CALLBACK_FILTER_HTTP_CONNECTION.
96 AC_MSG_CHECKING([for WEBSOCKETS LWS_CALLBACK_FILTER_HTTP_CONNECTION])
100 #include <libwebsockets.h>]],
101 [[int foo = LWS_CALLBACK_FILTER_HTTP_CONNECTION;]])],
102 [websockets_filter_http_connection=yes],
103 [websockets_filter_http_connection=no])
104 AC_MSG_RESULT([$websockets_filter_http_connection])
106 # Check for LWS_CALLBACK_CHANGE_MODE_POLL_FD.
107 AC_MSG_CHECKING([for WEBSOCKETS LWS_CALLBACK_CHANGE_MODE_POLL_FD])
110 [[#include <stdlib.h>
111 #include <libwebsockets.h>]],
112 [[int foo = LWS_CALLBACK_CHANGE_MODE_POLL_FD;]])],
113 [websockets_change_poll=yes],
114 [websockets_change_poll=no])
115 AC_MSG_RESULT([$websockets_change_poll])
117 # Check the signature of libwebsockets_serve_http_file to see if
118 # it takes an extra (other_headers) argument.
119 AC_MSG_CHECKING([for WEBSOCKETS libwebsockets_serve_http_file other_headers argument])
122 [[#include <stdlib.h>
123 #include <libwebsockets.h>]],
124 [[return libwebsockets_serve_http_file(NULL, NULL, "", "", "");]])],
125 [websockets_serve_file_extraarg=yes],
126 [websockets_serve_file_extraarg=no])
127 AC_MSG_RESULT([$websockets_serve_file_extraarg])
129 CFLAGS="$saved_CFLAGS"
130 LDFLAGS="$saved_LDFLAGS"
132 if test -n "$saved_LD_AS_NEEDED"; then
133 export LD_AS_NEEDED="$saved_LD_AS_NEEDED"
139 # Check for older websockets.
140 if test "$have_websockets" = "no"; then
141 saved_LDFLAGS="$LDFLAGS"
144 AC_MSG_CHECKING([for WEBSOCKETS without pkg-config support])
147 [[#include <stdlib.h>
148 #include <libwebsockets.h>]],
149 [[struct libwebsocket_context *ctx;
150 ctx = libwebsocket_create_context(0, NULL, NULL, NULL,
152 -1, -1, 0, NULL);]])],
153 [have_websockets=yes;old_websockets=no],
154 [have_websockets=no])
155 AC_MSG_RESULT([$have_websockets])
158 # Check if we have a really old libwebsockets, still without
159 # per-context user data.
160 if test "$old_websockets" != "no"; then
161 AC_MSG_CHECKING([for really old WEBSOCKETS])
164 [[#include <stdlib.h>
165 #include <libwebsockets.h>]],
166 [[struct libwebsocket_context *ctx;
167 ctx = libwebsocket_create_context(0, NULL, NULL, NULL,
170 [have_websockets=yes;old_websockets=yes],
172 AC_MSG_RESULT([$old_websockets])
175 WEBSOCKETS_LIBS="-lwebsockets"
176 if test "$old_websockets" = "yes"; then
177 WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_OLD"
179 if test "$websockets_cci" = "yes"; then
180 WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_CONTEXT_INFO"
182 if test "$websockets_query_ext" = "yes"; then
183 WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_QUERY_EXTENSIONS"
185 if test "$websockets_log_with_level" = "yes"; then
186 WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_LOG_WITH_LEVEL"
188 if test "$websockets_close_session" = "yes"; then
189 WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_CLOSE_SESSION"
191 if test "$websockets_filter_http_connection" = "yes"; then
192 WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_FILTER_HTTP_CONNECTION"
194 if test "$websockets_change_poll" = "yes"; then
195 WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_CHANGE_MODE_POLL_FD"
197 if test "$websockets_serve_file_extraarg" = "yes"; then
198 WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_SERVE_FILE_EXTRAARG"
201 LDFLAGS="$saved_LDFLAGS"
204 AC_MSG_NOTICE([libwebsockets support is disabled.])
207 # Bail out if we lack mandatory support.
208 if test "$enable_websockets" = "yes" -a "$have_websockets" = "no"; then
209 AC_MSG_ERROR([libwebsockets development libraries not found.])
212 # Enable if found and autosupport requested.
213 if test "$enable_websockets" = "auto"; then
214 enable_websockets=$have_websockets
217 # If enabled, set up our autoconf variables accordingly.
218 if test "$enable_websockets" = "yes"; then
219 AC_DEFINE([WEBSOCKETS_ENABLED], 1, [Enable websockets support ?])
220 if test "$old_websockets" = "yes"; then
221 AC_DEFINE([WEBSOCKETS_OLD], 1, [No per-context userdata ?])
225 # Finally substitute everything.
226 AM_CONDITIONAL(WEBSOCKETS_ENABLED, [test "$enable_websockets" = "yes"])
227 AM_CONDITIONAL(WEBSOCKETS_OLD, [test "$old_websockets" = "yes"])
228 AC_SUBST(WEBSOCKETS_ENABLED)
229 AC_SUBST(WEBSOCKETS_CFLAGS)
230 AC_SUBST(WEBSOCKETS_LIBS)
231 AC_SUBST(WEBSOCKETS_OLD)