source: trunk/m4/yat.m4

Last change on this file was 3661, checked in by Peter, 4 years ago

update copyright years

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 12.6 KB
Line 
1## $Id: yat.m4 3661 2017-07-14 01:10:35Z peter $
2#
3# serial 10  (yat 0.15)
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: 2017-07-14 01:10:35 +0000 (Fri, 14 Jul 2017) $
95#
96# COPYLEFT
97#
98#   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
99#   Copyright (C) 2009, 2010, 2011, 2012, 2013, 2017 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_MSG_CHECKING([for yat/utility/Vector.h])
219    _YAT_CHECK_HEADER([yat/utility/Vector.h], [
220      AC_MSG_RESULT([yes])
221      ac_yat_ok="yes"
222    ], [
223      AC_MSG_RESULT([no])
224      AC_MSG_CHECKING([for yat/utility/Vector.h with -DYAT_WITHOUT_CXX11])
225      CPPFLAGS="$CPPFLAGS -DYAT_WITHOUT_CXX11"
226      _YAT_CHECK_HEADER([yat/utility/Vector.h], [
227        YAT_CPPFLAGS="$YAT_CPPFLAGS -DYAT_WITHOUT_CXX11"
228        ac_yat_ok="yes"
229        AC_MSG_RESULT([yes])
230      ], [
231        ac_yat_ok="no"
232        AC_MSG_RESULT([no])
233      ])
234    ])
235
236    # checking that version in yat-config and version.h agree
237    AC_MSG_CHECKING([version in $yat_config])
238    yat_config_version=`$yat_config --version`
239    AC_MSG_RESULT([$yat_config_version])
240
241    AC_CACHE_CHECK([version in 'yat/utility/version.h'],
242      [yat_cv_header_version_equal_yat_config],
243      [yat_cv_header_version_equal_yat_config=no
244       AC_COMPILE_IFELSE(
245         [AC_LANG_PROGRAM([@%:@include <yat/utility/version.h>],
246          [ @%:@if YAT_VERSION_AT_LEAST(`$yat_config --version-major`,\
247                                     `$yat_config --version-minor`,\
248                                     `$yat_config --version-patch`)
249            // Versions agree
250            @%:@else
251            @%:@ error yat versions disagree
252            @%:@endif
253          ])
254         ],
255         [yat_cv_header_version_equal_yat_config=yes],
256         [yat_cv_header_version_equal_yat_config=no])
257
258      ])
259
260    AS_IF([test x$yat_cv_header_version_equal_yat_config = xyes], [
261           ac_yat_ok=yes;
262           AC_SUBST(YAT_CPPFLAGS)
263           AC_SUBST(YAT_CXXFLAGS)
264           AC_DEFINE([HAVE_YAT],[1],[define if yat library is available])
265          ], [
266           AC_MSG_WARN([
267           version declared in included yat/utility/version.h is not equal to
268           the one given from yat-config script: $yat_config.])
269           ac_yat_ok=no
270          ])
271
272    # restore FLAGS
273    CPPFLAGS=$ac_yat_save_CPPFLAGS
274    CXXFLAGS=$ac_yat_save_CXXFLAGS
275  fi
276  _YAT_ACTION([test "$ac_yat_ok" = "yes"],[$1],[$2])
277]) # YAT_CHECK_HEADER
278
279
280
281AC_DEFUN([YAT_CHECK_LIB],
282[
283  AC_PREREQ([2.60]) dnl we use YAT_FIND_YAT
284  AC_REQUIRE([YAT_FIND_YAT])  dnl
285  if test "$yat_config" != "no"; then
286    ac_yat_save_LDFLAGS=$LDFLAGS
287    ac_yat_save_LIBS=$LIBS
288    YAT_LDFLAGS=`$yat_config --ldflags`
289    YAT_LIBS=`$yat_config --libs`
290    LDFLAGS="$LDFLAGS $YAT_LDFLAGS"
291    LIBS="$LIBS $YAT_LIBS"
292    AC_LANG_ASSERT([C++])
293    AC_CACHE_CHECK([for utility::version(void) in yat],
294                   [yat_cv_lib_yat],
295                   [_YAT_CHECK_LIB_YAT([yat_cv_lib_yat=yes],
296                                       [yat_cv_lib_yat=no])])
297
298    AS_IF([test x$yat_cv_lib_yat = xyes], [
299                    ac_yat_ok="yes";
300                    AC_SUBST(YAT_LDFLAGS)
301                    AC_SUBST(YAT_LIBS)
302                    # be compatible with yat-config 0.5.x
303                    AS_IF([$yat_config --atleast-version=0.6],
304                          [YAT_LA_FILE=`$yat_config --yat-la-file`;],
305                          [YAT_LA_FILE=`$yat_config --link-libtool`;])
306                    AC_SUBST(YAT_LA_FILE)
307                    YAT_LT_ADD=`$yat_config --link-libtool`;
308                    AC_SUBST(YAT_LT_ADD)],
309                   [ac_yat_ok="no";
310                    AC_MSG_RESULT([no])
311                    AC_MSG_WARN([
312           the test program failed to link (or compile). See file config.log for
313           details on what occured.])
314                   ])
315    # restore FLAGS
316    LDFLAGS=$ac_yat_save_LDFLAGS
317    LIBS=$ac_yat_save_LIBS
318  fi
319
320  _YAT_ACTION([test "$ac_yat_ok" = "yes"],[$1],[$2])
321
322]) # YAT_CHECK_LIB
323
324
325# YAT_CHECK_LIB_WITH_BAM
326AC_DEFUN([YAT_CHECK_LIB_WITH_BAM],
327[
328  AC_PREREQ([2.60]) dnl we use YAT_FIND_YAT
329  AC_REQUIRE([YAT_FIND_YAT])  dnl
330  AS_IF([test x"$yat_config" = x""], [
331    yat_cv_lib_with_bam=no
332  ],[
333    ac_yat_save_CPPFLAGS=$CPPFLAGS
334    ac_yat_save_CXXFLAGS=$CXXFLAGS
335    ac_yat_save_LDFLAGS=$LDFLAGS
336    ac_yat_save_LIBS=$LIBS
337    CPPFLAGS="$CPPFLAGS `$yat_config --cppflags`"
338    CXXFLAGS="$CXXFLAGS `$yat_config --cxxflags`"
339    LDFLAGS="$LDFLAGS `$yat_config --ldflags`"
340    LIBS="$LIBS `$yat_config --libs`"
341    AC_LANG_ASSERT([C++])
342    AC_CACHE_CHECK([for class BamInFile],
343                   [yat_cv_lib_with_bam],
344                   [AC_LINK_IFELSE([
345                       AC_LANG_PROGRAM([[@%:@include <yat/omic/BamFile.h>]],
346                                       [using namespace theplu::yat::omic;
347                                        InBamFile is("myfile");])
348                     ],[
349                       yat_cv_lib_with_bam=yes
350                     ],[
351                       yat_cv_lib_with_bam=no
352                     ])
353                   ])
354
355    # restore FLAGS
356    CPPFLAGS=$ac_yat_save_CPPFLAGS
357    CXXFLAGS=$ac_yat_save_CXXFLAGS
358    LDFLAGS=$ac_yat_save_LDFLAGS
359    LIBS=$ac_yat_save_LIBS
360  ])
361  AS_CASE([$yat_cv_lib_with_bam],
362          [yes], [$1],
363          [no], [$2])
364]) # YAT_CHECK_LIB_WITH_BAM
365
366
367# Private macros
368#
369# if yat_ac_want_yat = no do nothing
370# if $1 do $2 else do $3
371#
372AC_DEFUN([_YAT_ACTION],
373[
374  AS_IF([test "x$yat_ac_want_yat" = "xno"],[],
375        [$1],[m4_default([$2], [:])],
376        [m4_default([$3], [:])])
377])
378
379
380# _YAT_CHECK_HEADER(header, [ACTION-IF_FOUND], [ACTION-IF-NOT-FOUND])
381#
382AC_DEFUN([_YAT_CHECK_HEADER],
383[
384    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([@%:@include <$1>], [])],
385                      [$2], [$3])
386])
387
388
389# _YAT_CHECK_LIB_YAT([ACTION-IF_FOUND], [ACTION-IF-NOT-FOUND])
390#
391AC_DEFUN([_YAT_CHECK_LIB_YAT],
392[
393    AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <string>
394                                      namespace theplu{
395                                      namespace yat{
396                                      namespace utility {
397                                      std::string version(void);
398                                      }}}
399                                    ]],
400                                    [using namespace theplu::yat::utility;
401                                     std::string s=version();])],
402                   [$1], [$2])
403])
Note: See TracBrowser for help on using the repository browser.