source: trunk/m4/yat.m4 @ 1809

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

updating copyright statements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 8.8 KB
Line 
1## $Id: yat.m4 1797 2009-02-12 18:07:10Z 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 18:07:10 +0000 (Thu, 12 Feb 2009) $
82#
83# COPYLEFT
84#
85#   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
86#   Copyright (C) 2009 Peter Johansson
87#
88#   This file is part of the yat library, http://dev.thep.lu.se/yat
89#
90#   The yat library is free software; you can redistribute it and/or
91#   modify it under the terms of the GNU General Public License as
92#   published by the Free Software Foundation; either version 3 of the
93#   License, or (at your option) any later version.
94#
95#   The yat library is distributed in the hope that it will be useful,
96#   but WITHOUT ANY WARRANTY; without even the implied warranty of
97#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
98#   General Public License for more details.
99#
100#   You should have received a copy of the GNU General Public License
101#   along with yat. If not, see <http://www.gnu.org/licenses/>.
102#
103
104#
105# serial 1  # version number of yat.m4
106#
107# see http://www.gnu.org/software/automake/manual/automake.html#Serials
108
109AC_DEFUN([YAT_CHECK_YAT],
110[
111ac_yat_check_yat_res="yes"
112AC_REQUIRE([YAT_FIND_YAT])  dnl
113YAT_CHECK_VERSION([$1],,[ac_yat_check_yat_res="no"])
114YAT_CHECK_HEADER(,[ac_yat_check_yat_res="no"])
115YAT_CHECK_LIB(,[ac_yat_check_yat_res="no"])
116# ACTION
117if test "$ac_yat_check_yat_res" != "no" ; then
118  m4_default([$2], [:])
119else
120  m4_default([$3], [:])
121fi 
122
123]) # YAT_CHECK_YAT
124
125
126AC_DEFUN([YAT_FIND_YAT],
127[
128  AC_ARG_WITH(yat,
129              AC_HELP_STRING([--with-yat=DIR],
130                [prefix for installed yat library or full path to yat-config]),
131    [ yat_config=no;
132      AC_MSG_NOTICE([looking for yat-config])
133      for p in $withval $withval/yat-config $withval/bin/yat-config ; do 
134        if test "$yat_config" = "no" ; then
135          AC_MSG_CHECKING([$p]);
136          if test -f "$p" && $p --help > /dev/null 2>&1 ; then
137            yat_config=$p;
138            AC_MSG_RESULT([yes]);
139          else
140            AC_MSG_RESULT([no]);
141          fi
142        fi
143      done     
144      if test "$yat_config" = "no" ; then
145        AC_MSG_WARN([
146           the --with-yat parameter is incorrect. It must
147           specify an install prefix, or a yat-config file.])
148      fi
149    ],
150    [ AC_PATH_PROG([yat_config], [yat-config], [no])
151      if test "$yat_config" = "no" ; then
152        AC_MSG_WARN([
153          the yat-config script installed by yat could not be found. If yat was
154          installed in PREFIX, make sure PREFIX/bin is in your path, or supply
155          the appropriate --with-yat option])
156      fi
157    ])
158
159  # ACTION
160  if test "$yat_config" != "no" ; then
161    m4_default([$2], [:])
162  else
163    m4_default([$3], [:])
164  fi 
165
166]) # YAT_FIND_YAT
167
168
169
170AC_DEFUN([YAT_CHECK_VERSION],
171[
172  AC_REQUIRE([YAT_FIND_YAT])  dnl
173  if test "$yat_config" != "no"; then
174    ac_yat_min_version=m4_default([$1], [0.5])
175    AC_MSG_CHECKING(if version of yat is at least $ac_yat_min_version)
176
177    if $yat_config --atleast-version=$ac_yat_min_version; then
178      AC_MSG_RESULT([yes])
179      ac_yat_version_ok=yes;
180    else
181      AC_MSG_RESULT([no])
182      ac_yat_version=`$yat_config --version`
183      AC_MSG_WARN([
184       '$yat_config --version' returned $ac_yat_version,
185        but the minimum required version is $ac_yat_min_version.])
186    fi
187  fi
188
189  # ACTION
190  if test "$ac_yat_version_ok" = "yes" ; then
191    m4_default([$2], [:])
192  else
193    m4_default([$3], [:])
194  fi 
195
196]) # YAT_CHECK_VERSION
197
198
199
200AC_DEFUN([YAT_CHECK_HEADER],
201[
202  AC_REQUIRE([YAT_FIND_YAT])  dnl
203  if test "$yat_config" != "no"; then
204    ac_yat_save_CPPFLAGS=$CPPFLAGS
205    ac_yat_save_CXXFLAGS=$CXXFLAGS
206    YAT_CPPFLAGS=`$yat_config --cppflags`
207    YAT_CXXFLAGS=`$yat_config --cxxflags`
208    CPPFLAGS="$CPPFLAGS $YAT_CPPFLAGS"
209    CXXFLAGS="$CXXFLAGS $YAT_CXXFLAGS"
210    AC_LANG_PUSH(C++)
211    # checking for Vector, which uses both GSL and Boost
212    AC_CHECK_HEADER([yat/utility/Vector.h],
213                    [ac_yat_ok="yes"],
214                    [ac_yat_ok="no"])
215   
216    # checking that version in yat-config and version.h agree
217    AC_MSG_CHECKING([version in $yat_config])
218    yat_config_version=`$yat_config --version`
219    AC_MSG_RESULT([$yat_config_version])
220    AC_MSG_CHECKING([YAT_VERSION in <yat/utility/version.h>])
221    AC_COMPILE_IFELSE(
222      [AC_LANG_PROGRAM([@%:@include <yat/utility/version.h>],
223        [ #if YAT_VERSION_AT_LEAST(`$yat_config --version-major`,\
224                                   `$yat_config --version-minor`,\
225                                   `$yat_config --version-patch`)         
226          // Versions agree
227          #else
228          # error yat versions disagree
229          #endif
230        ])
231      ],
232      [AC_MSG_RESULT([ok]);
233       ac_yat_ok="yes";
234       AC_SUBST(YAT_CPPFLAGS)
235       AC_SUBST(YAT_CXXFLAGS)
236       AC_DEFINE(HAVE_YAT,,[define if yat library is available])],
237      [AC_MSG_RESULT([incorrect]);
238       AC_MSG_WARN([
239        version declared in included yat/utility/version.h is not equal to
240        the one given from yat-config script: $yat_config.])
241       ac_yat_ok="no";
242      ])
243
244    # restore FLAGS
245    CPPFLAGS=$ac_yat_save_CPPFLAGS
246    CXXFLAGS=$ac_yat_save_CXXFLAGS
247    AC_LANG_POP(C++)
248  fi
249
250  # ACTION
251  if test "$ac_yat_ok" = "yes" ; then
252    m4_default([$1], [:])
253  else
254    m4_default([$2], [:])
255  fi 
256
257]) # YAT_CHECK_HEADER
258
259
260
261AC_DEFUN([YAT_CHECK_LIB],
262[
263  AC_REQUIRE([YAT_FIND_YAT])  dnl
264  if test "$yat_config" != "no"; then
265    ac_yat_save_LDFLAGS=$LDFLAGS
266    ac_yat_save_LIBS=$LIBS
267    YAT_LDFLAGS=`$yat_config --ldflags`
268    YAT_LIBS=`$yat_config --libs`
269    LDFLAGS="$LDFLAGS $YAT_LDFLAGS"
270    LIBS="$LIBS $YAT_LIBS"
271    AC_LANG_PUSH(C++)
272    AC_MSG_CHECKING([for utility::version(void) in yat])
273    AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <string>
274                                      namespace theplu{
275                                      namespace yat{
276                                      namespace utility {
277                                      std::string version(void);
278                                      }}}
279                                    ]],
280                                    [using namespace theplu::yat::utility;
281                                     std::string s=version();])],
282                   [ac_yat_ok="yes";
283                    AC_MSG_RESULT([yes])
284                    AC_SUBST(YAT_LDFLAGS)
285                    AC_SUBST(YAT_LIBS)
286                    YAT_LA_FILE=`$yat_config --link-libtool`;
287                    AC_SUBST(YAT_LA_FILE)],
288                   [ac_yat_ok="no";
289                    AC_MSG_RESULT([no])
290                    AC_MSG_WARN([
291           the test program failed to link (or compile). See file config.log for
292           details on what occured.])
293                   ])
294    # restore FLAGS
295    LDFLAGS=$ac_yat_save_LDFLAGS
296    LIBS=$ac_yat_save_LIBS
297    AC_LANG_POP(C++)
298  fi
299
300  # ACTION
301  if test "$ac_yat_ok" = "yes" ; then
302    m4_default([$1], [:])
303  else
304    m4_default([$2], [:])
305  fi 
306]) # YAT_CHECK_LIB
307
Note: See TracBrowser for help on using the repository browser.