1# Configure script for htslib, a C library for high-throughput sequencing data.
2#
3#    Copyright (C) 2015-2017 Genome Research Ltd.
4#
5#    Author: John Marshall <jm18@sanger.ac.uk>
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the "Software"), to deal
9# in the Software without restriction, including without limitation the rights
10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11# copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included in
15# all copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23# DEALINGS IN THE SOFTWARE.
24
25dnl Process this file with autoconf to produce a configure script
26AC_INIT([HTSlib], [1.4.1],
27        [samtools-help@lists.sourceforge.net], [], [http://www.htslib.org/])
28AC_PREREQ(2.63)  dnl This version introduced 4-argument AC_CHECK_HEADER
29AC_CONFIG_SRCDIR(hts.c)
30AC_CONFIG_HEADERS(config.h)
31
32dnl Copyright notice to be copied into the generated configure script
33AC_COPYRIGHT([Portions copyright (C) 2016 Genome Research Ltd.
34
35This configure script is free software: you are free to change and
36redistribute it.  There is NO WARRANTY, to the extent permitted by law.])
37
38dnl Notes to be copied (by autoheader) into the generated config.h.in
39AH_TOP([/* If you use configure, this file provides @%:@defines reflecting your
40   configuration choices.  If you have not run configure, suitable
41   conservative defaults will be used.
42
43   Autoheader adds a number of items to this template file that are not
44   used by HTSlib: STDC_HEADERS and most HAVE_*_H header file defines
45   are immaterial, as we assume standard ISO C headers and facilities;
46   the PACKAGE_* defines are unused and are overridden by the more
47   accurate PACKAGE_VERSION as computed by the Makefile.  */])
48
49AC_PROG_CC
50AC_PROG_RANLIB
51
52dnl Avoid chicken-and-egg problem where pkg-config supplies the
53dnl PKG_PROG_PKG_CONFIG macro, but we want to use it to check
54dnl for pkg-config...
55m4_ifdef([PKG_PROG_PKG_CONFIG], [PKG_PROG_PKG_CONFIG], [PKG_CONFIG=""])
56
57need_crypto=no
58pc_requires=
59static_LDFLAGS=
60static_LIBS='-lz -lm'
61private_LIBS=
62
63AC_ARG_ENABLE([bz2],
64  [AS_HELP_STRING([--disable-bz2],
65                  [omit support for BZ2-compressed CRAM files])],
66  [], [enable_bz2=yes])
67
68AC_ARG_ENABLE([gcs],
69  [AS_HELP_STRING([--enable-gcs],
70                  [support Google Cloud Storage URLs])],
71  [], [enable_gcs=check])
72
73AC_SYS_LARGEFILE
74
75AC_ARG_ENABLE([libcurl],
76  [AS_HELP_STRING([--enable-libcurl],
77                  [enable libcurl-based support for http/https/etc URLs])],
78  [], [enable_libcurl=check])
79
80AC_ARG_ENABLE([lzma],
81  [AS_HELP_STRING([--disable-lzma],
82                  [omit support for LZMA-compressed CRAM files])],
83  [], [enable_lzma=yes])
84
85AC_ARG_ENABLE([plugins],
86  [AS_HELP_STRING([--enable-plugins],
87                  [enable separately-compiled plugins for file access])],
88  [], [enable_plugins=no])
89AC_SUBST(enable_plugins)
90
91AC_ARG_WITH([plugin-dir],
92  [AS_HELP_STRING([--with-plugin-dir=DIR],
93                  [plugin installation location [LIBEXECDIR/htslib]])],
94  [case $withval in
95     yes|no) AC_MSG_ERROR([no directory specified for --with-plugin-dir]) ;;
96   esac],
97   [with_plugin_dir='$(libexecdir)/htslib'])
98AC_SUBST([plugindir], $with_plugin_dir)
99
100AC_ARG_WITH([plugin-path],
101  [AS_HELP_STRING([--with-plugin-path=PATH],
102                  [default HTS_PATH plugin search path [PLUGINDIR]])],
103  [case $withval in
104     yes) AC_MSG_ERROR([no path specified for --with-plugin-path]) ;;
105     no)  with_plugin_path= ;;
106   esac],
107  [with_plugin_path=$with_plugin_dir])
108AC_SUBST([pluginpath], $with_plugin_path)
109
110AC_ARG_ENABLE([s3],
111  [AS_HELP_STRING([--enable-s3],
112                  [support Amazon AWS S3 URLs])],
113  [], [enable_s3=check])
114
115AC_MSG_CHECKING([shared library type])
116test -n "$host_alias" || host_alias=unknown-`uname -s`
117case $host_alias in
118  *-cygwin* | *-CYGWIN*)
119    host_result="Cygwin DLL"
120    PLATFORM=CYGWIN
121    PLUGIN_EXT=.cygdll
122    ;;
123  *-darwin* | *-Darwin*)
124    host_result="Darwin dylib"
125    PLATFORM=Darwin
126    PLUGIN_EXT=.bundle
127    ;;
128  *)
129    host_result="plain .so"
130    PLATFORM=default
131    PLUGIN_EXT=.so
132    ;;
133esac
134AC_MSG_RESULT([$host_result])
135AC_SUBST([PLATFORM])
136
137dnl FIXME This pulls in dozens of standard header checks
138AC_FUNC_MMAP
139AC_CHECK_FUNCS(gmtime_r)
140
141# Darwin has a dubious fdatasync() symbol, but no declaration in <unistd.h>
142AC_CHECK_DECL([fdatasync(int)], [AC_CHECK_FUNCS(fdatasync)])
143
144if test $enable_plugins != no; then
145  AC_SEARCH_LIBS([dlopen], [dl], [],
146    [AC_MSG_ERROR([dlopen() not found
147
148Plugin support requires dynamic linking facilities from the operating system.
149Either configure with --disable-plugins or resolve this error to build HTSlib.])])
150  # TODO Test whether this is required and/or needs tweaking per-platform
151  LDFLAGS="$LDFLAGS -rdynamic"
152  static_LDFLAGS="$static_LDFLAGS -rdynamic"
153  case "$ac_cv_search_dlopen" in
154    -l*) static_LIBS="$static_LIBS $ac_cv_search_dlopen" ;;
155  esac
156  AC_DEFINE([ENABLE_PLUGINS], 1, [Define if HTSlib should enable plugins.])
157  AC_SUBST([PLUGIN_EXT])
158  AC_DEFINE_UNQUOTED([PLUGIN_EXT], ["$PLUGIN_EXT"],
159                     [Platform-dependent plugin filename extension.])
160fi
161
162AC_SEARCH_LIBS([log], [m], [],
163  [AC_MSG_ERROR([log() not found
164
165HTSLIB requires a working floating-point math library.
166FAILED.  This error must be resolved in order to build HTSlib successfully.])])
167
168zlib_devel=ok
169dnl Set a trivial non-empty INCLUDES to avoid excess default includes tests
170AC_CHECK_HEADER([zlib.h], [], [zlib_devel=missing], [;])
171AC_CHECK_LIB(z, inflate,  [], [zlib_devel=missing])
172
173if test $zlib_devel != ok; then
174  AC_MSG_ERROR([zlib development files not found
175
176HTSlib uses compression routines from the zlib library <http://zlib.net>.
177Building HTSlib requires zlib development files to be installed on the build
178machine; you may need to ensure a package such as zlib1g-dev (on Debian or
179Ubuntu Linux) or zlib-devel (on RPM-based Linux distributions or Cygwin)
180is installed.
181
182FAILED.  This error must be resolved in order to build HTSlib successfully.])
183fi
184
185dnl connect() etc. fns are in libc on linux, but libsocket on illumos/Solaris
186libsocket=unneeded
187AC_SEARCH_LIBS(connect, socket, [libsocket=needed], [])
188
189
190if test "$enable_bz2" != no; then
191  bz2_devel=ok
192  AC_CHECK_HEADER([bzlib.h], [], [bz2_devel=missing], [;])
193  AC_CHECK_LIB([bz2], [BZ2_bzBuffToBuffCompress], [], [bz2_devel=missing])
194  if test $bz2_devel != ok; then
195    AC_MSG_ERROR([libbzip2 development files not found
196
197The CRAM format may use bzip2 compression, which is implemented in HTSlib
198by using compression routines from libbzip2 <http://www.bzip.org/>.
199
200Building HTSlib requires libbzip2 development files to be installed on the
201build machine; you may need to ensure a package such as libbz2-dev (on Debian
202or Ubuntu Linux) or bzip2-devel (on RPM-based Linux distributions or Cygwin)
203is installed.
204
205Either configure with --disable-bz2 (which will make some CRAM files
206produced elsewhere unreadable) or resolve this error to build HTSlib.])
207  fi
208dnl Unfortunately the 'bzip2' package-cfg module is not standard.
209dnl Redhat/Fedora has it; Debian/Ubuntu does not.
210  if test -n "$PKG_CONFIG" && "$PKG_CONFIG" --exists bzip2; then
211     pc_requires="$pc_requires bzip2"
212  else
213     private_LIBS="$private_LIBS -lbz2"
214  fi
215  static_LIBS="$static_LIBS -lbz2"
216fi
217
218if test "$enable_lzma" != no; then
219  lzma_devel=ok
220  AC_CHECK_HEADER([lzma.h], [], [lzma_devel=missing], [;])
221  AC_CHECK_LIB([lzma], [lzma_easy_buffer_encode], [], [lzma_devel=missing])
222  if test $lzma_devel != ok; then
223    AC_MSG_ERROR([liblzma development files not found
224
225The CRAM format may use LZMA2 compression, which is implemented in HTSlib
226by using compression routines from liblzma <http://tukaani.org/xz/>.
227
228Building HTSlib requires liblzma development files to be installed on the
229build machine; you may need to ensure a package such as liblzma-dev (on Debian
230or Ubuntu Linux), xz-devel (on RPM-based Linux distributions or Cygwin), or
231xz (via Homebrew on macOS) is installed; or build XZ Utils from source.
232
233Either configure with --disable-lzma (which will make some CRAM files
234produced elsewhere unreadable) or resolve this error to build HTSlib.])
235  fi
236  pc_requires="$pc_requires liblzma"
237  static_LIBS="$static_LIBS -llzma"
238fi
239
240libcurl=disabled
241if test "$enable_libcurl" != no; then
242  AC_CHECK_LIB([curl], [curl_easy_pause],
243    [AC_DEFINE([HAVE_LIBCURL], 1, [Define if libcurl file access is enabled.])
244     libcurl=enabled],
245    [AC_CHECK_LIB([curl], [curl_easy_init],
246       [message="library is too old (7.18+ required)"],
247       [message="library not found"])
248     case "$enable_libcurl" in
249       check) AC_MSG_WARN([libcurl not enabled: $message]) ;;
250       *) AC_MSG_ERROR([libcurl $message
251
252Support for HTTPS and other SSL-based URLs requires routines from the libcurl
253library <http://curl.haxx.se/libcurl/>.  Building HTSlib with libcurl enabled
254requires libcurl development files to be installed on the build machine; you
255may need to ensure a package such as libcurl4-{gnutls,nss,openssl}-dev (on
256Debian or Ubuntu Linux) or libcurl-devel (on RPM-based Linux distributions
257or Cygwin) is installed.
258
259Either configure with --disable-libcurl or resolve this error to build HTSlib.])
260       ;;
261     esac])
262dnl -lcurl is only needed for static linking if hfile_libcurl is not a plugin
263  if test "$libcurl" = enabled ; then
264    if test "$enable_plugins" != yes ; then
265      static_LIBS="$static_LIBS -lcurl"
266    fi
267  fi
268fi
269AC_SUBST([libcurl])
270
271gcs=disabled
272if test "$enable_gcs" != no; then
273  if test $libcurl = enabled; then
274    AC_DEFINE([ENABLE_GCS], 1, [Define if HTSlib should enable GCS support.])
275    gcs=enabled
276  else
277    case "$enable_gcs" in
278      check) AC_MSG_WARN([GCS support not enabled: requires libcurl support]) ;;
279      *) AC_MSG_ERROR([GCS support not enabled
280
281Support for Google Cloud Storage URLs requires libcurl support to be enabled
282in HTSlib.  Configure with --enable-libcurl in order to use GCS URLs.])
283      ;;
284    esac
285  fi
286fi
287AC_SUBST([gcs])
288
289s3=disabled
290if test "$enable_s3" != no; then
291  if test $libcurl = enabled; then
292    s3=enabled
293    need_crypto="$enable_s3"
294  else
295    case "$enable_s3" in
296      check) AC_MSG_WARN([S3 support not enabled: requires libcurl support]) ;;
297      *) AC_MSG_ERROR([S3 support not enabled
298
299Support for Amazon AWS S3 URLs requires libcurl support to be enabled
300in HTSlib.  Configure with --enable-libcurl in order to use S3 URLs.])
301      ;;
302    esac
303  fi
304fi
305
306CRYPTO_LIBS=
307if test $need_crypto != no; then
308  AC_CHECK_FUNC([CCHmac],
309    [AC_DEFINE([HAVE_COMMONCRYPTO], 1,
310               [Define if you have the Common Crypto library.])],
311    [save_LIBS=$LIBS
312     AC_SEARCH_LIBS([HMAC], [crypto],
313       [AC_DEFINE([HAVE_HMAC], 1, [Define if you have libcrypto-style HMAC().])
314        case "$ac_cv_search_HMAC" in
315          -l*) CRYPTO_LIBS=$ac_cv_search_HMAC ;;
316        esac],
317     [case "$need_crypto" in
318     check) AC_MSG_WARN([S3 support not enabled: requires SSL development files])
319         s3=disabled ;;
320     *) AC_MSG_ERROR([SSL development files not found
321
322Support for AWS S3 URLs requires routines from an SSL library.  Building
323HTSlib with libcurl enabled requires SSL development files to be installed
324on the build machine; you may need to ensure a package such as libgnutls-dev,
325libnss3-dev, or libssl-dev (on Debian or Ubuntu Linux, corresponding to the
326libcurl4-*-dev package installed), or openssl-devel (on RPM-based Linux
327distributions or Cygwin) is installed.
328
329Either configure with --disable-s3 or resolve this error to build HTSlib.]) ;;
330       esac])
331     LIBS=$save_LIBS])
332dnl Only need to add to static_LIBS if not building as a plugin
333  if test "$enable_plugins" != yes ; then
334     static_LIBS="$static_LIBS $CRYPTO_LIBS"
335  fi
336fi
337
338if test "$s3" = enabled ; then
339   AC_DEFINE([ENABLE_S3], 1, [Define if HTSlib should enable S3 support.])
340fi
341AC_SUBST([s3])
342AC_SUBST([CRYPTO_LIBS])
343
344AC_SUBST([pc_requires])
345AC_SUBST([private_LIBS])
346AC_SUBST([static_LDFLAGS])
347AC_SUBST([static_LIBS])
348
349AC_CONFIG_FILES([config.mk htslib.pc.tmp:htslib.pc.in])
350AC_OUTPUT
351