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# Radio Cli Library
547#
548
549AC_MSG_CHECKING([whether to build radio-cli library])
550AC_ARG_ENABLE(radio-cli,
551    [AS_HELP_STRING([--enable-radio-cli], [Build radio-cli library @<:@default=no@:>@.])],
552    [
553        case "${enableval}" in
554
555        no|yes)
556            enable_radio_cli=${enableval}
557            ;;
558
559        *)
560            AC_MSG_ERROR([Invalid value ${enable_radio_cli} for --enable-radio-cli])
561            ;;
562        esac
563    ],
564    [enable_radio_cli=no])
565
566AC_MSG_RESULT(${enable_radio_cli})
567AM_CONDITIONAL([OPENTHREAD_ENABLE_RADIO_CLI], [test "${enable_radio_cli}" = "yes"])
568
569#
570# whether to build executables
571#
572
573AC_MSG_CHECKING([whether to build executables])
574AC_ARG_ENABLE(executable,
575    [AS_HELP_STRING([--enable-executable], [Build executables @<:@default=yes@:>@.])],
576    [
577        case "${enableval}" in
578
579        no|yes)
580            enable_executable=${enableval}
581            ;;
582
583        *)
584            AC_MSG_ERROR([Invalid value ${enable_executable} for --enable-executable])
585            ;;
586        esac
587    ],
588    [enable_executable=yes])
589
590AC_MSG_RESULT(${enable_executable})
591AM_CONDITIONAL([OPENTHREAD_ENABLE_EXECUTABLE], [test "${enable_executable}" = "yes"])
592
593#
594# CLI Library
595#
596
597AC_MSG_CHECKING([whether to build CLI library])
598AC_ARG_ENABLE(cli,
599    [AS_HELP_STRING([--enable-cli], [Build CLI library @<:@default=no@:>@.])],
600    [
601        case "${enableval}" in
602
603        no|yes)
604            enable_cli=${enableval}
605            ;;
606
607        *)
608            AC_MSG_ERROR([Invalid value ${enable_cli} for --enable-cli])
609            ;;
610        esac
611    ],
612    [enable_cli=no])
613
614AC_MSG_RESULT(${enable_cli})
615AM_CONDITIONAL([OPENTHREAD_ENABLE_CLI], [test "${enable_cli}" = "yes"])
616
617#
618# NCP Library
619#
620
621AC_MSG_CHECKING([whether to build NCP library])
622AC_ARG_ENABLE(ncp,
623    [AS_HELP_STRING([--enable-ncp], [Build NCP library @<:@default=no@:>@.])],
624    [
625        case "${enableval}" in
626
627        no|yes)
628            enable_ncp=${enableval}
629            ;;
630
631        *)
632            AC_MSG_ERROR([Invalid value ${enable_ncp} for --enable-ncp])
633            ;;
634        esac
635    ],
636    [enable_ncp=no])
637
638AC_MSG_RESULT(${enable_ncp})
639AM_CONDITIONAL([OPENTHREAD_ENABLE_NCP], [test "${enable_ncp}" = "yes"])
640
641#
642# Readline - readline library to use for POSIX CLI
643#
644
645AC_ARG_WITH(
646    [readline],
647    [AS_HELP_STRING([--with-readline],[Specify the readline library (no|readline|edit) @<:@default=no@:>@.])],
648    [],
649    [with_readline=no])
650
651case "${with_readline}" in
652"no")
653    ;;
654"readline")
655    # Prefer GNU readline installed by Homebrew.
656    if test "${OPENTHREAD_TARGET}" = darwin && brew --prefix readline > /dev/null; then
657        LDFLAGS="-L$(brew --prefix readline)/lib ${LDFLAGS}"
658        CPPFLAGS="-I$(brew --prefix readline)/include ${CPPFLAGS}"
659        PKG_CONFIG_PATH="$(brew --prefix)/lib/pkgconfig:$PKG_CONFIG_PATH"
660    fi
661    AC_CHECK_LIB([readline], [rl_callback_handler_install])
662    ;;
663"edit")
664    AC_CHECK_LIB([edit], [rl_callback_handler_install])
665    ;;
666*)
667    AC_MSG_ERROR([unexpected --with-readline=${with_readline}])
668    ;;
669esac
670
671#
672# Vendor Extension - Specify a C++ source file which will be built as part of OpenThread core library.
673#
674
675AC_ARG_WITH(
676    [vendor-extension],
677    [AS_HELP_STRING([--with-vendor-extension=<VENDOR_EXT.CPP>],[Specify a C++ source file built as part of OpenThread core library. @<:@default=no@:>@.])],
678    [
679        if test "${withval}" = "no"
680        then OPENTHREAD_ENABLE_VENDOR_EXTENSION=0
681        elif test '!' -f "${withval}"
682        then AC_MSG_ERROR([Can't open ${withval} for --with-vendor-extension])
683        else
684            OPENTHREAD_ENABLE_VENDOR_EXTENSION=1
685
686            # Get the absolute path.
687            OPENTHREAD_VENDOR_EXTENSION_SOURCE=$(cd `dirname ${withval}` && pwd)/$(basename ${withval})
688        fi
689    ],
690    [
691        OPENTHREAD_ENABLE_VENDOR_EXTENSION=0
692        with_vendor_extension=no
693    ])
694
695CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_ENABLE_VENDOR_EXTENSION=${OPENTHREAD_ENABLE_VENDOR_EXTENSION}"
696AC_MSG_CHECKING([for vendor extension])
697AC_MSG_RESULT(${OPENTHREAD_VENDOR_EXTENSION_SOURCE-no})
698AC_SUBST(OPENTHREAD_VENDOR_EXTENSION_SOURCE)
699AM_CONDITIONAL([OPENTHREAD_ENABLE_VENDOR_EXTENSION], [test "${OPENTHREAD_ENABLE_VENDOR_EXTENSION}" = "1"])
700
701#
702# NCP Vendor Hook Source - Specify a C++ file that implements the NCP vendor hook.
703#
704
705AC_ARG_WITH(
706    [ncp-vendor-hook-source],
707    [AS_HELP_STRING([--with-ncp-vendor-hook-source=<VENDOR_HOOK.CPP>],[Specify a C++ file that implements the NCP vendor hook. @<:@default=no@:>@.])],
708    [
709        if test "${withval}" = "no"
710        then OPENTHREAD_ENABLE_NCP_VENDOR_HOOK=0
711        elif test '!' -f "${withval}"
712        then AC_MSG_ERROR([Can't open ${withval} for --with-ncp-vendor-hook-source])
713        else
714            OPENTHREAD_ENABLE_NCP_VENDOR_HOOK=1
715            CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_ENABLE_NCP_VENDOR_HOOK=1"
716
717            # Get the absolute path.
718            OPENTHREAD_NCP_VENDOR_HOOK_SOURCE=$(cd `dirname ${withval}` && pwd)/$(basename ${withval})
719        fi
720    ],
721    [
722        OPENTHREAD_ENABLE_NCP_VENDOR_HOOK=0
723        with_ncp_vendor_hook_source=no
724    ])
725
726AC_MSG_CHECKING([for NCP vendor hook source])
727AC_MSG_RESULT(${OPENTHREAD_NCP_VENDOR_HOOK_SOURCE-no})
728AC_SUBST(OPENTHREAD_NCP_VENDOR_HOOK_SOURCE)
729AM_CONDITIONAL([OPENTHREAD_ENABLE_NCP_VENDOR_HOOK], [test "${OPENTHREAD_ENABLE_NCP_VENDOR_HOOK}" = "1"])
730
731#
732# NCP Spinel Encrypter
733#
734
735AC_ARG_WITH(
736    [ncp-spinel-encrypter-libs],
737    [AS_HELP_STRING([--with-ncp-spinel-encrypter-libs=<LIBSPINEL_ENCRYPTER.A>],[Specify library files (absolute paths) implementing the NCP Spinel Encrypter. @<:@default=no@:>@.])],
738    [
739        if test "${withval}" = "no"
740        then OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER=0
741        else
742            OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER=1
743            OPENTHREAD_NCP_SPINEL_ENCRYPTER_LIBS=${withval}
744        fi
745    ],
746    [
747        OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER=0
748        with_ncp_spinel_encrypter_libs=no
749    ])
750
751CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER=${OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER}"
752AC_MSG_CHECKING([for NCP Spinel Encrypter])
753AC_MSG_RESULT(${OPENTHREAD_NCP_SPINEL_ENCRYPTER_LIBS-no})
754AC_SUBST(OPENTHREAD_NCP_SPINEL_ENCRYPTER_LIBS)
755AM_CONDITIONAL([OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER], [test "${OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER}" = "1"])
756
757#
758# Linker Map Output
759#
760
761AC_ARG_ENABLE(linker-map,
762    [AS_HELP_STRING([--enable-linker-map],[Enable linker map output @<:@default=no@:>@.])],
763    [
764        case "${enableval}" in
765
766        no|yes)
767            enable_linker_map=${enableval}
768            ;;
769
770        *)
771            AC_MSG_ERROR([Invalid value ${enable_linker_map} for --enable-linker-map])
772            ;;
773        esac
774    ],
775    [enable_linker_map=no])
776
777AC_MSG_CHECKING([whether to enable linker map output])
778AC_MSG_RESULT(${enable_linker_map})
779AM_CONDITIONAL([OPENTHREAD_ENABLE_LINKER_MAP], [test "${enable_linker_map}" = "yes"])
780
781#
782# Custom linker file
783#
784
785AC_ARG_WITH(
786    [custom-linker-file],
787    [AS_HELP_STRING([--with-custom-linker-file=<linkerfile.ld>],[Specify custom linker file (absolute path). @<:@default=no@:>@.])],
788    [
789        with_custom_linker_file=yes
790        OPENTHREAD_CUSTOM_LINKER_FILE=${withval}
791    ],
792    [
793        with_custom_linker_file=no
794    ])
795
796AC_SUBST(OPENTHREAD_CUSTOM_LINKER_FILE)
797AM_CONDITIONAL([OPENTHREAD_ENABLE_CUSTOM_LINKER_FILE], [test "${with_custom_linker_file}" = "yes"])
798
799#
800# Examples
801#
802
803AC_MSG_CHECKING([whether to build examples])
804
805AC_ARG_WITH(examples,
806    [AS_HELP_STRING([--with-examples=TARGET],
807        [Build example applications for one of: simulation @<:@default=no@:>@.
808         Note that building example applications also builds the associated OpenThread platform libraries
809         and any third_party libraries needed to support the examples.])],
810    [
811        case "${with_examples}" in
812        no)
813            ;;
814        simulation)
815            ;;
816        *)
817            AC_MSG_RESULT(ERROR)
818            AC_MSG_ERROR([Invalid value given for --with-examples: ${with_examples}])
819            ;;
820        esac
821    ],
822    [with_examples=no])
823
824AM_CONDITIONAL([OPENTHREAD_ENABLE_EXAMPLES], [test ${with_examples} != "no"])
825
826AM_CONDITIONAL([OPENTHREAD_EXAMPLES_SIMULATION],[test "${with_examples}" = "simulation"])
827
828AM_COND_IF([OPENTHREAD_EXAMPLES_SIMULATION], CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_EXAMPLES_SIMULATION=1", CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_EXAMPLES_SIMULATION=0")
829
830case ${with_examples} in
831    no)
832        AC_MSG_RESULT([no])
833        ;;
834    *)
835        AC_MSG_RESULT([yes (${with_examples})])
836        ;;
837esac
838
839#
840# Platform
841#
842
843AC_MSG_CHECKING([whether to build platform libraries])
844
845AC_ARG_WITH(platform,
846    [AS_HELP_STRING([--with-platform=TARGET],
847        [Build OpenThread platform libraries for one of: posix, simulation @<:@default=simulation@:>@.])],
848    [
849        # Make sure the given target is valid.
850        case "${with_platform}" in
851        no|posix|simulation)
852            ;;
853        *)
854            AC_MSG_RESULT(ERROR)
855            AC_MSG_ERROR([Invalid value given for --with-platform: ${with_platform}])
856            ;;
857        esac
858
859        # If both --with-platform and --with-examples are specified, make sure the targets match.
860        case "${with_examples}" in
861        no)
862            ;;
863        ${with_platform})
864            ;;
865        *)
866            AC_MSG_RESULT(ERROR)
867            AC_MSG_ERROR([Invalid value given for --with-platform: The targets for --with-examples and --with-platform must match.])
868            ;;
869        esac
870
871    ],
872    [
873        # If --with-platform is NOT specified, but --with-examples is, automatically build the
874        # corresponding platform libraries. (Essentially, --with-examples implies --with-platform).
875        with_platform=${with_examples}
876    ])
877
878AM_CONDITIONAL([OPENTHREAD_ENABLE_PLATFORM], [test ${with_platform} != "no"])
879
880OPENTHREAD_ENABLE_PLATFORM=${with_platform}
881
882AM_CONDITIONAL([OPENTHREAD_PLATFORM_POSIX],     [test "${with_platform}" = "posix"])
883AM_CONDITIONAL([OPENTHREAD_PLATFORM_SIMULATION],[test "${with_platform}" = "simulation"])
884
885AM_COND_IF([OPENTHREAD_PLATFORM_POSIX], CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_PLATFORM_POSIX=1", CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_PLATFORM_POSIX=0")
886
887case ${with_platform} in
888    no)
889        AC_MSG_RESULT([no])
890        ;;
891    *)
892        AC_MSG_RESULT([yes (${with_platform})])
893        ;;
894esac
895
896#
897# Tools
898#
899
900AC_MSG_CHECKING([whether to build tools])
901AC_ARG_ENABLE(tools,
902    [AS_HELP_STRING([--disable-tools],[Disable building of tools @<:@default=no@:>@.])],
903    [
904        case "${enableval}" in
905
906        no|yes)
907            build_tools=${enableval}
908            ;;
909
910        *)
911            AC_MSG_ERROR([Invalid value ${enableval} for --enable-tools])
912            ;;
913
914        esac
915    ],
916    [build_tools=yes])
917AC_MSG_RESULT(${build_tools})
918AM_CONDITIONAL([OPENTHREAD_BUILD_TOOLS], [test "${build_tools}" = "yes"])
919
920#
921# Documentation
922#
923
924# Determine whether or not documentation (via Doxygen) should be built
925# or not, with 'auto' as the default and establish a default support
926# value for GraphViz 'dot' support.
927
928NL_ENABLE_DOCS([auto],[NO])
929
930AM_CONDITIONAL(OPENTHREAD_BUILD_DOCS, [test "${nl_cv_build_docs}" = "yes"])
931
932AM_CONDITIONAL(OPENTHREAD_POSIX, [test "${with_platform}" = "posix" -o "${with_examples}" = "simulation"])
933
934AM_CONDITIONAL([OPENTHREAD_ENABLE_SPINEL_RCP], [test OPENTHREAD_PLATFORM_POSIX || test OPENTHREAD_ENABLE_RADIO_ONLY])
935
936#
937# Checks for libraries and packages.
938#
939# At minimum, the following packages are optional, depending on
940# configuration:
941#
942#   * TBD
943#
944AC_MSG_NOTICE([checking required package dependencies])
945
946# NL_WITH_PACKAGE(...)
947
948#
949# Check for headers
950#
951
952OLD_CFLAGS="${CFLAGS}"
953CFLAGS="${CFLAGS} -Wno-error=address"
954AC_HEADER_STDBOOL
955CFLAGS="${OLD_CFLAGS}"
956AC_HEADER_STDC
957
958AC_CHECK_HEADERS([stdint.h])
959AC_CHECK_HEADERS([string.h])
960
961#
962# Check for types and structures
963#
964AC_TYPE_INT8_T
965AC_TYPE_INT16_T
966AC_TYPE_INT32_T
967AC_TYPE_INT64_T
968AC_TYPE_UINT8_T
969AC_TYPE_UINT16_T
970AC_TYPE_UINT32_T
971AC_TYPE_UINT64_T
972
973#
974# Checks for library functions
975#
976
977if test "${ac_no_link}" != "yes"; then
978    AC_CHECK_FUNCS([memcpy])
979fi
980
981# Add any mbedtls CPPFLAGS
982
983CPPFLAGS="${CPPFLAGS} ${MBEDTLS_CPPFLAGS}"
984
985# Add any code coverage CPPFLAGS and LDFLAGS
986
987CPPFLAGS="${CPPFLAGS} ${NL_COVERAGE_CPPFLAGS}"
988LIBS="${LIBS} ${NL_COVERAGE_LIBS}"
989LDFLAGS="${LDFLAGS} ${NL_COVERAGE_LDFLAGS}"
990
991CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_CONFIG_FILE='\"openthread-config-generic.h\"'"
992# At this point, we can restore the compiler flags to whatever the
993# user passed in, now that we're clear of an -Werror issues by
994# transforming -Wno-error back to -Werror.
995
996NL_RESTORE_WERROR
997
998#
999# Identify the various makefiles and auto-generated files for the package
1000#
1001AC_CONFIG_FILES([
1002Makefile
1003include/Makefile
1004src/Makefile
1005src/cli/Makefile
1006src/ncp/Makefile
1007src/core/Makefile
1008src/posix/Makefile
1009src/posix/platform/Makefile
1010src/lib/Makefile
1011src/lib/hdlc/Makefile
1012src/lib/platform/Makefile
1013src/lib/spinel/Makefile
1014src/lib/url/Makefile
1015third_party/Makefile
1016third_party/jlink/Makefile
1017third_party/mbedtls/Makefile
1018third_party/tcplp/Makefile
1019examples/Makefile
1020examples/apps/Makefile
1021examples/apps/cli/Makefile
1022examples/apps/ncp/Makefile
1023examples/platforms/Makefile
1024examples/platforms/simulation/Makefile
1025examples/platforms/utils/Makefile
1026tools/Makefile
1027tools/harness-automation/Makefile
1028tools/harness-thci/Makefile
1029tools/spi-hdlc-adapter/Makefile
1030tests/Makefile
1031tests/fuzz/Makefile
1032doc/Makefile
1033])
1034
1035#
1036# Generate the auto-generated files for the package
1037#
1038AC_OUTPUT
1039
1040#
1041# Summarize the package configuration
1042#
1043
1044AC_MSG_NOTICE([
1045
1046  Configuration Summary
1047  ---------------------
1048  Package                                   : ${PACKAGE_NAME}
1049  Version                                   : ${PACKAGE_VERSION}
1050  Interface                                 : $(echo $LIBOPENTHREAD_VERSION_INFO | $SED 's/:/./g')
1051  Build system                              : ${build}
1052  Host system                               : ${host}
1053  Host architecture                         : ${host_cpu}
1054  Host OS                                   : ${host_os}
1055  Cross compiling                           : ${cross_compiling}
1056  Build shared libraries                    : ${enable_shared}
1057  Build static libraries                    : ${enable_static}
1058  Build debug libraries                     : ${nl_cv_build_debug}
1059  Build optimized libraries                 : ${nl_cv_build_optimized}
1060  Build coverage libraries                  : ${nl_cv_build_coverage}
1061  Build coverage reports                    : ${nl_cv_build_coverage_reports}
1062  Address sanitizer support                 : ${enable_address_sanitizer}
1063  Lcov                                      : ${LCOV:--}
1064  Genhtml                                   : ${GENHTML:--}
1065  Build tests                               : ${nl_cv_build_tests}
1066  Build fuzz targets                        : ${enable_fuzz_targets}
1067  Build tools                               : ${build_tools}
1068  OpenThread tests                          : ${with_tests}
1069  Prefix                                    : ${prefix}
1070  Documentation support                     : ${nl_cv_build_docs}
1071  Doxygen                                   : ${DOXYGEN:--}
1072  GraphViz dot                              : ${DOT:--}
1073  C Preprocessor                            : ${CPP}
1074  C Compiler                                : ${CC}
1075  C++ Preprocessor                          : ${CXXCPP}
1076  C++ Compiler                              : ${CXX}
1077  Assembler Compiler                        : ${CCAS}
1078  Archiver                                  : ${AR}
1079  Archive Indexer                           : ${RANLIB}
1080  Symbol Stripper                           : ${STRIP}
1081  Object Copier                             : ${OBJCOPY}
1082  C Preprocessor flags                      : ${CPPFLAGS:--}
1083  C Compile flags                           : ${CFLAGS:--}
1084  C++ Compile flags                         : ${CXXFLAGS:--}
1085  Assembler flags                           : ${CCASFLAGS:--}
1086  Link flags                                : ${LDFLAGS:--}
1087  Link libraries                            : ${LIBS}
1088  Link maps                                 : ${enable_linker_map}
1089  OpenThread FTD support                    : ${enable_ftd}
1090  OpenThread MTD support                    : ${enable_mtd}
1091  OpenThread Radio Only support             : ${enable_radio_only}
1092  OpenThread CLI support                    : ${enable_cli}
1093  OpenThread NCP support                    : ${enable_ncp}
1094  OpenThread NCP Vendor Hook Source         : ${with_ncp_vendor_hook_source}
1095  OpenThread NCP Spinel Encrypter           : ${with_ncp_spinel_encrypter_libs}
1096  OpenThread Vendor Extension Source        : ${with_vendor_extension}
1097  OpenThread builtin mbedtls support        : ${enable_builtin_mbedtls}
1098  OpenThread Examples                       : ${with_examples}
1099  OpenThread Platform Libraries             : ${with_platform}
1100
1101])
1102