######################################################################
# Globally Distributed Content (Using BGP to Take Over the World)
# Paper based on work on Super Sparrow - http://superpsparrow.org/
#
# November 2000
# Copyright (C) 2000 Horms <horms@vergenet.net>
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307  USA
#
######################################################################

######################################################################
# Change these at will
######################################################################

PACKAGE  = ss_paper
MAJOR    = 0
MINOR    = 0
PATCH    = 1

EXTRA_DIST=COPYING Makefile
STUFF_RELEASE = /home/horms/public_html/linux/supersparrow/$(PACKAGE)/stuff
HTML_RELEASE = /home/horms/public_html/linux/supersparrow/$(PACKAGE)/html

######################################################################
# No user servicable parts below here
######################################################################


TEX=$(wildcard *.tex)
EPS=$(wildcard *.eps)
GIF=$(EPS:.eps=.gif)
BIB=$(wildcard *.bib)
BBL=$(BIB:.bib=.bbl)
HTML_GIF=html/img1.gif html/img2.gif html/img3.gif html/img4.gif
HTML_PATCH=node16.html.patch
HTML_SUBST=$(wildcard html.substitute/*)

DISTNAME     = $(PACKAGE)-$(MAJOR).$(MINOR).$(PATCH)
DISTFILES    = $(TEX) $(EPS) $(BIB) $(EXTRA_DIST) $(HTML_PATCH) \
		$(HTML_SUBST)


DVIPS   = dvips
LATEX   = latex
BIBTEX  = bibtex
MPAGE   = mpage -2
RM      = rm -f
MKDIR   = mkdir -p
CP      = cp
TAR     = tar
GZIP    = gzip
ECHO    = echo
PS2PDF  = ps2pdf
BZIP2   = bzip2
CHMOD   = chmod
TOUCH   = touch
LATEX2HTML = latex2html -dir html -no_images
CONVERT = convert
PATCH_CMD = patch
CAT     = cat
CD	= cd

PS=$(PACKAGE).ps
PS_SMALL=$(PACKAGE).small.ps
PDF=$(PACKAGE).pdf
DVI=$(PACKAGE).dvi
TEX_ROOT=$(PACKAGE).tex

.PHONY = all clobber clean dvi ps pdf release html

all: $(PACKAGE).dvi

clobber:
	$(RM) $(GIF) $(PS) $(PS_SMALL) $(DVI) $(PDF) $(AUX) $(BBL) $(ALL) \
		$(DISTNAME).tar.gz *.marker 
	$(RM) -r release html

clean:
	$(RM) $(DVI)

dvi: $(DVI)

ps: $(PS) $(PS_SMALL)

pdf: $(PDF)

html: html.marker $(HTML_GIF)

$(DVI): $(TEX) $(BBL)
	$(LATEX) $*

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

%pdf: %ps
	$(PS2PDF) $< $@

%.small.ps: %.ps
	$(MPAGE) $< > $@

%.bbl: %.bib
	$(LATEX) $*
	$(BIBTEX) $*
	$(LATEX) $*

release: release.marker

release.marker: $(PDF) html $(DISTNAME).tar.gz
	$(RM) -r $(STUFF_RELEASE) $(HTML_RELEASE)
	$(MKDIR) -p $(STUFF_RELEASE) $(HTML_RELEASE)
	$(CHMOD) 711 $(STUFF_RELEASE) $(HTML_RELEASE)
	$(CP) $(DISTNAME).tar.gz $(STUFF_RELEASE)/$(PACKAGE).tar.gz
	$(CP) $(PDF) $(PS) $(STUFF_RELEASE)
	$(GZIP) -d $(STUFF_RELEASE)/$(PACKAGE).tar.gz
	$(BZIP2) $(STUFF_RELEASE)/{$(PACKAGE).tar,$(PS)}
	$(CHMOD) 644 \
		$(STUFF_RELEASE)/{{$(PACKAGE).tar,$(PS)}.bz2,$(PDF)}
	$(CP) html/[^C][^V][^S]* $(HTML_RELEASE)/
	$(CHMOD) 644 $(HTML_RELEASE)/*
	$(TOUCH) release.marker
	
html.marker: $(TEX) html.substitute/
	$(LATEX2HTML) $(TEX_ROOT)
	$(RM) -r html/l2h*/
	$(RM) -r $(HTML_GIF)
	$(CP) html.substitute/[^C][^V][^S]* html/
	$(CAT) $(HTML_PATCH) | $(PATCH_CMD) -p 0 
	$(TOUCH) $@

dist: $(DISTNAME).tar.gz

$(DISTNAME).tar.gz: $(DISTFILES)
	$(RM) -rf $(DISTNAME)/
	$(MKDIR) $(DISTNAME)/
	@for i in $(DISTFILES); do \
		dir=`dirname $$i`; \
		file=`basename $$i`; \
		if [ ! -e $(DISTNAME)/$$dir ]; then \
			echo $(MKDIR) -p $(DISTNAME)/$$dir; \
			$(MKDIR) -p $(DISTNAME)/$$dir; \
		fi; \
		echo $(CP) $$i $(DISTNAME)/$$dir; \
		$(CP) $$i $(DISTNAME)/$$dir; \
	done
	$(TAR) -cf $(DISTNAME).tar $(DISTNAME)/
	$(RM) -f $(DISTNAME).tar.gz
	$(GZIP) $(DISTNAME).tar
	$(RM) -rf $(DISTNAME)/
	@$(ECHO) "############################################################"
	@$(ECHO) "# $(DISTNAME).tar.gz is ready for distribution"
	@$(ECHO) "############################################################"


#abc_apache.gif: abc_apache.eps
#	$(CONVERT) -crop 0x0+3+3 -geometry 614x433! $< $@
#
#abc_dns.gif: abc_dns.eps
#	$(CONVERT) -crop 0x0+3+3 -geometry 605x320! $< $@
#
#abc_pop.gif: abc_pop.eps
#	$(CONVERT) -crop 0x0+3+3 -geometry 605x530! $< $@
#
#abc_transit.gif: abc_transit.eps
#	$(CONVERT) -crop 0x0+3+3 -geometry 605x320! $< $@

%.gif: %.eps
	$(CONVERT) -crop 0x0+3+3 -geometry 85% $< $@


html/img4.gif: abc_apache.gif
	$(CP) $< $@
	$(CHMOD) a+r $@

html/img3.gif: abc_dns.gif
	$(CP) $< $@
	$(CHMOD) a+r $@

html/img2.gif: abc_pop.gif
	$(CP) $< $@
	$(CHMOD) a+r $@

html/img1.gif: abc_transit.gif
	$(CP) $< $@
	$(CHMOD) a+r $@
