source: trunk/m4/yat.m4 @ 1796

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

adding docs that yat-config and yat.m4 only works with yat 0.5 (or newer).

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