ACLOCAL_AMFLAGS = -I../m4

GIT_VERSION := $(shell $(top_srcdir)/git-version-gen $(top_srcdir)/.tarball-git-version)

AM_CPPFLAGS = -I${top_srcdir} -I${top_builddir} -I${top_srcdir}/kernel -I${top_builddir}/kernel -I${top_srcdir}/libpolys -I${top_builddir}/libpolys $(FACTORY_INCLUDES)  $(GMP_CPPFLAGS) $(NTL_CPPFLAGS) $(FLINT_CFLAGS) -DGIT_VERSION='"$(GIT_VERSION)"'

all-local: feOpt.inc feOptTS.inc feOptES.inc iparith.inc all.lib gftables MOD ${abs_builddir}/LIB Singular$(EXEEXT) ESingular$(EXEEXT) TSingular$(EXEEXT)

if SING_WIN
SUBDIRS = ${BUILTIN_MODULES} . dyn_modules
else
SUBDIRS = dyn_modules .
endif

########################### Possible builtin modules... #########################
BUILTIN_FLAGS = ${BUILTIN_LIBS}

########################### libSingular* #########################

libSingular_LTLIBRARIES = libSingular.la
libSingulardir = $(libdir)

libSingular_la_CPPFLAGS = ${AM_CPPFLAGS} -DLIBSINGULAR ${PTHREAD_CFLAGS}

SOURCES = \
   links/asciiLink.cc\
   attrib.cc\
   blackbox.cc\
   calcSVD.cc\
   cntrlc.cc\
   countedref.cc\
   denom_list.cc\
   eigenval_ip.cc\
   extra.cc\
   feOpt.cc\
   fehelp.cc\
   fevoices.cc\
   fglm.cc\
   gms.cc\
   grammar.cc\
   iparith.cc\
   ipassign.cc\
   ipconv.cc\
   ipid.cc\
   iplib.cc\
   ipprint.cc\
   ipshell.cc\
   libparse.cc\
   linearAlgebra_ip.cc\
   lists.cc\
   maps_ip.cc\
   misc_ip.cc\
   mod_lib.cc\
   links/ndbm.cc\
   newstruct.cc\
   number2.cc\
   pcv.cc\
   links/pipeLink.cc\
   scanner.cc\
   sdb.cc\
   links/silink.cc\
   links/sing_dbm.cc\
   links/slInit_Static.cc\
   links/ssiLink.cc\
   links/semaphore.c\
   subexpr.cc\
   pyobject_setup.cc\
   walk.cc\
   walk_ip.cc\
   wrapper.cc\
   mmstd.c claptmpl.cc\
   febase.cc \
   svd/libs/amp.cpp \
   svd/libs/ap.cpp

#   links/slInit_Dynamic.cc

libSingular_la_SOURCES   = $(SOURCES)

SingularHEADERS = \
   attrib.h \
   blackbox.h \
   cntrlc.h \
   countedref.h \
   links/dbm_sl.h \
   distrib.h \
   eigenval_ip.h \
   feOpt.h feOptTab.h fehelp.h \
   fglm.h \
   gms.h \
   grammar.h \
   idrec.h \
   ipconv.h \
   ipid.h \
   ipprint.h \
   ipshell.h \
   libparse.h \
   libsingular.h \
   linearAlgebra_ip.h\
   lists.h \
   locals.h \
   maps_ip.h \
   misc_ip.h \
   mmalloc.h \
   mod_lib.h \
   links/ndbm.h \
   newstruct.h \
   number2.h \
   pcv.h \
   links/pipeLink.h \
   pyobject_setup.h \
   sdb.h \
   links/silink.h \
   links/sing_dbm.h \
   links/slInit.h \
   links/ssiLink.h \
   links/simpleipc.h \
   stype.h \
   subexpr.h \
   table.h \
   tok.h \
   walk.h \
   fevoices.h \
   svd_si.h \
   svd/libs/amp.h  svd/libs/ap.h  svd/libs/stdafx.h \
   svd/bdsvd.h  svd/bidiagonal.h  svd/blas.h  svd/lq.h  svd/qr.h  svd/reflections.h \
   svd/rotations.h  svd/svd.h



# -DMAKE_DISTRIBUTION

# plural_cmd.inc
nodist_libSingular_la_SOURCES = feOpt.inc iparith.inc

libSingular_la_LDFLAGS    =$(SINGULAR_LDFLAGS) ${USEPPROCSDYNAMICLDFLAGS} ${USEPPROCSDYNAMICLD} -release ${PACKAGE_VERSION} ${PTHREAD_LDFLAGS}
libSingular_la_LIBADD     =${USEPPROCSDYNAMICLDFLAGS} ${USEPPROCSDYNAMICLD} ${BUILTIN_FLAGS} ${top_builddir}/kernel/libkernel.la ${PTHREAD_LIBS}

libSingular_includedir = ${includedir}/singular/Singular
nobase_libSingular_include_HEADERS = $(SingularHEADERS)

#########################################################
# handle all the generated *.inc

noinst_PROGRAMS = gentable1 feOptGen feOptES feOptTS

gentable1_SOURCES = gentable.cc grammar.h tok.h table.h
gentable1_CPPFLAGS = ${AM_CPPFLAGS}

feOptGen_SOURCES = feOptGen.cc feOptGen.h
feOptGen_CPPFLAGS = ${AM_CPPFLAGS}

feOptES_SOURCES = feOptGen.cc feOptGen.h
feOptES_CPPFLAGS = ${AM_CPPFLAGS} -DESINGULAR

feOptTS_SOURCES = feOptGen.cc feOptGen.h
feOptTS_CPPFLAGS = ${AM_CPPFLAGS} -DTSINGULAR

########################### Singular* #########################

EXTRA_PROGRAMS =  libparse Singulard

# the "optional_programs" variable should be defined in the configure
# script, and listed in an AC_SUBST macro
optional_Singular_programs =

bin_PROGRAMS = Singular ESingular TSingular $(optional_Singular_programs)

Singular_SOURCES = tesths.cc fegetopt.c fegetopt.h utils.cc  utils.h

Singular_LDADD = libSingular.la ${BUILTIN_FLAGS}

Singular_LDFLAGS = -static ${AM_LDFLAGS} ${BUILTIN_FLAGS}

Singulard_SOURCES = tesths.cc fegetopt.c fegetopt.h utils.cc  utils.h

Singulard_LDADD = libSingular.la ${BUILTIN_FLAGS}

Singulard_LDFLAGS = -shared ${AM_LDFLAGS} ${BUILTIN_FLAGS}

scriptdir = $(libexecdir)/singular/MOD
dist_script_SCRIPTS = singularsurf singularsurf_jupyter singularsurf_win

#### ESingular
ESingular_CPPFLAGS = ${AM_CPPFLAGS} -DESINGULAR -DPROTO
# ESingular_LDFLAGS = -static ${AM_LDFLAGS}
ESingular_LDADD =  ${top_builddir}/libpolys/reporter/libreporter.la \
${top_builddir}/libpolys/misc/libmisc.la ${top_builddir}/omalloc/libomalloc.la \
${top_builddir}/resources/libsingular_resources.la


ESingular_SOURCES = emacs.cc fegetopt.c fegetopt.h feOptES.inc feOpt.cc

#### same for TSingular
TSingular_CPPFLAGS = ${AM_CPPFLAGS} -DTSINGULAR -DPROTO
# TSingular_LDFLAGS = -static ${AM_LDFLAGS}
TSingular_LDADD = ${top_builddir}/libpolys/reporter/libreporter.la \
${top_builddir}/libpolys/misc/libmisc.la ${top_builddir}/omalloc/libomalloc.la \
${top_builddir}/resources/libsingular_resources.la

TSingular_SOURCES = emacs.cc fegetopt.c fegetopt.h feOptTS.inc feOpt.cc
# utils.cc utils.h


#### libparse
libparse_CPPFLAGS = ${AM_CPPFLAGS} -DSTANDALONE_PARSER

libparse_SOURCES = libparse.cc fegetopt.c fegetopt.h utils.cc  utils.h

libparse_LDADD = ${top_builddir}/omalloc/libomalloc.la
libparse_LDFLAGS = -static ${AM_LDFLAGS}

#########################################################
# the Singular library (*.lib files)

include ${srcdir}/singular-libs

singularlibrarydir = ${datadir}/singular
singularlibrary = $(SLIB0:%=LIB/%) $(SLIB1:%=LIB/%) $(PLIBS:%=LIB/%) $(SLIB2:%=LIB/%)
nobase_dist_singularlibrary_DATA = LIB/tst.lib LIB/help.cnf ${singularlibrary}
EXTRA_DIST = grammar.y libparse.ll make_alllib.sh LIB/all.lib.tmpl \
             singular-libs LIB/help.cnf LIB/.singularrc LIB/COPYING \
	     links/slInit_Dynamic.cc

singularalllibrarydir = ${datadir}/singular/LIB
singularalllibrary = all.lib
nobase_dist_singularalllibrary_DATA = all.lib

all.lib: ${srcdir}/make_alllib.sh ${srcdir}/LIB/all.lib.tmpl ${singularlibrary}
	${srcdir}/make_alllib.sh ${srcdir}/LIB/all.lib.tmpl ${SLIB0} ${PLIBS}

########################### TEST #########################
TESTS_ENVIRONMENT = SINGULARPATH='${top_builddir}/Singular/LIB:${top_srcdir}/Singular/LIB:${top_builddir}/libpolys/polys/.libs:${top_builddir}/factory/gftables'
TESTS_ENVIRONMENT += SINGULAR_ROOT_DIR='${top_builddir}'

TESTS=test

check_PROGRAMS=$(TESTS)

test_SOURCES = test.cc
test_LDADD = libSingular.la

#########################################################
# These files are built first
BUILT_SOURCES = feOpt.inc feOptTS.inc feOptES.inc iparith.inc all.lib gftables MOD
CLEANFILES = $(BUILT_SOURCES) $(EXTRA_PROGRAMS)

clean-local:
	if [ "${abs_builddir}" != "${abs_srcdir}" ]; then \
	  if [ -L ${abs_builddir}/LIB ]; then unlink ${abs_builddir}/LIB; fi \
	fi

feOpt.inc: feOptGen$(EXEEXT)
	${builddir}/feOptGen$(EXEEXT)

feOptES.inc: feOptES$(EXEEXT)
	${builddir}/feOptES$(EXEEXT)

feOptTS.inc: feOptTS$(EXEEXT)
	${builddir}/feOptTS$(EXEEXT)

iparith.inc: gentable1$(EXEEXT) table.h
	${builddir}/gentable1$(EXEEXT)

# # fake rule to fix parallel make http://www.gnu.org/s/hello/manual/automake/Multiple-Outputs.html

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

${abs_builddir}/LIB: ${srcdir}/LIB
	if [ "${abs_builddir}" != "${abs_srcdir}" ]; then \
	  ln -snf ${abs_srcdir}/LIB ${abs_builddir}/; \
	fi

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

echoLIBS:
	@echo ${SLIB0} ${SLIB1} ${SLIB2} ${PLIBS}

