1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
<html lang="en">
<head>
<title>Autoconf Macros - GNU Scientific Library -- Reference Manual</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU Scientific Library -- Reference Manual">
<meta name="generator" content="makeinfo 4.8">
<link title="Top" rel="start" href="index.html#Top">
<link rel="prev" href="Contributors-to-GSL.html" title="Contributors to GSL">
<link rel="next" href="GSL-CBLAS-Library.html" title="GSL CBLAS Library">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 The GSL Team.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``GNU General Public License'' and ``Free Software
Needs Free Documentation'', the Front-Cover text being ``A GNU Manual'',
and with the Back-Cover Text being (a) (see below). A copy of the
license is included in the section entitled ``GNU Free Documentation
License''.
(a) The Back-Cover Text is: ``You have freedom to copy and modify this
GNU Manual, like GNU software.''-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Autoconf-Macros"></a>
Next: <a rel="next" accesskey="n" href="GSL-CBLAS-Library.html">GSL CBLAS Library</a>,
Previous: <a rel="previous" accesskey="p" href="Contributors-to-GSL.html">Contributors to GSL</a>,
Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>
<h2 class="appendix">Appendix C Autoconf Macros</h2>
<p><a name="index-autoconf_002c-using-with-GSL-2493"></a>
For applications using <code>autoconf</code> the standard macro
<code>AC_CHECK_LIB</code> can be used to link with GSL automatically
from a <code>configure</code> script. The library itself depends on the
presence of a <span class="sc">cblas</span> and math library as well, so these must also be
located before linking with the main <code>libgsl</code> file. The following
commands should be placed in the <samp><span class="file">configure.ac</span></samp> file to perform
these tests,
<pre class="example"> AC_CHECK_LIB([m],[cos])
AC_CHECK_LIB([gslcblas],[cblas_dgemm])
AC_CHECK_LIB([gsl],[gsl_blas_dgemm])
</pre>
<p class="noindent">It is important to check for <code>libm</code> and <code>libgslcblas</code> before
<code>libgsl</code>, otherwise the tests will fail. Assuming the libraries
are found the output during the configure stage looks like this,
<pre class="example"> checking for cos in -lm... yes
checking for cblas_dgemm in -lgslcblas... yes
checking for gsl_blas_dgemm in -lgsl... yes
</pre>
<p class="noindent">If the library is found then the tests will define the macros
<code>HAVE_LIBGSL</code>, <code>HAVE_LIBGSLCBLAS</code>, <code>HAVE_LIBM</code> and add
the options <code>-lgsl -lgslcblas -lm</code> to the variable <code>LIBS</code>.
<p>The tests above will find any version of the library. They are suitable
for general use, where the versions of the functions are not important.
An alternative macro is available in the file <samp><span class="file">gsl.m4</span></samp> to test for
a specific version of the library. To use this macro simply add the
following line to your <samp><span class="file">configure.in</span></samp> file instead of the tests
above:
<pre class="example"> AX_PATH_GSL(GSL_VERSION,
[action-if-found],
[action-if-not-found])
</pre>
<p class="noindent">The argument <code>GSL_VERSION</code> should be the two or three digit
<span class="sc">major.minor</span> or <span class="sc">major.minor.micro</span> version number of the release
you require. A suitable choice for <code>action-if-not-found</code> is,
<pre class="example"> AC_MSG_ERROR(could not find required version of GSL)
</pre>
<p class="noindent">Then you can add the variables <code>GSL_LIBS</code> and <code>GSL_CFLAGS</code> to
your Makefile.am files to obtain the correct compiler flags.
<code>GSL_LIBS</code> is equal to the output of the <code>gsl-config --libs</code>
command and <code>GSL_CFLAGS</code> is equal to <code>gsl-config --cflags</code>
command. For example,
<pre class="example"> libfoo_la_LDFLAGS = -lfoo $(GSL_LIBS) -lgslcblas
</pre>
<p class="noindent">Note that the macro <code>AX_PATH_GSL</code> needs to use the C compiler so it
should appear in the <samp><span class="file">configure.in</span></samp> file before the macro
<code>AC_LANG_CPLUSPLUS</code> for programs that use C++.
<p>To test for <code>inline</code> the following test should be placed in your
<samp><span class="file">configure.in</span></samp> file,
<pre class="example"> AC_C_INLINE
if test "$ac_cv_c_inline" != no ; then
AC_DEFINE(HAVE_INLINE,1)
AC_SUBST(HAVE_INLINE)
fi
</pre>
<p class="noindent">and the macro will then be defined in the compilation flags or by
including the file <samp><span class="file">config.h</span></samp> before any library headers.
<p>The following autoconf test will check for <code>extern inline</code>,
<pre class="smallexample"> dnl Check for "extern inline", using a modified version
dnl of the test for AC_C_INLINE from acspecific.mt
dnl
AC_CACHE_CHECK([for extern inline], ac_cv_c_extern_inline,
[ac_cv_c_extern_inline=no
AC_TRY_COMPILE([extern $ac_cv_c_inline double foo(double x);
extern $ac_cv_c_inline double foo(double x) { return x+1.0; };
double foo (double x) { return x + 1.0; };],
[ foo(1.0) ],
[ac_cv_c_extern_inline="yes"])
])
if test "$ac_cv_c_extern_inline" != no ; then
AC_DEFINE(HAVE_INLINE,1)
AC_SUBST(HAVE_INLINE)
fi
</pre>
<p>The substitution of portability functions can be made automatically if
you use <code>autoconf</code>. For example, to test whether the BSD function
<code>hypot</code> is available you can include the following line in the
configure file <samp><span class="file">configure.in</span></samp> for your application,
<pre class="example"> AC_CHECK_FUNCS(hypot)
</pre>
<p class="noindent">and place the following macro definitions in the file
<samp><span class="file">config.h.in</span></samp>,
<pre class="example"> /* Substitute gsl_hypot for missing system hypot */
#ifndef HAVE_HYPOT
#define hypot gsl_hypot
#endif
</pre>
<p class="noindent">The application source files can then use the include command
<code>#include <config.h></code> to substitute <code>gsl_hypot</code> for each
occurrence of <code>hypot</code> when <code>hypot</code> is not available.
<hr>The GNU Scientific Library - a free numerical library licensed under the GNU GPL<br>Back to the <a href="/software/gsl/">GNU Scientific Library Homepage</a></body></html>
|