source: trunk/build_support/yat.m4 @ 1639

Last change on this file since 1639 was 1622, checked in by Peter, 13 years ago

prefer m4_default rather than raw m4 macro (ifelse).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 8.4 KB
Line 
1## $Id: yat.m4 1622 2008-11-11 02:56:23Z peter $
2
3# SYNOPSIS
4#
5#   YAT_CHECK_YAT([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
6#
7# DESCRIPTION
8#
9#   Test yat library of a particular version
10#
11#   This macro file can be used by applications to find and use the
12#   yat library.
13#   
14#   This macro calls:
15#   
16#     AC_SUBST(YAT_CPPFLAGS)
17#     AC_SUBST(YAT_CXXFLAGS)
18#     AC_SUBST(YAT_LDFLAGS)
19#     AC_SUBST(YAT_LIBS)
20#     AC_SUBST(YAT_LA_FILE)
21#
22#   defines:
23#
24#     HAVE_YAT
25#
26#   and sets the following variable:
27#
28#     yat_config:    If yat-config exists, $yat_config refers to it,
29#                    otherwise $yat_config is set to "no".
30#
31#
32#   YAT_CHECK_YAT is split into sub-macros:
33#
34#     YAT_FIND_YAT()
35#     YAT_CHECK_VERSION([MINIMUM-VERSION])
36#     YAT_CHECK_HEADER()
37#     YAT_CHECK_LIB()
38#
39#   so when preferable, you can call any of these instead.
40#
41#
42#   YAT_FIND_YAT([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
43#
44#     Finds the yat-config scripts. If there is no --with-yat
45#     specified, it will look in the PATH. Sets a shell variable
46#     $yat_config. $yat_config is required for the other macros and
47#     therefore if YAT_FIND_YAT has not been called, they will call
48#     YAT_FIND_YAT.
49#
50#
51#   YAT_CHECK_VERSION([MINIMUM-VERSION],[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
52#
53#     If the version of yat is at least MINIMUM-VERSION, execute
54#     ACTION-IF-FOUND, otherwise execute ACTION-IF-NOT-FOUND.
55#
56#
57#   YAT_CHECK_HEADER([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
58#
59#     If yat hearders are found and compilable, call
60#     AC_SUBST(YAT_CPPFLAGS) and AC_SUBST(YAT_CXXFLAGS), define
61#     HAVE_YAT, execute ACTION-IF-FOUND. If test compilation failed
62#     execute ACTION-IF-NOT-FOUND.
63#
64#
65#   YAT_CHECK_LIB([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
66#
67#     Compile a small program and link it to yat. On success call
68#     AC_SUBST(YAT_LDFLAGS), AC_SUBST(YAT_LIBS), and
69#     AC_SUBST(YAT_LA_FILE), and define HAVE_YAT, and execute
70#     ACTION-IF-FOUND. On failure execute ACTION-IF-NOT-FOUND.
71#
72#
73#
74# LAST MODIFICATION
75#
76#   $Date: 2008-11-11 02:56:23 +0000 (Tue, 11 Nov 2008) $
77#
78# COPYLEFT
79#
80#   Copyright (C) 2008 Peter Johansson
81#
82#   This file is part of the yat library, http://dev.thep.lu.se/yat
83#
84#   The yat library is free software; you can redistribute it and/or
85#   modify it under the terms of the GNU General Public License as
86#   published by the Free Software Foundation; either version 3 of the
87#   License, or (at your option) any later version.
88#
89#   The yat library is distributed in the hope that it will be useful,
90#   but WITHOUT ANY WARRANTY; without even the implied warranty of
91#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
92#   General Public License for more details.
93#
94#   You should have received a copy of the GNU General Public License
95#   along with yat. If not, see <http://www.gnu.org/licenses/>.
96#
97
98#
99# serial 0  # version number of yat.m4
100#
101# see http://www.gnu.org/software/automake/manual/automake.html#Serials
102
103AC_DEFUN([YAT_CHECK_YAT],
104[
105ac_yat_check_yat_res="yes"
106AC_REQUIRE([YAT_FIND_YAT])  dnl
107YAT_CHECK_VERSION([$1],,[ac_yat_check_yat_res="no"])
108YAT_CHECK_HEADER(,[ac_yat_check_yat_res="no"])
109YAT_CHECK_LIB(,[ac_yat_check_yat_res="no"])
110# ACTION
111if test "$ac_yat_check_yat_res" != "no" ; then
112  m4_default([$2], [:])
113else
114  m4_default([$3], [:])
115fi 
116
117]) # YAT_CHECK_YAT
118
119
120AC_DEFUN([YAT_FIND_YAT],
121[
122  AC_ARG_WITH(yat,
123              AC_HELP_STRING([--with-yat=DIR],
124                [prefix for installed yat library or full path to yat-config]),
125    [ yat_config=no;
126      AC_MSG_NOTICE([looking for yat-config])
127      for p in $withval $withval/yat-config $withval/bin/yat-config ; do 
128        if test "$yat_config" = "no" ; then
129          AC_MSG_CHECKING([$p]);
130          if test -f "$p" && $p --help > /dev/null 2>&1 ; then
131            yat_config=$p;
132            AC_MSG_RESULT([yes]);
133          else
134            AC_MSG_RESULT([no]);
135          fi
136        fi
137      done     
138      if test "$yat_config" = "no" ; then
139        AC_MSG_WARN(dnl
140[the --with-yat parameter is incorrect. It must
141specify an install prefix, or an yat-config file."])
142      fi
143    ],
144    [ AC_PATH_PROG([yat_config], [yat-config], [no])
145      if test "$yat_config" = "no" ; then
146        AC_MSG_WARN(dnl
147[the yat-config script installed by yat could not be found. If yat was
148 installed in PREFIX, make sure PREFIX/bin is in your path, or supply
149 the appropriate --with-yat option"])
150      fi
151    ])
152
153  # ACTION
154  if test "$yat_config" != "no" ; then
155    m4_default([$2], [:])
156  else
157    m4_default([$3], [:])
158  fi 
159
160]) # YAT_FIND_YAT
161
162
163
164AC_DEFUN([YAT_CHECK_VERSION],
165[
166  AC_REQUIRE([YAT_FIND_YAT])  dnl
167  if test "$yat_config" != "no"; then
168    ac_yat_min_version=m4_default([$1], [0.5])
169    AC_MSG_CHECKING(if version of yat is at least $ac_yat_min_version)
170
171    if $yat_config --atleast-version=$ac_yat_min_version; then
172      ac_yat_version_ok=yes;
173    else
174      ac_yat_version=`$yat_config --version`
175      AC_MSG_WARN(dnl
176['$yat_config --version' returned $ac_yat_version, but the minimum
177required version is $ac_yat_min_version."])
178      ac_yat_version_ok=no;
179    fi
180    AC_MSG_RESULT([$ac_yat_version_ok])
181  fi
182
183  # ACTION
184  if test "$ac_yat_version_ok" = "yes" ; then
185    m4_default([$2], [:])
186  else
187    m4_default([$3], [:])
188  fi 
189
190]) # YAT_CHECK_VERSION
191
192
193
194AC_DEFUN([YAT_CHECK_HEADER],
195[
196  AC_REQUIRE([YAT_FIND_YAT])  dnl
197  if test "$yat_config" != "no"; then
198    ac_yat_save_CPPFLAGS=$CPPFLAGS
199    ac_yat_save_CXXFLAGS=$CXXFLAGS
200    YAT_CPPFLAGS=`$yat_config --cppflags`
201    YAT_CXXFLAGS=`$yat_config --cxxflags`
202    CPPFLAGS="$CPPFLAGS $YAT_CPPFLAGS"
203    CXXFLAGS="$CXXFLAGS $YAT_CXXFLAGS"
204    AC_LANG_PUSH(C++)
205    # checking for Vector, which uses both GSL and Boost
206    AC_CHECK_HEADER([yat/utility/Vector.h],
207                    [ac_yat_ok="yes"],
208                    [ac_yat_ok="no"])
209   
210    # checking that version in yat-config and version.h agree
211    AC_MSG_CHECKING([version in $yat_config])
212    yat_config_version=`$yat_config --version`
213    AC_MSG_RESULT([$yat_config_version])
214    AC_MSG_CHECKING([YAT_VERSION in <yat/utility/version.h>])
215    AC_COMPILE_IFELSE(
216      [AC_LANG_PROGRAM([@%:@include <yat/utility/version.h>],
217        [ #if YAT_VERSION_AT_LEAST(`$yat_config --version-major`,\
218                                   `$yat_config --version-minor`,\
219                                   `$yat_config --version-patch`)         
220          // Versions agree
221          #else
222          # error yat versions disagree
223          #endif
224        ])
225      ],
226      [AC_MSG_RESULT([ok]);
227       ac_yat_ok="yes";
228       AC_SUBST(YAT_CPPFLAGS)
229       AC_SUBST(YAT_CXXFLAGS)
230       AC_DEFINE(HAVE_YAT,,[define if yat library is available])],
231      [AC_MSG_RESULT([incorrect]);
232       AC_MSG_WARN(dnl
233[version declared in included yat/utility/version.h is not equal to
234the one given from yat-config script: $yat_config."])
235       ac_yat_ok="no";
236      ])
237
238    # restore FLAGS
239    CPPFLAGS=$ac_yat_save_CPPFLAGS
240    CXXFLAGS=$ac_yat_save_CXXFLAGS
241    AC_LANG_POP(C++)
242  fi
243
244  # ACTION
245  if test "$ac_yat_ok" = "yes" ; then
246    m4_default([$1], [:])
247  else
248    m4_default([$2], [:])
249  fi 
250
251]) # YAT_CHECK_HEADER
252
253
254
255AC_DEFUN([YAT_CHECK_LIB],
256[
257  AC_REQUIRE([YAT_FIND_YAT])  dnl
258  if test "$yat_config" != "no"; then
259    ac_yat_save_LDFLAGS=$LDFLAGS
260    ac_yat_save_LIBS=$LIBS
261    YAT_LDFLAGS=`$yat_config --ldflags`
262    YAT_LIBS=`$yat_config --libs`
263    LDFLAGS="$LDFLAGS $YAT_LDFLAGS"
264    LIBS="$LIBS $YAT_LIBS"
265    AC_LANG_PUSH(C++)
266    AC_MSG_CHECKING([for utility::version(void) in yat])
267    AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <string>
268                                      namespace theplu{
269                                      namespace yat{
270                                      namespace utility {
271                                      std::string version(void);
272                                      }}}
273                                    ]],
274                                    [using namespace theplu::yat::utility;
275                                     std::string s=version();])],
276                   [ac_yat_ok="yes";
277                    AC_SUBST(YAT_LDFLAGS)
278                    AC_SUBST(YAT_LIBS)
279                    YAT_LA_FILE=`$yat_config --link-libtool`;
280                    AC_SUBST(YAT_LA_FILE)],
281                   [ac_yat_ok="no";
282                    AC_MSG_WARN(dnl
283[the test program failed to link (or compile). See file config.log for
284details on what occured."])
285                   ])
286    AC_MSG_RESULT([$ac_yat_ok])
287    # restore FLAGS
288    LDFLAGS=$ac_yat_save_LDFLAGS
289    LIBS=$ac_yat_save_LIBS
290    AC_LANG_POP(C++)
291  fi
292
293  # ACTION
294  if test "$ac_yat_ok" = "yes" ; then
295    m4_default([$1], [:])
296  else
297    m4_default([$2], [:])
298  fi 
299]) # YAT_CHECK_LIB
300
Note: See TracBrowser for help on using the repository browser.