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