# -*- makefile-gmake -*-

# @configure_input@
all: initialize phase1
include ../../include/config.Makefile
VPATH = @srcdir@
srcdir = $(shell cd @srcdir@; /bin/pwd)

USER ?= unknown-user

all: initialize
Makefile: Makefile.in ; cd ../.. && ./config.status Macaulay2/m2/Makefile
##############################
.SUFFIXES: .m2
.PHONY: html initialize prep tags install-tmp
# there is a parallel list of tutorials in overview3.m2
DUMPEDM2FILES := Core.m2 startup.m2
DUMPEDM2SRCFILES := Core.m2 startup.m2.in
DUMPEDM2DOCFILES := \
		@srcdir@/../packages/Macaulay2Doc/*.m2 \
		@srcdir@/../packages/Macaulay2Doc/functions/*.m2 \
		@srcdir@/../packages/Macaulay2Doc/operators/*.m2 \
		../packages/Macaulay2Doc.m2
OTHERM2FILES := sagbi.m2
############################## loadsequence
LOADSEQUENCE := $(shell cat @srcdir@/loadsequence)
DUMPEDM2FILES += $(LOADSEQUENCE)
DUMPEDM2SRCFILES += $(patsubst version.m2, version.m2.in, $(LOADSEQUENCE))
############################## mpcodes.m2
ifdef MP
mpcodes.m2: ../../include/MP.h mpcodes.sed
	sed -f mpcodes.sed $< > $@
all: mpcodes.m2
DUMPEDM2FILES += mpcodes.m2
endif
############################## tvalues.m2
STOP = --stop
ARGS = -q --silent $(STOP) -e errorDepth=0
DUMPEDM2FILES += tvalues.m2
TVFILES := $(wildcard @srcdir@/../d/*.d)
all: tvalues.m2
tvalues.m2: @srcdir@/tvalues-make.m2 $(TVFILES)
	@pre_exec_prefix@/bin/M2 $(ARGS) --no-preload --no-tvalues $< -e 'make "@srcdir@/../d/"; exit 0'
clean::;rm -f tvalues.m2
############################## installedpackages.m2
# an obsolete file
INSTALLEDPACKAGES := $(shell cat @srcdir@/installedpackages)
clean::; rm -f installedpackages.m2
OTHERDUMPEDM2FILES += \
	$(wildcard $(patsubst %, @srcdir@/../packages/%/*.m2, $(INSTALLEDPACKAGES))) \
	$(wildcard $(patsubst %, @srcdir@/../packages/%.m2  , $(INSTALLEDPACKAGES)))
#################################
all: tags
tags: Makefile @srcdir@/TAGS @srcdir@/TAGS.doc
clean::; rm -f TAGS @srcdir@/TAGS @srcdir@/TAGS.doc
@srcdir@/TAGS: \
		$(DUMPEDM2SRCFILES) \
		installedpackages \
		$(OTHERM2FILES) \
		$(shell @FIND@ @srcdir@/../packages -name "*.m2" -a -not -name .\#\* | sort) \
		../editors/emacs/make-M2-emacs-help.m2 \
		../editors/make-M2-symbols.m2 \
		@srcdir@/../*/COPYRIGHT \
		@srcdir@/basictests/*.m2 \
		@srcdir@/../packages/*.m2 \
		@srcdir@/../packages/*/*.m2 \
		@srcdir@/../tests/*/*.m2 \
		@srcdir@/../packages/SimpleDoc/doc.txt \
		loadsequence \
		Makefile.in \
		../editors/Makefile.in \
		../tests/Makefile.in \
		../tests/Makefile.test.in \
		../tests/slow/Makefile.in \
		../tests/engine/Makefile.in \
		../packages/Makefile.in \
		../../Makefile ../../GNUmakefile.in
	: making $@
	@ set -e ; \
	  cd @srcdir@ && \
	  for i in $(patsubst @srcdir@/%, "%", $^) ; \
	  do [ -f $$i ] || (echo "file not found: $$i" >&2; exit 1) ; echo  ; echo $$i,0 ; done >TAGS

@srcdir@/TAGS.doc: Makefile.in $(shell @FIND@ @srcdir@/../packages/Macaulay2Doc -not \( -name .svn -prune \) -type d)
	: making $@ : $^
	@ set -e ; \
	  cd @srcdir@ && \
	  @FIND@ ../packages/Macaulay2Doc -name '*.m2' | while read i ; do echo  ; echo $$i,0 ; done >TAGS.doc
clean::; rm -f TAGS.doc
prep:: $(DUMPEDM2FILES)

phase1:: prep

# try to eliminate this intermediate file:
phase1:: .Macaulay2-made
.Macaulay2-made: $(DUMPEDM2FILES) $(DUMPEDM2DOCFILES) @pre_exec_prefix@/bin/M2@EXE@
	touch $@
clean::; rm -f .Macaulay2-made
initialize: .gdb-directories .gdbinit .gdb-files
gdb: .gdb-directories .gdbinit .gdb-files
	LD_LIBRARY_PATH="$(BUILTLIBPATH)/lib:$(LD_LIBRARY_PATH)" gdb @pre_exec_prefix@/bin/M2@EXE@
.gdbinit: .gdbinit.$(USER); cp $< $@
clean::; rm -f .gdb-directories
.gdb-directories: ../../libraries/* Makefile
	echo '# -*- sh -*-' >$@
	/bin/echo 'echo -- loading .gdb-directories\n' >>$@
	for i in \
		../../libraries/*/build/*/. \
		../../libraries/ntl/build/*/src/. \
		../../libraries/libfac/build/*/factor/. \
		../../libraries/libfac/build/*/charset/. \
		;\
	do if [ -d $$i ] ;\
	   then echo directory $$i >>$@ ;\
	   fi ;\
	done
	/bin/echo 'echo -- loaded .gdb-directories\n' >>$@
.gdbinit.$(USER):; touch $@
clean::; rm -f .gdbinit
.gdb-files: Makefile
	echo '# -*- sh -*-' >$@
	/bin/echo 'echo -- loading .gdb-files\n' >>$@
	echo 'set environment LD_LIBRARY_PATH $(BUILTLIBPATH)/lib:$(LD_LIBRARY_PATH)' >>$@
	echo 'file @pre_exec_prefix@/bin/M2@EXE@' >>$@
	/bin/echo 'echo -- loaded .gdb-files\n' >>$@
clean::; rm -f .gdb-files
profile: gmon.out; LD_LIBRARY_PATH="$(BUILTLIBPATH)/lib:$(LD_LIBRARY_PATH)" gprof @pre_exec_prefix@/bin/M2@EXE@ >profile
clean::; rm -f profile
@pre_packagesdir@ :; @INSTALL@ -d $@
@pre_packagesdir@/Core  : ; @INSTALL@ -d $@
@pre_packagesdir@/Core/% : % ; @INSTALL_DATA@ $^ $@
FILES_TO_COPY := $(DUMPEDM2FILES) loadsequence installedpackages
all:@pre_packagesdir@ @pre_packagesdir@/Core $(addprefix @pre_packagesdir@/Core/, $(FILES_TO_COPY))
clean::; rm -rf cache *.obj *.exe runexample temp.data distfiles loads.m2 mpcodes.m2 core gmon.out
distclean: clean; rm -f Makefile version.m2
# Local Variables:
# compile-command: "make -C $M2BUILDDIR/Macaulay2/m2 "
# End:
.NOTPARALLEL:
