xref: /netbsd-src/external/gpl2/xcvs/dist/m4/acx_extract_cpp_defn.m4 (revision a7c918477dd5f12c1da816ba05caf44eab2d06d6)
1*a7c91847Schristos# Extract data from preprocessor output using sed expresions.
2*a7c91847Schristos
3*a7c91847Schristos# Copyright (c) 2003
4*a7c91847Schristos#               Derek R. Price, Ximbiot <http://ximbiot.com>,
5*a7c91847Schristos#               and the Free Software Foundation, Inc.
6*a7c91847Schristos
7*a7c91847Schristos# This program is free software; you can redistribute it and/or modify
8*a7c91847Schristos# it under the terms of the GNU General Public License as published by
9*a7c91847Schristos# the Free Software Foundation; either version 2, or (at your option)
10*a7c91847Schristos# any later version.
11*a7c91847Schristos
12*a7c91847Schristos# This program is distributed in the hope that it will be useful,
13*a7c91847Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*a7c91847Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*a7c91847Schristos# GNU General Public License for more details.
16*a7c91847Schristos
17*a7c91847Schristos# You should have received a copy of the GNU General Public License
18*a7c91847Schristos# along with this program; if not, write to the Free Software
19*a7c91847Schristos# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20*a7c91847Schristos# 02111-1307, USA.
21*a7c91847Schristos
22*a7c91847Schristos# ACX_EXTRACT_CPP_DEFN(VARIABLE, PROGRAM,
23*a7c91847Schristos#                      [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
24*a7c91847Schristos# -------------------------------------------
25*a7c91847Schristos# Extract single line definitions from preprocessor output.  If the
26*a7c91847Schristos# output of the C preprocessor on PROGRAM contains a definition for VARIABLE,
27*a7c91847Schristos# assign it to shell variable VARIABLE and run ACTION-IF-FOUND.  Otherwise run
28*a7c91847Schristos# ACTION-IF-NOT-FOUND.
29*a7c91847SchristosAC_DEFUN([ACX_EXTRACT_CPP_DEFN],
30*a7c91847Schristos[AC_LANG_PREPROC_REQUIRE()dnl
31*a7c91847SchristosAC_LANG_CONFTEST([AC_LANG_SOURCE([[$2]])])
32*a7c91847Schristosdnl eval is necessary to expand ac_cpp.
33*a7c91847Schristosdnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell.
34*a7c91847Schristosac_extract_cpp_result=`(eval "$ac_cpp -dM conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
35*a7c91847Schristosdnl m4 quote the argument to sed to prevent m4 from eating character classes
36*a7c91847Schristosdnl
37*a7c91847Schristosdnl C89 6.8.3 Specifies that all whitespace separation in macro definitions is
38*a7c91847Schristosdnl equivalent, so eat leading and trailing whitespace to account for
39*a7c91847Schristosdnl preprocessor quirks (commands 1.2 & 1.3 in the sed script below).
40*a7c91847Schristos  sed -n ["/^#define $1 /{
41*a7c91847Schristos            s/^#define $1 //;
42*a7c91847Schristos	    s/^ *//;
43*a7c91847Schristos	    s/ *\$//;
44*a7c91847Schristos            p;}"] 2>&AS_MESSAGE_LOG_FD`
45*a7c91847Schristosif test -n "$ac_extract_cpp_result"; then
46*a7c91847Schristos  $1=$ac_extract_cpp_result
47*a7c91847Schristosm4_ifvaln([$3], [$3])dnl
48*a7c91847Schristosm4_ifvaln([$4], [else
49*a7c91847Schristos  $4])dnl
50*a7c91847Schristosfi
51*a7c91847Schristosrm -f conftest*
52*a7c91847Schristos])# ACX_EXTRACT_CPP_DEFN
53*a7c91847Schristos
54*a7c91847Schristos
55*a7c91847Schristos
56*a7c91847Schristos# ACX_EXTRACT_HEADER_DEFN(VARIABLE, HEADER-FILE,
57*a7c91847Schristos#                    [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
58*a7c91847Schristos# ---------------------------------------------------------
59*a7c91847SchristosAC_DEFUN([ACX_EXTRACT_HEADER_DEFN],
60*a7c91847Schristos[ACX_EXTRACT_CPP_DEFN([$1],
61*a7c91847Schristos[#include <$2>
62*a7c91847Schristos], [$3], [$4])])
63