source: trunk/m4/yat_add_flag.m4 @ 1371

Last change on this file since 1371 was 1337, checked in by Peter Johansson, 11 years ago

using macros from yat to create files .release and .release_year

File size: 3.3 KB
Line 
1## $Id: yat_add_flag.m4 2202 2010-02-21 18:39:13Z 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: 2010-02-21 13:39:13 -0500 (Sun, 21 Feb 2010) $
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_PREREQ([2.63]) dnl we use AS_VAR_IF
49  AC_REQUIRE([AC_PROG_SED])
50  for yat_flag in $2; do
51    # ignore flag if
52    # 1) it is -I/usr/include
53    # 2) it is -I/usr/local/include and CXX is g++
54    # 3) it is -D* and * is already defined in $1, $CPPFLAGS, or AC_DEFINE
55    ignore=no
56    AS_CASE([$yat_flag],
57            [-I/usr/include], [ignore=yes],
58            [-I/usr/local/include],[AS_IF([test "x$CXX" = "xg++"],[ignore=yes])],
59            [-D*], [yat_def=`AS_ECHO([$yat_flag]) | $SED 's,^-D,,;s,=.*,,'`;
60                    yat_save_CPPFLAGS="$CPPFLAGS"
61                    m4_if([$1], [CPPFLAGS], [], [CPPFLAGS="$$1 $CPPFLAGS"])
62                    AC_CHECK_DECL([$yat_def],[ignore=yes])
63                    CPPFLAGS="$yat_save_CPPFLAGS"])
64
65    AS_VAR_IF([ignore], [no],
66          [YAT_FIND_STR([$1], [$yat_flag], ,
67                        [AX_CXXCPP_CHECK_FLAG([$yat_flag], ,,
68                                              [$1="$$1 $yat_flag"])])])
69  done
70]) # YAT_CPP_ADD_FLAG
71
72
73AC_DEFUN([YAT_CXX_ADD_FLAG],
74[
75  AC_PREREQ([2.61]) dnl we use AX_CXX_CHECK_FLAG
76  for yat_flag in $2; do
77    YAT_FIND_STR([$1], [$yat_flag], ,
78                 [AX_CXX_CHECK_FLAG([$yat_flag], ,, [$1="$$1 $yat_flag"])])
79  done
80]) # YAT_CXX_ADD_FLAG
81
82AC_DEFUN([YAT_LD_ADD_FLAG],
83[
84  AC_PREREQ([2.61]) dnl we use AX_LD_CHECK_FLAG
85  for yat_flag in $2; do
86    # ignore flag if
87    # 1) it is -L/usr/lib
88    # 2) it is -L/usr/local/lib and CXX is g++
89    AS_IF([test "x$yat_flag" = "x-L/usr/lib"],,
90          [test "x$CXX" = "xg++" && test "x$yat_flag" = "x-L/usr/local/lib"],,
91          [YAT_FIND_STR([$1], [$yat_flag], ,
92                        [AX_LD_CHECK_FLAG([$yat_flag], ,,
93                                          [$1="$$1 $yat_flag"])])])
94  done
95]) # YAT_LD_ADD_FLAG
96
97AC_DEFUN([YAT_FIND_STR],
98[
99  # YAT_FIND_STR
100  found=no;       
101  for a in $$1; do
102    AS_IF([test "x$a" = "x$2"],[found=yes])
103  done
104
105  # ACTION
106  AS_IF([test "$found" = "yes"], [m4_default([$3], [:])],
107        [m4_default([$4], [:])])
108
109]) # YAT_FIND_STR
110
Note: See TracBrowser for help on using the repository browser.