source: trunk/build_support/yat.m4 @ 1412

Last change on this file since 1412 was 1412, checked in by Peter, 15 years ago

yat autoconf macro
For details on the macro see header in file.

In the description (refs #283) test was suggested to include tests for
secondary libraries such as GSL. I haven't done that explicitely, but
in the compilation test, I chose to include Vector.h because it uses
both GSL and Boost. The linking requirements are also checked in an
indirect fashion, because if the yat-config file is not manipulated it
should give ldflags to all the required libs such as -lm, which
implies failure if they are not present.

If anyone wants more detailed tests on these packages, I think one
should use macro provided from these projects.

Should describe this and yat-config in README before closing this ticket.

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