source: trunk/m4/yat.m4 @ 2021

Last change on this file since 2021 was 2021, checked in by Peter, 11 years ago

fixes #525 and #518

Added a variable YAT_LT_ADD in YAT_CHECK_LIB. Made YAT_LA_FILE also
work with old (0.5) yat-config.

fixed a bug in _YAT_ACTION so $3 is executed and not $2 when appropriate.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 9.3 KB
Line 
1## $Id: yat.m4 2021 2009-08-04 03:09:47Z 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#     AC_SUBST(YAT_LT_ADD)
27#
28#   defines:
29#
30#     HAVE_YAT
31#
32#   and sets the following variable:
33#
34#     yat_config:    If yat-config exists, $yat_config refers to it,
35#                    otherwise $yat_config is set to "no".
36#
37#
38#   YAT_CHECK_YAT is split into sub-macros:
39#
40#     YAT_FIND_YAT()
41#     YAT_CHECK_VERSION([MINIMUM-VERSION])
42#     YAT_CHECK_HEADER()
43#     YAT_CHECK_LIB()
44#
45#   so when preferable, you can call any of these instead.
46#
47#
48#   YAT_FIND_YAT([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
49#
50#     Finds the yat-config scripts. If there is no --with-yat
51#     specified, it will look in the PATH. Sets a shell variable
52#     $yat_config. $yat_config is required for the other macros and
53#     therefore if YAT_FIND_YAT has not been called, they will call
54#     YAT_FIND_YAT. If --without-yat (or equivalently --with-yat=no)
55#     is given, all tests and actions are turned off.
56#
57#
58#   YAT_CHECK_VERSION([MINIMUM-VERSION],[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
59#
60#     If the version of yat is at least MINIMUM-VERSION, execute
61#     ACTION-IF-FOUND, otherwise execute ACTION-IF-NOT-FOUND.
62#
63#
64#   YAT_CHECK_HEADER([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
65#
66#     If yat headers are found and compilable, call
67#     AC_SUBST(YAT_CPPFLAGS) and AC_SUBST(YAT_CXXFLAGS), define
68#     HAVE_YAT, execute ACTION-IF-FOUND. If test compilation failed
69#     execute ACTION-IF-NOT-FOUND.
70#
71#
72#   YAT_CHECK_LIB([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
73#
74#     Compile a small program and link it to yat. On success call
75#     AC_SUBST(YAT_LDFLAGS), AC_SUBST(YAT_LIBS), AC_SUBST(YAT_LT_ADD),
76#     and AC_SUBST(YAT_LA_FILE), and define HAVE_YAT, and execute
77#     ACTION-IF-FOUND. On failure execute ACTION-IF-NOT-FOUND.
78#
79#
80#
81# LAST MODIFICATION
82#
83#   $Date: 2009-08-04 03:09:47 +0000 (Tue, 04 Aug 2009) $
84#
85# COPYLEFT
86#
87#   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
88#   Copyright (C) 2009 Peter Johansson
89#
90#   This file is part of the yat library, http://dev.thep.lu.se/yat
91#
92#   The yat library is free software; you can redistribute it and/or
93#   modify it under the terms of the GNU General Public License as
94#   published by the Free Software Foundation; either version 3 of the
95#   License, or (at your option) any later version.
96#
97#   The yat library is distributed in the hope that it will be useful,
98#   but WITHOUT ANY WARRANTY; without even the implied warranty of
99#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
100#   General Public License for more details.
101#
102#   You should have received a copy of the GNU General Public License
103#   along with yat. If not, see <http://www.gnu.org/licenses/>.
104#
105
106#
107# serial 3  # version number of yat.m4
108#
109# see http://www.gnu.org/software/automake/manual/automake.html#Serials
110
111AC_DEFUN([YAT_CHECK_YAT],
112[
113ac_yat_check_yat_res="yes"
114AC_REQUIRE([YAT_FIND_YAT])  dnl
115YAT_CHECK_VERSION([$1],,[ac_yat_check_yat_res="no"])
116YAT_CHECK_HEADER(,[ac_yat_check_yat_res="no"])
117YAT_CHECK_LIB(,[ac_yat_check_yat_res="no"])
118
119_YAT_ACTION([test "$ac_yat_check_yat_res" != "no"],[$2],[$3])
120
121]) # YAT_CHECK_YAT
122
123
124AC_DEFUN([YAT_FIND_YAT],
125[
126  AC_ARG_WITH([yat],
127     [AC_HELP_STRING([--with-yat=DIR],
128                [prefix for installed yat library or full path to yat-config])],
129     [],
130     [with_yat=yes])
131
132  yat_config=no;
133  yat_ac_want_yat=yes;
134  AS_IF([test "x$with_yat" = "xno"],
135    [yat_ac_want_yat=no],
136    [test "x$with_yat" = "xyes"],       
137    [AC_PATH_PROG([yat_config], [yat-config], [no])
138     AS_IF([test "$yat_config" = "no"],
139       [AC_MSG_WARN([
140           the yat-config script installed by yat could not be found. If yat was
141           installed in PREFIX, make sure PREFIX/bin is in your path, or supply
142           the appropriate --with-yat option])
143       ])
144    ],
145    [AC_MSG_NOTICE([looking for yat-config])
146     for p in $with_yat $with_yat/yat-config $with_yat/bin/yat-config ; do 
147       AS_IF([test "x$yat_config" = "xno"],
148             [AC_MSG_CHECKING([$p]);
149              AS_IF([test -f "$p" && $p --help > /dev/null 2>&1],
150                    [yat_config=$p;
151                     AC_MSG_RESULT([yes]);],
152                    [AC_MSG_RESULT([no]);])
153             ])
154     done     
155     AS_IF([test "$yat_config" = "no"],
156        [AC_MSG_WARN([
157           the --with-yat parameter is incorrect. It must
158           specify an install prefix, or a yat-config file.])
159        ])
160    ])
161
162  _YAT_ACTION([test "$yat_config" != "no"],[$1],[$2])
163
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  _YAT_ACTION([test "$ac_yat_version_ok" = "yes"],[$2],[$3])
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([
233        version declared in included yat/utility/version.h is not equal to
234        the 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  _YAT_ACTION([test "$ac_yat_ok" = "yes"],[$1],[$2])
245
246]) # YAT_CHECK_HEADER
247
248
249
250AC_DEFUN([YAT_CHECK_LIB],
251[
252  AC_REQUIRE([YAT_FIND_YAT])  dnl
253  if test "$yat_config" != "no"; then
254    ac_yat_save_LDFLAGS=$LDFLAGS
255    ac_yat_save_LIBS=$LIBS
256    YAT_LDFLAGS=`$yat_config --ldflags`
257    YAT_LIBS=`$yat_config --libs`
258    LDFLAGS="$LDFLAGS $YAT_LDFLAGS"
259    LIBS="$LIBS $YAT_LIBS"
260    AC_LANG_PUSH(C++)
261    AC_MSG_CHECKING([for utility::version(void) in yat])
262    AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <string>
263                                      namespace theplu{
264                                      namespace yat{
265                                      namespace utility {
266                                      std::string version(void);
267                                      }}}
268                                    ]],
269                                    [using namespace theplu::yat::utility;
270                                     std::string s=version();])],
271                   [ac_yat_ok="yes";
272                    AC_MSG_RESULT([yes])
273                    AC_SUBST(YAT_LDFLAGS)
274                    AC_SUBST(YAT_LIBS)
275                    # be compatible with yat-config 0.5.x
276                    AS_IF([$yat_config --atleast-version=0.6],
277                          [YAT_LA_FILE=`$yat_config --link-libtool`;],
278                          [YAT_LA_FILE=`$yat_config --yat-la-file`;])
279                    AC_SUBST(YAT_LA_FILE)],
280                    YAT_LT_ADD=`$yat_config --link-libtool`
281                    AC_SUBST(YAT_LT_ADD)],
282                   [ac_yat_ok="no";
283                    AC_MSG_RESULT([no])
284                    AC_MSG_WARN([
285           the test program failed to link (or compile). See file config.log for
286           details on what occured.])
287                   ])
288    # restore FLAGS
289    LDFLAGS=$ac_yat_save_LDFLAGS
290    LIBS=$ac_yat_save_LIBS
291    AC_LANG_POP(C++)
292  fi
293
294  _YAT_ACTION([test "$ac_yat_ok" = "yes"],[$1],[$2])
295
296]) # YAT_CHECK_LIB
297
298# Private macro
299#
300# if yat_ac_want_yat = no do nothing
301# if $1 do $2 else do $3
302#
303AC_DEFUN([_YAT_ACTION],
304[
305  AS_IF([test "x$yat_ac_want_yat" = "xno"],[],
306        [$1],[m4_default([$2], [:])],
307        [m4_default([$3], [:])])
308])
Note: See TracBrowser for help on using the repository browser.