INTERPSYS=$(axiom_build_bindir)/interpsys
DATABASES_SHORT=compress.daase interp.daase browse.daase category.daase \
                operation.daase libdb.text comdb.text USERS.DAASE/index.KAF \
                DEPENDENTS.DAASE/index.KAF
DATABASES=$(addprefix $(axiom_targetdir)/algebra/, $(DATABASES_SHORT))

subdir = src/etc/

pamphlets = Makefile.pamphlet $(asq_SOURCES)


.PHONY: all all-asq
all: all-ax

all-ax all-asq: 
	if [ -f ../algebra/use_lisp ] ; then \
	  ${MAKE} BUILD_WAY=use_lisp stamp; \
	else \
	  ${MAKE} BUILD_WAY=normal stamp ; \
	fi
	@echo finished $(builddir)

stamp: stamp-databases $(axiom_target_bindir)/asq$(EXEEXT) \
		$(axiom_target_libdir)/summary \
		$(axiom_target_libdir)/copyright \
		$(axiom_target_bindir)/axiom \
		$(axiom_target_bindir)/fricas \
                $(axiom_target_libdir)/SPADEDIT \
                $(axiom_target_docdir)/spadhelp/help.help
	-rm -f stamp
	$(STAMP) stamp

ifeq ($(BUILD_WAY),use_lisp)
stamp-databases:
	cp $(axiom_src_datadir)/algebra/*.daase $(axiom_targetdir)/algebra
	cp $(axiom_src_datadir)/algebra/libdb.text $(axiom_targetdir)/algebra
	cp $(axiom_src_datadir)/algebra/comdb.text $(axiom_targetdir)/algebra
	-mkdir $(axiom_targetdir)/algebra/USERS.DAASE \
             $(axiom_targetdir)/algebra/DEPENDENTS.DAASE
	cp $(axiom_src_datadir)/algebra/USERS.DAASE/index.KAF \
             $(axiom_targetdir)/algebra/USERS.DAASE
	cp \
	  $(axiom_src_datadir)/algebra/DEPENDENTS.DAASE/index.KAF \
             $(axiom_targetdir)/algebra/DEPENDENTS.DAASE
	-rm -f stamp-databases
	$(STAMP) stamp-databases
endif

ifneq ($(BUILD_WAY),use_lisp)

# The databases are built in this Makefile even though the prerequisits
# are actually made during the previous step in the algebra directory.
# This allows us to use a simple wildcard to express the fact that
# all of the 'algebra/*.NRLIB/*.$(FASLEXT)' files are required in
# order to build the databases. If any if any of these are changed,
# the databases must be re-built.

stamp-databases: ../algebra/*.NRLIB/*.$(FASLEXT)
	@ echo 4 rebuilding databases...
	(cd ../algebra ; \
           echo ')lisp (make-databases "" nil)' | AXIOM=$(AXIOM) ${INTERPSYS} )
	cp ../algebra/*.daase $(axiom_targetdir)/algebra
	cp ../algebra/libdb.text $(axiom_targetdir)/algebra
	cp ../algebra/comdb.text $(axiom_targetdir)/algebra
	-mkdir $(axiom_targetdir)/algebra/USERS.DAASE \
             $(axiom_targetdir)/algebra/DEPENDENTS.DAASE
	cp ../algebra/USERS.DAASE/index.KAF \
                   $(axiom_targetdir)/algebra/USERS.DAASE
	cp ../algebra/DEPENDENTS.DAASE/index.KAF \
                   $(axiom_targetdir)/algebra/DEPENDENTS.DAASE
	-rm -f stamp-databases
	$(STAMP) stamp-databases
endif
bin_PROGRAMS = asq$(EXEEXT)
asq_sources = asq.c
asq_SOURCES = $(addsuffix .pamphlet, $(asq_sources))
asq_objects = $(asq_sources:.c=.$(OBJEXT))

$(axiom_target_bindir)/asq$(EXEEXT): asq.c $(axiom_c_macros_h)
	@echo 4 making $@ from $<
	${CC} ${CCF} $(axiom_includes) -o $@ asq.c

asq.c: $(srcdir)/asq.c.pamphlet
	$(axiom_build_document) --tangle --output=$@ $<

$(axiom_target_libdir)/summary: $(srcdir)/summary
	cp $< $@ 

$(axiom_target_libdir)/copyright: $(srcdir)/copyright
	cp $< $@ 

$(axiom_target_docdir)/spadhelp/help.help:
	if [ -f $(axiom_src_datadir)/spadhelp/help.help ] ; then \
	   cp $(axiom_src_datadir)/spadhelp/* \
	      $(axiom_target_docdir)/spadhelp ; \
	else \
	   echo "Help files not installed" > $@ ; \
	fi

$(axiom_target_libdir)/SPADEDIT: $(srcdir)/spadedit.pamphlet
	$(axiom_build_document) --tangle --output=$@ $<
	chmod +x $@

$(axiom_target_bindir)/fricas: $(srcdir)/fricas
	cp $< $@
	chmod +x $@

$(axiom_target_bindir)/axiom: $(srcdir)/fricas
	@echo 1 making $@ from $<
	cp $< $@
	chmod +x $(axiom_target_bindir)/axiom

mostlyclean-local:
	-rm -f $(asq_sources) $(asq_objects)
	-rm -f stamp stamp-databases

clean-local: mostlyclean-local
	-rm -f $(axiom_target_libdir)/summary
	-rm -f $(axiom_target_libdir)/copyright
	-rm -f $(axiom_target_bindir)/axiom
	-rm -f $(axiom_target_bindir)/asq$(EXEEXT)

distclean-local: clean-local
