source: trunk/m4/yat.m4 @ 2777

Last change on this file since 2777 was 2777, checked in by Peter, 10 years ago

typo

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