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], m4_esyscmd_s([./version.sh 2>/dev/null]),
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
32m4_include([m4/hts_prog_cc_warnings.m4])
33
34dnl Copyright notice to be copied into the generated configure script
35AC_COPYRIGHT([Portions copyright (C) 2016 Genome Research Ltd.
36
37This configure script is free software: you are free to change and
38redistribute it.  There is NO WARRANTY, to the extent permitted by law.])
39
40dnl Notes to be copied (by autoheader) into the generated config.h.in
41AH_TOP([/* If you use configure, this file provides @%:@defines reflecting your
42   configuration choices.  If you have not run configure, suitable
43   conservative defaults will be used.
44
45   Autoheader adds a number of items to this template file that are not
46   used by HTSlib: STDC_HEADERS and most HAVE_*_H header file defines
47   are immaterial, as we assume standard ISO C headers and facilities;
48   the PACKAGE_* defines are unused and are overridden by the more
49   accurate PACKAGE_VERSION as computed by the Makefile.  */])
50
51AC_PROG_CC
52AC_PROG_RANLIB
53
54dnl Turn on compiler warnings, if possible
55HTS_PROG_CC_WARNINGS
56dnl Flags to treat warnings as errors.  These need to be applied to CFLAGS
57dnl later as they can interfere with some of the tests (notably AC_SEARCH_LIBS)
58HTS_PROG_CC_WERROR(hts_late_cflags)
59
60dnl Avoid chicken-and-egg problem where pkg-config supplies the
61dnl PKG_PROG_PKG_CONFIG macro, but we want to use it to check
62dnl for pkg-config...
63m4_ifdef([PKG_PROG_PKG_CONFIG], [PKG_PROG_PKG_CONFIG], [PKG_CONFIG=""])
64
65need_crypto=no
66pc_requires=
67static_LDFLAGS=$LDFLAGS
68static_LIBS='-lpthread -lz -lm'
69private_LIBS=$LDFLAGS
70
71AC_ARG_ENABLE([bz2],
72  [AS_HELP_STRING([--disable-bz2],
73                  [omit support for BZ2-compressed CRAM files])],
74  [], [enable_bz2=yes])
75
76AC_ARG_ENABLE([gcs],
77  [AS_HELP_STRING([--enable-gcs],
78                  [support Google Cloud Storage URLs])],
79  [], [enable_gcs=check])
80
81AC_SYS_LARGEFILE
82AC_FUNC_FSEEKO
83
84AC_ARG_ENABLE([libcurl],
85  [AS_HELP_STRING([--enable-libcurl],
86                  [enable libcurl-based support for http/https/etc URLs])],
87  [], [enable_libcurl=check])
88
89AC_ARG_ENABLE([lzma],
90  [AS_HELP_STRING([--disable-lzma],
91                  [omit support for LZMA-compressed CRAM files])],
92  [], [enable_lzma=yes])
93
94AC_ARG_ENABLE([plugins],
95  [AS_HELP_STRING([--enable-plugins],
96                  [enable separately-compiled plugins for file access])],
97  [], [enable_plugins=no])
98AC_SUBST(enable_plugins)
99
100AC_ARG_WITH([libdeflate],
101  [AS_HELP_STRING([--with-libdeflate],
102                  [use libdeflate for faster crc and deflate algorithms])],
103  [], [with_libdeflate=check])
104
105AC_ARG_WITH([plugin-dir],
106  [AS_HELP_STRING([--with-plugin-dir=DIR],
107                  [plugin installation location [LIBEXECDIR/htslib]])],
108  [case $withval in
109     yes|no) AC_MSG_ERROR([no directory specified for --with-plugin-dir]) ;;
110   esac],
111   [with_plugin_dir='$(libexecdir)/htslib'])
112AC_SUBST([plugindir], $with_plugin_dir)
113
114AC_ARG_WITH([plugin-path],
115  [AS_HELP_STRING([--with-plugin-path=PATH],
116                  [default HTS_PATH plugin search path [PLUGINDIR]])],
117  [case $withval in
118     yes) AC_MSG_ERROR([no path specified for --with-plugin-path]) ;;
119     no)  with_plugin_path= ;;
120   esac],
121  [with_plugin_path=$with_plugin_dir])
122AC_SUBST([pluginpath], $with_plugin_path)
123
124AC_ARG_ENABLE([s3],
125  [AS_HELP_STRING([--enable-s3],
126                  [support Amazon AWS S3 URLs])],
127  [], [enable_s3=check])
128
129test -n "$host_alias" || host_alias=unknown-`uname -s`
130AC_MSG_CHECKING([shared library type for $host_alias])
131case $host_alias in
132  *-cygwin* | *-CYGWIN*)
133    host_result="Cygwin DLL"
134    PLATFORM=CYGWIN
135    PLUGIN_EXT=.cygdll
136    ;;
137  *-darwin* | *-Darwin*)
138    host_result="Darwin dylib"
139    PLATFORM=Darwin
140    PLUGIN_EXT=.bundle
141    ;;
142  *-msys* | *-MSYS* | *-mingw* | *-MINGW*)
143    host_result="MSYS dll"
144    PLATFORM=MSYS
145    PLUGIN_EXT=.dll
146    # This also sets __USE_MINGW_ANSI_STDIO which in turn makes PRId64,
147    # %lld and %z printf formats work.  It also enforces the snprintf to
148    # be C99 compliant so it returns the correct values (in kstring.c).
149    CPPFLAGS="$CPPCFLAGS -D_XOPEN_SOURCE=600"
150    ;;
151  *)
152    host_result="plain .so"
153    PLATFORM=default
154    PLUGIN_EXT=.so
155    ;;
156esac
157AC_MSG_RESULT([$host_result])
158AC_SUBST([PLATFORM])
159
160dnl FIXME This pulls in dozens of standard header checks
161AC_FUNC_MMAP
162AC_CHECK_FUNCS([gmtime_r fsync drand48])
163
164# Darwin has a dubious fdatasync() symbol, but no declaration in <unistd.h>
165AC_CHECK_DECL([fdatasync(int)], [AC_CHECK_FUNCS(fdatasync)])
166
167if test $enable_plugins != no; then
168  AC_SEARCH_LIBS([dlopen], [dl], [],
169    [AC_MSG_ERROR([dlopen() not found
170
171Plugin support requires dynamic linking facilities from the operating system.
172Either configure with --disable-plugins or resolve this error to build HTSlib.])])
173  # TODO Test whether this is required and/or needs tweaking per-platform
174  LDFLAGS="$LDFLAGS -rdynamic"
175  static_LDFLAGS="$static_LDFLAGS -rdynamic"
176  case "$ac_cv_search_dlopen" in
177    -l*) static_LIBS="$static_LIBS $ac_cv_search_dlopen" ;;
178  esac
179  AC_DEFINE([ENABLE_PLUGINS], 1, [Define if HTSlib should enable plugins.])
180  AC_SUBST([PLUGIN_EXT])
181  AC_DEFINE_UNQUOTED([PLUGIN_EXT], ["$PLUGIN_EXT"],
182                     [Platform-dependent plugin filename extension.])
183fi
184
185AC_SEARCH_LIBS([log], [m], [],
186  [AC_MSG_ERROR([log() not found
187
188HTSLIB requires a working floating-point math library.
189FAILED.  This error must be resolved in order to build HTSlib successfully.])])
190
191zlib_devel=ok
192dnl Set a trivial non-empty INCLUDES to avoid excess default includes tests
193AC_CHECK_HEADER([zlib.h], [], [zlib_devel=missing], [;])
194AC_CHECK_LIB(z, inflate,  [], [zlib_devel=missing])
195
196if test $zlib_devel != ok; then
197  AC_MSG_ERROR([zlib development files not found
198
199HTSlib uses compression routines from the zlib library <http://zlib.net>.
200Building HTSlib requires zlib development files to be installed on the build
201machine; you may need to ensure a package such as zlib1g-dev (on Debian or
202Ubuntu Linux) or zlib-devel (on RPM-based Linux distributions or Cygwin)
203is installed.
204
205FAILED.  This error must be resolved in order to build HTSlib successfully.])
206fi
207
208dnl connect() etc. fns are in libc on linux, but libsocket on illumos/Solaris
209AC_SEARCH_LIBS([recv], [socket ws2_32], [
210if test "$ac_cv_search_recv" != "none required"
211then
212  static_LIBS="$static_LIBS $ac_cv_search_recv"
213fi], [AC_MSG_ERROR([unable to find the recv() function])])
214
215if test "$enable_bz2" != no; then
216  bz2_devel=ok
217  AC_CHECK_HEADER([bzlib.h], [], [bz2_devel=missing], [;])
218  AC_CHECK_LIB([bz2], [BZ2_bzBuffToBuffCompress], [], [bz2_devel=missing])
219  if test $bz2_devel != ok; then
220    AC_MSG_ERROR([libbzip2 development files not found
221
222The CRAM format may use bzip2 compression, which is implemented in HTSlib
223by using compression routines from libbzip2 <http://www.bzip.org/>.
224
225Building HTSlib requires libbzip2 development files to be installed on the
226build machine; you may need to ensure a package such as libbz2-dev (on Debian
227or Ubuntu Linux) or bzip2-devel (on RPM-based Linux distributions or Cygwin)
228is installed.
229
230Either configure with --disable-bz2 (which will make some CRAM files
231produced elsewhere unreadable) or resolve this error to build HTSlib.])
232  fi
233dnl Unfortunately the 'bzip2' package-cfg module is not standard.
234dnl Redhat/Fedora has it; Debian/Ubuntu does not.
235  if test -n "$PKG_CONFIG" && "$PKG_CONFIG" --exists bzip2; then
236     pc_requires="$pc_requires bzip2"
237  else
238     private_LIBS="$private_LIBS -lbz2"
239  fi
240  static_LIBS="$static_LIBS -lbz2"
241fi
242
243if test "$enable_lzma" != no; then
244  lzma_devel=ok
245  AC_CHECK_HEADERS([lzma.h], [], [lzma_devel=header-missing], [;])
246  AC_CHECK_LIB([lzma], [lzma_easy_buffer_encode], [], [lzma_devel=missing])
247  if test $lzma_devel = missing; then
248    AC_MSG_ERROR([liblzma development files not found
249
250The CRAM format may use LZMA2 compression, which is implemented in HTSlib
251by using compression routines from liblzma <http://tukaani.org/xz/>.
252
253Building HTSlib requires liblzma development files to be installed on the
254build machine; you may need to ensure a package such as liblzma-dev (on Debian
255or Ubuntu Linux), xz-devel (on RPM-based Linux distributions or Cygwin), or
256xz (via Homebrew on macOS) is installed; or build XZ Utils from source.
257
258Either configure with --disable-lzma (which will make some CRAM files
259produced elsewhere unreadable) or resolve this error to build HTSlib.])
260  fi
261  pc_requires="$pc_requires liblzma"
262  static_LIBS="$static_LIBS -llzma"
263fi
264
265AS_IF([test "x$with_libdeflate" != "xno"],
266  [libdeflate=ok
267   AC_CHECK_HEADER([libdeflate.h],[],[libdeflate='missing header'],[;])
268   AC_CHECK_LIB([deflate], [libdeflate_deflate_compress],[],[libdeflate='missing library'])
269   AS_IF([test "$libdeflate" = "ok"],
270    [AC_DEFINE([HAVE_LIBDEFLATE], 1, [Define if libdeflate is available.])
271     private_LIBS="$private_LIBS -ldeflate"
272     static_LIBS="$static_LIBS -ldeflate"],
273    [AS_IF([test "x$with_libdeflate" != "xcheck"],
274       [AC_MSG_ERROR([libdeflate development files not found: $libdeflate
275
276You requested libdeflate, but do not have the required header / library
277files.  The source for libdeflate is available from
278<https://github.com/ebiggers/libdeflate>.  You may have to adjust
279search paths in CPPFLAGS and/or LDFLAGS if the header and library
280are not currently on them.
281
282Either configure with --without-libdeflate or resolve this error to build
283HTSlib.])])])])
284
285libcurl=disabled
286if test "$enable_libcurl" != no; then
287  AC_CHECK_LIB([curl], [curl_easy_pause],
288    [AC_DEFINE([HAVE_LIBCURL], 1, [Define if libcurl file access is enabled.])
289     libcurl=enabled],
290    [AC_CHECK_LIB([curl], [curl_easy_init],
291       [message="library is too old (7.18+ required)"],
292       [message="library not found"])
293     case "$enable_libcurl" in
294       check) AC_MSG_WARN([libcurl not enabled: $message]) ;;
295       *) AC_MSG_ERROR([libcurl $message
296
297Support for HTTPS and other SSL-based URLs requires routines from the libcurl
298library <http://curl.haxx.se/libcurl/>.  Building HTSlib with libcurl enabled
299requires libcurl development files to be installed on the build machine; you
300may need to ensure a package such as libcurl4-{gnutls,nss,openssl}-dev (on
301Debian or Ubuntu Linux) or libcurl-devel (on RPM-based Linux distributions
302or Cygwin) is installed.
303
304Either configure with --disable-libcurl or resolve this error to build HTSlib.])
305       ;;
306     esac])
307dnl -lcurl is only needed for static linking if hfile_libcurl is not a plugin
308  if test "$libcurl" = enabled ; then
309    if test "$enable_plugins" != yes ; then
310      static_LIBS="$static_LIBS -lcurl"
311    fi
312  fi
313fi
314AC_SUBST([libcurl])
315
316gcs=disabled
317if test "$enable_gcs" != no; then
318  if test $libcurl = enabled; then
319    AC_DEFINE([ENABLE_GCS], 1, [Define if HTSlib should enable GCS support.])
320    gcs=enabled
321  else
322    case "$enable_gcs" in
323      check) AC_MSG_WARN([GCS support not enabled: requires libcurl support]) ;;
324      *) AC_MSG_ERROR([GCS support not enabled
325
326Support for Google Cloud Storage URLs requires libcurl support to be enabled
327in HTSlib.  Configure with --enable-libcurl in order to use GCS URLs.])
328      ;;
329    esac
330  fi
331fi
332AC_SUBST([gcs])
333
334s3=disabled
335if test "$enable_s3" != no; then
336  if test $libcurl = enabled; then
337    s3=enabled
338    need_crypto="$enable_s3"
339  else
340    case "$enable_s3" in
341      check) AC_MSG_WARN([S3 support not enabled: requires libcurl support]) ;;
342      *) AC_MSG_ERROR([S3 support not enabled
343
344Support for Amazon AWS S3 URLs requires libcurl support to be enabled
345in HTSlib.  Configure with --enable-libcurl in order to use S3 URLs.])
346      ;;
347    esac
348  fi
349fi
350
351CRYPTO_LIBS=
352if test $need_crypto != no; then
353  AC_CHECK_FUNC([CCHmac],
354    [AC_DEFINE([HAVE_COMMONCRYPTO], 1,
355               [Define if you have the Common Crypto library.])],
356    [save_LIBS=$LIBS
357     AC_SEARCH_LIBS([HMAC], [crypto],
358       [AC_DEFINE([HAVE_HMAC], 1, [Define if you have libcrypto-style HMAC().])
359        case "$ac_cv_search_HMAC" in
360          -l*) CRYPTO_LIBS=$ac_cv_search_HMAC ;;
361        esac],
362     [case "$need_crypto" in
363     check) AC_MSG_WARN([S3 support not enabled: requires SSL development files])
364         s3=disabled ;;
365     *) AC_MSG_ERROR([SSL development files not found
366
367Support for AWS S3 URLs requires routines from an SSL library.  Building
368HTSlib with libcurl enabled requires SSL development files to be installed
369on the build machine; you may need to ensure a package such as libgnutls-dev,
370libnss3-dev, or libssl-dev (on Debian or Ubuntu Linux, corresponding to the
371libcurl4-*-dev package installed), or openssl-devel (on RPM-based Linux
372distributions or Cygwin) is installed.
373
374Either configure with --disable-s3 or resolve this error to build HTSlib.]) ;;
375       esac])
376     LIBS=$save_LIBS])
377dnl Only need to add to static_LIBS if not building as a plugin
378  if test "$enable_plugins" != yes ; then
379     static_LIBS="$static_LIBS $CRYPTO_LIBS"
380  fi
381fi
382
383dnl Look for PTHREAD_MUTEX_RECURSIVE.
384dnl This is normally in pthread.h except on some broken glibc implementations.
385AC_CHECK_DECL(PTHREAD_MUTEX_RECURSIVE, [], [AC_DEFINE([_XOPEN_SOURCE],[600], [Needed for PTHREAD_MUTEX_RECURSIVE])], [[#include <pthread.h>]])
386
387if test "$s3" = enabled ; then
388   AC_DEFINE([ENABLE_S3], 1, [Define if HTSlib should enable S3 support.])
389fi
390
391dnl Apply value from HTS_PROG_CC_WERROR (if set)
392AS_IF([test "x$hts_late_cflags" != x],[CFLAGS="$CFLAGS $hts_late_cflags"])
393
394AC_SUBST([s3])
395AC_SUBST([CRYPTO_LIBS])
396
397AC_SUBST([pc_requires])
398AC_SUBST([private_LIBS])
399AC_SUBST([static_LDFLAGS])
400AC_SUBST([static_LIBS])
401
402AC_CONFIG_FILES([config.mk htslib.pc.tmp:htslib.pc.in])
403AC_OUTPUT
404