
## ----------------------------------------
## -- Old-style Axiom makefile variables --
## ----------------------------------------

COMMAND_DIR=$(DESTDIR)$(libdir)/fricas/target/$(target)/bin
COMMAND=$(COMMAND_DIR)/fricas

pamphlets = configure.ac.pamphlet Makefile.pamphlet

subdir = 

SUBDIRS = src

build_srcdir = $(builddir)/src

AXIOM_SRC_TARGETS = all-algebra all-asq all-axiomsys all-book all-boot \
	all-clef all-doc all-graph all-hyper all-input all-interpsys \
	all-lib all-lisp all-sman all-src

.PHONY: all install $(AXIOM_SRC_TARGETS)
all: all-ax all-contrib

# Generate the efricas script.
all-contrib: all-src
	cd contrib/emacs && ${MAKE}

all-ax: all-src
	@echo finished system build on `date` | tee >lastBuildDate

all-src: stamp-rootdirs @axiom_all_prerequisites@

all-input: all-src

$(AXIOM_SRC_TARGETS):
	cd $(build_srcdir) && $(MAKE) $@

stamp-rootdirs: $(axiom_build_document)
	mkdir -p $(axiom_build_bindir)
	mkdir -p $(axiom_build_libdir)
	mkdir -p $(axiom_target_bindir)
	mkdir -p $(axiom_target_libdir)
	mkdir -p $(axiom_target_docdir)/spadhelp
	mkdir -p $(axiom_target_datadir)/msgs
	mkdir -p $(axiom_target_texdir)
	mkdir -p $(axiom_targetdir)/algebra/
	mkdir -p $(axiom_targetdir)/autoload
	mkdir -p $(axiom_target_srcdir)/algebra
	mkdir -p ${TMP}
	$(STAMP) stamp-rootdirs


.PHONY: all-noweb
all-noweb: stamp-noweb

stamp-noweb:
	@echo Making in noweb
	( mkdir noweb && \
	  cd noweb && \
	  $(TAR) -zxf "@noweb_tarball@" && \
	  cd src && \
	  cat Makefile \
	      | sed -e "s|^BIN=.*|BIN=$(axiom_build_bindir)|" \
                    -e "s|^LIB=.*|LIB=$(axiom_build_libdir)|" \
		    -e "s|^MAN=.*|MAN=$(axiom_build_mandir)|" \
                    -e "s|^TEXINPUTS=.*|TEXINPUTS=$(axiom_target_texdir)|" \
		    -e 's/ make / $$\(MAKE\) /' \
		    -e "s,c/nt,c/nt$(EXEEXT)," \
		    -e "s,c/markup,c/markup$(EXEEXT)," \
		    -e "s,c/mnt,c/mnt$(EXEEXT)," \
		    -e "s,c/finduses,c/finduses$(EXEEXT)," \
	      > Makefile.tmp && mv Makefile.tmp Makefile && \
	  ./awkname $(AWK) && $(MAKE) -j 1 all install )
	$(STAMP) stamp-noweb


book:
	@ echo 79 building the book as $(axiom_target_docdir)/book.dvi 
	mkdir -p ${TMP}
	mkdir -p $(axiom_target_docdir)/ps
	$(INSTALL) $(axiom_src_srcdir)/doc/book.pamphlet $(axiom_target_docdir)
	cp $(axiom_src_srcdir)/doc/ps/* $(axiom_target_docdir)/ps
	(cd $(axiom_target_docdir) ; \
	    latex book.pamphlet --interaction nonstopmode && \
	      latex book.pamphlet --interaction nonstopmode ; \
	  rm book.pamphlet ; \
	  rm book.toc ; \
	  rm book.log ; \
	  rm book.aux )
	@ echo 80 The book is at $(axiom_target_docdir)/book.dvi 

reltarget = target/$(target)

install: install-src install-contrib

install-src:
	@echo Installing FriCAS in $(prefix)
	rm -rf '$(DESTDIR)$(libdir)/fricas'
	$(mkinstalldirs) '$(DESTDIR)$(libdir)/fricas'
	$(mkinstalldirs) '$(DESTDIR)$(libdir)/fricas/$(reltarget)/lib'
	for A in algebra autoload doc share src lib/graph ; do \
	  for B in `find $(reltarget)/$$A -type d -print` ; do \
	     $(mkinstalldirs) '$(DESTDIR)$(libdir)'/fricas/$$B \
	       || exit 1 ; \
	  done ; \
	  for B in `find $(reltarget)/$$A -type f -print` ; do \
	     $(INSTALL_DATA) $$B '$(DESTDIR)$(libdir)'/fricas/$$B \
	       || exit 1 ; \
	  done ; \
	done
	$(mkinstalldirs) '$(DESTDIR)$(libdir)/fricas/$(reltarget)/bin'
	for A in bin/AXIOMsys bin/asq bin/clef bin/htadd bin/hypertex \
	         bin/sman bin/viewAlone lib/ex2ht lib/hthits lib/session \
		 lib/spadbuf lib/spadclient lib/view2D lib/view3D \
		 lib/viewman ; do \
	   if [ -f $(reltarget)/$$A$(EXEEXT) ] ; then \
	      $(INSTALL_PROGRAM) $(reltarget)/$$A$(EXEEXT) \
	         '$(DESTDIR)$(libdir)'/fricas/$(reltarget)/$$A$(EXEEXT) \
		|| exit 1 ; \
	   fi ; \
	done
	if [ -f $(reltarget)/lib/libspad.so ] ; then \
	   $(INSTALL_PROGRAM) $(reltarget)/lib/libspad.so \
	       '$(DESTDIR)$(libdir)'/fricas/$(reltarget)/lib/libspad.so \
	     || exit 1 ; \
	fi
	if [ -f $(reltarget)/lib/gmp_wrap.so ] ; then \
	   $(INSTALL_PROGRAM) $(reltarget)/lib/gmp_wrap.so \
	       '$(DESTDIR)$(libdir)'/fricas/$(reltarget)/lib/gmp_wrap.so \
	     || exit 1 ; \
	fi
	for A in SPADEDIT htsearch presea ; do \
	   if [ -f $(reltarget)/lib/$$A ] ; then \
	      $(INSTALL_SCRIPT) $(reltarget)/lib/$$A \
	        '$(DESTDIR)$(libdir)'/fricas/$(reltarget)/lib/$$A \
	       || exit 1 ; \
	   fi ; \
	done
	for A in command.list copyright summary ; do \
	   $(INSTALL_DATA) $(reltarget)/lib/$$A \
	      '$(DESTDIR)$(libdir)'/fricas/$(reltarget)/lib/$$A \
	     || exit 1 ; \
	done
	echo '#!/bin/sh -' > '${COMMAND}'.tmp
	echo AXIOM="'$(libdir)/fricas/target/$(target)'" >> '${COMMAND}'.tmp
	echo export AXIOM >> '${COMMAND}'.tmp
	echo PATH='$${AXIOM}/bin':'$${PATH}' >> '${COMMAND}'.tmp
	echo export PATH >> '${COMMAND}'.tmp
	cat $(axiom_src_srcdir)/etc/fricas >> '${COMMAND}'.tmp
	$(INSTALL_SCRIPT) '${COMMAND}'.tmp '${COMMAND}'
	-rm '${COMMAND}'.tmp
	$(INSTALL_SCRIPT) '${COMMAND}' '${COMMAND_DIR}/axiom'
	rm -f '$(DESTDIR)$(bindir)'/fricas
	$(mkinstalldirs) '$(DESTDIR)$(bindir)'
	$(INSTALL_SCRIPT) '$(COMMAND)' '$(DESTDIR)$(bindir)/fricas'
	if test x"@BUILD_ALDOR_INTERFACE@" = xyes ; then \
	    cd src/aldor && $(MAKE) install; \
	fi
	@echo 79 FriCAS installation finished.

install-contrib:
	$(mkinstalldirs) '$(DESTDIR)$(bindir)'
	$(mkinstalldirs) '$(DESTDIR)@emacsdatadir@'
	cd contrib/emacs && $(MAKE) install;
	@echo 79 FriCAS contrib installation finished.


mostlyclean-local:
	@-rm -f lastBuildDate

clean-local: mostlyclean-local
	-rm -f stamp-*
	-cd contrib/emacs && ${MAKE} clean
	-rm -rf $(axiom_targetdir)
	-rm -rf build/$(target)

distclean-local: clean-local
	@-rm -rf build
	@-rm -f config.status config.log
	@-rm -f Makefile

$(top_builddir)/config.status: $(top_srcdir)/configure
	$(SHELL) ./config.status --recheck

$(RECURSIVE_TARGETS): stamp-rootdirs @axiom_all_prerequisites@

