• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# configure.ac for the libcoap package
2#
3# Copyright (C) 2010-2021 Olaf Bergmann <bergmann@tzi.org>
4# Copyright (C) 2015-2018 Carsten Schoenert <c.schoenert@t-online.de>
5# Copyright (C) 2018-2021 Jon Shallow <supjps-libcoap@jpshallow.com>
6#
7# SPDX-License-Identifier: BSD-2-Clause
8#
9# This file is part of the CoAP library libcoap. Please see README for terms
10# of use.
11#
12# Please run 'autogen.sh' to let autoconf produce a configure script.
13
14# Define the libcoap software version here. Note! The libtool versions are
15# defined later.
16m4_define([libcoap_major_version], [4])
17m4_define([libcoap_minor_version], [3])
18m4_define([libcoap_micro_version], [0])
19
20# define an appending release state if needed, for example for pre-releases
21# like 'alpha' or 'rc1', for a full release keep the value empty!
22m4_define([libcoap_release_state], [])
23
24# concatenate the full libcoap version string
25m4_define([libcoap_version], [m4_format([%s.%s.%s%s], libcoap_major_version, libcoap_minor_version, libcoap_micro_version, libcoap_release_state)])
26
27AC_INIT([libcoap], [libcoap_version], [libcoap-developers@lists.sourceforge.net], [libcoap], [https://libcoap.net/])
28AC_PREREQ([2.64])
29AM_INIT_AUTOMAKE([1.10 -Wall no-define no-dist-gzip dist-bzip2])
30PKG_PROG_PKG_CONFIG([0.20])
31AM_SILENT_RULES([yes])
32AC_HEADER_ASSERT
33
34# Generate one configuration header file for building the library itself with
35# an auto generated template. We need later a second one
36# (include/coap$LIBCOAP_API_VERSION/libcoap.h) that will be installed alongside the library.
37AC_CONFIG_HEADERS([coap_config.h])
38
39AC_PROG_CC
40AM_PROG_CC_C_O
41AC_PROG_SED
42AC_CONFIG_MACRO_DIR([m4])
43m4_pattern_allow([AM_PROG_AR])
44AM_PROG_AR
45AC_PROG_LN_S
46AC_PROG_MKDIR_P
47
48AC_C_BIGENDIAN
49
50# enable the automatically build of shared and static libraries
51LT_INIT([shared static])
52
53# Setting the libtool versioning
54###################################################################################
55#                                                                                 #
56#  To set the version of the library, libtool provides the -version-info          #
57#  parameter, which accepts three numbers, separated by colons, that are called   #
58#  respectively, current, revision and age. Both their name and their behavior,   #
59#  nowadays, have to be considered fully arbitrary, as the explanation provided   #
60#  in the official documentation is confusing to say the least, and can be, in    #
61#  some cases, considered completely wrong.                                       #
62#  https://autotools.io/libtool/version.html                                      #
63#                                                                                 #
64###################################################################################
65#
66# How to work with the libtool versioning?
67#
68# Follow the following steps from top to bottom. This means always start at point 1
69# if you plan to make a release and change the values.
70# Every new library starts with a version 'current'  (short 'c') = 0
71#                                         'revision' (short 'r') = 0
72#                                         'age'      (short 'a') = 0
73#
74# Update the libtool versioning only after the release of a public release of libcoap.
75# Go through the following checklist from top to bottom and check your needs, following
76# the reminded changes if you can say "Yes" for specific check.
77#
78# 1. Only existing code has changed, no functional changes
79#    If the library source code has changed but *no* new symbols were added at all
80#    since the last update, then increment revision (c:r:a becomes c:r+1:a).
81#    This is usually happen if the existing source of a function was changed for
82#    bug fixing e.g.
83#
84#  --> Increase the 'LT_LIBCOAP_REVISION' value with *every* new software release
85#      within one release cycle.
86#
87# 2. Interfaces were added, functions have changed or are removed
88#    If any interfaces [exported functions or data] have been added, got internal
89#    changes that implies a different behavior or removed and by this the visible
90#    symbols have changed since the last update, increment current, and set
91#    revision to 0 (c:r:a becomes c+1:r=0:a).
92#
93#  --> Increase the 'LT_LIBCOAP_CURRENT' value whenever as an interface has been added
94#      or removed. This implies also a API change! You mostly have to change the
95#      'libcoap_major_version' or at least 'libcoap_minor_version' then too!
96#  --> Set 'LT_LIBCOAP_REVISION' to 0.
97#
98# 3. Interfaces were added but none removed or changed
99#    If any interfaces have been added since the last public release and non of the
100#    existing interfaces were removed and existing interfaces have not changed internal
101#    functionality then the new library is backward compatible. Existing binaries can
102#    use the new library the same than as the existing old library without loosing
103#    existing functionality or breakage.
104#    Increase age by 1 (c:r:a becomes c:r:a+1).
105#
106#  --> Increase the 'LT_LIBCOAP_AGE' value only if the changes made to the ABI are
107#      backward compatible.
108#
109# 4. Interfaces were removed or have functional changes
110#    If any interfaces within the library have been removed since the last public
111#    release or got some internal changes that let the interface act different than
112#    before, then set age to 0. The library isn't backwards compatible.
113#
114#  --> Set 'LT_LIBCOAP_AGE' to 0.
115
116LT_LIBCOAP_CURRENT=3
117LT_LIBCOAP_REVISION=0
118LT_LIBCOAP_AGE=0
119LIBCOAP_SO_VERSION=$LT_LIBCOAP_CURRENT.$LT_LIBCOAP_REVISION.$LT_LIBCOAP_AGE
120
121# Announce the libtool version
122AC_SUBST(LT_LIBCOAP_CURRENT)
123AC_SUBST(LT_LIBCOAP_REVISION)
124AC_SUBST(LT_LIBCOAP_AGE)
125AC_SUBST(LIBCOAP_SO_VERSION)
126
127# Defining the API Version
128LIBCOAP_API_VERSION=3
129AC_SUBST(LIBCOAP_API_VERSION)
130
131# Define a numeric version string
132m4_define([version_number],
133          [m4_format([%u%03u%03u],
134                     libcoap_major_version,
135                     libcoap_minor_version,
136                     libcoap_micro_version)])
137LIBCOAP_VERSION=version_number
138AC_SUBST(LIBCOAP_VERSION)
139
140# Adding some default warning options for code QS
141# see https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
142# and http://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html
143WARNING_CFLAGS="\
144-pedantic \
145-Wall \
146-Wcast-qual \
147-Wextra \
148-Wformat-security \
149-Winline \
150-Wmissing-declarations \
151-Wmissing-prototypes \
152-Wnested-externs \
153-Wpointer-arith \
154-Wshadow \
155-Wstrict-prototypes \
156-Wswitch-default \
157-Wswitch-enum \
158-Wunused \
159-Wwrite-strings \
160"
161
162# check whether or not the compiler supports -Wlogical-op (clang does not...)
163AX_CHECK_COMPILE_FLAG([-Wlogical-op], [WARNING_CFLAGS="$WARNING_CFLAGS -Wlogical-op"],,[-Werror])
164AX_CHECK_COMPILE_FLAG([-fdiagnostics-color], [CFLAGS="$CFLAGS -fdiagnostics-color"],,[-Werror])
165AX_CHECK_COMPILE_FLAG([-Wunused-result], [WARNING_CFLAGS="$WARNING_CFLAGS -Wunused-result"])
166
167AC_SUBST([WARNING_CFLAGS])
168
169AX_CHECK_LINK_FLAG([-Wl,--version-script=${srcdir}/libcoap-${LIBCOAP_API_VERSION}.map],
170                   [libcoap_SYMBOLS="-Wl,--version-script=\$(srcdir)/libcoap-\$(LIBCOAP_API_VERSION).map"],
171                   [libcoap_SYMBOLS="-export-symbols \$(top_builddir)/libcoap-\$(LIBCOAP_API_VERSION).sym"])
172
173AC_SUBST(libcoap_SYMBOLS)
174
175# configure options
176# __documentation__
177
178AC_ARG_ENABLE([documentation],
179              [AS_HELP_STRING([--enable-documentation],
180                              [Enable building all the documentation [default=yes]])],
181              [build_documentation="$enableval"],
182              [build_documentation="yes"])
183
184AM_CONDITIONAL(BUILD_DOCUMENTATION, [test "x$build_documentation" = "xyes"])
185
186doxygen_version_required=1.7.0
187dot_version_required=2.26.0
188
189AC_ARG_ENABLE([doxygen],
190              [AS_HELP_STRING([--enable-doxygen],
191                              [Enable building the doxygen documentation [default=yes]])],
192              [build_doxygen="$enableval"],
193              [build_doxygen="yes"])
194
195if test -z "$enable_doxygen"; then
196    if test "x$enable_documentation" = "xno"; then
197        build_doxygen="no"
198    fi
199fi
200
201if test "x$build_doxygen" = "xyes"; then
202    # Check for doxygen
203    AC_PATH_PROGS([DOXYGEN], [doxygen])
204    if test -z "$DOXYGEN"; then
205        if test "x$build_doxygen" = "xyes"; then
206            AC_MSG_WARN([==> You want to build the doxygen documentation but doxygen was not found!])
207            AC_MSG_ERROR([==> Install the package that contains doxygen or disable the doxygen documentation using '--disable-doxygen'.])
208        fi
209    else
210        AC_MSG_CHECKING([for compatible doxygen version (>= $doxygen_version_required)])
211        doxygen_version=`$DOXYGEN --version`
212        AS_VERSION_COMPARE([$doxygen_version],
213                           [$doxygen_version_required],
214                           [AC_MSG_RESULT([no])
215                            DOXYGEN=""],
216                           [AC_MSG_RESULT([yes $doxygen_version])],
217                           [AC_MSG_RESULT([yes $doxygen_version])])
218        if test "x$DOXYGEN" = "x" -a "x$build_doxygen" = "xyes"; then
219            AC_MSG_WARN([==> Doxygen $doxygen_version too old. Doxygen >= $doxygen_version_required required for documentation build.])
220            AC_MSG_ERROR([==> Install required doxygen version or disable the doxygen documentation using '--disable-doxygen'.])
221        else
222            # we found doxygen and the version is valid
223            # now checking dot (needed for graphics)
224            AC_PATH_PROG([DOT], [dot])
225            if test "x$DOT" = "x"; then
226                AC_MSG_WARN([==> dot not found - continuing without DOT support])
227                AC_MSG_WARN([==> The libcoap html documentation will be build without DOT graphics!])
228                HAVE_DOT="NO"
229                USE_CALL_GRAPH="NO"
230            else
231                AC_MSG_CHECKING([for compatible dot version (>= $dot_version_required)])
232                case $host in
233                    *-freebsd1*)
234                    # csh and tcsh have a different output redirection than more recent shells
235                    # cmd >& file   # Redirect both stdout and stderr to file.
236                    # cmd >>& file  # Append both stdout and stderr to file.
237                    # cmd1 | cmd2   # pipe stdout to cmd2
238                    # cmd1 |& cmd2  # pipe stdout and stderr to cmd2
239                    # Using an explicit call with the default always available C-shell on FreeBSD,
240                    # the user may have installed another shell from a port which we don't know here
241                    dot_version=`export DOT=$DOT && csh -c '$DOT -V |& cut -f5 -d" "'`
242                    ;;
243
244                    *)
245                    dot_version=`$DOT -V 2>&1 | cut -f5 -d" "`
246                    ;;
247
248                esac
249                AS_VERSION_COMPARE([$dot_version],
250                                   [$dot_version_required],
251                                   [AC_MSG_RESULT([no])
252                                    DOT=""],
253                                   [AC_MSG_RESULT([yes $dot_version])],
254                                   [AC_MSG_RESULT([yes $dot_version])])
255                if test "x$DOT" = "x" -a "x$build_doxygen" = "xyes"; then
256                    AC_MSG_WARN([==> Graphviz dot $dot_version too old. Graphviz >= $dot_version_required required for doxygen build.])
257                    AC_MSG_ERROR([==> Install required graphviz version or disable the doxygen documentation using '--disable-doxygen'.])
258                fi
259                # we found dot and the version is valid
260                HAVE_DOT="YES"
261                # let doxygen create caller graphics
262                # see http://www.stack.nl/~dimitri/doxygen/manual/config.html#cfg_call_graph
263                USE_CALL_GRAPH="YES"
264                # exporting the tests to doc/Doxygen(.in)
265                AC_SUBST(HAVE_DOT)
266                AC_SUBST(USE_CALL_GRAPH)
267            fi
268        fi
269    fi
270fi
271AM_CONDITIONAL(BUILD_DOXYGEN, [test "x$build_doxygen" = "xyes"])
272
273AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"])
274AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])])
275
276# __manpages__
277
278AC_ARG_ENABLE([manpages],
279              [AS_HELP_STRING([--enable-manpages],
280                              [Enable building the manpages [default=yes]])],
281              [build_manpages="$enableval"],
282              [build_manpages="yes"])
283
284if test -z "$enable_manpages"; then
285    if test "x$enable_documentation" = "xno"; then
286        build_manpages="no"
287    fi
288fi
289
290if test "x$build_manpages" = "xyes"; then
291    AC_ARG_VAR([A2X], [a2x command])
292    AC_PATH_PROG([A2X], [a2x])
293    if test "x$A2X" = "x"; then
294        AC_MSG_WARN([==> You want to build the manpages, but a2x was not found!])
295        AC_MSG_ERROR([==> Install the package that contains a2x (mostly asciidoc) or disable the build of the manpages using '--disable-manpages'.])
296        build_manpages="no"
297    else
298        AX_CHECK_A2X_TO_MANPAGE([], [
299            AC_MSG_RESULT([no])
300            AC_MSG_WARN([==> You want to build the manpages with a2x, but manpage formatting does not work!])
301            AC_MSG_ERROR([==> Install the packages that contains the docbook DTD and XSL stylesheets (presumably docbook, docbook-xml) or disable the build of the manpages using '--disable-manpages'.])
302            build_manpages="no"
303        ])
304    fi
305fi
306AM_CONDITIONAL(BUILD_MANPAGES, [test "x$build_manpages" = "xyes"])
307
308# configure options
309# __dtls__
310# The Datagram Transport Layer Security (DTLS) feature needs cryptography
311# functions.
312# We currently support the GnuTLS and OpenSSL library. The user can preselect
313# the cryptography library that should be used by adding '--with-gnutls' or
314# '--with-openssl'.
315# If the user isn't using a selection we first search for GnuTLS and fallback
316# to OpenSSL if the GnuTLS library couldn't be found.
317
318gnutls_version_required=3.3.0
319openssl_version_required=1.1.0
320mbedtls_version_required=2.7.10
321
322AC_ARG_ENABLE([dtls],
323              [AS_HELP_STRING([--enable-dtls],
324                              [Enable building with DTLS support [default=yes]])],
325              [build_dtls="$enableval"],
326              [build_dtls="yes"])
327
328AC_ARG_WITH([gnutls],
329            [AS_HELP_STRING([--with-gnutls],
330                            [Use GnuTLS for DTLS functions])],
331            [with_gnutls="$withval"],
332            [with_gnutls="no"])
333
334AC_ARG_WITH([openssl],
335            [AS_HELP_STRING([--with-openssl],
336                            [Use OpenSSL for DTLS functions])],
337            [with_openssl="$withval"],
338            [with_openssl="no"])
339
340AC_ARG_WITH([mbedtls],
341            [AS_HELP_STRING([--with-mbedtls],
342                            [Use Mbed TLS for DTLS functions])],
343            [with_mbedtls="$withval"],
344            [with_mbedtls="no"])
345
346AC_ARG_WITH([tinydtls],
347           [AS_HELP_STRING([--with-tinydtls],
348                           [Use TinyDTLS for DTLS functions])],
349           [with_tinydtls="$withval"],
350           [with_tinydtls="no"])
351
352if test "x$with_gnutls" = "xyes" -o "x$with_openssl" = "xyes" -o "x$with_mbedtls" = "xyes" -o "x$with_tinydtls" = "xyes"; then
353    if test "x$build_dtls" = "x"; then
354        # Give an advice that '--with_gnutls', '--with_openssl', '--with-mbedtls' or '--with-tinydtls' was used but
355        # DTLS support isn't configured.
356        AC_MSG_NOTICE([==> Using the configure options '--with-gnutls', '--with-openssl', '--with-mbedtls' or '--with-tinydtls' without '--enable-dtls' is useles and will be ignored.])
357    fi
358fi
359
360# O.K. the user hasn't de-selected DTLS
361if test "x$build_dtls" = "xyes"; then
362    # The user can't select multiple crypto libraries.
363    TLSCOUNT=0
364    if test "x$with_gnutls" = "xyes"; then
365        TLSCOUNT=`expr $TLSCOUNT + 1`
366    fi
367    if test "x$with_openssl" = "xyes"; then
368        TLSCOUNT=`expr $TLSCOUNT + 1`
369    fi
370    if test "x$with_mbedtls" = "xyes"; then
371        TLSCOUNT=`expr $TLSCOUNT + 1`
372    fi
373    if test "x$with_tinydtls" = "xyes"; then
374        TLSCOUNT=`expr $TLSCOUNT + 1`
375    fi
376    if test "$TLSCOUNT" -gt 1; then
377        AC_MSG_ERROR([==> You can't use more than 1 of the options '--with-gnutls', '--with-openssl', '--with-mbedtls' or '--with-tinydtls' at the same time while '--enable-dtls' is selected!
378                  ==> Please note, the option '--enable-dtls' is turned on by default if not explicitly disabled!])
379    fi
380
381    # Check for all possible usable and supported SSL crypto libraries
382    # GnuTLS
383    PKG_CHECK_MODULES([GnuTLS],
384                      [gnutls],
385                      [have_gnutls="yes"],
386                      [have_gnutls="no"])
387
388    # OpenSSL
389    PKG_CHECK_MODULES([OpenSSL],
390                      [openssl],
391                      [have_openssl="yes"],
392                      [have_openssl="no"])
393
394    # Mbed TLS [does not have mbedtls.pc pkg-config file]
395    AC_CHECK_LIB(mbedtls, mbedtls_version_get_string,
396                 [have_mbedtls="yes"; MbedTLS_CFLAGS="" ; MbedTLS_LIBS="-lmbedtls -lmbedcrypto -lmbedx509"],
397                 [have_mbedtls="no"], -lmbedx509 -lmbedcrypto)
398    if test "x$have_mbedtls" = "xyes"; then
399        if test "x$cross_compiling" = "xyes" ; then
400            # Have no option but to do this
401            mbedtls_version=$mbedtls_version_required
402        else
403            # Get actual library version
404            AC_LANG_PUSH(C)
405            local_MbedTLS_save_LIBS=$LIBS
406            LIBS="$MbedTLS_LIBS $LIBS"
407            AC_LINK_IFELSE([dnl
408                AC_LANG_SOURCE(
409                    [[#include <stdio.h>
410                     #include <mbedtls/version.h>
411                     int main () {
412                       char str[20];
413                       mbedtls_version_get_string(str);
414                       fprintf(stdout,"%s\n",str);
415                       return 0;
416                     }]])],
417               [mbedtls_version=$(./conftest$EXEEXT)],
418               [AC_MSG_ERROR(Failed to determine Mbed TLS version)])
419            LIBS=$local_MbedTLS_save_LIBS
420            AC_LANG_POP(C)
421        fi
422    fi
423
424    # TinyDTLS ?
425    # TBD ?
426
427    # The user wants to use explicit GnuTLS if '--with-gnutls' was set.
428    if test "x$with_gnutls" = "xyes"; then
429        # Some more sanity checking.
430        if test "x$have_gnutls" != "xyes"; then
431            AC_MSG_ERROR([==> You want to build libcoap with DTLS support by the GnuTLS library but pkg-config file 'gnutls.pc' could not be found!
432                      Install the package(s) that contains the development files for GnuTLS,
433                      or select a different TLS library or disable the DTLS support using '--disable-dtls'.])
434        fi
435        AC_MSG_NOTICE([The use of GnuTLS was explicitly requested with configure option '--with-gnutls'!])
436
437        # check for valid GnuTLS version
438        gnutls_version=`pkg-config --modversion gnutls`
439        AX_CHECK_GNUTLS_VERSION
440        have_openssl="no" # don't confuse AC_MSG_RESULT at the end of the script
441        have_mbedtls="no" # don't confuse AC_MSG_RESULT at the end of the script
442        have_tinydtls="no" # don't confuse AC_MSG_RESULT at the end of the script
443    fi
444
445    # The user wants to use explicit OpenSSL if '--with-openssl was set'.
446    if test "x$with_openssl" = "xyes"; then
447        # Some more sanity checking.
448        if test "x$have_openssl" != "xyes"; then
449            AC_MSG_ERROR([==> You want to build libcoap with DTLS support by the OpenSSL library but pkg-config file 'openssl.pc' could not be found!
450                      Install the package(s) that contains the development files for OpenSSL,
451                      or select a different TLS library or disable the DTLS support using '--disable-dtls'.])
452        fi
453        AC_MSG_NOTICE([The use of OpenSSL was explicitly requested with configure option '--with-openssl'!])
454
455        # check for valid OpenSSL version
456        openssl_version=`pkg-config --modversion openssl`
457        AX_CHECK_OPENSSL_VERSION
458        have_gnutls="no" # don't confuse AC_MSG_RESULT at the end of the script
459        have_mbedtls="no" # don't confuse AC_MSG_RESULT at the end of the script
460        have_tinydtls="no" # don't confuse AC_MSG_RESULT at the end of the script
461    fi
462
463    # The user wants to use explicit Mbed TLS if '--with-mbedtls was set'.
464    if test "x$with_mbedtls" = "xyes"; then
465        # Some more sanity checking.
466        if test "x$have_mbedtls" != "xyes"; then
467            AC_MSG_ERROR([==> You want to build libcoap with DTLS support by the Mbed TLS library but library 'mbedtls' could not be found!
468                      Install the package(s) that contains the development files for Mbed TLS,
469                      or select a different TLS library or disable the DTLS support using '--disable-dtls'.])
470        fi
471        AC_MSG_NOTICE([The use of Mbed TLS was explicitly requested with configure option '--with-mbedtls'!])
472
473        # check for valid Mbed TLS version (mbedtls.pc does not exist - hmm)
474        # mbedtls_version determined previously
475        AX_CHECK_MBEDTLS_VERSION
476        have_gnutls="no" # don't confuse AC_MSG_RESULT at the end of the script
477        have_openssl="no" # don't confuse AC_MSG_RESULT at the end of the script
478        have_tinydtls="no" # don't confuse AC_MSG_RESULT at the end of the script
479    fi
480
481    # The user wants to use explicit TinyDTLS if '--with-tinydtls was set'.
482    if test "x$with_tinydtls" = "xyes" ; then
483        if test -d "$srcdir/ext/tinydtls"; then
484           AC_CONFIG_SUBDIRS([ext/tinydtls])
485           have_tinydtls="yes"
486         else
487           have_tinydtls="no" # don't confuse AC_MSG_RESULT at the end of the script
488         fi
489         have_gnutls="no" # don't confuse AC_MSG_RESULT at the end of the script
490         have_openssl="no" # don't confuse AC_MSG_RESULT at the end of the script
491         have_mbedtls="no" # don't confuse AC_MSG_RESULT at the end of the script
492    fi
493
494    if test "$TLSCOUNT" -eq 0; then
495      # The user hasn't requested the use of a specific cryptography library
496      # we try first GnuTLS for usability ...
497      if test "x$have_gnutls" = "xyes"; then
498          gnutls_version=`pkg-config --modversion gnutls`
499          AX_CHECK_GNUTLS_VERSION
500          AC_MSG_NOTICE([Using auto selected library GnuTLS for DTLS support!])
501          with_gnutls_auto="yes"
502          have_openssl="no" # don't confuse AC_MSG_RESULT at the end of the script
503          have_mbedtls="no" # don't confuse AC_MSG_RESULT at the end of the script
504          have_tinydtls="no" # don't confuse AC_MSG_RESULT at the end of the script
505
506      # ... and if not found check OpenSSL is suitable.
507      elif test "x$have_openssl" = "xyes"; then
508          openssl_version=`pkg-config --modversion openssl`
509          AX_CHECK_OPENSSL_VERSION
510          AC_MSG_NOTICE([Using auto selected library OpenSSL for DTLS support!])
511          with_openssl_auto="yes"
512          have_gnutls="no" # don't confuse AC_MSG_RESULT at the end of the script
513          have_mbedtls="no" # don't confuse AC_MSG_RESULT at the end of the script
514          have_tinydtls="no" # don't confuse AC_MSG_RESULT at the end of the script
515
516      # ... and if not found check Mbed TLS is suitable.
517      elif test "x$have_mbedtls" = "xyes"; then
518          # Mbed TLS [does not have mbedtls.pc pkg-config file]
519          # mbedtls_version determined previously
520          AX_CHECK_MBEDTLS_VERSION
521          AC_MSG_NOTICE([Using auto selected library Mbed TLS for DTLS support!])
522          with_mbedtls_auto="yes"
523          have_gnutls="no" # don't confuse AC_MSG_RESULT at the end of the script
524          have_openssl="no" # don't confuse AC_MSG_RESULT at the end of the script
525          have_tinydtls="no" # don't confuse AC_MSG_RESULT at the end of the script
526
527      # Note that tinyDTLS is used only when explicitly requested.
528      # Giving out an error message if we haven't found at least one crypto library.
529      else
530          AC_MSG_ERROR([==> Option '--enable-dtls' is set but none of the needed cryptography libraries GnuTLS, OpenSSL or Mbed TLS could be found!
531                        Install at least one of the package(s) that contains the development files for GnuTLS (>= $gnutls_version_required), OpenSSL(>= $openssl_version_required), or Mbed TLS(>= $mbedtls_version_required)
532                        or disable the DTLS support using '--disable-dtls'.])
533      fi
534    fi
535
536    # Saving the DTLS related Compiler flags.
537    if test "x$with_gnutls" = "xyes" -o "x$with_gnutls_auto" = "xyes"; then
538        DTLS_CFLAGS="$GnuTLS_CFLAGS"
539        DTLS_LIBS="$GnuTLS_LIBS"
540        AC_DEFINE(HAVE_LIBGNUTLS, [1], [Define if the system has libgnutls28])
541    fi
542    if test "x$with_openssl" = "xyes" -o "x$with_openssl_auto" = "xyes"; then
543        DTLS_CFLAGS="$OpenSSL_CFLAGS"
544        DTLS_LIBS="$OpenSSL_LIBS"
545        AC_DEFINE(HAVE_OPENSSL, [1], [Define if the system has libssl1.1])
546    fi
547    if test "x$with_mbedtls" = "xyes" -o "x$with_mbedtls_auto" = "xyes"; then
548        DTLS_CFLAGS="$MbedTLS_CFLAGS"
549        DTLS_LIBS="$MbedTLS_LIBS"
550        AC_DEFINE(HAVE_MBEDTLS, [1], [Define if the system has libmbedtls2.7.10])
551    fi
552    if test "x$with_tinydtls" = "xyes"; then
553        DTLS_CFLAGS="-I \$(top_srcdir)/ext/tinydtls"
554        if test "x$enable_shared" = "xyes"; then
555            DTLS_LIBS="-L\$(top_builddir)/ext/tinydtls -ltinydtls"
556        else
557            # Needed as TinyDTLS compiling does not recognize --disable-shared
558            # and still builds libtinydtls.so which gets linked in otherwise
559            DTLS_LIBS="-L\$(top_builddir)/ext/tinydtls -l:libtinydtls.a"
560        fi
561        AC_DEFINE(HAVE_LIBTINYDTLS, [1], [Define if the system has libtinydtls])
562    fi
563    AC_SUBST(DTLS_CFLAGS)
564    AC_SUBST(DTLS_LIBS)
565fi
566
567# Define the Library name extension for the TLS the library was linked against
568if test "x$with_openssl" = "xyes" -o "x$with_openssl_auto" = "xyes"; then
569    LIBCOAP_DTLS_LIB_EXTENSION_NAME=-openssl
570elif test "x$with_gnutls" = "xyes" -o "x$with_gnutls_auto" = "xyes"; then
571    LIBCOAP_DTLS_LIB_EXTENSION_NAME=-gnutls
572elif test "x$with_mbedtls" = "xyes" -o "x$with_mbedtls_auto" = "xyes"; then
573    LIBCOAP_DTLS_LIB_EXTENSION_NAME=-mbedtls
574elif test "x$with_tinydtls" = "xyes"; then
575    LIBCOAP_DTLS_LIB_EXTENSION_NAME=-tinydtls
576else
577    LIBCOAP_DTLS_LIB_EXTENSION_NAME=-notls
578fi
579
580LIBCOAP_NAME_SUFFIX="$LIBCOAP_API_VERSION$LIBCOAP_DTLS_LIB_EXTENSION_NAME"
581
582AC_SUBST(LIBCOAP_NAME_SUFFIX)
583AC_SUBST(LIBCOAP_DTLS_LIB_EXTENSION_NAME)
584AC_SUBST([DOLLAR_SIGN],[$])
585
586# configure options
587# __tests__
588AC_ARG_ENABLE([tests],
589              [AS_HELP_STRING([--enable-tests],
590                              [Enable building the binary testsuite. Requires --enable-static  [default=no]])],
591              [build_tests="$enableval"],
592              [build_tests="no"])
593
594if test "x$build_tests" = "xyes"; then
595    PKG_CHECK_MODULES([CUNIT],
596                      [cunit],
597                      [have_cunit=yes
598                       AC_DEFINE(HAVE_LIBCUNIT, [1], [Define if the system has libcunit])],
599                      [have_cunit=no
600                       AC_MSG_WARN([==> You want to build the testing binary but the pkg-config file cunit.pc could not be found or installed CUnit version is too old!])
601                       AC_MSG_ERROR([==> Install the package(s) that contains the development files for CUnit or disable the testing binary using '--disable-tests'.])
602                      ])
603    if test "x$enable_static" = "xno"; then
604        enable_static=yes
605        AC_MSG_WARN([--enable-tests requires --enable-static which is now enabled.])
606    fi
607fi
608AM_CONDITIONAL(HAVE_CUNIT, [test "x$CUNIT_LIBS" != "x"])
609
610# configure options
611# __examples__
612AC_ARG_ENABLE([examples],
613              [AS_HELP_STRING([--enable-examples],
614                              [Enable building the example binaries [default=yes]])],
615              [build_examples="$enableval"],
616              [build_examples="yes"])
617
618AM_CONDITIONAL(BUILD_EXAMPLES, [test "x$build_examples" = "xyes"])
619
620# configure options
621# __examples-source
622AC_ARG_ENABLE([examples-source],
623              [AS_HELP_STRING([--enable-examples-source],
624                              [Enable installing example source to DATAROOTDIR/libcoap/examples [default=yes]])],
625              [build_examples_source="$enableval"],
626              [build_examples_source="yes"])
627
628AM_CONDITIONAL(BUILD_EXAMPLES_SOURCE, [test "x$build_examples_source" = "xyes"])
629
630# configure options
631# __gcov__
632AC_ARG_ENABLE([gcov],
633              [AS_HELP_STRING([--enable-gcov],
634                              [Enable building with gcov test coverage support [default=no]])],
635              [build_gcov="$enableval"],
636              [build_gcov="no"
637               AC_MSG_WARN([gcov is disabled])
638              ])
639
640if test "x$build_gcov" = "xyes"; then
641   if test "x$GCC" != "xyes"; then
642        AC_MSG_ERROR([Currently, gcov is assumed to work with GCC-compatible compilers only.])
643   else
644        AX_CHECK_COMPILE_FLAG([-fprofile-arcs], [CFLAGS="$CFLAGS -fprofile-arcs"])
645        AX_CHECK_COMPILE_FLAG([-ftest-coverage], [CFLAGS="$CFLAGS -ftest-coverage"])
646        # FIXME: clang complains about '--coverage'
647        AX_CHECK_COMPILE_FLAG([--coverage], [CFLAGS="$CFLAGS --coverage -O0" LDFLAGS="$LDFLAGS --coverage"])
648   fi
649fi
650
651# configure options
652# __license-install__
653AC_ARG_ENABLE([license-install],
654              [AS_HELP_STRING([--enable-license-install],
655                              [Enable installing LICENSE to DOCDIR [default=yes]])],
656              [build_license_install="$enableval"],
657              [build_license_install="yes"])
658
659AM_CONDITIONAL(BUILD_LICENSE_INSTALL, [test "x$build_license_install" = "xyes"])
660
661# configure options
662# __tcp__
663AC_ARG_ENABLE([tcp],
664              [AS_HELP_STRING([--enable-tcp],
665                              [Enable building with TCP support [default=yes]])],
666              [build_tcp="$enableval"],
667              [build_tcp="yes"])
668
669AC_DEFINE(COAP_DISABLE_TCP, [0], [Define to 1 to build without TCP support.])
670AS_IF([test "x$build_tcp" != "xyes"], [AC_DEFINE(COAP_DISABLE_TCP, [1])])
671AC_SUBST(COAP_DISABLE_TCP)
672
673# configure options
674# __async__
675AC_ARG_ENABLE([async],
676              [AS_HELP_STRING([--enable-async],
677                              [Enable building with support for separate responses [default=yes]])],
678              [build_async="$enableval"],
679              [build_async="yes"])
680
681AS_IF([test "x$build_async" != "xyes"],
682      [AC_DEFINE(WITHOUT_ASYNC, [1], [Define to build without support for separate responses.])])
683
684# configure options
685# __add_default_names__
686AC_ARG_ENABLE([add-default-names],
687              [AS_HELP_STRING([--enable-add-default-names],
688                              [Enable adding libraries / examples with default names [default=yes]])],
689              [build_add_default_names="$enableval"],
690              [build_add_default_names="yes"])
691
692AM_CONDITIONAL(BUILD_ADD_DEFAULT_NAMES, [test "x$build_add_default_names" = "xyes"])
693
694# end configure options
695#######################
696
697###########################################
698# from configure options independent checks
699
700# Check for (ex)ctags binary
701# The needed ctags binary name differs on FreeBSD and Linux, on Linux
702# systems we search for 'ctags', on FreeBSD for 'exctags'
703case $host in
704    # FreeBSD has exctags from the ctags port
705    *-freebsd1*)
706    AC_ARG_VAR([CTAGS_PROG],[the 'exctags' program to use for make target 'update-map-file'])
707    AC_PATH_PROG([CTAGS_PROG],[exctags])
708    ;;
709
710    *)
711    # Linux distributions have exuberant-ctags
712    AC_ARG_VAR([CTAGS_PROG],[the 'ctags' program to use for make target 'update-map-file'])
713    AC_PATH_PROG([CTAGS_PROG],[ctags])
714    ;;
715
716esac
717
718if test "x$CTAGS_PROG" = "x"; then
719    AC_MSG_NOTICE([==> Note: '(ex)ctags' command not found!])
720    AC_MSG_WARN([==> Without ctags you will be unable to run the target 'update-map-file'!])
721    AC_MSG_WARN([==> This is no problem if you just want to build the library libcoap.])
722else
723    if test "`$CTAGS_PROG --help | grep '\--<LANG>-kinds'`" = ""; then
724        AC_MSG_NOTICE([==> Note: Your ctags binary does not support '--c-kinds'!])
725        AC_MSG_NOTICE([==> Most likely, you are using the GNU Emacs ctag and not exuberant ctag.])
726        AC_MSG_WARN([==> This option is required for the target 'update-map-file'.])
727        AC_MSG_WARN([==> which is not a problem if you just want to build the library libcoap.])
728    fi
729fi
730
731# Checks for header files.
732AC_CHECK_HEADERS([assert.h arpa/inet.h limits.h netdb.h netinet/in.h \
733                  pthread.h \
734                  stdlib.h string.h strings.h sys/socket.h sys/time.h \
735                  time.h unistd.h sys/unistd.h syslog.h sys/ioctl.h net/if.h])
736
737# For epoll, need two headers (sys/epoll.h sys/timerfd.h), but set up one #define
738AC_CHECK_HEADER([sys/epoll.h])
739AC_CHECK_HEADER([sys/timerfd.h])
740if test "x$ac_cv_header_sys_epoll_h" = "xyes" -a "x$ac_cv_header_sys_timerfd_h" = "xyes"; then
741    have_epoll="yes"
742    AC_ARG_WITH([epoll],
743            [AS_HELP_STRING([--with-epoll],
744                            [Use epoll for I/O handling [if O/S supports it]])],
745            [with_epoll="$withval"],
746            [with_epoll="yes"])
747else
748    have_epoll="no"
749    if test "x$with_epoll" = "xyes"; then
750        AC_MSG_WARN([==> Underlying O/S does not support epoll - --with-epoll ignored.])
751        with_epoll="no"
752    fi
753fi
754
755if test "x$with_epoll" = "xyes"; then
756    AC_DEFINE(COAP_EPOLL_SUPPORT, 1, [Define if the system has epoll support])
757fi
758
759AC_ARG_ENABLE([small-stack],
760        [AS_HELP_STRING([--enable-small-stack],
761                        [Use small-stack if the available stack space is restricted [default=no]])],
762        [enable_small_stack="$enableval"],
763        [enable_small_stack="no"])
764
765if test "x$enable_small_stack" = "xyes"; then
766    AC_DEFINE(COAP_CONSTRAINED_STACK, 1, [Define if the system has small stack size])
767fi
768
769# Checks for typedefs, structures, and compiler characteristics.
770AC_TYPE_SIZE_T
771AC_TYPE_SSIZE_T
772
773# Checks for library functions.
774AC_CHECK_FUNCS([memset select socket strcasecmp strrchr getaddrinfo \
775                strnlen malloc pthread_mutex_lock getrandom if_nametoindex])
776
777# Check if -lsocket -lnsl is required (specifically Solaris)
778AC_SEARCH_LIBS([socket], [socket])
779AC_SEARCH_LIBS([inet_ntop], [nsl])
780
781# Check if clock_gettime() requires librt, when available
782AC_SEARCH_LIBS([clock_gettime], [rt])
783
784#check for struct cmsghdr
785AC_CHECK_TYPES([struct cmsghdr],,,[
786AC_INCLUDES_DEFAULT
787#include <sys/socket.h>])
788
789AC_MSG_CHECKING([operating system])
790
791# Set up here some extra platform depended defines and variables.
792# The "ADDITIONAL_CFLAGS" is need as this stand-alone definition
793# for the doxygen part.
794case $host in
795    *-linux* | *-uclinux*)
796    AC_MSG_RESULT([Linux])
797    ADDITIONAL_CFLAGS="-D_GNU_SOURCE"
798
799    # Not yet needed but if some code definitions have to depend on the platform.
800    #AC_DEFINE(OS_LINUX, 1, [Linux backend])
801    #AC_SUBST(OS_LINUX)
802    ;;
803
804    *-cygwin*)
805    AC_MSG_RESULT([Cygwin])
806    ADDITIONAL_CFLAGS="-D_GNU_SOURCE -D_CYGWIN_ENV"
807    LDFLAGS="-no-undefined $LDFLAGS"
808    ;;
809
810    *-solaris*)
811    AC_MSG_RESULT([Solaris])
812    # set _XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED to enable XPG4v2 (POSIX 2004)
813    # set __EXTENSION__ to shut up feature test macros that restrict -std=c99
814    # to only C99 (and nothing newer)
815    ADDITIONAL_CFLAGS="-D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=600 -D__EXTENSIONS__=1"
816    ;;
817
818    *-darwin*)
819    AC_MSG_RESULT([Darwin])
820    ADDITIONAL_CFLAGS="-D_GNU_SOURCE"
821
822    AC_DEFINE(__APPLE_USE_RFC_3542, 1, [Define this to 1 for ancillary data on MacOS])
823
824    # Not yet needed but if some code definitions have to depend on the platform.
825    #AC_DEFINE(OS_MACOS, 1, [MacOS backend])
826    #AC_SUBST(OS_MACOS)
827    ;;
828
829    *-freebsd1*)
830    AC_MSG_RESULT([FreeBSD-1x])
831    ADDITIONAL_CFLAGS="-D_GNU_SOURCE"
832    ;;
833
834    *kfreebsd*)
835    AC_MSG_RESULT([kFreeBSD])
836    ADDITIONAL_CFLAGS="-D_GNU_SOURCE"
837    ;;
838
839    *)
840    AC_MSG_WARN([==> Currently unsupported operating system '${host}' !])
841    AC_MSG_ERROR([==> If you can provide patches to support your operating system please write to 'libcoap-developers@lists.sourceforge.net'.])
842esac
843
844# Exporting the PREDEFINED_CFLAGS definition
845PREDEFINED_CFLAGS=`echo $ADDITIONAL_CFLAGS | $SED -e 's/-D//g'`
846AC_SUBST(PREDEFINED_CFLAGS)
847
848# And finally combining the CFLAGS together ...
849CFLAGS="$CFLAGS $ADDITIONAL_CFLAGS"
850
851# Override the various template files, currently just makefiles and the
852# pkgconfig *.pc file.
853# Later if the API version is changing don't forget to change the
854# libcoap-$LIBCOAP_API_VERSION.pc.in file too!! You will have to change
855# the 'Cflags' variable to something like
856#     Cflags: -I${includedir}/coap-@LIBCOAP_API_VERSION@
857#
858AC_CONFIG_FILES([
859Makefile
860coap_config.h.lwip
861coap_config.h.riot
862coap_config.h.windows
863doc/Makefile
864examples/Makefile
865include/coap$LIBCOAP_API_VERSION/coap.h
866include/coap$LIBCOAP_API_VERSION/coap.h.windows
867man/coap.txt
868man/coap_async.txt
869man/coap_attribute.txt
870man/coap_block.txt
871man/coap_cache.txt
872man/coap_context.txt
873man/coap_encryption.txt
874man/coap_endpoint_client.txt
875man/coap_endpoint_server.txt
876man/coap_handler.txt
877man/coap_io.txt
878man/coap_keepalive.txt
879man/coap_logging.txt
880man/coap_observe.txt
881man/coap_pdu_access.txt
882man/coap_pdu_setup.txt
883man/coap_recovery.txt
884man/coap_resource.txt
885man/coap_session.txt
886man/coap_string.txt
887man/coap_tls_library.txt
888man/coap-client.txt
889man/coap-server.txt
890man/coap-rd.txt
891man/Makefile
892tests/test_common.h
893tests/Makefile
894tests/oss-fuzz/Makefile.ci
895libcoap-$LIBCOAP_NAME_SUFFIX.pc:libcoap-$LIBCOAP_API_VERSION.pc.in
896])
897
898AC_OUTPUT
899
900AC_MSG_RESULT([
901libcoap configuration summary:
902      libcoap package version  : "$PACKAGE_VERSION"
903      libcoap library version  : "$LIBCOAP_SO_VERSION"
904      libcoap API version      : "$LIBCOAP_API_VERSION"
905      libcoap DTLS lib extn    : "$LIBCOAP_DTLS_LIB_EXTENSION_NAME"
906      host system              : "$host"]);
907if test "x$build_tcp" != "xno"; then
908    AC_MSG_RESULT([      build with TCP support   : "yes"])
909else
910    AC_MSG_RESULT([      build with TCP support   : "no"])
911fi
912if test "x$with_gnutls" = "xyes" -o "x$with_gnutls_auto" = "xyes"; then
913    AC_MSG_RESULT([      build DTLS support       : "yes"])
914    AC_MSG_RESULT([          -->  GnuTLS around   : "yes" (found GnuTLS $gnutls_version)])
915    AC_MSG_RESULT([               GNUTLS_CFLAGS   : "$GnuTLS_CFLAGS"])
916    AC_MSG_RESULT([               GNUTLS_LIBS     : "$GnuTLS_LIBS"])
917fi
918if test "x$with_openssl" = "xyes" -o "x$with_openssl_auto" = "xyes"; then
919    AC_MSG_RESULT([      build DTLS support       : "yes"])
920    AC_MSG_RESULT([         -->  OpenSSL around   : "yes" (found OpenSSL $openssl_version)])
921    AC_MSG_RESULT([              OPENSSL_CFLAGS   : "$OpenSSL_CFLAGS"])
922    AC_MSG_RESULT([              OPENSSL_LIBS     : "$OpenSSL_LIBS"])
923fi
924if test "x$with_mbedtls" = "xyes" -o "x$with_mbedtls_auto" = "xyes"; then
925    AC_MSG_RESULT([      build DTLS support       : "yes"])
926    AC_MSG_RESULT([         -->  Mbed TLS around  : "yes" (found Mbed TLS $mbedtls_version)])
927    AC_MSG_RESULT([              MBEDTLS_CFLAGS   : "$MbedTLS_CFLAGS"])
928    AC_MSG_RESULT([              MBEDTLS_LIBS     : "$MbedTLS_LIBS"])
929fi
930if test "x$with_tinydtls" = "xyes"; then
931    AC_MSG_RESULT([      build DTLS support       : "yes"])
932    AC_MSG_RESULT([         -->  tinyDTLS around  : "yes"])
933    AC_MSG_RESULT([              TINYDTLS_CFLAGS  : "$DTLS_CFLAGS"])
934    AC_MSG_RESULT([              TINYDTLS_LIBS    : "$DTLS_LIBS"])
935fi
936if test "x$build_dtls" != "xyes"; then
937    AC_MSG_RESULT([      build DTLS support       : "no"])
938fi
939if test "x$build_add_default_names" = "xyes"; then
940    AC_MSG_RESULT([      add default names        : "yes"])
941else
942    AC_MSG_RESULT([      add default names        : "no"])
943fi
944if test "x$have_epoll" = "xyes"; then
945    AC_MSG_RESULT([      build using epoll        : "$with_epoll"])
946fi
947AC_MSG_RESULT([      enable small stack size  : "$enable_small_stack"])
948if test "x$build_async" != "xno"; then
949    AC_MSG_RESULT([      enable separate responses: "yes"])
950else
951    AC_MSG_RESULT([      enable separate responses: "no"])
952fi
953if test "x$build_doxygen" = "xyes"; then
954    AC_MSG_RESULT([      build doxygen pages      : "yes"])
955    AC_MSG_RESULT([          --> Doxygen around   : "yes" ($DOXYGEN $doxygen_version)])
956    if test "x$DOT" = "x"; then
957        AC_MSG_RESULT([             -->  dot around   : "no" (DOT not found!)])
958    else
959        AC_MSG_RESULT([             -->  dot around   : "yes" ($DOT $dot_version)])
960    fi
961else
962    if test "x$build_doxygen" = "xno"; then
963        AC_MSG_RESULT([      build doxygen pages      : "no"])
964    fi
965fi
966if test "x$build_manpages" = "xyes"; then
967    AC_MSG_RESULT([      build man pages          : "yes"])
968else
969    AC_MSG_RESULT([      build man pages          : "no"])
970fi
971if test "x$build_tests" = "xyes"; then
972    AC_MSG_RESULT([      build unit test binary   : "yes"])
973else
974    AC_MSG_RESULT([      build unit test binary   : "no"])
975fi
976if test "x$build_examples" = "xyes"; then
977    AC_MSG_RESULT([      build examples           : "yes"])
978else
979    AC_MSG_RESULT([      build examples           : "no"])
980fi
981if test "x$build_examples_source" = "xyes"; then
982    AC_MSG_RESULT([      install examples source  : "yes"])
983else
984    AC_MSG_RESULT([      install examples source  : "no"])
985fi
986if test "x$build_gcov" = "xyes"; then
987    AC_MSG_RESULT([      build with gcov support  : "yes"])
988else
989    AC_MSG_RESULT([      build with gcov support  : "no"])
990fi
991if test "x$enable_shared" = "xyes"; then
992    AC_MSG_RESULT([      build shared library     : "yes"])
993else
994    AC_MSG_RESULT([      build shared library     : "no"])
995fi
996if test "x$enable_static" = "xyes"; then
997    AC_MSG_RESULT([      build static library     : "yes"])
998else
999    AC_MSG_RESULT([      build static library     : "no"])
1000fi
1001