1# Configure script for bcftools, utilities for VCF/BCF files.
2#
3#    Copyright (C) 2015,2017-2020 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([BCFtools], [@PORTVERSION@],
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([main.c])
30AC_CONFIG_HEADERS([config.h])
31
32m4_include([m4/ax_with_htslib.m4])
33m4_include([m4/hts_prog_cc_warnings.m4])
34
35dnl Copyright notice to be copied into the generated configure script
36AC_COPYRIGHT([Portions copyright (C) 2015,2017-2020 Genome Research Ltd.
37
38This configure script is free software: you are free to change and
39redistribute it.  There is NO WARRANTY, to the extent permitted by law.])
40
41AC_PROG_CC
42
43dnl Turn on compiler warnings, if possible
44HTS_PROG_CC_WARNINGS
45dnl Flags to treat warnings as errors.  These need to be applied to CFLAGS
46dnl later as they can interfere with some of the tests (notably AC_SEARCH_LIBS)
47HTS_PROG_CC_WERROR(hts_late_cflags)
48
49AC_SYS_LARGEFILE
50
51AC_ARG_ENABLE([bcftools-plugins],
52  [AS_HELP_STRING([--disable-bcftools-plugins],
53                  [do not build optional plugins])],
54  [], [enable_bcftools_plugins=yes])
55AC_SUBST(enable_bcftools_plugins)
56
57AC_ARG_WITH([bcf-plugin-dir],
58  [AS_HELP_STRING([--with-bcf-plugin-dir=DIR],
59                  [plugin installation location [LIBEXECDIR/bcftools]])],
60  [case $withval in
61     yes|no) AC_MSG_ERROR([no directory specified for --with-plugin-dir]) ;;
62   esac],
63   [with_bcf_plugin_dir='$(libexecdir)/bcftools'])
64AC_SUBST([bcf_plugindir], $with_bcf_plugin_dir)
65
66AC_ARG_WITH([bcf-plugin-path],
67  [AS_HELP_STRING([--with-bcf-plugin-path=PATH],
68                  [default BCFTOOLS_PLUGINS plugin search path [PLUGINDIR]])],
69  [case $withval in
70     yes) AC_MSG_ERROR([no path specified for --with-bcf-plugin-path]) ;;
71     no)  with_bcf_plugin_path= ;;
72   esac],
73  [with_bcf_plugin_path=$with_bcf_plugin_dir])
74AC_SUBST([bcf_pluginpath], $with_bcf_plugin_path)
75
76AC_ARG_ENABLE([perl-filters],
77  [AS_HELP_STRING([--enable-perl-filters],
78                  [build in support for PERL scripts in -i/-e filtering expressions])],
79  [], [enable_perl_filters=no])
80AC_SUBST(enable_perl_filters)
81
82AC_ARG_ENABLE([libgsl],
83  [AS_HELP_STRING([--enable-libgsl],
84                  [build options that require the GNU scientific library (changes bcftools license to GPL, see INSTALL for details)])],
85  [], [enable_libgsl=no])
86
87AC_ARG_WITH([cblas],
88  [AS_HELP_STRING([--with-cblas],
89                  [which cblas library to use (only needed with libgsl; default: try cblas then gslcblas)])],
90  [AS_CASE([$withval],
91	   [no],[AC_MSG_ERROR([no library name specified for --with-cblas])])],
92  [with_cblas=yes])
93
94AX_WITH_HTSLIB
95if test "$ax_cv_htslib" != yes; then
96  AC_MSG_ERROR([HTSlib development files not found
97
98BCFtools uses HTSlib to parse bioinformatics file formats etc.  Building it
99requires an unpacked HTSlib source tree (which will be built in conjunction
100with bcftools) or a previously-installed HTSlib.  In either case you may
101need to configure --with-htslib=DIR to locate the appropriate HTSlib.
102
103FAILED.  You must supply an HTSlib in order to build bcftools successfully.])
104fi
105
106if test "$ax_cv_htslib_which" = source; then
107  Hsource=
108  Hinstall='#'
109else
110  Hsource='#'
111  Hinstall=
112fi
113AC_SUBST([Hsource])
114AC_SUBST([Hinstall])
115
116AS_IF([test "$enable_bcftools_plugins" != "no"], [dnl
117  AC_MSG_CHECKING([shared library type])
118  test -n "$host_alias" || host_alias=unknown-`uname -s`
119  AS_CASE([$host_alias],
120    [*-cygwin* | *-CYGWIN*],[dnl
121      host_result="Cygwin DLL"
122      PLATFORM=CYGWIN
123      PLUGIN_EXT=.cygdll
124      HTSLIB_DLL=libhts.dll.a
125	  ],
126
127    [*-msys* | *-MSYS* | *-mingw* | *-MINGW*],[dnl
128      host_result="MSYS dll"
129      PLATFORM=MSYS
130      PLUGIN_EXT=.dll
131      HTSLIB_DLL=hts.dll.a
132      # This also sets __USE_MINGW_ANSI_STDIO which in turn makes PRId64,
133      # %lld and %z printf formats work.  It also enforces the snprintf to
134      # be C99 compliant so it returns the correct values (in kstring.c).
135      CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=600"],
136
137    [*-darwin* | *-Darwin*],[dnl
138      host_result="Darwin dylib"
139      PLATFORM=Darwin
140      PLUGIN_EXT=.so],
141
142    [*],[dnl
143      host_result="plain .so"
144      PLATFORM=default
145      PLUGIN_EXT=.so])
146  AC_MSG_RESULT([$host_result])
147  AC_SUBST([PLATFORM])
148  AC_SUBST([PLUGIN_EXT])
149  AC_DEFINE_UNQUOTED([PLUGIN_EXT], ["$PLUGIN_EXT"],
150                     [Platform-dependent plugin filename extension.])
151  AC_SUBST([HTSLIB_DLL])
152  AC_DEFINE([ENABLE_BCF_PLUGINS], 1,
153            [Define if BCFtools should enable plugins.])
154
155  AS_CASE([$PLUGIN_EXT],
156    [*cygdll | *so],
157	  [AC_SEARCH_LIBS([dlopen], [dl], [],
158        [AC_MSG_ERROR([dlopen() not found
159Plugin support requires dynamic linking facilities from the operating system.
160Either configure with --disable-bcftools-plugins or resolve this error to
161build bcftools.])])],
162    [*dll],
163	  [AC_SEARCH_LIBS([LoadLibraryA], [], [],
164        [AC_MSG_ERROR([LoadLibraryA() not found
165Plugin support requires dynamic linking facilities from the operating system.
166Either configure with --disable-bcftools-plugins or resolve this error to
167build bcftools.])])],
168	)
169
170  AC_MSG_CHECKING([if the compiler accepts -rdynamic])
171  save_CFLAGS=$CFLAGS
172  CFLAGS="$CFLAGS -rdynamic"
173  AC_LINK_IFELSE([AC_LANG_PROGRAM()],[cc_rdynamic=yes],[cc_rdynamic=no])
174  CFLAGS=$save_CFLAGS
175  AC_MSG_RESULT([$cc_rdynamic])
176  AS_IF([test "$cc_rdynamic" = "yes"],dnl
177    [CC_RDYNAMIC_OPT=-rdynamic],[CC_RDYNAMIC_OPT=])
178  AC_SUBST([CC_RDYNAMIC_OPT])
179])
180save_LIBS=$LIBS
181zlib_devel=ok
182dnl Set a trivial non-empty INCLUDES to avoid excess default includes tests
183AC_CHECK_HEADER([zlib.h], [], [zlib_devel=missing], [;])
184AC_CHECK_LIB(z, inflate,  [], [zlib_devel=missing])
185LIBS=$save_LIBS
186
187if test $zlib_devel != ok; then
188  AC_MSG_ERROR([zlib development files not found
189
190BCFtools uses compression routines from the zlib library <http://zlib.net>.
191Building bcftools requires zlib development files to be installed on the build
192machine; you may need to ensure a package such as zlib1g-dev (on Debian or
193Ubuntu Linux) or zlib-devel (on RPM-based Linux distributions) is installed.
194
195FAILED.  This error must be resolved in order to build bcftools successfully.])
196fi
197
198AS_IF([test "$enable_libgsl" != "no"], [dnl
199  gsl_devel=ok
200  save_LIBS="$LIBS"dnl Libraries for GSL are listed in $(GSL_LIBS)
201  GSL_LIBS=
202  AC_CHECK_HEADER([gsl/gsl_version.h], [], [gsl_devel=missing], [;])
203  AS_IF([test "$gsl_devel" != "missing"], [dnl
204    AS_CASE([$with_cblas],
205      [yes],[AC_SEARCH_LIBS([cblas_dgemm],[cblas gslcblas],
206              [GSL_LIBS="$ac_cv_search_cblas_dgemm"],
207              [gsl_devel=missing])],
208      [AC_CHECK_LIB([$with_cblas],[cblas_dgemm],
209         [GSL_LIBS="-l$with_cblas"],[gsl_devel=missing])])
210  ])
211  AS_IF([test "$gsl_devel" != "missing"], [dnl
212    AC_CHECK_LIB(gsl, gsl_multifit_gradient,
213      [GSL_LIBS="-lgsl $GSL_LIBS"], [gsl_devel=missing], [$GSL_LIBS])
214  ])
215
216  AS_IF([test "$gsl_devel" != "ok"], [dnl
217    AC_MSG_ERROR([libgsl development files not found
218
219The bcftools polysomy command uses routines from the GNU Scientific library
220<https://www.gnu.org/software/gsl/>.  Building BCFtools with libgsl enabled
221requires libgsl development files to be installed on the build machine; you
222may need to ensure a package such as libgsl0-dev (on Debian or Ubuntu linux)
223or gsl-devel (on RPM-based Linux distributions) is installed.
224
225Either configure with --disable-libgsl or resolve this error to build bcftools.
226    ])
227  ])
228
229  LIBS="$save_LIBS"
230  USE_GPL=1
231  AC_SUBST([USE_GPL])
232  AC_SUBST([GSL_LIBS])
233])
234
235AS_IF([test "$enable_perl_filters" != "no" ], [dnl
236    save_LIBS="$LIBS"
237    if ! perl -MExtUtils::Embed -e ccopts -e ldopts >/dev/null 2>&1; then
238       AC_MSG_ERROR([Cannot `perl -MExtUtils::Embed -e ccopts -e ldopts`])
239    fi
240    AC_DEFINE([ENABLE_PERL_FILTERS], 1, [Define if BCFtools should enable for support PERL scripts in -i/-e filtering expressions.])
241    PERL_CCOPTS="`perl -MExtUtils::Embed -e ccopts`"
242    PERL_LIBS="`perl -MExtUtils::Embed -e ldopts`"
243    dnl A hack to remove faulty "-arch i386" on mac as it breaks linking
244    if test "x$PLATFORM" = "xDarwin"; then
245        PERL_CCOPTS="`perl -MExtUtils::Embed -e ccopts | sed 's,-arch i386,,'`"
246        PERL_LIBS="`perl -MExtUtils::Embed -e ldopts | sed 's,-arch i386,,'`"
247    fi
248    AC_SUBST([PERL_CCOPTS])
249    AC_SUBST([PERL_LIBS])
250
251    dnl Look for libperl
252    AC_SEARCH_LIBS(Perl_call_pv, perl, [], [
253        AC_MSG_ERROR([Unable to find the Perl_call_pv() function for perl filters])
254    ],[$PERL_CCOPTS $PERL_LIBS])
255    LIBS="$save_LIBS"
256])
257
258dnl Apply value from HTS_PROG_CC_WERROR (if set)
259AS_IF([test "x$hts_late_cflags" != x],[CFLAGS="$CFLAGS $hts_late_cflags"])
260
261dnl Look for regcomp in various libraries (needed on windows/mingw).
262AC_SEARCH_LIBS(regcomp, regex, [libregex=needed], [])
263
264dnl Force POSIX mode on Windows/Mingw
265test -n "$host_alias" || host_alias=unknown-`uname -s`
266case $host_alias in
267  *-msys* | *-MSYS* | *-mingw* | *-MINGW*)
268    host_result="MSYS dll"
269    PLATFORM=MSYS
270    PLUGIN_EXT=.dll
271    # This also sets __USE_MINGW_ANSI_STDIO which in turn makes PRId64,
272    # %lld and %z printf formats work.  It also enforces the snprintf to
273    # be C99 compliant so it returns the correct values (in kstring.c).
274    CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=600"
275    ;;
276esac
277
278AC_CONFIG_FILES([config.mk])
279AC_OUTPUT
280
281AS_IF([test "x$USE_GPL" != "x"], [dnl
282  AC_MSG_NOTICE([License has been changed to GPL.
283
284Linking against the GNU scientific library requires that the resulting
285binary is licensed using the GNU General Public License.  In particular,
286this means you will have to follow the terms of this license in order
287to distribute binary copies.  For more information see the INSTALL file.
288
289Text of the GNU General Public License can be found in the LICENSE file,
290or at http://www.gnu.org/copyleft/gpl.html
291
292Information on the GNU Scientific Library, including the rationale for
293its choice of license can be found at https://www.gnu.org/software/gsl/
294])])
295