# -*- Mode: makefile -*-
# $Id: Makefile,v 1.10 2002/04/07 21:02:14 apharris Exp $

# Makefile for IMHO documentation

SGMLFILES	:= tutorial.sgml
WWWTARGETS	:= $(SGMLFILES:.sgml=.html) $(SGMLFILES:.sgml=_nochunks.html)	\
		   $(SGMLFILES:.sgml=.txt) $(SGMLFILES:.sgml=.pdf)
SGML_VALIDATE	:= nsgmls -E0 -gues

.SUFFIXES: .sgml .html .fig .eps .pdf .txt .rtf .dvi .pic .gif .tiff

.PHONY: default
default:	$(WWWTARGETS)

.PHONY: wwwdist
wwwdist:	default

current-date:	$(wildcard *.sgml)
	date +"%e %b %Y" > $@

.PHONY: tags
tags:	TAGS

TAGS:
	etags *.sgml

-include Makefile.docs

Makefile.docs: Makefile.docs.in
	preheat -o $@ $<

# validate our SGML files
.PHONY: validate
validate:
	@for file in $(SGMLFILES); do				 	 \
		echo "validating $$file"				;\
		$(SGML_VALIDATE) $$file					;\
		echo							;\
	done

# LispDoc - disabled

# CLOSFILES	:= $(wildcard ../*.lisp)
# LISP		:= $(shell if ! command -v cmulisp 2> /dev/null &&	\
# 			! command -v lisp 2> /dev/null &&		\
# 			! command -v clisp 2> /dev/null; then		\
# 			echo you-need-a-lisp-interpreter;		\
# 			echo no lisp interpreter available 1>&2; fi)

# LISP_SYSDIR	:= $(HOME)/lisp/src
# LDOC_DIR	:= $(LISP_SYSDIR)/lispdoc

# .PHONY: docs
# docs: doc.tex imho-manual.tex
# 	echo $(LDOC_DIR)
# 	TEXINPUTS=:$(LDOC_DIR):. latex imho-manual.tex

# # This doesn't work yet: lisp-doc needs to provide 'styles' for its
# # output.

# .PHONY: html-docs
# html-docs: doc.tex imho-manual.tex
# 	echo $(LDOC_DIR)
# 	TEXINPUTS=:$(LDOC_DIR):. latex2html imho-manual.tex

# doc.tex: $(CLOSFILES)
# 	echo '(oos "IMHO" :compile) (oos "LispDoc" :compile)		\
# (with-open-file (doc "doc.tex" :direction :output			\
#                                      :if-exists :supersede)		\
#   (labels ((sep (list string char)					\
# 	     (let ((pos (position char string)))			\
# 	       (if (not pos)						\
# 		   (nreverse (cons string list))			\
# 		   (sep (cons (subseq string 0 pos) list)		\
# 			  (subseq string (+ 1 pos))			\
# 			  char)))))					\
#     (scan-files								\
#       (sep nil (cdr (assoc :scanfiles *environment-list*)) #\ )) doc))	\
# (quit)' | SCANFILES="$(CLOSFILES)" $(LISP)

# make clean shouldn't clean stuff which is normally distributed,
# e.g., the meaningful contents of 'make dist'
.PHONY: clean
clean:
	rm -f *~ *.bak core
#	doc stuff we don't need
	rm -f *.out *.log *.aux

.PHONY: distclean
distclean:	clean
	rm -f current-date *.html
ifneq ($(wildcard Makefile.docs),)
	$(MAKE) preheat-clean
endif
	rm -f Makefile.docs

