2 # Copyright 2020 Project nlbuild-autotools Authors. All Rights Reserved.
3 # Copyright 2015-2016 Nest Labs Inc. All Rights Reserved.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
20 # This file defines a GNU autoconf M4-style macro that adds an
21 # --enable-optimization configuration option to the package and
22 # controls whether the package will be built with or without code
27 # NL_ENABLE_OPTIMIZATION(default)
29 # default - Whether the option should be enabled (yes) or disabled (no)
32 # Adds an --enable-optimization configuration option to the package with a
33 # default value of 'default' (should be either 'no' or 'yes') and controls
34 # whether the package will be built with or without code optimization.
36 # The value 'nl_cv_build_optimized' will be set to the result. In
37 # addition, the contents of CFLAGS, CXXFLAGS, OBJCFLAGS, and OBJCXXFLAGS may
38 # be altered by the use of this macro, converting -O<something> to -O0.
40 # NOTE: The behavior of this is influenced by nl_cv_build_coverage from
43 #------------------------------------------------------------------------------
44 AC_DEFUN([NL_ENABLE_OPTIMIZATION],
46 # Check whether or not a default value has been passed in.
51 [m4_fatal([$0: invalid default value '$1'; must be 'yes' or 'no'])])
53 AC_CACHE_CHECK([whether to build code-optimized instances of programs and libraries],
54 [nl_cv_build_optimized],
56 AC_ARG_ENABLE(optimization,
57 [AS_HELP_STRING([--enable-optimization],[Enable the generation of code-optimized instances @<:@default=$1@:>@.])],
59 case "${enableval}" in
62 nl_cv_build_optimized=${enableval}
64 if test "${nl_cv_build_coverage}" = "yes" && test "${nl_cv_build_optimized}" = "yes"; then
65 AC_MSG_ERROR([both --enable-optimization and --enable-coverage cannot used. Please, choose one or the other to enable.])
70 AC_MSG_ERROR([Invalid value ${enableval} for --enable-optimized])
76 if test "${nl_cv_build_coverage}" = "yes"; then
77 AC_MSG_WARN([--enable-coverage was specified, optimization disabled])
78 nl_cv_build_optimized=no
81 nl_cv_build_optimized=$1
87 if test "${nl_cv_build_optimized}" = "no"; then
88 CFLAGS="`echo ${CFLAGS} | sed -e 's,-O[[[:alnum:]]]*,-O0,g'`"
89 CXXFLAGS="`echo ${CXXFLAGS} | sed -e 's,-O[[[:alnum:]]]*,-O0,g'`"
90 OBJCFLAGS="`echo ${OBJCFLAGS} | sed -e 's,-O[[[:alnum:]]]*,-O0,g'`"
91 OBJCXXFLAGS="`echo ${OBJCXXFLAGS} | sed -e 's,-O[[[:alnum:]]]*,-O0,g'`"