ACLOCAL_AMFLAGS = -I ../../m4

AM_CPPFLAGS	= -I${top_srcdir} -I${top_builddir} \
${FACTORY_INCLUDES} ${RESOURCES_INCLUDES} ${OMALLOC_INCLUDES} \
${FLINT_CFLAGS} $(NTL_CXXFLAGS) ${NTL_CPPFLAGS} ${GMP_CPPFLAGS}

AM_CXXFLAGS =


if ENABLE_P_PROCS_STATIC
  USE_P_PROCS_STATIC_CC = templates/p_Procs_Static.cc
  USE_P_PROCS_STATIC = -Dp_Procs_Static
else
  USE_P_PROCS_STATIC_CC =
  USE_P_PROCS_STATIC =
endif

if ENABLE_P_PROCS_DYNAMIC
  USE_P_PROCS_DYNAMIC_CC = templates/p_Procs_Dynamic.cc
  P_PROCS_CPPFLAGS_COMMON = ${AM_CPPFLAGS} -DDYNAMIC_VERSION
  P_PROCS_MODULE_LDFLAGS = -module -export-dynamic -avoid-version
else
  USE_P_PROCS_DYNAMIC_CC =
  P_PROCS_CPPFLAGS_COMMON = ${AM_CPPFLAGS}
  P_PROCS_MODULE_LDFLAGS = -module
endif


libpolys_LTLIBRARIES = libpolys.la
libpolysdir = $(libdir)

SOURCES = \
	monomials/p_polys.cc monomials/ring.cc monomials/maps.cc \
	operations/pShallowCopyDelete.cc operations/p_Mult_q.cc \
	nc/sca.cc nc/summator.cc nc/ncSAFormula.cc nc/ncSACache.cc nc/ncSAMult.cc \
	pCoeff.cc pDebug.cc polys0.cc prCopy.cc prCopyMacros.h \
	kbuckets.cc sbuckets.cc weight.cc weight0.cc simpleideals.cc matpol.cc \
	sparsmat.cc \
	shiftop.cc \
        ${USE_P_PROCS_STATIC_CC} ${USE_P_PROCS_DYNAMIC_CC} mod_raw.cc \
        ext_fields/algext.cc ext_fields/transext.cc \
	clapsing.cc clapconv.cc  flintconv.cc flint_mpoly.cc\
	nc/old.gring.cc PolyEnumerator.cc

LIBPOLYSHEADERS = monomials/ring.h monomials/monomials.h \
  monomials/p_polys.h monomials/maps.h PolyEnumerator.h  prCopy.h \
	nc/nc.h nc/sca.h nc/summator.h nc/ncSAFormula.h nc/ncSACache.h nc/ncSAMult.h nc/gb_hack.h \
	operations/pShallowCopyDelete.h \
	templates/p_Procs.h templates/p_MemAdd.h templates/p_MemCmp.h \
	kbuckets.h sbuckets.h simpleideals.h weight.h matpol.h \
	sparsmat.h clapsing.h clapconv.h flintconv.h flint_mpoly.h\
	pCoeff.h shiftop.h \
	ext_fields/algext.h ext_fields/transext.h mod_raw.h

EXTRA_DIST = \
	prCopy.pl prCopyTemplate.cc \
	templates/p_Procs_Lib.cc templates/p_MemCopy.h templates/p_Numbers.h \
	templates/p_Procs_Set.h templates/p_Procs_Static.h templates/p_Procs_Dynamic.h \
	templates/p_Procs_Impl.h templates/p_Delete__T.cc templates/p_Copy__T.cc \
	templates/p_ShallowCopyDelete__T.cc templates/p_Mult_nn__T.cc \
	templates/pp_Mult_nn__T.cc templates/pp_Mult_mm__T.cc templates/p_Mult_mm__T.cc \
	templates/pp_Mult_Coeff_mm_DivSelect__T.cc templates/pp_Mult_nn__T.cc \
	templates/pp_Mult_Coeff_mm_DivSelectMult__T.cc \
	templates/pp_Mult_mm_Noether__T.cc operations/p_Mult_q.h \
	templates/p_kBucketSetLm__T.cc templates/p_Minus_mm_Mult_qq__T.cc \
	templates/p_Merge_q__T.cc templates/p_Add_q__T.cc templates/p_Neg__T.cc


p_Procs_FieldGeneral_la_CPPFLAGS = -Dp_Procs_FieldGeneral ${P_PROCS_CPPFLAGS_COMMON}
p_Procs_FieldIndep_la_CPPFLAGS = -Dp_Procs_FieldIndep ${P_PROCS_CPPFLAGS_COMMON}
p_Procs_FieldQ_la_CPPFLAGS = -Dp_Procs_FieldQ ${P_PROCS_CPPFLAGS_COMMON}
p_Procs_FieldZp_la_CPPFLAGS = -Dp_Procs_FieldZp ${P_PROCS_CPPFLAGS_COMMON}

p_Procs_FieldGeneral_la_LDFLAGS = ${P_PROCS_MODULE_LDFLAGS}
p_Procs_FieldIndep_la_LDFLAGS = ${P_PROCS_MODULE_LDFLAGS}
p_Procs_FieldQ_la_LDFLAGS = ${P_PROCS_MODULE_LDFLAGS}
p_Procs_FieldZp_la_LDFLAGS = ${P_PROCS_MODULE_LDFLAGS}

P_PROCS = templates/p_Procs_Lib.cc

p_Procs_FieldGeneral_la_SOURCES = ${P_PROCS}
p_Procs_FieldIndep_la_SOURCES = ${P_PROCS}
p_Procs_FieldQ_la_SOURCES = ${P_PROCS}
p_Procs_FieldZp_la_SOURCES = ${P_PROCS}


moduledir = $(libexecdir)/singular/MOD

if ENABLE_P_PROCS_DYNAMIC
  module_LTLIBRARIES=p_Procs_FieldGeneral.la p_Procs_FieldIndep.la p_Procs_FieldQ.la p_Procs_FieldZp.la
endif

libpolys_includedir=$(includedir)/singular/polys

nobase_libpolys_include_HEADERS = $(LIBPOLYSHEADERS)

libpolys_la_SOURCES = ${SOURCES}

EXTRA_libpolys_la_SOURCES = templates/p_Procs_Static.cc templates/p_Procs_Dynamic.cc

libpolys_la_LDFLAGS= $(SINGULAR_LDFLAGS) ${USEPPROCSDYNAMICLDFLAGS} ${USEPPROCSDYNAMICLD} -release ${PACKAGE_VERSION}
libpolys_la_LIBADD = ${USEPPROCSDYNAMICLDFLAGS} ${USEPPROCSDYNAMICLD} ${top_builddir}/coeffs/libcoeffs.la


#################################################
# autogenerated sources
noinst_PROGRAMS = p_Procs_Generate
nodist_p_Procs_Generate_SOURCES = templates/p_Procs.inc
p_Procs_Generate_SOURCES = p_Procs_Generate.cc
p_Procs_Generate_CPPFLAGS = ${AM_CPPFLAGS} ${USE_P_PROCS_STATIC}
BUILT_SOURCES = prCopy.inc gftables MOD templates/p_Procs.inc

templates/p_Procs.inc: p_Procs_Generate.cc
	$(MAKE) $(AM_MAKEFLAGS) CXX="$(CXX_FOR_BUILD)" \
	CXXFLAGS="$(CXXFLAGS_FOR_BUILD)" \
	CPPFLAGS="-I${abs_top_srcdir} -I${abs_top_builddir} -I${top_srcdir} -I${top_builddir} ${FACTORY_INCLUDES} $(CPPFLAGS_FOR_BUILD) ${USE_P_PROCS_STATIC}" \
	LDFLAGS="" LIBS="" p_Procs_Generate
	./p_Procs_Generate$(BUILD_EXEEXT) > ./templates/p_Procs.inc

prCopy.inc: prCopy.pl
	perl ${srcdir}/prCopy.pl >  prCopy.inc

CLEANFILES = $(BUILT_SOURCES) p_Procs_Generate

######################################################################

TESTS = test
check_PROGRAMS = $(TESTS)

test_LDADD=libpolys.la \
${top_builddir}/reporter/libreporter.la ${top_builddir}/misc/libmisc.la \
$(FACTORY_LIBS) $(RESOURCES_LIBS) $(OMALLOC_LIBS) \
$(FLINT_LIBS) $(GMP_LIBS) $(NTL_LIBS)

test_SOURCES=test.cc

gftables: ${top_srcdir}/../factory/gftables
	ln -snf ${top_srcdir}/../factory/gftables ${builddir}/gftables

MOD:
	if [ -d "${top_builddir}/libpolys/polys/.libs" ]; then \
	  ln -snf ${top_builddir}/libpolys/polys/.libs/ ${abs_builddir}/MOD; \
	fi
