1dnl Copyright 2011 Google Inc.
2dnl All rights reserved.
3dnl
4dnl Redistribution and use in source and binary forms, with or without
5dnl modification, are permitted provided that the following conditions are
6dnl met:
7dnl
8dnl * Redistributions of source code must retain the above copyright
9dnl   notice, this list of conditions and the following disclaimer.
10dnl * Redistributions in binary form must reproduce the above copyright
11dnl   notice, this list of conditions and the following disclaimer in the
12dnl   documentation and/or other materials provided with the distribution.
13dnl * Neither the name of Google Inc. nor the names of its contributors
14dnl   may be used to endorse or promote products derived from this software
15dnl   without specific prior written permission.
16dnl
17dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29dnl ATF_ARG_WITH
30dnl
31dnl Adds a --with-atf flag to the configure script that allows the user to
32dnl enable or disable atf support.
33dnl
34dnl The ATF_CHECK_{C,CXX,SH} macros honor the flag defined herein if
35dnl instantiated.  If not instantiated, they will request the presence of
36dnl the libraries unconditionally.
37dnl
38dnl Defines the WITH_ATF Automake conditional if ATF has been found by any
39dnl of the ATF_CHECK_{C,CXX,SH} macros.
40AC_DEFUN([ATF_ARG_WITH], [
41    m4_define([atf_arg_with_called], [yes])
42
43    m4_divert_text([DEFAULTS], [with_atf=auto])
44    AC_ARG_WITH([atf],
45                [AS_HELP_STRING([--with-atf=<yes|no|auto>],
46                                [build atf-based test programs])],
47                [with_atf=${withval}], [with_atf=auto])
48
49    m4_divert_text([DEFAULTS], [
50        found_atf_c=no
51        found_atf_cxx=no
52        found_atf_sh=no
53    ])
54    AM_CONDITIONAL([WITH_ATF], [test x"${found_atf_c}" = x"yes" -o \
55                                     x"${found_atf_cxx}" = x"yes" -o \
56                                     x"${found_atf_sh}" = x"yes"])
57])
58
59dnl _ATF_CHECK_ARG_WITH(check, error_message)
60dnl
61dnl Internal macro to execute a check conditional on the --with-atf flag
62dnl and handle the result accordingly.
63dnl
64dnl 'check' specifies the piece of code to be run to detect the feature.
65dnl This code must set the 'found' shell variable to yes or no depending
66dnl on the raw result of the check.
67AC_DEFUN([_ATF_CHECK_ARG_WITH], [
68    m4_ifdef([atf_arg_with_called], [
69        m4_fatal([ATF_ARG_WITH must be called after the ATF_CHECK_* checks])
70    ])
71
72    m4_divert_text([DEFAULTS], [with_atf=yes])
73
74    if test x"${with_atf}" = x"no"; then
75        _found=no
76    else
77        $1
78        if test x"${with_atf}" = x"auto"; then
79            _found="${found}"
80        else
81            if test x"${found}" = x"yes"; then
82                _found=yes
83            else
84                AC_MSG_ERROR([$2])
85            fi
86        fi
87    fi
88])
89