source: trunk/m4/yat_add_flag.m4 @ 2088

Last change on this file since 2088 was 2088, checked in by Peter, 14 years ago

reverting r2086. Autoconf 2.63 is now needed to bootstrap yat from svn checkout. bumping AC_PREREQ in configure.ac to reflect that. refs #570.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 3.1 KB
Line 
1## $Id: yat_add_flag.m4 2088 2009-10-21 12:03:23Z peter $
2
3# SYNOPSIS
4#
5#   YAT_CPP_ADD_FLAG([FLAGS], [FLAG])
6#
7#   YAT_CXX_ADD_FLAG([FLAGS], [FLAG])
8#
9#   YAT_LD_ADD_FLAG([FLAGS], [FLAG])
10#
11# DESCRIPTION
12#
13#   Check that FLAG is not already included in FLAGS and test that
14#   FLAG is supported by C++ compiler. If true FLAG is appended to
15#   FLAGS.
16#
17# LAST MODIFICATION
18#
19#   $Date: 2009-10-21 12:03:23 +0000 (Wed, 21 Oct 2009) $
20#
21# COPYLEFT
22#
23#   Copyright (C) 2008, 2009 Peter Johansson
24#
25#   This file is part of the yat library, http://dev.thep.lu.se/yat
26#
27#   The yat library is free software; you can redistribute it and/or
28#   modify it under the terms of the GNU General Public License as
29#   published by the Free Software Foundation; either version 3 of the
30#   License, or (at your option) any later version.
31#
32#   The yat library is distributed in the hope that it will be useful,
33#   but WITHOUT ANY WARRANTY; without even the implied warranty of
34#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
35#   General Public License for more details.
36#
37#   You should have received a copy of the GNU General Public License
38#   along with yat. If not, see <http://www.gnu.org/licenses/>.
39#
40
41#
42# serial 5 
43#
44# see http://www.gnu.org/software/automake/manual/automake.html#Serials
45
46AC_DEFUN([YAT_CPP_ADD_FLAG],
47[
48  AC_REQUIRE([AC_PROG_SED])
49  for yat_flag in $2; do
50    # ignore flag if
51    # 1) it is -I/usr/include
52    # 2) it is -I/usr/local/include and CXX is g++
53    # 3) it is -D* and * is already defined in $1, $CPPFLAGS, or AC_DEFINE
54    ignore=no
55    AS_CASE([$yat_flag],
56            [-I/usr/include], [ignore=yes],
57            [-I/usr/local/include],[AS_IF([test "x$CXX" = "xg++"],[ignore=yes])],
58            [-D*], [yat_def=`AS_ECHO([$yat_flag]) | $SED 's,^-D,,;s,=.*,,'`;
59                    yat_save_CPPFLAGS="$CPPFLAGS"
60                    m4_if([$1], [CPPFLAGS], [], [CPPFLAGS="$$1 $CPPFLAGS"])
61                    AX_C_IFDEF([$yat_def],[ignore=yes])
62                    CPPFLAGS="$yat_save_CPPFLAGS"])
63
64    AS_VAR_IF([ignore], [no],
65          [YAT_FIND_STR([$1], [$yat_flag], ,
66                        [AX_CXXCPP_CHECK_FLAG([$yat_flag], ,,
67                                              [$1="$$1 $yat_flag"])])])
68  done
69]) # YAT_CPP_ADD_FLAG
70
71
72AC_DEFUN([YAT_CXX_ADD_FLAG],
73[
74  for yat_flag in $2; do
75    YAT_FIND_STR([$1], [$yat_flag], ,
76                 [AX_CXX_CHECK_FLAG([$yat_flag], ,, [$1="$$1 $yat_flag"])])
77  done
78]) # YAT_CXX_ADD_FLAG
79
80AC_DEFUN([YAT_LD_ADD_FLAG],
81[
82  for yat_flag in $2; do
83    # ignore flag if
84    # 1) it is -L/usr/lib
85    # 2) it is -L/usr/local/lib and CXX is g++
86    AS_IF([test "x$yat_flag" = "x-L/usr/lib"],,
87          [test "x$CXX" = "xg++" && test "x$yat_flag" = "x-L/usr/local/lib"],,
88          [YAT_FIND_STR([$1], [$yat_flag], ,
89                        [AX_LD_CHECK_FLAG([$yat_flag], ,,
90                                          [$1="$$1 $yat_flag"])])])
91  done
92]) # YAT_LD_ADD_FLAG
93
94AC_DEFUN([YAT_FIND_STR],
95[
96  # YAT_FIND_STR
97  found=no;       
98  for a in $$1; do
99    AS_IF([test "x$a" = "x$2"],[found=yes])
100  done
101
102  # ACTION
103  AS_IF([test "$found" = "yes"], [m4_default([$3], [:])],
104        [m4_default([$4], [:])])
105
106]) # YAT_FIND_STR
107
Note: See TracBrowser for help on using the repository browser.