subdir = src/paste/
pamphlets = Makefile.pamphlet

TAXDIR = $(axiom_targetdir)
THTDIR = $(axiom_target_datadir)/hypertex/pages
SMAN = $(axiom_target_bindir)/sman
IN=     $(axiom_src_srcdir)/input
HTADD=$(axiom_target_bindir)/htadd

# need NAG libraries
NAGPHTS = ANNA-ES ug15

# exint gives wrong results
PHTS = ALIST ARRAY1 ARRAY2 BBTREE BINARY BOP BSTREE CARD CARTEN CCLASS \
       CHAR CLIF COMPLEX CONTFRAC CYCLES DECIMAL DERHAM DFLOAT DMP \
       EQ EQTBL EXIT EXPR FARRAY FILE FLOAT FNAME FPARFRAC FR FR2 \
       FRAC GBF GSTBL HEAP HEXADEC INT INTHEORY KAFILE KERNEL LAZM3PK \
       LEXP LEXTRIPK LIB LIST LODO LODO1 LODO2 LPOLY LWORD MAGMA \
       MAPPKG1 MATRIX MKFUNC MPOLY MSET NONE OCT ODPOL OP OVAR PERMAN \
       PFR POLY QUAT QUAT2 RADIX RECLOS REGSET ROMAN \
       SEG SET SINT SQMATRIX SREGSET \
       STBL STREAM STRING STRTBL SYMBOL TABLE TEXTFILE UNISEG UP \
       VECTOR VOID WUTSET XPBWPOLY XPOLY XPR ZDSOLVE ZLINDEP evalex exdiff \
       exlap exlimit exmatrix exseries exsum function grpthry \
       numbers polys ug02 ug03 ug04 ug05 ug06 ug12 ug13

GPHTS = SEGBIND explot2d coverex explot3d graphics \
        ug01 ug07 ug08 ug10 ug11

.PHONY: all nphts gphts

# FriCAs can precompute output and images for later use by
# HyperDoc (see HyperDoc page HTXAdvPage5 and 'src/hyper/htinp.pamphlet').
# This capability is used here to generate most '.pht' used by HyperDoc.

# Without acces to X server we can build only normal pages
all:
	(cd $(THTDIR); \
	  rm -f ht.db ; \
	  ${HTADD} *.ht)
	if [ -f copy_nphts ] ; then \
	   ${MAKE} copy-nphts ; \
	else \
	   $(MAKE) nphts ; \
	fi
	if [ -f copy_gphts ] ; then ${MAKE} copy-gphts ; fi
	(cd $(THTDIR); \
	  rm -f ht.db ; \
	  ${HTADD} *.ht *.pht )

nphts: $(addprefix $(THTDIR)/, $(addsuffix .pht, $(PHTS)))

gphts: $(addprefix $(THTDIR)/, $(addsuffix .pht, $(GPHTS))) mobius.VIEW
	cp -r *.VIEW $(axiom_target_datadir)/viewports

copy-nphts:
	for A in $(addsuffix .pht, $(PHTS)); do \
	  cp $(srcdir)/$${A} $(THTDIR) ; \
	done

copy-gphts:
	for A in $(addsuffix .pht, $(GPHTS)); do \
	  cp $(srcdir)/$${A} $(THTDIR) ; \
	done
	cp -r $(srcdir)/*.VIEW $(axiom_target_datadir)/viewports

GRINPUTS = bouquet.input vectors.input arrows.input ribbon.input newton.input

ug10.pht: $(GRINPUTS)

$(GRINPUTS):  %.input : $(IN)/%.input.pamphlet
	$(axiom_build_document) --tangle --output=$@ $<

$(addprefix $(THTDIR)/, $(addsuffix .pht, $(PHTS) $(GPHTS))): \
    $(THTDIR)/%.pht : %.pht
	cp $< $@

# -noihere works around race in session
$(addsuffix .pht, $(PHTS)): %.pht : $(THTDIR)/%.ht
	(AXIOM=$(TAXDIR); LC_CTYPE=ISO-8859-1; export AXIOM LC_CTYPE; \
         unset DAASE; $(SMAN) -noihere -paste $<)

# -noihere works around race in session
$(addsuffix .pht, $(GPHTS)): %.pht : $(THTDIR)/%.ht
	(AXIOM=$(TAXDIR); export AXIOM; \
         unset DAASE; $(SMAN) -noihere -paste $<)

mobius.input: $(IN)/mobius.input
	cp $< $@

# Clumsy, there should be better way.
mobius.VIEW: mobius.input
	echo '#!/bin/sh' > mob-ax
	echo '$(TAXDIR)/bin/AXIOMsys < mobius.input' >> mob-ax
	chmod u+x mob-ax
	(export AXIOM=$(TAXDIR); unset DAASE; $(SMAN) -noht -noclef \
            -ws ./mob-ax)

mostlyclean-local:
	if [ ! -f copy_gphts ] ; then \
	    rm -rf *.VIEW ; \
	    rm -f *.pht ; \
	fi
	rm -f mob-ax *.input

clean-local: mostlyclean-local

