1#                                               -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3
4#
5#  Copyright (c) 2016, The OpenThread Authors.
6#  All rights reserved.
7#
8#  Redistribution and use in source and binary forms, with or without
9#  modification, are permitted provided that the following conditions are met:
10#  1. Redistributions of source code must retain the above copyright
11#     notice, this list of conditions and the following disclaimer.
12#  2. Redistributions in binary form must reproduce the above copyright
13#     notice, this list of conditions and the following disclaimer in the
14#     documentation and/or other materials provided with the distribution.
15#  3. Neither the name of the copyright holder nor the
16#     names of its contributors may be used to endorse or promote products
17#     derived from this software without specific prior written permission.
18#
19#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29#  POSSIBILITY OF SUCH DAMAGE.
30#
31
32#
33# Declare autoconf version requirements
34#
35AC_PREREQ([2.68])
36
37#
38# Initialize autoconf for the package
39#
40AC_INIT([OPENTHREAD],
41        m4_esyscmd([third_party/nlbuild-autotools/repo/scripts/mkversion -b `cat .default-version` .]),
42        [openthread-devel@googlegroups.com],
43        [openthread],
44        [http://github.com/openthread/openthread])
45
46# Tell the rest of the build system the absolute path where the
47# nlbuild-autotools repository is rooted at.
48
49AC_SUBST(nlbuild_autotools_stem,[third_party/nlbuild-autotools/repo])
50AC_SUBST(abs_top_nlbuild_autotools_dir,[\${abs_top_srcdir}/\${nlbuild_autotools_stem}])
51
52#
53# OPENTHREAD interface current, revision, and age versions.
54#
55# Maintainters: Please manage these fields as follows:
56#
57#   Interfaces removed:    CURRENT++, AGE = 0, REVISION = 0
58#   Interfaces added:      CURRENT++, AGE++,   REVISION = 0
59#   No interfaces changed:                     REVISION++
60#
61#
62AC_SUBST(LIBOPENTHREAD_VERSION_CURRENT,  [0])
63AC_SUBST(LIBOPENTHREAD_VERSION_AGE,      [5])
64AC_SUBST(LIBOPENTHREAD_VERSION_REVISION, [0])
65AC_SUBST(LIBOPENTHREAD_VERSION_INFO,     [${LIBOPENTHREAD_VERSION_CURRENT}:${LIBOPENTHREAD_VERSION_REVISION}:${LIBOPENTHREAD_VERSION_AGE}])
66
67#
68# Check the sanity of the source directory by checking for the
69# presence of a key watch file
70#
71AC_CONFIG_SRCDIR([include/openthread/error.h])
72
73#
74# Tell autoconf where to find auxilliary build tools (e.g. config.guess,
75# install-sh, missing, etc.)
76#
77AC_CONFIG_AUX_DIR([third_party/nlbuild-autotools/repo/third_party/autoconf])
78
79#
80# Tell autoconf where to find auxilliary M4 macros
81#
82AC_CONFIG_MACRO_DIRS([third_party/nlbuild-autotools/repo/third_party/autoconf/m4 third_party/nlbuild-autotools/repo/autoconf/m4])
83
84#
85# Tell autoconf what file the package is using to aggregate C preprocessor
86# defines.
87#
88AC_CONFIG_HEADERS([include/openthread-config-generic.h])
89
90#
91# Figure out what the canonical build and host tuples are.
92#
93AC_CANONICAL_BUILD
94AC_CANONICAL_HOST
95
96#
97# Mac OS X / Darwin ends up putting some versioning cruft on the end of its
98# tuple that we don't care about in this script. Create "clean" variables
99# devoid of it.
100#
101
102NL_FILTERED_CANONICAL_BUILD
103NL_FILTERED_CANONICAL_HOST
104
105#
106# Configure automake with the desired options, indicating that this is not
107# a native GNU package, that we want "silent" build rules, and that we want
108# objects built in the same subdirectory as their source rather than collapsed
109# together at the top-level directory.
110#
111# Disable silent build rules by either passing --disable-silent-rules to
112# configure or passing V=1 to make
113#
114AM_INIT_AUTOMAKE([1.14 foreign silent-rules subdir-objects tar-pax])
115
116#
117# Silent build rules requires at least automake-1.11. Employ
118# techniques for not breaking earlier versions of automake.
119#
120m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
121AM_SILENT_RULES([yes])
122
123#
124# Enable maintainer mode to prevent the package from constantly trying
125# to rebuild configure, Makefile.in, etc. Rebuilding such files rarely,
126# if ever, needs to be done "in the field".
127#
128# Use the included 'bootstrap' script instead when necessary.
129#
130AM_MAINTAINER_MODE
131
132#
133# Host-os-specific checks
134#
135
136case ${host_os} in
137
138    *darwin*)
139        OPENTHREAD_TARGET=darwin
140        ;;
141
142    *linux*)
143        OPENTHREAD_TARGET=linux
144        ;;
145
146esac
147
148AM_CONDITIONAL([OPENTHREAD_TARGET_DARWIN], [test "${OPENTHREAD_TARGET}" = "darwin"])
149AM_CONDITIONAL([OPENTHREAD_TARGET_LINUX], [test "${OPENTHREAD_TARGET}" = "linux"])
150
151#
152# Checks for build host programs
153#
154
155# This is a hack to restore some old broken behavior that was
156# removed in pull request #1527. It's use is highly discouraged,
157# you should try to fix your build environment instead.
158AC_ARG_ENABLE(no-executables-hack,
159    [AS_HELP_STRING([--enable-no-executables-hack],
160        [Enable hack that prevents link checks at configure time. Highly discouraged.])])
161AC_MSG_CHECKING([whether to disable executable checking])
162if test "${enable_no_executables_hack}" = "yes"
163then
164    AC_MSG_RESULT([yes])
165    AC_NO_EXECUTABLES
166else
167    AC_MSG_RESULT([no])
168fi
169
170# Passing -Werror to GCC-based or -compatible compilers breaks some
171# autoconf tests (see
172# http://lists.gnu.org/archive/html/autoconf-patches/2008-09/msg00014.html).
173#
174# If -Werror has been passed transform it into -Wno-error. We'll
175# transform it back later with NL_RESTORE_WERROR.
176
177NL_SAVE_WERROR
178
179# Check for compilers.
180#
181# These should be checked BEFORE we check for and, implicitly,
182# initialize libtool such that libtool knows what languages it has to
183# work with.
184
185AC_PROG_CPP
186AC_PROG_CPP_WERROR
187
188AC_PROG_CC
189AC_PROG_CC_C_O
190
191AC_PROG_CXXCPP
192
193AC_PROG_CXX
194AC_PROG_CXX_C_O
195
196AM_PROG_AS
197
198AC_C_BIGENDIAN
199
200# Check for other compiler toolchain tools.
201
202AC_CHECK_TOOL(AR, ar)
203AC_CHECK_TOOL(RANLIB, ranlib)
204AC_CHECK_TOOL(OBJCOPY, objcopy)
205AC_CHECK_TOOL(STRIP, strip)
206
207# Check for other host tools.
208
209AC_PROG_INSTALL
210AC_PROG_LN_S
211
212AC_PATH_PROG(CMP, cmp)
213
214# Check for and initialize libtool
215
216LT_INIT
217AC_PROG_LIBTOOL
218
219#
220# Checks for specific compiler characteristics
221#
222
223#
224# Common compiler flags we would like to have.
225#
226#   -Wall                        CC, CXX
227#
228
229PROSPECTIVE_CFLAGS="-Wall -Wextra -Wshadow -Wundef -Wcast-align -Werror -Wno-error=undef -std=c99 -pedantic-errors"
230PROSPECTIVE_CXXFLAGS="-Wall -Wextra -Wshadow -Wundef -Wcast-align -Werror -Wno-error=undef -std=c++11 -Wno-c++14-compat -fno-exceptions -pedantic-errors"
231
232AC_CACHE_CHECK([whether $CC is Clang],
233    [nl_cv_clang],
234    [nl_cv_clang=no
235    if test "x${GCC}" = "xyes"; then
236        AC_EGREP_CPP([NL_CC_IS_CLANG],
237            [/* Note: Clang 2.7 lacks __clang_[a-z]+__ */
238#            if defined(__clang__) && defined(__llvm__)
239             NL_CC_IS_CLANG
240#            endif
241            ],
242            [nl_cv_clang=yes])
243    fi
244    ])
245
246if test "${nl_cv_clang}" = "yes"; then
247    PROSPECTIVE_CFLAGS="${PROSPECTIVE_CFLAGS} -Wconversion -Wno-gnu-zero-variadic-macro-arguments"
248    PROSPECTIVE_CXXFLAGS="${PROSPECTIVE_CXXFLAGS} -Wconversion"
249fi
250
251convert_warning_flags_to_positive() {
252    flags_to_check=""
253    warning_flag_backup=""
254    for option in ${1}; do
255        case "$option"
256        in
257           -Wno-*)
258                flags_to_check="${flags_to_check} -W${option##-Wno-}"
259                warning_flag_backup="${warning_flag_backup} ${option##-Wno-}";;
260            *)
261                flags_to_check="${flags_to_check} ${option}";;
262        esac
263    done
264}
265
266restore_negative_form_of_warning_flags() {
267    final_flags=${1}
268    for positive_option in ${warning_flag_backup}; do
269        final_flags=$(echo $ECHO_N $final_flags | $SED "s|-W${positive_option}|-Wno-${positive_option}|g")
270    done
271    unset flags_to_check
272    unset warning_flag_backup
273}
274
275check_prospective_CFLAGS() {
276    if test "${nl_cv_clang}" = "yes"; then
277        AX_CHECK_COMPILER_OPTIONS([C], ${PROSPECTIVE_CFLAGS})
278    else
279        convert_warning_flags_to_positive "${PROSPECTIVE_CFLAGS}"
280        AX_CHECK_COMPILER_OPTIONS([C], ${flags_to_check})
281        restore_negative_form_of_warning_flags "${CFLAGS}"
282        CFLAGS=${final_flags}
283        unset final_flags
284    fi
285}
286
287check_prospective_CXXFLAGS() {
288    if test "${nl_cv_clang}" = "yes"; then
289        AX_CHECK_COMPILER_OPTIONS([C++], ${PROSPECTIVE_CXXFLAGS})
290    else
291        convert_warning_flags_to_positive "${PROSPECTIVE_CXXFLAGS}"
292        AX_CHECK_COMPILER_OPTIONS([C++], ${flags_to_check})
293        restore_negative_form_of_warning_flags "${CXXFLAGS}"
294        CXXFLAGS=${final_flags}
295        unset final_flags
296    fi
297}
298
299check_prospective_CFLAGS
300check_prospective_CXXFLAGS
301
302# Disable building shared libraries by default (can be enabled with --enable-shared)
303
304AC_DISABLE_SHARED
305
306#
307# Debug instances
308#
309AC_MSG_NOTICE([checking whether to build debug instances])
310
311# Debug
312
313NL_ENABLE_DEBUG([no])
314
315AM_CONDITIONAL([OPENTHREAD_BUILD_DEBUG], [test "${nl_cv_build_debug}" = "yes"])
316
317#
318# Code coverage and compiler optimization
319#
320
321# Coverage
322
323NL_ENABLE_COVERAGE([no])
324
325AM_CONDITIONAL([OPENTHREAD_BUILD_COVERAGE], [test "${nl_cv_build_coverage}" = "yes"])
326
327NL_ENABLE_COVERAGE_REPORTS([auto])
328
329AM_CONDITIONAL([OPENTHREAD_BUILD_COVERAGE_REPORTS], [test "${nl_cv_build_coverage_reports}" = "yes"])
330
331# Optimization
332
333NL_ENABLE_OPTIMIZATION([yes])
334
335AM_CONDITIONAL([OPENTHREAD_BUILD_OPTIMIZED], [test "${nl_cv_build_optimized}" = "yes"])
336
337# Fuzz Targets
338
339AC_MSG_CHECKING([whether to build fuzz targets])
340AC_ARG_ENABLE(fuzz-targets,
341    [AS_HELP_STRING([--enable-fuzz-targets],[Enable building of fuzz targets @<:@default=no@:>@.])],
342    [
343        case "${enableval}" in
344
345        no|yes)
346            enable_fuzz_targets=${enableval}
347            ;;
348
349        *)
350            AC_MSG_ERROR([Invalid value ${enableval} for --enable-fuzz-targets])
351            ;;
352
353        esac
354    ],
355    [enable_fuzz_targets=no])
356AC_MSG_RESULT(${enable_fuzz_targets})
357
358AM_CONDITIONAL([OPENTHREAD_ENABLE_FUZZ_TARGETS], [test "${enable_fuzz_targets}" = "yes"])
359
360if test "${enable_fuzz_targets}" = "no" ; then
361    PROSPECTIVE_CXXFLAGS="-fno-rtti"
362    check_prospective_CXXFLAGS
363fi
364
365# Address Sanitizer
366
367AC_MSG_CHECKING([whether to build with Address Sanitizer support])
368AC_ARG_ENABLE(address-sanitizer,
369    [AS_HELP_STRING([--enable-address-sanitizer],[Enable Address Sanitizer support @<:@default=no@:>@.])],
370    [
371        case "${enableval}" in
372
373        no|yes)
374            enable_address_sanitizer=${enableval}
375            ;;
376
377        *)
378            AC_MSG_ERROR([Invalid value ${enableval} for --enable-address-sanitizer])
379            ;;
380
381        esac
382    ],
383    [enable_address_sanitizer=no])
384AC_MSG_RESULT(${enable_address_sanitizer})
385
386AM_CONDITIONAL([OPENTHREAD_WITH_ADDRESS_SANITIZER], [test "${enable_address_sanitizer}" = "yes"])
387
388if test "${enable_address_sanitizer}" = "yes" ; then
389
390    PROSPECTIVE_CFLAGS="-fsanitize=address"
391    PROSPECTIVE_CXXFLAGS="-fsanitize=address"
392
393    # Check if the compilers support address sanitizer
394    check_prospective_CFLAGS
395    check_prospective_CXXFLAGS
396fi
397
398#
399# Tests
400#
401AC_MSG_NOTICE([checking whether to build tests])
402
403NL_ENABLE_TESTS([yes])
404
405AM_CONDITIONAL([OPENTHREAD_BUILD_TESTS], [test "${nl_cv_build_tests}" = "yes"])
406
407#
408# Builtin mbedtls
409#
410
411AC_ARG_ENABLE(builtin-mbedtls,
412    [AS_HELP_STRING([--enable-builtin-mbedtls],[Enable builtin mbedtls @<:@default=yes@:>@.])],
413    [
414        case "${enableval}" in
415
416        no|yes)
417            enable_builtin_mbedtls=${enableval}
418            ;;
419
420        *)
421            AC_MSG_ERROR([Invalid value ${enable_builtin_mbedtls} for --enable-builtin-mbedtls])
422            ;;
423        esac
424    ],
425    [enable_builtin_mbedtls=yes])
426
427if test "$enable_builtin_mbedtls" = "yes" -a ! "${MBEDTLS_CPPFLAGS}"; then
428    MBEDTLS_CPPFLAGS="-I\${abs_top_srcdir}/third_party/mbedtls"
429    MBEDTLS_CPPFLAGS="${MBEDTLS_CPPFLAGS} -I\${abs_top_srcdir}/third_party/mbedtls/repo/include"
430    MBEDTLS_CPPFLAGS="${MBEDTLS_CPPFLAGS} -DMBEDTLS_CONFIG_FILE=\\\"mbedtls-config.h\\\""
431fi
432
433if test "$enable_builtin_mbedtls" = "yes"; then
434    CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS=1"
435else
436    CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS=0"
437fi
438
439AC_MSG_CHECKING([whether mbed TLS should be enabled])
440AC_MSG_RESULT(${enable_builtin_mbedtls})
441AM_CONDITIONAL([OPENTHREAD_ENABLE_BUILTIN_MBEDTLS], [test "${enable_builtin_mbedtls}" = "yes"])
442
443#
444# POSIX Daemon
445#
446
447AC_MSG_CHECKING([whether to build POSIX applicaton in daemon mode])
448AC_ARG_ENABLE(posix-daemon,
449    [AS_HELP_STRING([--enable-posix-daemon], [Build POSIX application in daemon mode@<:@default=no@:>@.])],
450    [
451        case "${enableval}" in
452
453        no|yes)
454            enable_posix_daemon=${enableval}
455            ;;
456
457        *)
458            AC_MSG_ERROR([Invalid value ${enable_posix} for --enable-posix-daemon])
459            ;;
460        esac
461    ],
462    [enable_posix_daemon=no])
463
464if test "$enable_posix_daemon" = "yes"; then
465    CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE=1"
466else
467    CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE=0"
468fi
469
470AC_MSG_RESULT(${enable_posix_daemon})
471AM_CONDITIONAL([OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE], [test "${enable_posix_daemon}" = "yes"])
472
473#
474# FTD Library
475#
476
477AC_MSG_CHECKING([whether to build FTD library])
478AC_ARG_ENABLE(ftd,
479    [AS_HELP_STRING([--enable-ftd], [Build FTD library @<:@default=no@:>@.])],
480    [
481        case "${enableval}" in
482
483        no|yes)
484            enable_ftd=${enableval}
485            ;;
486
487        *)
488            AC_MSG_ERROR([Invalid value ${enable_ftd} for --enable-ftd])
489            ;;
490        esac
491    ],
492    [enable_ftd=no])
493
494AC_MSG_RESULT(${enable_ftd})
495AM_CONDITIONAL([OPENTHREAD_ENABLE_FTD], [test "${enable_ftd}" = "yes"])
496
497#
498# MTD Library
499#
500
501AC_MSG_CHECKING([whether to build MTD library])
502AC_ARG_ENABLE(mtd,
503    [AS_HELP_STRING([--enable-mtd], [Build MTD library @<:@default=no@:>@.])],
504    [
505        case "${enableval}" in
506
507        no|yes)
508            enable_mtd=${enableval}
509            ;;
510
511        *)
512            AC_MSG_ERROR([Invalid value ${enable_mtd} for --enable-mtd])
513            ;;
514        esac
515    ],
516    [enable_mtd=no])
517
518AC_MSG_RESULT(${enable_mtd})
519AM_CONDITIONAL([OPENTHREAD_ENABLE_MTD], [test "${enable_mtd}" = "yes"])
520
521#
522# Radio Library
523#
524
525AC_MSG_CHECKING([whether to build radio-only library])
526AC_ARG_ENABLE(radio-only,
527    [AS_HELP_STRING([--enable-radio-only], [Build radio-only library @<:@default=no@:>@.])],
528    [
529        case "${enableval}" in
530
531        no|yes)
532            enable_radio_only=${enableval}
533            ;;
534
535        *)
536            AC_MSG_ERROR([Invalid value ${enable_radio_only} for --enable-radio-only])
537            ;;
538        esac
539    ],
540    [enable_radio_only=no])
541
542AC_MSG_RESULT(${enable_radio_only})
543AM_CONDITIONAL([OPENTHREAD_ENABLE_RADIO_ONLY], [test "${enable_radio_only}" = "yes"])
544
545#
546# whether to build executables
547#
548
549AC_MSG_CHECKING([whether to build executables])
550AC_ARG_ENABLE(executable,
551    [AS_HELP_STRING([--enable-executable], [Build executables @<:@default=yes@:>@.])],
552    [
553        case "${enableval}" in
554
555        no|yes)
556            enable_executable=${enableval}
557            ;;
558
559        *)
560            AC_MSG_ERROR([Invalid value ${enable_executable} for --enable-executable])
561            ;;
562        esac
563    ],
564    [enable_executable=yes])
565
566AC_MSG_RESULT(${enable_executable})
567AM_CONDITIONAL([OPENTHREAD_ENABLE_EXECUTABLE], [test "${enable_executable}" = "yes"])
568
569#
570# CLI Library
571#
572
573AC_MSG_CHECKING([whether to build CLI library])
574AC_ARG_ENABLE(cli,
575    [AS_HELP_STRING([--enable-cli], [Build CLI library @<:@default=no@:>@.])],
576    [
577        case "${enableval}" in
578
579        no|yes)
580            enable_cli=${enableval}
581            ;;
582
583        *)
584            AC_MSG_ERROR([Invalid value ${enable_cli} for --enable-cli])
585            ;;
586        esac
587    ],
588    [enable_cli=no])
589
590AC_MSG_RESULT(${enable_cli})
591AM_CONDITIONAL([OPENTHREAD_ENABLE_CLI], [test "${enable_cli}" = "yes"])
592
593#
594# NCP Library
595#
596
597AC_MSG_CHECKING([whether to build NCP library])
598AC_ARG_ENABLE(ncp,
599    [AS_HELP_STRING([--enable-ncp], [Build NCP library @<:@default=no@:>@.])],
600    [
601        case "${enableval}" in
602
603        no|yes)
604            enable_ncp=${enableval}
605            ;;
606
607        *)
608            AC_MSG_ERROR([Invalid value ${enable_ncp} for --enable-ncp])
609            ;;
610        esac
611    ],
612    [enable_ncp=no])
613
614AC_MSG_RESULT(${enable_ncp})
615AM_CONDITIONAL([OPENTHREAD_ENABLE_NCP], [test "${enable_ncp}" = "yes"])
616
617#
618# Udev - udev library to use for POSIX NCP
619#
620
621AC_ARG_WITH([udev],
622    AS_HELP_STRING([--with-udev], [Use udev library for monitoring tty events]))
623
624AS_IF([test "x$with_udev" = "xyes"], [
625    AC_CHECK_LIB([udev], [udev_new])
626    AC_CHECK_HEADER([libudev.h])
627])
628
629AS_IF([test "x$ac_cv_lib_udev_udev_new" == "xno" || test "x$ac_cv_header_libudev_h" == "xno"],
630    [AC_MSG_ERROR([--with-udev was given, but test for udev failed])])
631
632#
633# Readline - readline library to use for POSIX CLI
634#
635
636AC_ARG_WITH(
637    [readline],
638    [AS_HELP_STRING([--with-readline],[Specify the readline library (no|readline|edit) @<:@default=no@:>@.])],
639    [],
640    [with_readline=no])
641
642case "${with_readline}" in
643"no")
644    ;;
645"readline")
646    # Prefer GNU readline installed by Homebrew.
647    if test "${OPENTHREAD_TARGET}" = darwin && brew --prefix readline > /dev/null; then
648        LDFLAGS="-L$(brew --prefix readline)/lib ${LDFLAGS}"
649        CPPFLAGS="-I$(brew --prefix readline)/include ${CPPFLAGS}"
650        PKG_CONFIG_PATH="$(brew --prefix)/lib/pkgconfig:$PKG_CONFIG_PATH"
651    fi
652    AC_CHECK_LIB([readline], [rl_callback_handler_install])
653    ;;
654"edit")
655    AC_CHECK_LIB([edit], [rl_callback_handler_install])
656    ;;
657*)
658    AC_MSG_ERROR([unexpected --with-readline=${with_readline}])
659    ;;
660esac
661
662#
663# Vendor Extension - Specify a C++ source file which will be built as part of OpenThread core library.
664#
665
666AC_ARG_WITH(
667    [vendor-extension],
668    [AS_HELP_STRING([--with-vendor-extension=<VENDOR_EXT.CPP>],[Specify a C++ source file built as part of OpenThread core library. @<:@default=no@:>@.])],
669    [
670        if test "${withval}" = "no"
671        then OPENTHREAD_ENABLE_VENDOR_EXTENSION=0
672        elif test '!' -f "${withval}"
673        then AC_MSG_ERROR([Can't open ${withval} for --with-vendor-extension])
674        else
675            OPENTHREAD_ENABLE_VENDOR_EXTENSION=1
676
677            # Get the absolute path.
678            OPENTHREAD_VENDOR_EXTENSION_SOURCE=$(cd `dirname ${withval}` && pwd)/$(basename ${withval})
679        fi
680    ],
681    [
682        OPENTHREAD_ENABLE_VENDOR_EXTENSION=0
683        with_vendor_extension=no
684    ])
685
686CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_ENABLE_VENDOR_EXTENSION=${OPENTHREAD_ENABLE_VENDOR_EXTENSION}"
687AC_MSG_CHECKING([for vendor extension])
688AC_MSG_RESULT(${OPENTHREAD_VENDOR_EXTENSION_SOURCE-no})
689AC_SUBST(OPENTHREAD_VENDOR_EXTENSION_SOURCE)
690AM_CONDITIONAL([OPENTHREAD_ENABLE_VENDOR_EXTENSION], [test "${OPENTHREAD_ENABLE_VENDOR_EXTENSION}" = "1"])
691
692#
693# NCP Vendor Hook Source - Specify a C++ file that implements the NCP vendor hook.
694#
695
696AC_ARG_WITH(
697    [ncp-vendor-hook-source],
698    [AS_HELP_STRING([--with-ncp-vendor-hook-source=<VENDOR_HOOK.CPP>],[Specify a C++ file that implements the NCP vendor hook. @<:@default=no@:>@.])],
699    [
700        if test "${withval}" = "no"
701        then OPENTHREAD_ENABLE_NCP_VENDOR_HOOK=0
702        elif test '!' -f "${withval}"
703        then AC_MSG_ERROR([Can't open ${withval} for --with-ncp-vendor-hook-source])
704        else
705            OPENTHREAD_ENABLE_NCP_VENDOR_HOOK=1
706            CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_ENABLE_NCP_VENDOR_HOOK=1"
707
708            # Get the absolute path.
709            OPENTHREAD_NCP_VENDOR_HOOK_SOURCE=$(cd `dirname ${withval}` && pwd)/$(basename ${withval})
710        fi
711    ],
712    [
713        OPENTHREAD_ENABLE_NCP_VENDOR_HOOK=0
714        with_ncp_vendor_hook_source=no
715    ])
716
717AC_MSG_CHECKING([for NCP vendor hook source])
718AC_MSG_RESULT(${OPENTHREAD_NCP_VENDOR_HOOK_SOURCE-no})
719AC_SUBST(OPENTHREAD_NCP_VENDOR_HOOK_SOURCE)
720AM_CONDITIONAL([OPENTHREAD_ENABLE_NCP_VENDOR_HOOK], [test "${OPENTHREAD_ENABLE_NCP_VENDOR_HOOK}" = "1"])
721
722#
723# NCP Spinel Encrypter
724#
725
726AC_ARG_WITH(
727    [ncp-spinel-encrypter-libs],
728    [AS_HELP_STRING([--with-ncp-spinel-encrypter-libs=<LIBSPINEL_ENCRYPTER.A>],[Specify library files (absolute paths) implementing the NCP Spinel Encrypter. @<:@default=no@:>@.])],
729    [
730        if test "${withval}" = "no"
731        then OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER=0
732        else
733            OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER=1
734            OPENTHREAD_NCP_SPINEL_ENCRYPTER_LIBS=${withval}
735        fi
736    ],
737    [
738        OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER=0
739        with_ncp_spinel_encrypter_libs=no
740    ])
741
742CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER=${OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER}"
743AC_MSG_CHECKING([for NCP Spinel Encrypter])
744AC_MSG_RESULT(${OPENTHREAD_NCP_SPINEL_ENCRYPTER_LIBS-no})
745AC_SUBST(OPENTHREAD_NCP_SPINEL_ENCRYPTER_LIBS)
746AM_CONDITIONAL([OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER], [test "${OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER}" = "1"])
747
748#
749# Linker Map Output
750#
751
752AC_ARG_ENABLE(linker-map,
753    [AS_HELP_STRING([--enable-linker-map],[Enable linker map output @<:@default=no@:>@.])],
754    [
755        case "${enableval}" in
756
757        no|yes)
758            enable_linker_map=${enableval}
759            ;;
760
761        *)
762            AC_MSG_ERROR([Invalid value ${enable_linker_map} for --enable-linker-map])
763            ;;
764        esac
765    ],
766    [enable_linker_map=no])
767
768AC_MSG_CHECKING([whether to enable linker map output])
769AC_MSG_RESULT(${enable_linker_map})
770AM_CONDITIONAL([OPENTHREAD_ENABLE_LINKER_MAP], [test "${enable_linker_map}" = "yes"])
771
772#
773# Custom linker file
774#
775
776AC_ARG_WITH(
777    [custom-linker-file],
778    [AS_HELP_STRING([--with-custom-linker-file=<linkerfile.ld>],[Specify custom linker file (absolute path). @<:@default=no@:>@.])],
779    [
780        with_custom_linker_file=yes
781        OPENTHREAD_CUSTOM_LINKER_FILE=${withval}
782    ],
783    [
784        with_custom_linker_file=no
785    ])
786
787AC_SUBST(OPENTHREAD_CUSTOM_LINKER_FILE)
788AM_CONDITIONAL([OPENTHREAD_ENABLE_CUSTOM_LINKER_FILE], [test "${with_custom_linker_file}" = "yes"])
789
790#
791# Examples
792#
793
794AC_MSG_CHECKING([whether to build examples])
795
796AC_ARG_WITH(examples,
797    [AS_HELP_STRING([--with-examples=TARGET],
798        [Build example applications for one of: simulation, cc2538 @<:@default=no@:>@.
799         Note that building example applications also builds the associated OpenThread platform libraries
800         and any third_party libraries needed to support the examples.])],
801    [
802        case "${with_examples}" in
803        no)
804            ;;
805        simulation|cc2538)
806            ;;
807        *)
808            AC_MSG_RESULT(ERROR)
809            AC_MSG_ERROR([Invalid value given for --with-examples: ${with_examples}])
810            ;;
811        esac
812    ],
813    [with_examples=no])
814
815AM_CONDITIONAL([OPENTHREAD_ENABLE_EXAMPLES], [test ${with_examples} != "no"])
816
817AM_CONDITIONAL([OPENTHREAD_EXAMPLES_SIMULATION],[test "${with_examples}" = "simulation"])
818AM_CONDITIONAL([OPENTHREAD_EXAMPLES_CC2538],    [test "${with_examples}" = "cc2538"])
819
820AM_COND_IF([OPENTHREAD_EXAMPLES_SIMULATION], CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_EXAMPLES_SIMULATION=1", CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_EXAMPLES_SIMULATION=0")
821
822case ${with_examples} in
823    no)
824        AC_MSG_RESULT([no])
825        ;;
826    *)
827        AC_MSG_RESULT([yes (${with_examples})])
828        ;;
829esac
830
831#
832# Platform
833#
834
835AC_MSG_CHECKING([whether to build platform libraries])
836
837AC_ARG_WITH(platform,
838    [AS_HELP_STRING([--with-platform=TARGET],
839        [Build OpenThread platform libraries for one of: cc2538, posix, simulation @<:@default=simulation@:>@.])],
840    [
841        # Make sure the given target is valid.
842        case "${with_platform}" in
843        no|cc2538|posix|simulation)
844            ;;
845        *)
846            AC_MSG_RESULT(ERROR)
847            AC_MSG_ERROR([Invalid value given for --with-platform: ${with_platform}])
848            ;;
849        esac
850
851        # If both --with-platform and --with-examples are specified, make sure the targets match.
852        case "${with_examples}" in
853        no)
854            ;;
855        ${with_platform})
856            ;;
857        *)
858            AC_MSG_RESULT(ERROR)
859            AC_MSG_ERROR([Invalid value given for --with-platform: The targets for --with-examples and --with-platform must match.])
860            ;;
861        esac
862
863    ],
864    [
865        # If --with-platform is NOT specified, but --with-examples is, automatically build the
866        # corresponding platform libraries. (Essentially, --with-examples implies --with-platform).
867        with_platform=${with_examples}
868    ])
869
870AM_CONDITIONAL([OPENTHREAD_ENABLE_PLATFORM], [test ${with_platform} != "no"])
871
872OPENTHREAD_ENABLE_PLATFORM=${with_platform}
873
874AM_CONDITIONAL([OPENTHREAD_PLATFORM_CC2538],    [test "${with_platform}" = "cc2538"])
875AM_CONDITIONAL([OPENTHREAD_PLATFORM_POSIX],     [test "${with_platform}" = "posix"])
876AM_CONDITIONAL([OPENTHREAD_PLATFORM_SIMULATION],[test "${with_platform}" = "simulation"])
877
878AM_COND_IF([OPENTHREAD_PLATFORM_POSIX], CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_PLATFORM_POSIX=1", CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_PLATFORM_POSIX=0")
879
880case ${with_platform} in
881    no)
882        AC_MSG_RESULT([no])
883        ;;
884    *)
885        AC_MSG_RESULT([yes (${with_platform})])
886        ;;
887esac
888
889#
890# Tools
891#
892
893AC_MSG_CHECKING([whether to build tools])
894AC_ARG_ENABLE(tools,
895    [AS_HELP_STRING([--disable-tools],[Disable building of tools @<:@default=no@:>@.])],
896    [
897        case "${enableval}" in
898
899        no|yes)
900            build_tools=${enableval}
901            ;;
902
903        *)
904            AC_MSG_ERROR([Invalid value ${enableval} for --enable-tools])
905            ;;
906
907        esac
908    ],
909    [build_tools=yes])
910AC_MSG_RESULT(${build_tools})
911AM_CONDITIONAL([OPENTHREAD_BUILD_TOOLS], [test "${build_tools}" = "yes"])
912
913#
914# Documentation
915#
916
917# Determine whether or not documentation (via Doxygen) should be built
918# or not, with 'auto' as the default and establish a default support
919# value for GraphViz 'dot' support.
920
921NL_ENABLE_DOCS([auto],[NO])
922
923AM_CONDITIONAL(OPENTHREAD_BUILD_DOCS, [test "${nl_cv_build_docs}" = "yes"])
924
925AM_CONDITIONAL(OPENTHREAD_POSIX, [test "${with_platform}" = "posix" -o "${with_examples}" = "simulation"])
926
927AM_CONDITIONAL([OPENTHREAD_ENABLE_SPINEL_RCP], [test OPENTHREAD_PLATFORM_POSIX || test OPENTHREAD_ENABLE_RADIO_ONLY])
928
929#
930# Checks for libraries and packages.
931#
932# At minimum, the following packages are optional, depending on
933# configuration:
934#
935#   * TBD
936#
937AC_MSG_NOTICE([checking required package dependencies])
938
939# NL_WITH_PACKAGE(...)
940
941#
942# Check for headers
943#
944
945OLD_CFLAGS="${CFLAGS}"
946CFLAGS="${CFLAGS} -Wno-error=address"
947AC_HEADER_STDBOOL
948CFLAGS="${OLD_CFLAGS}"
949AC_HEADER_STDC
950
951AC_CHECK_HEADERS([stdint.h])
952AC_CHECK_HEADERS([string.h])
953
954#
955# Check for types and structures
956#
957AC_TYPE_INT8_T
958AC_TYPE_INT16_T
959AC_TYPE_INT32_T
960AC_TYPE_INT64_T
961AC_TYPE_UINT8_T
962AC_TYPE_UINT16_T
963AC_TYPE_UINT32_T
964AC_TYPE_UINT64_T
965
966#
967# Checks for library functions
968#
969
970if test "${ac_no_link}" != "yes"; then
971    AC_CHECK_FUNCS([memcpy])
972fi
973
974# Add any mbedtls CPPFLAGS
975
976CPPFLAGS="${CPPFLAGS} ${MBEDTLS_CPPFLAGS}"
977
978# Add any code coverage CPPFLAGS and LDFLAGS
979
980CPPFLAGS="${CPPFLAGS} ${NL_COVERAGE_CPPFLAGS}"
981LIBS="${LIBS} ${NL_COVERAGE_LIBS}"
982LDFLAGS="${LDFLAGS} ${NL_COVERAGE_LDFLAGS}"
983
984# At this point, we can restore the compiler flags to whatever the
985# user passed in, now that we're clear of an -Werror issues by
986# transforming -Wno-error back to -Werror.
987
988NL_RESTORE_WERROR
989
990#
991# Identify the various makefiles and auto-generated files for the package
992#
993AC_CONFIG_FILES([
994Makefile
995include/Makefile
996src/Makefile
997src/cli/Makefile
998src/ncp/Makefile
999src/core/Makefile
1000src/posix/Makefile
1001src/posix/platform/Makefile
1002src/lib/Makefile
1003src/lib/hdlc/Makefile
1004src/lib/platform/Makefile
1005src/lib/spinel/Makefile
1006src/lib/url/Makefile
1007third_party/Makefile
1008third_party/jlink/Makefile
1009third_party/mbedtls/Makefile
1010third_party/tcplp/Makefile
1011examples/Makefile
1012examples/apps/Makefile
1013examples/apps/cli/Makefile
1014examples/apps/ncp/Makefile
1015examples/platforms/Makefile
1016examples/platforms/cc2538/Makefile
1017examples/platforms/simulation/Makefile
1018examples/platforms/utils/Makefile
1019tools/Makefile
1020tools/harness-automation/Makefile
1021tools/harness-thci/Makefile
1022tools/spi-hdlc-adapter/Makefile
1023tests/Makefile
1024tests/fuzz/Makefile
1025tests/scripts/Makefile
1026tests/scripts/thread-cert/Makefile
1027tests/unit/Makefile
1028doc/Makefile
1029])
1030
1031#
1032# Generate the auto-generated files for the package
1033#
1034AC_OUTPUT
1035
1036#
1037# Summarize the package configuration
1038#
1039
1040AC_MSG_NOTICE([
1041
1042  Configuration Summary
1043  ---------------------
1044  Package                                   : ${PACKAGE_NAME}
1045  Version                                   : ${PACKAGE_VERSION}
1046  Interface                                 : $(echo $LIBOPENTHREAD_VERSION_INFO | $SED 's/:/./g')
1047  Build system                              : ${build}
1048  Host system                               : ${host}
1049  Host architecture                         : ${host_cpu}
1050  Host OS                                   : ${host_os}
1051  Cross compiling                           : ${cross_compiling}
1052  Build shared libraries                    : ${enable_shared}
1053  Build static libraries                    : ${enable_static}
1054  Build debug libraries                     : ${nl_cv_build_debug}
1055  Build optimized libraries                 : ${nl_cv_build_optimized}
1056  Build coverage libraries                  : ${nl_cv_build_coverage}
1057  Build coverage reports                    : ${nl_cv_build_coverage_reports}
1058  Address sanitizer support                 : ${enable_address_sanitizer}
1059  Lcov                                      : ${LCOV:--}
1060  Genhtml                                   : ${GENHTML:--}
1061  Build tests                               : ${nl_cv_build_tests}
1062  Build fuzz targets                        : ${enable_fuzz_targets}
1063  Build tools                               : ${build_tools}
1064  OpenThread tests                          : ${with_tests}
1065  Prefix                                    : ${prefix}
1066  Documentation support                     : ${nl_cv_build_docs}
1067  Doxygen                                   : ${DOXYGEN:--}
1068  GraphViz dot                              : ${DOT:--}
1069  C Preprocessor                            : ${CPP}
1070  C Compiler                                : ${CC}
1071  C++ Preprocessor                          : ${CXXCPP}
1072  C++ Compiler                              : ${CXX}
1073  Assembler Compiler                        : ${CCAS}
1074  Archiver                                  : ${AR}
1075  Archive Indexer                           : ${RANLIB}
1076  Symbol Stripper                           : ${STRIP}
1077  Object Copier                             : ${OBJCOPY}
1078  C Preprocessor flags                      : ${CPPFLAGS:--}
1079  C Compile flags                           : ${CFLAGS:--}
1080  C++ Compile flags                         : ${CXXFLAGS:--}
1081  Assembler flags                           : ${CCASFLAGS:--}
1082  Link flags                                : ${LDFLAGS:--}
1083  Link libraries                            : ${LIBS}
1084  Link maps                                 : ${enable_linker_map}
1085  OpenThread FTD support                    : ${enable_ftd}
1086  OpenThread MTD support                    : ${enable_mtd}
1087  OpenThread Radio Only support             : ${enable_radio_only}
1088  OpenThread CLI support                    : ${enable_cli}
1089  OpenThread NCP support                    : ${enable_ncp}
1090  OpenThread NCP Vendor Hook Source         : ${with_ncp_vendor_hook_source}
1091  OpenThread NCP Spinel Encrypter           : ${with_ncp_spinel_encrypter_libs}
1092  OpenThread Vendor Extension Source        : ${with_vendor_extension}
1093  OpenThread builtin mbedtls support        : ${enable_builtin_mbedtls}
1094  OpenThread Examples                       : ${with_examples}
1095  OpenThread Platform Libraries             : ${with_platform}
1096
1097])
1098