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