# https://www.singular.uni-kl.de/
# svn co svn+ssh://monty.mathematik.uni-kl.de/usr/local/Singular/svn/trunk
# svn co http://www.singular.uni-kl.de/svn/trunk
# old URL = ftp://www.mathematik.uni-kl.de/pub/Math/Singular/Factory
# URL = ftp://jim.mathematik.uni-kl.de/pub/Math/Factory
# https://github.com/Singular/Sources
# https://service.mathematik.uni-kl.de/ftp/pub/Math/Factory/factory-4.2.0.tar.gz
# ftp://jim.mathemathematik.uni-kl.de/pub/Math/Singular
# https://www.singular.uni-kl.de
# https://www.singular.uni-kl.de/ftp/pub/Math/Singular/SOURCES/4-3-0/singular-4.3.0.tar.gz

# We seem to be the only users of the factory library, which is part of
# Singular.  Its source code accompanies binary installations of Singular,
# under Arch Linux, for example.  To get a more recent tar file for factory,
# I ask Hans Schoenemann <hannes@mathematik.uni-kl.de> to make one and post
# it at one of the ftp sites above.  Version 4.1.3 is available.

URL = http://macaulay2.com/Downloads/OtherSourceCode
VERSION = 4.2.1
# PATCHFILE = @abs_srcdir@/patch-$(VERSION)
PRECONFIGURE = autoreconf -vif

BUILDTARGET = all ftmpl_inst.o
LIBRARIES = ftmpl_inst.o

LICENSEFILES = COPYING

# Sometimes the official factory library tar file is incomplete, in that it leaves out
# the m4 macros needed to rebuild the autoconf files, and the file configure.ac will
# try to include ../m4, which is where the files were stored in the Singular source tree.
# These files include various macros that start with AX_.  Solution: create a new tar file
# with the files added to ./m4 and edit configure.ac.  Get compatible libtool macro files
# with something like "cp /usr/local/Cellar/libtool/2.4.2/share/aclocal/* m4/.".  Then run
# "autoreconf -v -f -i".  Include any patches to configure.ac, rather than
# patching on the fly later with PATCHFILE here, as that will usually result
# in an error about an incorrect installed version of aclocal.

# Factory's configure script doesn't find libraries using the standard autoconf macros (sigh), so
# it is necessary to examine the log (in the code below) to ensure that flint and ntl are both found.
ifeq (@BUILD_ntl@,yes)
CONFIGOPTIONS += --with-ntl='$(LIBRARIESDIR)'
endif
ifeq (@BUILD_flint@,yes)
CONFIGOPTIONS += --with-flint='$(LIBRARIESDIR)'
endif

CONFIGOPTIONS += --disable-omalloc --enable-streamio
CONFIGOPTIONS += --includedir='$(LIBRARIESDIR)/include/'
CONFIGOPTIONS += --disable-shared
CONFIGOPTIONS += --without-Singular

ifeq (@DEBUG@,yes)
CONFIGOPTIONS += --enable-assertions 
endif
CHECKCMD = true
include ../Makefile.library

CONFIGURECMD += && ( set -x ; grep '^.define HAVE_NTL 1' _config.h && grep '^.define HAVE_FLINT 1' _config.h )

# add code to add these options only for gcc
WARNFLAGS += -Wno-uninitialized -Wno-write-strings
## add code to add these options only for recent enough versions of gcc
# WARNFLAGS += -Wno-int-to-pointer-cast
# WARNFLAGS += -Wno-unused-but-set-variable

ifeq (@OPTIMIZE@,yes)
WARNFLAGS += -Wno-deprecated
endif

#CXXFLAGS += --no-rtti --no-exceptions

BUILDOPTIONS += WARNFLAGS='$(WARNFLAGS)' AM_DEFAULT_VERBOSITY=1

# These are old routines, long deprecated, missing in mpir 1.3.0
# but mpfr 2.4.2 still uses them, try removing them with 2.4.3:
CPPFLAGS += -Dmpz_div_2exp=mpz_fdiv_q_2exp -Dmpz_div_ui=mpz_fdiv_q_ui -Dmpz_div=mpz_fdiv_q
CFLAGS += -Wimplicit -Werror
CXXFLAGS += -Wno-deprecated-register

Makefile: @srcdir@/Makefile.in ; cd ../.. && ./config.status libraries/factory/Makefile
# HINT:
# Under freebsd there is a problem in the file /usr/include/c++/3.4/cwchar .
# You have to bracket the following include with extern "C" like this:
#    extern "C" {
#      #include <wchar.h>
#    }

.installed-$(VERSION) : $(LIBRARIESDIR)/include/factory/cf_assert.h \
			$(LIBRARIESDIR)/include/factory/templates/ftmpl_list.cc
$(LIBRARIESDIR)/include/factory/cf_assert.h : $(BUILDDIR)/cf_assert.h .compiled-$(VERSION) 
	$(MKDIR_P) $(LIBRARIESDIR)/include/factory
	@INSTALL_DATA@ $< $@
$(LIBRARIESDIR)/include/factory/templates/ftmpl_list.cc : $(BUILDDIR)/templates/ftmpl_list.cc .compiled-$(VERSION) 
	$(MKDIR_P) $(LIBRARIESDIR)/include/factory/templates
	@INSTALL_DATA@ $< $@

uninstall clean ::
	if [ -d $(LIBRARIESDIR) ] ;\
	then cd $(LIBRARIESDIR) && rm -rf \
		include/factory.h include/factoryconf.h include/cf_gmp.h include/templates/ftmpl_* include/factory ; \
	fi

#post-install: $(LIBRARIESDIR)/lib/libcfmem-newdelete-removed
#$(LIBRARIESDIR)/lib/libcfmem-newdelete-removed : $(LIBRARIESDIR)/lib/libcfmem.a
#	ar -d "$^" newdelete.o
#	touch "$@"

# Local Variables:
# compile-command: "make -C $M2BUILDDIR/libraries/factory "
# End:
