## Process this file with automake to produce Makefile.in

AUTOMAKE_OPTIONS = subdir-objects

if MAINTAINER_MODE
# Export these so that we run the locally installed autotools when building
# from a bootstrapped git tree.
export ACLOCAL AUTOCONF AUTOHEADER AUTOM4TE AUTOMAKE
endif

AM_CXXFLAGS += $(WERROR)

AM_CPPFLAGS = -I$(top_srcdir)/common -I$(top_srcdir)/include
if VPATH_BUILD
# Needed for the generated files include/xapian/version.h
# include/xapian/error.h and include/xapian/errordispatch.h
AM_CPPFLAGS += -I'$(top_builddir)/include'
endif
AM_CPPFLAGS += $(ICU_CPPFLAGS)
AM_CXXFLAGS += $(ICU_CFLAGS)

# Order is relevant: when building, tests must be after ".".
SUBDIRS = . docs tests

noinst_HEADERS =
BUILT_SOURCES =
noinst_LTLIBRARIES =
CLEANFILES =
DISTCLEANFILES =
MAINTAINERCLEANFILES =
bin_PROGRAMS =
EXTRA_PROGRAMS =

.PHONY: coverage-reconfigure coverage-reconfigure-maintainer-mode coverage-check

# This relies on GNU make (for the pattern rule) but it's just a convenience
# as you can run these check-* targets with any make using:
#
#   cd tests ; make check-FOO
#
# So the pain of maintaining a huge list of target forwarding rules here isn't
# worth it.
#
# Note: We use @PERCENT@ here instead of a literal % to suppress an automake
# portability warning.
check-@PERCENT@:
	cd tests && $(MAKE) $(AM_MAKEFLAGS) $@

## -O0 - optimisation can result in confusing coverage reports.
## --coverage - inserts code to generate coverage data
## VALGRIND= - generating coverage data is slow enough by itself.
COVERAGE_CONFIGURE = \
    $(srcdir)/configure CXXFLAGS='-O0 --coverage' VALGRIND= \
	$(COVERAGE_CONFIGURE_ARGS)

coverage-reconfigure: distclean
	$(COVERAGE_CONFIGURE)

coverage-reconfigure-maintainer-mode: distclean
	$(COVERAGE_CONFIGURE) --enable-maintainer-mode

coverage-check:
	## GNU find specific.
	find . -name '*.gcda' -delete
	## Don't run under valgrind even if configure was run by hand.
	$(MAKE) $(AM_MAKEFLAGS) check VALGRIND=
	rm -f xapian-core.lcov
	lcov --capture -d . --quiet --rc 'lcov_branch_coverage=1' --no-external -o xapian-core.lcov
	rm -rf lcov
	genhtml --demangle-cpp --branch-coverage $(GENHTML_ARGS) -q -p '$(abs_builddir)' -t "Test Coverage for xapian-core `git log -n1 --abbrev-commit --format=%h`" -o lcov xapian-core.lcov

# We want to clean out build tree paths from the copy of xapian-config we
# install, mostly in the interests of facilitating reproducible builds.
bin_SCRIPTS = installable/xapian-config

# Create the installable version in a subdirectory.  It's not made executable
# until install time, which hopefully should avoid people trying to use it when
# building against an uninstalled xapian-core.
installable/xapian-config: xapian-config
	$(MKDIR_P) installable
	$(SED) '/##UNINSTONLYBEGIN/,/##UNINSTONLYEND/d' xapian-config > installable/xapian-config.tmp
	mv installable/xapian-config.tmp installable/xapian-config

CLEANFILES += installable/xapian-config

noinst_SCRIPTS = xapian-config

DISTCLEANFILES += xapian-config

EXTRA_DIST = ChangeLog ChangeLog.0 ChangeLog.examples HACKING \
 include/xapian/error.h include/xapian/errordispatch.h \
 generate-exceptions exception_data.pm preautoreconf

EXTRA_DIST += \
 emscripten/README.md \
 emscripten/xapianjstest.cc

cmakedir = $(libdir)/cmake/xapian
cmake_DATA = cmake/xapian-config.cmake cmake/xapian-config-version.cmake

# docsource.mk is generated by preautoreconf, run by bootstrap prior to
# it running autoreconf.
include docsource.mk

# Install the m4 file containing the XO_LIB_XAPIAN autoconf macro.
m4datadir = $(datadir)/aclocal
dist_m4data_DATA = m4-macros/xapian.m4

# Install the pkg-config file containing the correct compiler options.
pkgconfigdir = $(libdir)/pkgconfig
nodist_pkgconfig_DATA = pkgconfig/xapian-core.pc
DISTCLEANFILES += pkgconfig/xapian-core.pc

libxapian_la = libxapian.la
lib_LTLIBRARIES = libxapian.la
libxapian_la_SOURCES = $(lib_src)
libxapian_la_LIBADD = $(XAPIAN_LIBS) $(ICU_LIBS)
libxapian_la_LDFLAGS = \
    $(XAPIAN_LDFLAGS) $(NO_UNDEFINED) -version-info $(LIBRARY_VERSION_INFO) $(lib_ldflags)

lib_src =
lib_ldflags =

if !MAINTAINER_NO_DOCS
dist_man_MANS = xapian-config.1
endif

include api/Makefile.mk
include bin/Makefile.mk
include backends/Makefile.mk
# FIXME: Clustering API needs further work before release.
#include cluster/Makefile.mk
include common/Makefile.mk
include examples/Makefile.mk
include expand/Makefile.mk
include geospatial/Makefile.mk
include include/Makefile.mk
include languages/Makefile.mk
include matcher/Makefile.mk
include net/Makefile.mk
include queryparser/Makefile.mk
include unicode/Makefile.mk
include weight/Makefile.mk

xapianinclude_HEADERS += include/xapian/error.h

# If these files change, we need to rerun configure to reprocess them -
# making them dependencies of config.status achieves that.
CONFIG_STATUS_DEPENDENCIES = include/xapian/version_h.cc

if MAINTAINER_MODE
BUILT_SOURCES += include/xapian/error.h include/xapian/errordispatch.h

include/xapian/error.h include/xapian/errordispatch.h: generate-exceptions exception_data.pm
	$(PERL) -w -I"$(srcdir)" "$(srcdir)/generate-exceptions"
endif

if !MAINTAINER_NO_DOCS
MAINTAINERCLEANFILES += $(dist_man_MANS)
endif

if DOCUMENTATION_RULES
xapian-config.1: xapian-config makemanpage
	./makemanpage ./xapian-config xapian-config xapian-config.1
endif

MAINTAINERCLEANFILES += $(BUILT_SOURCES)

.PHONY: check-syntax

check-syntax:
	$(CXXCOMPILE) -fsyntax-only -gstabs+ $(check_sources)
