1AC_PREREQ(2.62)
2AC_INIT(ABySS, 2.3.1, abyss-users@bcgsc.ca, abyss,
3		http://www.bcgsc.ca/platform/bioinfo/software/abyss)
4
5AC_CONFIG_MACRO_DIR([m4])
6m4_include(m4/m4_ax_pthread.m4)
7m4_include([m4/ax_cxx_compile_stdcxx.m4])
8AX_CXX_COMPILE_STDCXX(11, noext, mandatory)
9
10AM_INIT_AUTOMAKE(1.9.6 foreign subdir-objects)
11AC_CONFIG_SRCDIR([ABYSS/abyss.cc])
12AC_CONFIG_HEADER([config.h])
13
14# Checks for programs.
15AC_PROG_AWK
16AC_PROG_CC
17AC_PROG_CPP
18AC_PROG_CXX
19AC_PROG_INSTALL
20AC_PROG_RANLIB
21AC_CHECK_TOOL(GHC, ghc)
22AM_CONDITIONAL([HAVE_GHC], ["$GHC" --version])
23AC_CHECK_PROG(PANDOC, pandoc, yes)
24AM_CONDITIONAL([HAVE_PANDOC], [test x"$PANDOC" = x"yes"])
25AM_PROG_AR
26
27# Checks for header files.
28AC_CHECK_HEADERS([dlfcn.h fcntl.h float.h limits.h \
29	stddef.h stdint.h stdlib.h sys/param.h])
30AC_HEADER_STDBOOL
31AC_HEADER_STDC
32
33# Checks for typedefs, structures, and compiler characteristics.
34AC_C_BIGENDIAN
35AC_C_CONST
36AC_C_INLINE
37AC_CHECK_TYPES([ptrdiff_t])
38AC_TYPE_MODE_T
39AC_TYPE_PID_T
40AC_TYPE_SIZE_T
41AC_TYPE_SSIZE_T
42AC_TYPE_INT64_T
43AC_TYPE_UINT8_T
44AC_TYPE_UINT16_T
45AC_TYPE_UINT32_T
46AC_TYPE_UINT64_T
47
48# Check for std::hash and std::tr1::hash.
49AC_LANG_PUSH([C++])
50AC_CHECK_TYPE([std::hash<int>],
51	AC_DEFINE(HAVE_STD_HASH, [1],
52		[Define if the system provides std::hash]),
53	[], [
54#ifdef __FUJITSU
55#include <string>
56#else
57#include <functional>
58#endif])
59AC_CHECK_TYPE([std::tr1::hash<int>],
60	AC_DEFINE(HAVE_STD_TR1_HASH, [1],
61		[Define if the system provides std::tr1::hash]),
62	[], [#include <tr1/functional>])
63AC_CHECK_TYPE([std::tr1::tuple<int>],
64	AC_DEFINE(HAVE_STD_TR1_TUPLE, [1],
65		[Define if the system provides std::tr1::tuple]),
66	[], [#include <tr1/tuple>])
67if test "x$ac_cv_type_std__tr1__tuple_int_" = "xyes"; then
68	# Avoid double-declaration of std::tr1::tuple by boost.
69	# See http://stackoverflow.com/questions/1156003/c-namespace-collision-with-gtest-and-boost
70	# for explanation.
71	AC_DEFINE(BOOST_HAS_TR1_TUPLE, [1],
72	[Define to disable declaration of std::tr1::tuple by boost])
73fi
74AM_CONDITIONAL([HAVE_TR1_TUPLE], [test x"$ac_cv_type_std__tr1__tuple_int_" = x"yes"])
75AC_LANG_POP([C++])
76
77# Checks for library functions.
78AC_CHECK_FUNCS([dup2 gethostname getopt_long getpagesize \
79				memset strdup strerror strtoul])
80AC_FUNC_FORK
81AC_FUNC_MALLOC
82AC_FUNC_MEMCMP
83AC_FUNC_REALLOC
84AC_FUNC_SETVBUF_REVERSED
85AC_FUNC_VPRINTF
86
87# Checks for library constants.
88AC_CHECK_DECL(HOST_NAME_MAX, [],
89	AC_DEFINE(HOST_NAME_MAX, [_POSIX_HOST_NAME_MAX],
90			  [Define if the system does not provide HOST_NAME_MAX]),
91	[#include <limits.h>])
92
93# Options to configure.
94# Boost
95AC_ARG_WITH(boost, AS_HELP_STRING([--with-boost=PATH],
96			[specify directory for the boost header files]))
97if test "$with_boost" -a -d "$with_boost"; then
98	boost_cppflags="-isystem$with_boost -isystem$with_boost/include"
99fi
100
101# MPI
102AC_ARG_WITH(mpi, AS_HELP_STRING([--with-mpi=PATH],
103	[specify prefix directory for the installed MPI parallel
104	computing library]))
105if test "$with_mpi" -a -d "$with_mpi"; then
106	mpi_cppflags="-isystem$with_mpi/include"
107	if test -d "$with_mpi/lib64"; then
108		mpi_ldflags="-L$with_mpi/lib64"
109	else
110		mpi_ldflags="-L$with_mpi/lib"
111	fi
112fi
113
114AC_ARG_ENABLE(mpich, AS_HELP_STRING([--enable-mpich],
115	[use MPICH (default is to use Open MPI)]))
116AC_ARG_ENABLE(lammpi, AS_HELP_STRING([--enable-lammpi],
117	[use LAM/MPI (default is to use Open MPI)]))
118
119# SQLite
120AC_ARG_WITH(sqlite, AS_HELP_STRING([--with-sqlite=PATH],
121	[specify prefix directory for the installed sqlite library]))
122if test "$with_sqlite" -a "$with_sqlite" != "no" -a -d "$with_sqlite"; then
123	sqlite_cppflags="-I$with_sqlite/include"
124	if test -d "$with_sqlite/lib64"; then
125		sqlite_ldflags="-L$with_sqlite/lib64 -lsqlite3"
126	else
127		sqlite_ldflags="-L$with_sqlite/lib -lsqlite3"
128	fi
129fi
130
131# SparseHash
132AC_ARG_WITH(sparsehash, AS_HELP_STRING([--with-sparsehash=PATH],
133	[specify prefix directory for the installed sparsehash library]))
134if test "$with_sparsehash" -a "$with_sparsehash" != "no" -a -d "$with_sparsehash" ; then
135	sparsehash_cppflags="-isystem$with_sparsehash/include"
136	sparsehash_ldflags="-L$with_sparsehash/lib"
137fi
138
139AC_ARG_ENABLE(fm, AS_HELP_STRING([--enable-fm],
140	[specify the width of the FM-index in bits (default is 64-bit)]),
141	[], [enable_fm=64])
142AC_DEFINE_UNQUOTED(FMBITS, $enable_fm,
143				   [Width of bits of the FM-index in bits])
144
145AC_ARG_ENABLE(maxk, AS_HELP_STRING([--enable-maxk=N],
146	[set the maximum k-mer length (default is 128)]),
147	[], [enable_maxk=128])
148AC_DEFINE_UNQUOTED(MAX_KMER, [$enable_maxk], [maximum k-mer length])
149
150AC_ARG_ENABLE(max-hashes, AS_HELP_STRING([--enable-max-hashes],
151	[set the maximum number of Bloom filter hash functions (default is 32)]),
152	[], [enable_max_hashes=32])
153AC_DEFINE_UNQUOTED(MAX_HASHES, [$enable_max_hashes], [maximum Bloom filter hash functions])
154
155# Find the absolute path to the source.
156my_abs_srcdir=$(cd $srcdir; pwd)
157
158# Set compiler flags.
159boost_ver=1.56.0
160boost_ver_dir=boost_1_56_0
161AC_SUBST(CPPFLAGS,
162		 "-I$my_abs_srcdir $boost_cppflags $mpi_cppflags $sqlite_cppflags $sparsehash_cppflags $CPPFLAGS -isystem$my_abs_srcdir/$boost_ver_dir")
163AC_SUBST(LDFLAGS, "$mpi_ldflags $sqlite_ldflags $sparsehash_ldflags $LDFLAGS")
164
165# Check for pthread.h / libpthread
166# (optional 'make check' dependency)
167AX_PTHREAD([have_pthread="yes"])
168AM_CONDITIONAL([HAVE_PTHREAD], [test x"$have_pthread" = x"yes"])
169
170# Check for the MPI parallel computing library.
171libs="$LIBS"
172AC_DEFINE(MPICH_SKIP_MPICXX, 1,
173		  [Define to disable MPICH C++ bindings])
174AC_DEFINE(OMPI_SKIP_MPICXX, 1,
175		  [Define to disable OpenMPI C++ bindings])
176AC_CHECK_HEADERS([mpi.h])
177if test "$enable_mpich"; then
178	AC_CHECK_LIB([pthread], [pthread_create])
179	AC_CHECK_LIB([mpl], [MPL_env2int])
180	AC_CHECK_LIB([mpich], [MPI_Init])
181	ac_cv_lib_mpi_MPI_Init=$ac_cv_lib_mpich_MPI_Init
182elif test "$enable_lammpi"; then
183	AC_CHECK_LIB([pthread], [pthread_create])
184	AC_CHECK_LIB([dl], [dlopen])
185	AC_CHECK_LIB([lam], [lam_mutex_lock])
186	AC_CHECK_LIB([mpi], [MPI_Init])
187	AC_LANG_PUSH([C++])
188	AC_CHECK_LIB([lammpi++], [main])
189	AC_LANG_POP([C++])
190else
191	AC_CHECK_LIB([mpi], [MPI_Init])
192fi
193AM_CONDITIONAL([HAVE_LIBMPI],
194	[test $ac_cv_header_mpi_h = yes -a $ac_cv_lib_mpi_MPI_Init = yes])
195AC_SUBST(MPI_LIBS, "$LIBS")
196LIBS="$libs"
197
198# Check for the math library.
199AC_CHECK_LIB([m], [sqrt])
200AC_CHECK_FUNCS([pow sqrt])
201AC_CHECK_FUNC(ceilf, [], AC_DEFINE(ceilf, [ceil],
202			  [Define if the system does not provide ceilf]))
203
204# Check for the dynamic linking library.
205AC_CHECK_LIB([dl], [dlsym])
206
207# Check for popcnt instruction.
208AC_COMPILE_IFELSE(
209	[AC_LANG_PROGRAM([[#include <stdint.h>],
210					  [uint64_t x = 0;]],
211					 [[__asm__("popcnt %1,%0" : "=r" (x) : "r" (x));]])],
212	[AC_DEFINE([HAVE_POPCNT], 1, [Define to 1 if you have popcnt.])],
213	[AC_DEFINE([HAVE_POPCNT], 0, [Define to 0 if you do not have popcnt.])])
214
215# Check for the hash table implementation.
216AC_LANG([C++])
217AC_CHECK_HEADERS([ \
218	functional \
219	tr1/functional \
220	boost/functional/hash.hpp \
221	boost/property_map/property_map.hpp \
222	google/sparse_hash_map \
223	unordered_map tr1/unordered_map \
224	unordered_set tr1/unordered_set \
225	boost/unordered_set.hpp \
226])
227
228# Check for Boost.
229if test $ac_cv_header_boost_property_map_property_map_hpp != yes; then
230	AC_MSG_ERROR([ABySS requires the Boost C++ libraries, which may
231	be downloaded from here: http://www.boost.org/users/download/
232	It is not necessary to compile Boost before installing it. The
233	following commands will download and install Boost for ABySS:
234	cd $my_abs_srcdir
235	wget http://downloads.sourceforge.net/project/boost/boost/$boost_ver/$boost_ver_dir.tar.bz2
236	tar jxf $boost_ver_dir.tar.bz2
237	cd -])
238fi
239
240# Check for SQLite
241libs="$LIBS"
242if test "$with_sqlite" != "no"; then
243	AC_CHECK_HEADERS([sqlite3.h])
244	AC_CHECK_LIB([sqlite3],[main])
245fi
246if (test "$ac_cv_header_sqlite3_h" = "yes" -a "$ac_cv_lib_sqlite3_main" = "yes"); then
247	AC_DEFINE(_SQL, 1, [Define to 1 if you have sqlite lib/header])
248fi
249AM_CONDITIONAL(HAVE_SQLITE3,
250	[test "$ac_cv_header_sqlite3_h" = "yes" -a "$ac_cv_lib_sqlite3_main" = "yes"],
251	[Define to 1 if you have sqlite lib/header])
252AC_SUBST(SQLITE_LIBS, "$LIBS")
253LIBS=$libs
254
255# Check for OpenMP.
256AC_OPENMP
257if test -z $OPENMP_CXXFLAGS; then
258	OPENMP_CXXFLAGS=-Wno-unknown-pragmas
259fi
260
261# Set compiler flags.
262
263AC_ARG_ENABLE([werror], AS_HELP_STRING([--disable-werror],
264	[do not treat compiler warnings as errors]))
265
266if test x"$enable_werror" = x"no"; then
267	AC_SUBST(AM_CXXFLAGS, '-Wall -Wextra')
268elif test x"$enable_werror" = x"yes"; then
269	AC_SUBST(AM_CXXFLAGS, '-Wall -Wextra -Werror')
270else
271	# default
272	AC_SUBST(AM_CXXFLAGS, '-Wall -Wextra -Werror')
273fi
274
275# Build abyss-paired-dbg and abyss-paired-dbg-mpi
276AM_CONDITIONAL([PAIRED_DBG], [true])
277
278AC_CONFIG_FILES([
279	Makefile
280	ABYSS/Makefile
281	Align/Makefile
282	Assembly/Makefile
283	Common/Makefile
284	DataLayer/Makefile
285	FMIndex/Makefile
286	Graph/Makefile
287	Parallel/Makefile
288	bin/Makefile
289	doc/Makefile
290	dialign/Makefile
291	kmerprint/Makefile
292	AdjList/Makefile
293	Konnector/Makefile
294	DAssembler/Makefile
295	DistanceEst/Makefile
296	Layout/Makefile
297	Map/Makefile
298	Overlap/Makefile
299	PopBubbles/Makefile
300	Scaffold/Makefile
301	SimpleGraph/Makefile
302	MergePaths/Makefile
303	KAligner/Makefile
304	PairedDBG/Makefile
305	ParseAligns/Makefile
306	PathOverlap/Makefile
307	Consensus/Makefile
308	FilterGraph/Makefile
309	GapFiller/Makefile
310	Sealer/Makefile
311	vendor/gtest-1.7.0/Makefile
312	RResolver/Makefile
313	Unittest/Makefile
314	LogKmerCount/Makefile
315	Bloom/Makefile
316	BloomDBG/Makefile
317	DataBase/Makefile
318	vendor/Makefile
319])
320
321if test "$with_sparsehash" != "no" -a "$ac_cv_header_google_sparse_hash_map" != "yes"; then
322	AC_MSG_ERROR([ABySS should be compiled with Google sparsehash to
323	reduce memory usage. It may be downloaded here:
324	https://code.google.com/p/sparsehash/
325
326	If you do not wish to use sparsehash, specify --without-sparsehash.])
327fi
328
329if test x"$have_pthread" != x"yes"; then
330	AC_MSG_WARN([Warning: Running the unit tests with 'make check' has been disabled
331	because pthread.h and/or libpthread could not be found.])
332fi
333
334AC_OUTPUT
335