source: trunk/m4/yat.m4 @ 3105

Last change on this file since 3105 was 3054, checked in by Peter, 8 years ago

fetch flags directly from yat-config as variables YAT_* might be unpopulated; barf out properly if yat-config is unavalibale; document macro. closes #757

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 12.0 KB
Line 
1## $Id: yat.m4 3054 2013-06-14 23:41:42Z peter $
2#
3# serial 9  (yat 0.11)
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#   YAT_CHECK_LIB_WITH_BAM([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
85#
86#     Test if libyat has bam support. Compile a small program using
87#     class omic::InBamFile and link it to libyat. On success execute
88#     ACTION-IF-FOUND. On failure execute ACTION-IF-NOT-FOUND. Macro
89#     requires that yat-config is available, see YAT_FIND_YAT above.
90#
91#
92# LAST MODIFICATION
93#
94#   $Date: 2013-06-14 23:41:42 +0000 (Fri, 14 Jun 2013) $
95#
96# COPYLEFT
97#
98#   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
99#   Copyright (C) 2009, 2010, 2011, 2012, 2013 Peter Johansson
100#
101#   This file is part of the yat library, http://dev.thep.lu.se/yat
102#
103#   The yat library is free software; you can redistribute it and/or
104#   modify it under the terms of the GNU General Public License as
105#   published by the Free Software Foundation; either version 3 of the
106#   License, or (at your option) any later version.
107#
108#   The yat library is distributed in the hope that it will be useful,
109#   but WITHOUT ANY WARRANTY; without even the implied warranty of
110#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
111#   General Public License for more details.
112#
113#   You should have received a copy of the GNU General Public License
114#   along with yat. If not, see <http://www.gnu.org/licenses/>.
115#
116
117AC_DEFUN([YAT_CHECK_YAT],
118[
119AC_PREREQ([2.60]) dnl we use YAT_FIND_YAT
120ac_yat_check_yat_res="yes"
121AC_REQUIRE([YAT_FIND_YAT])  dnl
122YAT_CHECK_VERSION([$1],,[ac_yat_check_yat_res="no"])
123
124AS_IF([test x$ac_yat_check_yat_res = xyes], [
125  YAT_CHECK_HEADER(,[ac_yat_check_yat_res="no"])
126])
127
128AS_IF([test x$ac_yat_check_yat_res = xyes], [
129  YAT_CHECK_LIB(,[ac_yat_check_yat_res="no"])
130])
131
132_YAT_ACTION([test "$ac_yat_check_yat_res" != "no"],[$2],[$3])
133
134]) # YAT_CHECK_YAT
135
136
137AC_DEFUN([YAT_FIND_YAT],
138[
139  AC_PREREQ([2.60]) dnl we use multi-arg AS_IF
140  AC_ARG_WITH([yat],
141     [AS_HELP_STRING([--with-yat=DIR],
142                [prefix for installed yat library or full path to yat-config])],
143     [],
144     [with_yat=yes])
145
146  yat_config=no;
147  yat_ac_want_yat=yes;
148  AS_IF([test "x$with_yat" = "xno"],
149    [yat_ac_want_yat=no],
150    [test "x$with_yat" = "xyes"],
151    [AC_PATH_PROG([yat_config], [yat-config], [no])
152     AS_IF([test "$yat_config" = "no"],
153       [AC_MSG_WARN([
154           the yat-config script installed by yat could not be found. If yat was
155           installed in PREFIX, make sure PREFIX/bin is in your path, or supply
156           the appropriate --with-yat option])
157       ])
158    ],
159    [AC_MSG_NOTICE([looking for yat-config])
160     for p in $with_yat $with_yat/yat-config $with_yat/bin/yat-config ; do
161       AS_IF([test "x$yat_config" = "xno"],
162             [AC_MSG_CHECKING([$p]);
163              AS_IF([test -f "$p" && $p --help > /dev/null 2>&1],
164                    [yat_config=$p;
165                     AC_MSG_RESULT([yes]);],
166                    [AC_MSG_RESULT([no]);])
167             ])
168     done
169     AS_IF([test "$yat_config" = "no"],
170        [AC_MSG_WARN([
171           the --with-yat parameter is incorrect. It must
172           specify an install prefix, or a yat-config file.])
173        ])
174    ])
175  _YAT_ACTION([test "$yat_config" != "no"],[$1],[$2])
176]) # YAT_FIND_YAT
177
178
179
180AC_DEFUN([YAT_CHECK_VERSION],
181[
182  AC_PREREQ([2.60]) dnl we use YAT_FIND_YAT
183  AC_REQUIRE([YAT_FIND_YAT])  dnl
184  if test "$yat_config" != "no"; then
185    m4_pushdef([yat_min_version], [m4_default([$1], [0.5])]) dnl
186    AC_MSG_CHECKING([if version of yat is at least yat_min_version])
187
188    if $yat_config --atleast-version=yat_min_version; then
189      AC_MSG_RESULT([yes])
190      ac_yat_version_ok=yes;
191    else
192      AC_MSG_RESULT([no])
193      ac_yat_version=`$yat_config --version`
194      AC_MSG_WARN([
195       '$yat_config --version' returned $ac_yat_version,
196        but the minimum required version is yat_min_version.])
197    fi
198    m4_popdef([yat_min_version]) dnl
199  fi
200  _YAT_ACTION([test "$ac_yat_version_ok" = "yes"],[$2],[$3])
201]) # YAT_CHECK_VERSION
202
203
204
205AC_DEFUN([YAT_CHECK_HEADER],
206[
207  AC_PREREQ([2.60]) dnl we use YAT_FIND_YAT
208  AC_REQUIRE([YAT_FIND_YAT])  dnl
209  if test "$yat_config" != "no"; then
210    ac_yat_save_CPPFLAGS=$CPPFLAGS
211    ac_yat_save_CXXFLAGS=$CXXFLAGS
212    YAT_CPPFLAGS=`$yat_config --cppflags`
213    YAT_CXXFLAGS=`$yat_config --cxxflags`
214    CPPFLAGS="$CPPFLAGS $YAT_CPPFLAGS"
215    CXXFLAGS="$CXXFLAGS $YAT_CXXFLAGS"
216    AC_LANG_ASSERT([C++])
217    # checking for Vector, which uses both GSL and Boost
218    AC_CHECK_HEADER([yat/utility/Vector.h],
219                    [ac_yat_ok="yes"],
220                    [ac_yat_ok="no"])
221
222    # checking that version in yat-config and version.h agree
223    AC_MSG_CHECKING([version in $yat_config])
224    yat_config_version=`$yat_config --version`
225    AC_MSG_RESULT([$yat_config_version])
226
227    AC_CACHE_CHECK([version in 'yat/utility/version.h'],
228      [yat_cv_header_version_equal_yat_config],
229      [yat_cv_header_version_equal_yat_config=no
230       AC_COMPILE_IFELSE(
231         [AC_LANG_PROGRAM([@%:@include <yat/utility/version.h>],
232          [ @%:@if YAT_VERSION_AT_LEAST(`$yat_config --version-major`,\
233                                     `$yat_config --version-minor`,\
234                                     `$yat_config --version-patch`)
235            // Versions agree
236            @%:@else
237            @%:@ error yat versions disagree
238            @%:@endif
239          ])
240         ],
241         [yat_cv_header_version_equal_yat_config=yes],
242         [yat_cv_header_version_equal_yat_config=no])
243
244      ])
245
246    AS_IF([test x$yat_cv_header_version_equal_yat_config = xyes], [
247           ac_yat_ok=yes;
248           AC_SUBST(YAT_CPPFLAGS)
249           AC_SUBST(YAT_CXXFLAGS)
250           AC_DEFINE([HAVE_YAT],[1],[define if yat library is available])
251          ], [
252           AC_MSG_WARN([
253           version declared in included yat/utility/version.h is not equal to
254           the one given from yat-config script: $yat_config.])
255           ac_yat_ok=no
256          ])
257
258    # restore FLAGS
259    CPPFLAGS=$ac_yat_save_CPPFLAGS
260    CXXFLAGS=$ac_yat_save_CXXFLAGS
261  fi
262  _YAT_ACTION([test "$ac_yat_ok" = "yes"],[$1],[$2])
263]) # YAT_CHECK_HEADER
264
265
266
267AC_DEFUN([YAT_CHECK_LIB],
268[
269  AC_PREREQ([2.60]) dnl we use YAT_FIND_YAT
270  AC_REQUIRE([YAT_FIND_YAT])  dnl
271  if test "$yat_config" != "no"; then
272    ac_yat_save_LDFLAGS=$LDFLAGS
273    ac_yat_save_LIBS=$LIBS
274    YAT_LDFLAGS=`$yat_config --ldflags`
275    YAT_LIBS=`$yat_config --libs`
276    LDFLAGS="$LDFLAGS $YAT_LDFLAGS"
277    LIBS="$LIBS $YAT_LIBS"
278    AC_LANG_ASSERT([C++])
279    AC_CACHE_CHECK([for utility::version(void) in yat],
280                   [yat_cv_lib_yat],
281                   [_YAT_CHECK_LIB_YAT([yat_cv_lib_yat=yes],
282                                       [yat_cv_lib_yat=no])])
283
284    AS_IF([test x$yat_cv_lib_yat = xyes], [
285                    ac_yat_ok="yes";
286                    AC_SUBST(YAT_LDFLAGS)
287                    AC_SUBST(YAT_LIBS)
288                    # be compatible with yat-config 0.5.x
289                    AS_IF([$yat_config --atleast-version=0.6],
290                          [YAT_LA_FILE=`$yat_config --yat-la-file`;],
291                          [YAT_LA_FILE=`$yat_config --link-libtool`;])
292                    AC_SUBST(YAT_LA_FILE)
293                    YAT_LT_ADD=`$yat_config --link-libtool`;
294                    AC_SUBST(YAT_LT_ADD)],
295                   [ac_yat_ok="no";
296                    AC_MSG_RESULT([no])
297                    AC_MSG_WARN([
298           the test program failed to link (or compile). See file config.log for
299           details on what occured.])
300                   ])
301    # restore FLAGS
302    LDFLAGS=$ac_yat_save_LDFLAGS
303    LIBS=$ac_yat_save_LIBS
304  fi
305
306  _YAT_ACTION([test "$ac_yat_ok" = "yes"],[$1],[$2])
307
308]) # YAT_CHECK_LIB
309
310
311# YAT_CHECK_LIB_WITH_BAM
312AC_DEFUN([YAT_CHECK_LIB_WITH_BAM],
313[
314  AC_PREREQ([2.60]) dnl we use YAT_FIND_YAT
315  AC_REQUIRE([YAT_FIND_YAT])  dnl
316  AS_IF([test x"$yat_config" = x""], [
317    yat_cv_lib_with_bam=no
318  ],[
319    ac_yat_save_CPPFLAGS=$CPPFLAGS
320    ac_yat_save_CXXFLAGS=$CXXFLAGS
321    ac_yat_save_LDFLAGS=$LDFLAGS
322    ac_yat_save_LIBS=$LIBS
323    CPPFLAGS="$CPPFLAGS `$yat_config --cppflags`"
324    CXXFLAGS="$CXXFLAGS `$yat_config --cxxflags`"
325    LDFLAGS="$LDFLAGS `$yat_config --ldflags`"
326    LIBS="$LIBS `$yat_config --libs`"
327    AC_LANG_ASSERT([C++])
328    AC_CACHE_CHECK([for class BamInFile],
329                   [yat_cv_lib_with_bam],
330                   [AC_LINK_IFELSE([
331                       AC_LANG_PROGRAM([[@%:@include <yat/omic/BamFile.h>]],
332                                       [using namespace theplu::yat::omic;
333                                        InBamFile is("myfile");])
334                     ],[
335                       yat_cv_lib_with_bam=yes
336                     ],[
337                       yat_cv_lib_with_bam=no
338                     ])
339                   ])
340
341    # restore FLAGS
342    CPPFLAGS=$ac_yat_save_CPPFLAGS
343    CXXFLAGS=$ac_yat_save_CXXFLAGS
344    LDFLAGS=$ac_yat_save_LDFLAGS
345    LIBS=$ac_yat_save_LIBS
346  ])
347  AS_CASE([$yat_cv_lib_with_bam],
348          [yes], [$1],
349          [no], [$2])
350]) # YAT_CHECK_LIB_WITH_BAM
351
352
353# Private macros
354#
355# if yat_ac_want_yat = no do nothing
356# if $1 do $2 else do $3
357#
358AC_DEFUN([_YAT_ACTION],
359[
360  AS_IF([test "x$yat_ac_want_yat" = "xno"],[],
361        [$1],[m4_default([$2], [:])],
362        [m4_default([$3], [:])])
363])
364
365
366# _YAT_CHECK_LIB_YAT([ACTION-IF_FOUND], [ACTION-IF-NOT-FOUND])
367#
368AC_DEFUN([_YAT_CHECK_LIB_YAT],
369[
370    AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <string>
371                                      namespace theplu{
372                                      namespace yat{
373                                      namespace utility {
374                                      std::string version(void);
375                                      }}}
376                                    ]],
377                                    [using namespace theplu::yat::utility;
378                                     std::string s=version();])],
379                   [$1], [$2])
380])
Note: See TracBrowser for help on using the repository browser.