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

# Copyright 2010 University of Helsinki
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

# to silence: 
# libtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
ACLOCAL_AMFLAGS=-I m4

# targets
if EXTRA_DEMOS
CONFERENCE_DEMOS=hfst-ospell-norvig hfst-ospell-fsmnlp-2012 hfst-ospell-cicling\
				 hfst-ospell-survey hfst-ospell-lrec2013 hfst-ispell
endif # EXTRA_DEMOS

bin_PROGRAMS=hfst-ospell $(CONFERENCE_DEMOS)
#lib_LTLIBRARIES=libhfstospell.la
man1_MANS=hfst-ospell.1

PKG_LIBS=
PKG_CXXFLAGS=

if WANT_ARCHIVE
PKG_LIBS+=$(LIBARCHIVE_LIBS)
PKG_CXXFLAGS+=$(LIBARCHIVE_CFLAGS)
endif

#if WANT_LIBXMLPP
#PKG_LIBS+=$(LIBXMLPP_LIBS)
#PKG_CXXFLAGS+=$(LIBXMLPP_CFLAGS)
#endif

if WANT_TINYXML2
PKG_LIBS+=$(TINYXML2_LIBS)
PKG_CXXFLAGS+=$(TINYXML2_CFLAGS)
endif

# library parts
#libhfstospell_la_SOURCES=

#libhfstospell_la_CXXFLAGS=$(AM_CXXFLAGS) $(CXXFLAGS) $(PKG_CXXFLAGS)
#libhfstospell_la_LDFLAGS=-no-undefined -version-info 4:0:0 \
						 $(PKG_LIBS)

# link sample program against library here
hfst_ospell_SOURCES=main.cc hfst-ol.cc ospell.cc \
						 ZHfstOspeller.cc ZHfstOspellerXmlMetadata.cc \
	tinyxml2.cc \
	libarchive/archive_acl.c				\
	libarchive/archive_acl_private.h			\
	libarchive/archive_check_magic.c			\
	libarchive/archive_crc32.h				\
	libarchive/archive_crypto.c				\
	libarchive/archive_crypto_private.h			\
	libarchive/archive_endian.h				\
	libarchive/archive_entry.c				\
	libarchive/archive_entry.h				\
	libarchive/archive_entry_copy_stat.c			\
	libarchive/archive_entry_link_resolver.c		\
	libarchive/archive_entry_locale.h			\
	libarchive/archive_entry_private.h			\
	libarchive/archive_entry_sparse.c			\
	libarchive/archive_entry_stat.c				\
	libarchive/archive_entry_strmode.c			\
	libarchive/archive_entry_xattr.c			\
	libarchive/archive_options.c				\
	libarchive/archive_options_private.h			\
	libarchive/archive_platform.h				\
	libarchive/archive_ppmd_private.h			\
	libarchive/archive_ppmd7.c				\
	libarchive/archive_ppmd7_private.h			\
	libarchive/archive_private.h				\
	libarchive/archive_rb.c					\
	libarchive/archive_rb.h					\
	libarchive/archive_read.c				\
	libarchive/archive_read_data_into_fd.c			\
	libarchive/archive_read_disk_entry_from_file.c		\
	libarchive/archive_read_disk_posix.c			\
	libarchive/archive_read_disk_private.h			\
	libarchive/archive_read_disk_set_standard_lookup.c	\
	libarchive/archive_read_extract.c			\
	libarchive/archive_read_open_fd.c			\
	libarchive/archive_read_open_file.c			\
	libarchive/archive_read_open_filename.c			\
	libarchive/archive_read_open_memory.c			\
	libarchive/archive_read_private.h			\
	libarchive/archive_read_set_options.c			\
	libarchive/archive_read_support_filter_all.c		\
	libarchive/archive_read_support_filter_compress.c	\
	libarchive/archive_read_support_filter_gzip.c		\
	libarchive/archive_read_support_filter_none.c		\
	libarchive/archive_read_support_filter_program.c	\
	libarchive/archive_read_support_filter_rpm.c		\
	libarchive/archive_read_support_filter_uu.c		\
	libarchive/archive_read_support_filter_xz.c		\
	libarchive/archive_read_support_format_7zip.c		\
	libarchive/archive_read_support_format_all.c		\
	libarchive/archive_read_support_format_ar.c		\
	libarchive/archive_read_support_format_by_code.c	\
	libarchive/archive_read_support_format_cab.c		\
	libarchive/archive_read_support_format_cpio.c		\
	libarchive/archive_read_support_format_empty.c		\
	libarchive/archive_read_support_format_iso9660.c	\
	libarchive/archive_read_support_format_lha.c		\
	libarchive/archive_read_support_format_mtree.c		\
	libarchive/archive_read_support_format_rar.c		\
	libarchive/archive_read_support_format_raw.c		\
	libarchive/archive_read_support_format_tar.c		\
	libarchive/archive_read_support_format_xar.c		\
	libarchive/archive_read_support_format_zip.c		\
	libarchive/archive_string.c				\
	libarchive/archive_string.h				\
	libarchive/archive_string_composition.h			\
	libarchive/archive_string_sprintf.c			\
	libarchive/archive_util.c				\
	libarchive/archive_virtual.c				\
	libarchive/archive_write.c				\
	libarchive/archive_write_disk_posix.c			\
	libarchive/archive_write_disk_private.h			\
	libarchive/archive_write_disk_set_standard_lookup.c	\
	libarchive/archive_write_open_fd.c			\
	libarchive/archive_write_open_file.c			\
	libarchive/archive_write_open_filename.c		\
	libarchive/archive_write_open_memory.c			\
	libarchive/archive_write_private.h			\
	libarchive/archive_write_add_filter_compress.c	\
	libarchive/archive_write_add_filter_gzip.c		\
	libarchive/archive_write_add_filter_none.c		\
	libarchive/archive_write_add_filter_program.c	\
	libarchive/archive_write_add_filter_xz.c		\
	libarchive/archive_write_set_format.c			\
	libarchive/archive_write_set_format_7zip.c		\
	libarchive/archive_write_set_format_ar.c		\
	libarchive/archive_write_set_format_by_name.c		\
	libarchive/archive_write_set_format_cpio.c		\
	libarchive/archive_write_set_format_cpio_newc.c		\
	libarchive/archive_write_set_format_iso9660.c		\
	libarchive/archive_write_set_format_mtree.c		\
	libarchive/archive_write_set_format_pax.c		\
	libarchive/archive_write_set_format_shar.c		\
	libarchive/archive_write_set_format_ustar.c		\
	libarchive/archive_write_set_format_gnutar.c		\
	libarchive/archive_write_set_format_xar.c		\
	libarchive/archive_write_set_format_zip.c		\
	libarchive/archive_write_set_options.c			\
	libarchive/config_freebsd.h				\
	libarchive/archive_read_support_filter_bzip2.c		\
	libarchive/archive_write_add_filter_bzip2.c		\
	libarchive/filter_fork.c				\
	libarchive/filter_fork.h				\
	libarchive/archive_entry_copy_bhfi.c			\
	libarchive/archive_read_disk_windows.c			\
	libarchive/archive_windows.h				\
	libarchive/archive_windows.c				\
	libarchive/archive_write_disk_windows.c			\
	libarchive/filter_fork_windows.c

#hfst_ospell_LDADD=libhfstospell.la
hfst_ospell_CXXFLAGS=$(AM_CXXFLAGS) $(CXXFLAGS) \
					 $(PKG_CXXFLAGS)

if EXTRA_DEMOS
hfst_ospell_norvig_SOURCES=main-norvig.cc
#hfst_ospell_norvig_LDADD=libhfstospell.la
hfst_ospell_norvig_CXXFLAGS=$(AM_CXXFLAGS) $(CXXFLAGS) \
							$(PKG_CXXFLAGS)

hfst_ospell_cicling_SOURCES=main-cicling.cc
#hfst_ospell_cicling_LDADD=libhfstospell.la
hfst_ospell_cicling_CXXFLAGS=$(AM_CXXFLAGS) $(CXXFLAGS) \
							 $(PKG_CXXFLAGS)

hfst_ospell_lrec2013_SOURCES=main-lrec2013.cc
#hfst_ospell_lrec2013_LDADD=libhfstospell.la
hfst_ospell_lrec2013_CXXFLAGS=$(AM_CXXFLAGS) $(CXXFLAGS) \
							$(PKG_CXXFLAGS)

hfst_ospell_survey_SOURCES=main-survey.cc
#hfst_ospell_survey_LDADD=libhfstospell.la
hfst_ospell_survey_CXXFLAGS=$(AM_CXXFLAGS) $(CXXFLAGS) \
							$(PKG_CXXFLAGS)

hfst_ospell_fsmnlp_2012_SOURCES=main-fsmnlp-2012.cc
#hfst_ospell_fsmnlp_2012_LDADD=libhfstospell.la
hfst_ospell_fsmnlp_2012_CXXFLAGS=$(AM_CXXFLAGS) $(CXXFLAGS) \
								 $(PKG_CXXFLAGS)
endif # EXTRA_DEMOS

hfst_ispell_SOURCES=main-ispell.cc
#hfst_ispell_LDADD=libhfstospell.la
hfst_ispell_CXXFLAGS=$(AM_CXXFLAGS) $(CXXFLAGS) \
							$(PKG_CXXFLAGS)

# install headers for library in hfst's includedir
include_HEADERS=hfst-ol.h ospell.h ol-exceptions.h \
				ZHfstOspeller.h ZHfstOspellerXmlMetadata.h tinyxml2.h

# pkgconfig
pkgconfigdir=$(libdir)/pkgconfig
pkgconfig_DATA=hfstospell.pc

# tests
if CAN_TEST
TXTS=acceptor.default.txt errmodel.default.txt errmodel.extrachars.txt
check_DATA=speller_basic.zhfst empty_descriptions.zhfst \
		   empty_titles.zhfst empty_locale.zhfst \
		   trailing_spaces.zhfst \
		   spl.hfstol sug.hfstol err.hfstol \
		   acceptor.default.hfst errmodel.default.hfst \
		   errmodel.extrachars.hfst bad_errormodel.zhfst
# Actual test scripts:
TESTS=basic-zhfst.sh basic-legacy.sh basic-zhfst-fallback.sh \
	  empty-descriptions.sh empty-titles.sh empty-locale.sh \
	  trailing-spaces.sh bad-errormodel.sh empty-zhfst.sh
XFAIL_TESTS=empty-descriptions.sh empty-titles.sh empty-locale.sh empty-zhfst.sh
EXTRA_DIST=$(TXTS) $(TESTS) \
			basic_test.xml empty_descriptions.xml empty_titles.xml \
			empty_locale.xml trailing_spaces.xml \
			test.strings

clean-local:
	-rm -rf $(check_DATA) index.xml
endif # CAN_TEST

# N.B. Do not parallel test, race condition exists
empty_descriptions.zhfst: acceptor.default.hfst errmodel.default.hfst empty_descriptions.xml
	cp -f $(srcdir)/empty_descriptions.xml index.xml
	$(ZIP) $(ZIPFLAGS) $@ acceptor.default.hfst errmodel.default.hfst index.xml

empty_titles.zhfst: acceptor.default.hfst errmodel.default.hfst empty_titles.xml
	cp -f $(srcdir)/empty_titles.xml index.xml
	$(ZIP) $(ZIPFLAGS) $@ acceptor.default.hfst errmodel.default.hfst index.xml

empty_locale.zhfst: acceptor.default.hfst errmodel.default.hfst empty_locale.xml
	cp -f $(srcdir)/empty_locale.xml index.xml
	$(ZIP) $(ZIPFLAGS) $@ acceptor.default.hfst errmodel.default.hfst index.xml

trailing_spaces.zhfst: acceptor.default.hfst errmodel.default.hfst trailing_spaces.xml
	cp -f $(srcdir)/trailing_spaces.xml index.xml
	$(ZIP) $(ZIPFLAGS) $@ acceptor.default.hfst errmodel.default.hfst index.xml

# N.B. Do not parallel test, race condition exists
speller_basic.zhfst: acceptor.default.hfst errmodel.default.hfst basic_test.xml
	cp $(srcdir)/basic_test.xml index.xml
	$(ZIP) $(ZIPFLAGS) $@ acceptor.default.hfst errmodel.default.hfst index.xml

bad_errormodel.zhfst: acceptor.default.hfst errmodel.extrachars.hfst index.xml
	cp -f $(srcdir)/errmodel.extrachars.hfst errmodel.default.hfst
	$(ZIP) $(ZIPFLAGS) $@ acceptor.default.hfst errmodel.default.hfst index.xml

sug.hfstol: acceptor.default.hfst
	-ln -sf $< $@

spl.hfstol: acceptor.default.hfst
	-ln -sf $< $@

err.hfstol: errmodel.default.hfst
	-ln -sf $< $@

.txt.hfst:
	hfst-txt2fst $< | hfst-fst2fst -f olw -o $@

.txt.hfstol:
	hfst-txt2fst $< | hfst-fst2fst -f olw -o $@

hfst-ospell.1: hfst-ospell
	help2man --no-discard-stderr $< > $@
