packaging: set AMB change notification signals.
[profile/ivi/murphy.git] / m4 / websockets.m4
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.
5 #
6
7 AC_DEFUN([CHECK_WEBSOCKETS],
8 [
9 AC_LANG_PUSH([C])
10 AC_ARG_ENABLE(websockets,
11               [  --enable-websockets     enable websockets support],
12               [enable_websockets=$enableval], [enable_websockets=auto])
13
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"
24         saved_LIBS="$LIBS"
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
31         # else branch.
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
34         # tests.
35         saved_LD_AS_NEEDED="$LD_AS_NEEDED"
36         unset LD_AS_NEEDED
37         CFLAGS="`pkg-config --cflags libwebsockets`"
38         LIBS="`pkg-config --libs libwebsockets`"
39
40         # Check for new context creation API.
41         AC_MSG_CHECKING([for WEBSOCKETS new context creation API])
42         AC_LINK_IFELSE(
43            [AC_LANG_PROGRAM(
44                  [[#include <stdlib.h>
45                    #include <libwebsockets.h>]],
46                  [[struct libwebsocket_context *ctx;
47                    ctx = libwebsocket_create_context(NULL);]])],
48             [websockets_cci=yes],
49             [websockets_cci=no])
50         AC_MSG_RESULT([$websockets_cci])
51
52         # Check for new libwebsockets_get_internal_extensions.
53         AC_MSG_CHECKING([for WEBSOCKETS internal extension query API])
54         AC_LINK_IFELSE(
55            [AC_LANG_PROGRAM(
56                  [[#include <stdlib.h>
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])
63
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.])
72         AC_LINK_IFELSE(
73            [AC_LANG_PROGRAM(
74                  [[#include <stdlib.h>
75                    #include <libwebsockets.h>
76                    static void logger(int level, const char *line) {
77                        return;
78                    }]],
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])
83
84         # Check whether we have libwebsocket_close_and_free_session.
85         AC_MSG_CHECKING([for WEBSOCKETS close_and_free_session API])
86         AC_LINK_IFELSE(
87            [AC_LANG_PROGRAM(
88                  [[#include <stdlib.h>
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])
94
95         # Check for LWS_CALLBACK_FILTER_HTTP_CONNECTION.
96         AC_MSG_CHECKING([for WEBSOCKETS LWS_CALLBACK_FILTER_HTTP_CONNECTION])
97         AC_LINK_IFELSE(
98            [AC_LANG_PROGRAM(
99                  [[#include <stdlib.h>
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])
105
106         # Check for LWS_CALLBACK_CHANGE_MODE_POLL_FD.
107         AC_MSG_CHECKING([for WEBSOCKETS LWS_CALLBACK_CHANGE_MODE_POLL_FD])
108         AC_LINK_IFELSE(
109            [AC_LANG_PROGRAM(
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])
116
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])
120         AC_LINK_IFELSE(
121            [AC_LANG_PROGRAM(
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])
128
129         CFLAGS="$saved_CFLAGS"
130         LDFLAGS="$saved_LDFLAGS"
131         LIBS="$saved_LIBS"
132         if test -n "$saved_LD_AS_NEEDED"; then
133             export LD_AS_NEEDED="$saved_LD_AS_NEEDED"
134         fi
135     else
136         WEBSOCKETS_CFLAGS=""
137     fi
138
139     # Check for older websockets.
140     if test "$have_websockets" = "no"; then
141         saved_LDFLAGS="$LDFLAGS"
142         saved_LIBS="$LIBS"
143         LIBS="-lwebsockets"
144         AC_MSG_CHECKING([for WEBSOCKETS without pkg-config support])
145         AC_LINK_IFELSE(
146            [AC_LANG_PROGRAM(
147                  [[#include <stdlib.h>
148                    #include <libwebsockets.h>]],
149                  [[struct libwebsocket_context *ctx;
150                    ctx = libwebsocket_create_context(0, NULL, NULL, NULL,
151                                                      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])
156     fi
157
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])
162         AC_LINK_IFELSE(
163             [AC_LANG_PROGRAM(
164                  [[#include <stdlib.h>
165                    #include <libwebsockets.h>]],
166                  [[struct libwebsocket_context *ctx;
167                    ctx = libwebsocket_create_context(0, NULL, NULL, NULL,
168                                                      NULL, NULL,
169                                                      -1, -1, 0);]])],
170             [have_websockets=yes;old_websockets=yes],
171             [old_websockets=no])
172         AC_MSG_RESULT([$old_websockets])
173     fi
174
175     WEBSOCKETS_LIBS="-lwebsockets"
176     if test "$old_websockets" = "yes"; then
177         WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_OLD"
178     fi
179     if test "$websockets_cci" = "yes"; then
180         WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_CONTEXT_INFO"
181     fi
182     if test "$websockets_query_ext" = "yes"; then
183         WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_QUERY_EXTENSIONS"
184     fi
185     if test "$websockets_log_with_level" = "yes"; then
186         WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_LOG_WITH_LEVEL"
187     fi
188     if test "$websockets_close_session" = "yes"; then
189         WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_CLOSE_SESSION"
190     fi
191     if test "$websockets_filter_http_connection" = "yes"; then
192         WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_FILTER_HTTP_CONNECTION"
193     fi
194     if test "$websockets_change_poll" = "yes"; then
195         WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_CHANGE_MODE_POLL_FD"
196     fi
197     if test "$websockets_serve_file_extraarg" = "yes"; then
198         WEBSOCKETS_CFLAGS="$WEBSOCKETS_CFLAGS -DWEBSOCKETS_SERVE_FILE_EXTRAARG"
199     fi
200
201     LDFLAGS="$saved_LDFLAGS"
202     LIBS="$saved_LIBS"
203 else
204     AC_MSG_NOTICE([libwebsockets support is disabled.])
205 fi
206
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.])
210 fi
211
212 # Enable if found and autosupport requested.
213 if test "$enable_websockets" = "auto"; then
214     enable_websockets=$have_websockets
215 fi
216
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 ?])
222     fi
223 fi
224
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)
232
233 AC_LANG_POP
234 ])