tests: Reduce user burden for running "make check".
[cascardo/ovs.git] / m4 / openvswitch.m4
1 # -*- autoconf -*-
2
3 # Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at:
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 m4_include([m4/compat.at])
18
19 dnl Checks for --enable-coverage and updates CFLAGS and LDFLAGS appropriately.
20 AC_DEFUN([OVS_CHECK_COVERAGE],
21   [AC_REQUIRE([AC_PROG_CC])
22    AC_ARG_ENABLE(
23      [coverage],
24      [AC_HELP_STRING([--enable-coverage],
25                      [Enable gcov coverage tool.])],
26      [case "${enableval}" in
27         (yes) coverage=true ;;
28         (no)  coverage=false ;;
29         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-coverage]) ;;
30       esac],
31      [coverage=false])
32    if $coverage; then
33      # Autoconf by default puts "-g -O2" in CFLAGS.  We need to remove the -O2
34      # option for coverage to be useful.  This does it without otherwise
35      # interfering with anything that the user might have put there.
36      old_CFLAGS=$CFLAGS
37      CFLAGS=
38      for option in $old_CFLAGS; do
39         case $option in
40             (-O2) ;;
41             (*) CFLAGS="$CFLAGS $option" ;;
42         esac
43      done
44
45      OVS_CFLAGS="$OVS_CFLAGS --coverage"
46      OVS_LDFLAGS="$OVS_LDFLAGS --coverage"
47    fi])
48
49 dnl Checks for --enable-ndebug and defines NDEBUG if it is specified.
50 AC_DEFUN([OVS_CHECK_NDEBUG],
51   [AC_ARG_ENABLE(
52      [ndebug],
53      [AC_HELP_STRING([--enable-ndebug],
54                      [Disable debugging features for max performance])],
55      [case "${enableval}" in
56         (yes) ndebug=true ;;
57         (no)  ndebug=false ;;
58         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ndebug]) ;;
59       esac],
60      [ndebug=false])
61    AM_CONDITIONAL([NDEBUG], [test x$ndebug = xtrue])])
62
63 dnl Checks for ESX.
64 AC_DEFUN([OVS_CHECK_ESX],
65   [AC_CHECK_HEADER([vmware.h],
66                    [ESX=yes],
67                    [ESX=no])
68    AM_CONDITIONAL([ESX], [test "$ESX" = yes])
69    if test "$ESX" = yes; then
70       AC_DEFINE([ESX], [1], [Define to 1 if building on ESX.])
71    fi])
72
73 dnl Checks for WINDOWS.
74 AC_DEFUN([OVS_CHECK_WIN32],
75   [AC_CHECK_HEADER([windows.h],
76                    [WIN32=yes],
77                    [WIN32=no])
78    AM_CONDITIONAL([WIN32], [test "$WIN32" = yes])
79    if test "$WIN32" = yes; then
80       AC_ARG_WITH([pthread],
81          [AS_HELP_STRING([--with-pthread=DIR],
82             [root of the pthread-win32 directory])],
83          [
84             case "$withval" in
85             "" | y | ye | yes | n | no)
86             AC_MSG_ERROR([Invalid --with-pthread value])
87               ;;
88             *)
89             PTHREAD_WIN32_DIR=$withval/lib/x86
90             PTHREAD_WIN32_DIR_DLL=/${withval/:/}/dll/x86
91             PTHREAD_INCLUDES=-I$withval/include
92             PTHREAD_LDFLAGS=-L$PTHREAD_WIN32_DIR
93             PTHREAD_LIBS="-lpthreadVC2"
94             AC_SUBST([PTHREAD_WIN32_DIR_DLL])
95             AC_SUBST([PTHREAD_INCLUDES])
96             AC_SUBST([PTHREAD_LDFLAGS])
97             AC_SUBST([PTHREAD_LIBS])
98               ;;
99             esac
100          ], [
101             AC_MSG_ERROR([pthread directory not specified])
102          ]
103       )
104       AC_ARG_WITH([debug],
105          [AS_HELP_STRING([--with-debug],
106             [Build without compiler optimizations])],
107          [
108             MSVC_CFLAGS="-O0"
109             AC_SUBST([MSVC_CFLAGS])
110          ], [
111             MSVC_CFLAGS="-O2"
112             AC_SUBST([MSVC_CFLAGS])
113          ]
114       )
115
116       AC_DEFINE([WIN32], [1], [Define to 1 if building on WIN32.])
117       AH_BOTTOM([#ifdef WIN32
118 #include "include/windows/windefs.h"
119 #endif])
120    fi])
121
122 dnl OVS_CHECK_WINDOWS
123 dnl
124 dnl Configure Visual Studio solution build
125 AC_DEFUN([OVS_CHECK_VISUAL_STUDIO_DDK], [
126 AC_ARG_WITH([vstudiotarget],
127          [AS_HELP_STRING([--with-vstudiotarget=target_type],
128             [Target type: Debug/Release])],
129          [
130             case "$withval" in
131             "Release") ;;
132             "Debug") ;;
133             *) AC_MSG_ERROR([No valid Visual Studio configuration found]) ;;
134             esac
135
136             VSTUDIO_CONFIG=$withval
137          ], [
138             VSTUDIO_CONFIG=
139          ]
140       )
141
142   AC_SUBST([VSTUDIO_CONFIG])
143   AC_DEFINE([VSTUDIO_DDK], [1], [System uses the Visual Studio build target.])
144   AM_CONDITIONAL([VSTUDIO_DDK], [test -n "$VSTUDIO_CONFIG"])
145 ])
146
147 dnl Checks for Netlink support.
148 AC_DEFUN([OVS_CHECK_NETLINK],
149   [AC_CHECK_HEADER([linux/netlink.h],
150                    [HAVE_NETLINK=yes],
151                    [HAVE_NETLINK=no],
152                    [#include <sys/socket.h>
153    ])
154    AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
155    if test "$HAVE_NETLINK" = yes; then
156       AC_DEFINE([HAVE_NETLINK], [1],
157                 [Define to 1 if Netlink protocol is available.])
158    fi])
159
160 dnl Checks for OpenSSL.
161 AC_DEFUN([OVS_CHECK_OPENSSL],
162   [AC_ARG_ENABLE(
163      [ssl],
164      [AC_HELP_STRING([--disable-ssl], [Disable OpenSSL support])],
165      [case "${enableval}" in
166         (yes) ssl=true ;;
167         (no)  ssl=false ;;
168         (*) AC_MSG_ERROR([bad value ${enableval} for --enable-ssl]) ;;
169       esac],
170      [ssl=check])
171
172    if test "$ssl" != false; then
173        AX_CHECK_OPENSSL(
174          [HAVE_OPENSSL=yes],
175          [HAVE_OPENSSL=no
176           if test "$ssl" = check; then
177             AC_MSG_WARN([Cannot find openssl:
178
179 $SSL_PKG_ERRORS
180
181 OpenFlow connections over SSL will not be supported.
182 (You may use --disable-ssl to suppress this warning.)])
183           else
184             AC_MSG_ERROR([Cannot find openssl (use --disable-ssl to configure without SSL support)])
185           fi])
186    else
187        HAVE_OPENSSL=no
188    fi
189    AC_SUBST([HAVE_OPENSSL])
190    AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
191    if test "$HAVE_OPENSSL" = yes; then
192       AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
193    fi])
194
195 dnl Checks for libraries needed by lib/socket-util.c.
196 AC_DEFUN([OVS_CHECK_SOCKET_LIBS],
197   [AC_CHECK_LIB([socket], [connect])
198    AC_SEARCH_LIBS([gethostbyname], [resolv])])
199
200 dnl Checks for the directory in which to store the PKI.
201 AC_DEFUN([OVS_CHECK_PKIDIR],
202   [AC_ARG_WITH(
203      [pkidir],
204      AC_HELP_STRING([--with-pkidir=DIR],
205                     [PKI hierarchy directory [[LOCALSTATEDIR/lib/openvswitch/pki]]]),
206      [PKIDIR=$withval],
207      [PKIDIR='${localstatedir}/lib/openvswitch/pki'])
208    AC_SUBST([PKIDIR])])
209
210 dnl Checks for the directory in which to store pidfiles.
211 AC_DEFUN([OVS_CHECK_RUNDIR],
212   [AC_ARG_WITH(
213      [rundir],
214      AC_HELP_STRING([--with-rundir=DIR],
215                     [directory used for pidfiles
216                     [[LOCALSTATEDIR/run/openvswitch]]]),
217      [RUNDIR=$withval],
218      [RUNDIR='${localstatedir}/run/openvswitch'])
219    AC_SUBST([RUNDIR])])
220
221 dnl Checks for the directory in which to store logs.
222 AC_DEFUN([OVS_CHECK_LOGDIR],
223   [AC_ARG_WITH(
224      [logdir],
225      AC_HELP_STRING([--with-logdir=DIR],
226                     [directory used for logs [[LOCALSTATEDIR/log/PACKAGE]]]),
227      [LOGDIR=$withval],
228      [LOGDIR='${localstatedir}/log/${PACKAGE}'])
229    AC_SUBST([LOGDIR])])
230
231 dnl Checks for the directory in which to store the Open vSwitch database.
232 AC_DEFUN([OVS_CHECK_DBDIR],
233   [AC_ARG_WITH(
234      [dbdir],
235      AC_HELP_STRING([--with-dbdir=DIR],
236                     [directory used for conf.db [[SYSCONFDIR/PACKAGE]]]),
237      [DBDIR=$withval],
238      [DBDIR='${sysconfdir}/${PACKAGE}'])
239    AC_SUBST([DBDIR])])
240
241 dnl Defines HAVE_BACKTRACE if backtrace() is found.
242 AC_DEFUN([OVS_CHECK_BACKTRACE],
243   [AC_SEARCH_LIBS([backtrace], [execinfo ubacktrace],
244                   [AC_DEFINE([HAVE_BACKTRACE], [1],
245                              [Define to 1 if you have backtrace(3).])])])
246
247 dnl Defines HAVE_PERF_EVENT if linux/perf_event.h is found.
248 AC_DEFUN([OVS_CHECK_PERF_EVENT],
249   [AC_CHECK_HEADERS([linux/perf_event.h])])
250
251 dnl Checks for valgrind/valgrind.h.
252 AC_DEFUN([OVS_CHECK_VALGRIND],
253   [AC_CHECK_HEADERS([valgrind/valgrind.h])])
254
255 dnl Checks for Python 2.x, x >= 7.
256 AC_DEFUN([OVS_CHECK_PYTHON],
257   [AC_CACHE_CHECK(
258      [for Python 2.x for x >= 7],
259      [ovs_cv_python],
260      [if test -n "$PYTHON"; then
261         ovs_cv_python=$PYTHON
262       else
263         ovs_cv_python=no
264         for binary in python python2.7; do
265           ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
266           for dir in $PATH; do
267             IFS=$ovs_save_IFS
268             test -z "$dir" && dir=.
269             if test -x "$dir"/"$binary" && "$dir"/"$binary" -c 'import sys
270 if sys.hexversion >= 0x02070000 and sys.hexversion < 0x03000000:
271     sys.exit(0)
272 else:
273     sys.exit(1)'; then
274               ovs_cv_python=$dir/$binary
275               break 2
276             fi
277           done
278         done
279       fi])
280    AC_SUBST([HAVE_PYTHON])
281    AM_MISSING_PROG([PYTHON], [python])
282    if test $ovs_cv_python != no; then
283      PYTHON=$ovs_cv_python
284      HAVE_PYTHON=yes
285    else
286      HAVE_PYTHON=no
287    fi
288    AM_CONDITIONAL([HAVE_PYTHON], [test "$HAVE_PYTHON" = yes])])
289
290 dnl Checks for dot.
291 AC_DEFUN([OVS_CHECK_DOT],
292   [AC_CACHE_CHECK(
293     [for dot],
294     [ovs_cv_dot],
295     [dnl "dot" writes -V output to stderr:
296      if (dot -V) 2>&1 | grep '^dot - [[gG]]raphviz version' >/dev/null 2>&1; then
297        ovs_cv_dot=yes
298      else
299        ovs_cv_dot=no
300      fi])
301    AM_CONDITIONAL([HAVE_DOT], [test "$ovs_cv_dot" = yes])])
302
303 dnl Checks for groff.
304 AC_DEFUN([OVS_CHECK_GROFF],
305   [AC_CACHE_CHECK(
306     [for groff],
307     [ovs_cv_groff],
308     [if (groff -v) >/dev/null 2>&1; then
309        ovs_cv_groff=yes
310      else
311        ovs_cv_groff=no
312      fi])
313    AM_CONDITIONAL([HAVE_GROFF], [test "$ovs_cv_groff" = yes])])
314
315 dnl Checks for thread-local storage support.
316 dnl
317 dnl Checks whether the compiler and linker support the C11
318 dnl thread_local macro from <threads.h>, and if so defines
319 dnl HAVE_THREAD_LOCAL.  If not, checks whether the compiler and linker
320 dnl support the GCC __thread extension, and if so defines
321 dnl HAVE___THREAD.
322 AC_DEFUN([OVS_CHECK_TLS],
323   [AC_CACHE_CHECK(
324      [whether $CC has <threads.h> that supports thread_local],
325      [ovs_cv_thread_local],
326      [AC_LINK_IFELSE(
327         [AC_LANG_PROGRAM([#include <threads.h>
328 static thread_local int var;], [return var;])],
329         [ovs_cv_thread_local=yes],
330         [ovs_cv_thread_local=no])])
331    if test $ovs_cv_thread_local = yes; then
332      AC_DEFINE([HAVE_THREAD_LOCAL], [1],
333                [Define to 1 if the C compiler and linker supports the C11
334                 thread_local matcro defined in <threads.h>.])
335    else
336      AC_CACHE_CHECK(
337        [whether $CC supports __thread],
338        [ovs_cv___thread],
339        [AC_LINK_IFELSE(
340           [AC_LANG_PROGRAM([static __thread int var;], [return var;])],
341           [ovs_cv___thread=yes],
342           [ovs_cv___thread=no])])
343      if test $ovs_cv___thread = yes; then
344        AC_DEFINE([HAVE___THREAD], [1],
345                  [Define to 1 if the C compiler and linker supports the
346                   GCC __thread extenions.])
347      fi
348    fi])
349
350 dnl OVS_CHECK_ATOMIC_LIBS
351 dnl
352 dnl Check to see if -latomic is need for GCC atomic built-ins.
353 AC_DEFUN([OVS_CHECK_ATOMIC_LIBS],
354    [AC_SEARCH_LIBS([__atomic_load_8], [atomic])])
355
356 dnl OVS_CHECK_GCC4_ATOMICS
357 dnl
358 dnl Checks whether the compiler and linker support GCC 4.0+ atomic built-ins.
359 dnl A compile-time only check is not enough because the compiler defers
360 dnl unimplemented built-ins to libgcc, which sometimes also lacks
361 dnl implementations.
362 AC_DEFUN([OVS_CHECK_GCC4_ATOMICS],
363   [AC_CACHE_CHECK(
364      [whether $CC supports GCC 4.0+ atomic built-ins],
365      [ovs_cv_gcc4_atomics],
366      [AC_LINK_IFELSE(
367         [AC_LANG_PROGRAM([[#include <stdlib.h>
368
369 #define ovs_assert(expr) if (!(expr)) abort();
370 #define TEST_ATOMIC_TYPE(TYPE)                  \
371     {                                           \
372         TYPE x = 1;                             \
373         TYPE orig;                              \
374                                                 \
375         __sync_synchronize();                   \
376         ovs_assert(x == 1);                     \
377                                                 \
378         __sync_synchronize();                   \
379         x = 3;                                  \
380         __sync_synchronize();                   \
381         ovs_assert(x == 3);                     \
382                                                 \
383         orig = __sync_fetch_and_add(&x, 1);     \
384         ovs_assert(orig == 3);                  \
385         __sync_synchronize();                   \
386         ovs_assert(x == 4);                     \
387                                                 \
388         orig = __sync_fetch_and_sub(&x, 2);     \
389         ovs_assert(orig == 4);                  \
390         __sync_synchronize();                   \
391         ovs_assert(x == 2);                     \
392                                                 \
393         orig = __sync_fetch_and_or(&x, 6);      \
394         ovs_assert(orig == 2);                  \
395         __sync_synchronize();                   \
396         ovs_assert(x == 6);                     \
397                                                 \
398         orig = __sync_fetch_and_and(&x, 10);    \
399         ovs_assert(orig == 6);                  \
400         __sync_synchronize();                   \
401         ovs_assert(x == 2);                     \
402                                                 \
403         orig = __sync_fetch_and_xor(&x, 10);    \
404         ovs_assert(orig == 2);                  \
405         __sync_synchronize();                   \
406         ovs_assert(x == 8);                     \
407     }]], [dnl
408 TEST_ATOMIC_TYPE(char);
409 TEST_ATOMIC_TYPE(unsigned char);
410 TEST_ATOMIC_TYPE(signed char);
411 TEST_ATOMIC_TYPE(short);
412 TEST_ATOMIC_TYPE(unsigned short);
413 TEST_ATOMIC_TYPE(int);
414 TEST_ATOMIC_TYPE(unsigned int);
415 TEST_ATOMIC_TYPE(long int);
416 TEST_ATOMIC_TYPE(unsigned long int);
417 TEST_ATOMIC_TYPE(long long int);
418 TEST_ATOMIC_TYPE(unsigned long long int);
419 ])],
420         [ovs_cv_gcc4_atomics=yes],
421         [ovs_cv_gcc4_atomics=no])])
422    if test $ovs_cv_gcc4_atomics = yes; then
423      AC_DEFINE([HAVE_GCC4_ATOMICS], [1],
424                [Define to 1 if the C compiler and linker supports the GCC 4.0+
425                 atomic built-ins.])
426    fi])
427
428 dnl OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(SIZE)
429 dnl
430 dnl Checks __atomic_always_lock_free(SIZE, 0)
431 AC_DEFUN([OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE], 
432   [AC_CACHE_CHECK(
433     [value of __atomic_always_lock_free($1)],
434     [ovs_cv_atomic_always_lock_free_$1],
435     [AC_COMPUTE_INT(
436         [ovs_cv_atomic_always_lock_free_$1],
437         [__atomic_always_lock_free($1, 0)],
438         [],
439         [ovs_cv_atomic_always_lock_free_$1=unsupported])])
440    if test ovs_cv_atomic_always_lock_free_$1 != unsupported; then
441      AC_DEFINE_UNQUOTED(
442        [ATOMIC_ALWAYS_LOCK_FREE_$1B],
443        [$ovs_cv_atomic_always_lock_free_$1],
444        [If the C compiler is GCC 4.7 or later, define to the return value of
445         __atomic_always_lock_free($1, 0).  If the C compiler is not GCC or is
446         an older version of GCC, the value does not matter.])
447    fi])
448
449 dnl OVS_CHECK_POSIX_AIO
450 AC_DEFUN([OVS_CHECK_POSIX_AIO],
451   [AC_SEARCH_LIBS([aio_write], [rt])
452    AM_CONDITIONAL([HAVE_POSIX_AIO], [test "$ac_cv_search_aio_write" != no])])
453
454 dnl OVS_CHECK_INCLUDE_NEXT
455 AC_DEFUN([OVS_CHECK_INCLUDE_NEXT],
456   [AC_REQUIRE([gl_CHECK_NEXT_HEADERS])
457    gl_CHECK_NEXT_HEADERS([$1])])
458
459 dnl OVS_CHECK_PRAGMA_MESSAGE
460 AC_DEFUN([OVS_CHECK_PRAGMA_MESSAGE],
461   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
462    [[_Pragma("message(\"Checking for pragma message\")")
463    ]])],
464      [AC_DEFINE(HAVE_PRAGMA_MESSAGE,1,[Define if compiler supports #pragma
465      message directive])])
466   ])