# Copyright 1995 Massachusetts Institute of Technology

all_subdirs:
	@sub="$(SUBDIRS)"; \
	for i in $$sub; do if test -n "$$i"; then \
	      (cd $$i; $(MAKE)  all); \
	fi; done;

clean:
	@sub="$(SUBDIRS)"; \
	for i in $$sub; do if test -n "$$i"; then \
	      (cd $$i; $(MAKE) build_top=$(build_top)/$$i $@); \
	fi; done;
	$(RM) $(DIRT)


#install: default
#	@sub="$(SUBDIRS)"; \
#	for i in $$sub; do if test -n "$$i"; then \
#	      (cd $$i; make $@); \
	fi; done;
#	@make localinstall

#incdepend: .dependtime
#depend: .dependtime

#.dependtime: $(SOURCES)
#	touch temp
#	$(MKDEPEND) $(MKDEPC++FLAGS) -f temp $(C++FILES)
#	touch $(MKDEPFILE)
#	$(MKDEPEND) $(MKDEPCFLAGS) -f $(MKDEPFILE) $(CFILES)
#	cat temp >> $(MKDEPFILE)
#	rm -f temp temp.bak
#	touch $@

# must add a dependency like
#    foo.dvi: foo.stamp
# to use this rule properly.
#
# The line that runs LATEX needs to run inside a subshell to turn off
# "make"'s status checking. It blows away .aux because the .aux file
# created is bad and also breaks bibtex. It touches .stamp to force a
# rebuild.
.tex.dvi:
	$(TEXSTAMP) $< > $*.stampold
	@echo "Running latex..."
	@sh -c "$(LATEX) $< || (rm -f $*.aux; sleep 1; touch $*.stamp; exit 1)"
	$(TEXSTAMP) $< > $*.stamp
	@-cmp -s $*.stamp $*.stampold; \
	if [ $$? = "1" ]; \
	then \
	    sleep 1; \
	    echo "==> Rebuilding $@"; \
	    touch $*.stamp; \
	    $(MAKE) $@; \
	else \
	    echo "==> No need to rebuild $@"; \
	    if [ -r $*.ind ]; then touch $*.ind; fi; \
	    if [ -r $*.bbl ]; then touch $*.bbl; fi; \
	    touch $@; \
	fi
	@rm -f $*.stampold

# must add dependencies like
#    foo.ind: foo.stamp
#    foo.dvi: foo.ind
# to use this rule properly.
.tex.ind:
	@if [ -f $*.idx ]; then \
	   echo makeindex $*.idx; \
	   makeindex $*.idx; \
	else \
	   echo touch $@; \
	   touch $@; \
        fi

# must add dependencies like
#    foo.bbl: foo.stamp foo.bib
#    foo.dvi: foo.bbl
# to use this rule properly.
.tex.bbl:
	@if [ -r $*.aux ]; then echo bibtex $*; sh -c "bibtex $* || echo"; else echo; fi

.tex.stamp:
	touch $@

.dvi.ps:
	$(DVIPS) $(DVIPSOPTS) $< -o $@

.C.i:
	$(C++F) -E $< > $@

.c.i:
	$(CCF) -E $< > $@

$(DOCDIR)/%.h.tex::%.h
	$(GRIND) -tex -o $@ $<


.C.o:
	$(C++F) -c $<




