########################################################################
# Creating a installed version of KOMA-Script
# Copyright (c) Markus Kohm, 1998-12-01
#
#>>>> USE THIS ONLY, IF THERE IS A TDS-COMPATIBLE TEX-INSTALLATION! <<<<
#>>>>     DO NOT CHANGE ANYTHING BUT THE CUSTOMIZATION SECTION!     <<<<
#
# Definined rules:
#   default   default rule if make is called without parameter,
#             generates all KOMA-Script-files.
#   all       same as default but without TEXMF-test
#   adrguide  generates original adrguide
#   scrguide  generates scrguide
#   screnggu  generates english scrguide
#   install   installs all files in a TDS-tree
#   clean     deletes all generated files from default and adrguide
#             and all not needed files from scrguide and screnggu.
#   tar       generates a tar file koma-script.tar.gz with all
#             source-files
########################################################################

########################################################################
#   Start of customization section
########################################################################

# The texmf-directory, where to install new stuff (see texmf.cnf)
# If you don't know what to do, search for directory texmf at /usr.
# With teTeX and linux often following is used:
# TEXMF=/usr/TeX/texmf
TEXMF=

# If texhash must run after installation, you can invoke this:
#TEXHASH=texhash

######### Edit following only, if you want to change defaults!

# The directory, where to install *.cls and *.sty
CLSDIR=$(TEXMF)/tex/latex/koma-script

# The directory, where to install documentation
DOCDIR=$(TEXMF)/doc/latex/koma-script

# The directory, where to install demo-files
DEMODIR=$(DOCDIR)/demo

########################################################################
#   End of customization section                     
########################################################################

LATEX      = latex
RM         = rm -f
INSTALL    = install
MKDIR      = mkdir
MAKEINDEX  = makeindex -g -r -s scrguide.ist
DVIPS      = dvips -Plj3
ECHO       = echo
TARCREATE  = tar -zcvf
LL         = ls -l

LOGMESSAGE = KOMA-Script was made at `date`.
GERMREADME = 'Wenn Sie Deutsch verstehen, lesen Sie bitte liesmich.txt.'
ENGREADME  = 'If you do not understand german, read readme.txt.'

########################################################################

NEWS_FILES  = scr_new1.tex \
              scr_new2.tex \
              scr_new3.tex \
              scr_new4.tex \
              scr_new5.tex \
              scr_new6.tex \
              scr_new7.tex \
              scr_new8.tex \
              scr_new9.tex \
              scrnew10.tex \
              scrnew11.tex \
              scrnew12.tex \
              scrnew13.tex \
              scrnew14.tex \
              scrnew15.tex \
              scrnew16.tex \
              scrnew17.tex

GUIDE_FILES = scrguide.tex \
              scrguide.dvi \
              scrguide.ps  \
              scrguide.ist \
              scrguide.ind                  

ENGU_FILES  = scrguide-english/screnggu.ps  \
              scrguide-english/screnggu.dvi \
              scrguide-english/screnggu.tex \
              scrguide-english/screnggu.ind \

RSRC_FILES  = komascr.ins    \
              scrclass.ins   \
              scrclass.dtx   \
              scrlettr.dtx   \
              adrguide.tex   \
              script20.dtx   \
              scrtime.ins    \
              scrtime.dtx    \
              scrpage.ins    \
              scrpage.dtx

SRC_FILES   = $(RSRC_FILES)  \
              $(NEWS_FILES)  \
              $(GUIDE_FILES) \
              $(ENGU_FILES)  \
              liesmich.txt   \
              readme.txt     \
	      LEGAL.TXT      \
              LEGALDE.TXT    \
              INSTALL.TXT    \
              INSTALLD.TXT   \

CLS_FILES   = scrartcl.cls \
              scrreprt.cls \
              scrbook.cls  \
              typearea.sty \
              scrlettr.cls \
              script.sty   \
              script_s.sty \
              script_l.sty \
              scrtime.sty  \
              scrdate.sty  \
              scrpage.sty

DOC_FILES   = scrguide.tex                  \
              scrguide.dvi                  \
              scrguide.ps                   \
              scrguide.ist                  \
              scrguide.ind                  \
              scrguide-english/screnggu.tex \
              scrguide-english/screnggu.dvi \
              scrguide-english/screnggu.ps  \
              scrguide-english/screnggu.ind \
              liesmich.txt                  \
              readme.txt                    \
              komabug.tex                   \
              adrguide.tex                  \
              adrguide.dvi                  \
              LEGAL.TXT                     \
              LEGALDE.TXT                   \
              INSTALL.TXT                   \
              INSTALLD.TXT                  \
              $(NEWS_FILES)                 \
              ${NEWS_FILES:.tex=.dvi}

DEMO_FILES  = phone.tex    \
              dir.tex      \
              addrconv.bst \
              addrconv.tex \
              birthday.bst \
              birthday.tex \
              email.bst    \
              email.tex    \
              example.bib

########################################################################
 
default:
	@if test ! "$(TEXMF)"; then \
	  $(ECHO) "Destination directories not set." ; \
	  $(ECHO) "Please edit TEXMF at the Makefile first!"; \
	  exit 1 ; \
	else \
	  $(MAKE) all ; \
	fi

all: komascript.log adrguide scrguide scrguide-english

komascript.log: $(SRC_FILES) ${NEWS_FILES:.tex=.dvi}
	$(LATEX) komascr.ins
	$(ECHO) $(LOGMESSAGE) > komascript.log

scr_new%.dvi: scr_new%.tex
	$(LATEX) $<

scrnew%.dvi: scrnew%.tex
	$(LATEX) $<

adrguide: adrguide.dvi

adrguide.dvi: adrguide.tex
	$(LATEX) adrguide.tex
	$(LATEX) adrguide.tex

scrguide: scrguide.dvi scrguide.ps

scrguide.dvi: scrguide.tex
	$(LATEX) scrguide.tex
	$(LATEX) scrguide.tex
	$(MAKEINDEX) scrguide.idx
	$(LATEX) scrguide.tex

scrguide.ps: scrguide.dvi
	$(DVIPS) -o scrguide.ps scrguide.dvi

screnggu: scrguide-english

scrguide-english: scrguide-english/screnggu.dvi \
                  scrguide-english/screnggu.ps

scrguide-english/screnggu.dvi: scrguide-english/screnggu.tex
	cd scrguide-english && $(LATEX) screnggu.tex
	cd scrguide-english && $(LATEX) screnggu.tex
	$(MAKEINDEX) scrguide-english/screnggu.idx
	cd scrguide-english && $(LATEX) screnggu.tex

scrguide-english/screnggu.ps: scrguide-english/screnggu.dvi
	cd scrguide-english && $(DVIPS) -o screnggu.ps screnggu.dvi


########################################################################

install: komascript.log
	-$(MKDIR) $(CLSDIR)
	$(INSTALL) $(CLS_FILES) $(CLSDIR)
	-$(MKDIR) $(DOCDIR)
	$(INSTALL) $(DOC_FILES) $(DOCDIR)
	-$(MKDIR) $(DEMODIR)
	$(INSTALL) $(DEMO_FILES) $(DEMODIR)
	@if test ! "$(TEXHASH)" ; then \
	  echo "Maybe you have to run texhash or something else, now.";\
	else \
	  $(TEXHASH); \
	fi

########################################################################

clean: 
	$(RM) *.aux *.log *.idx *.gls *.ilg *.toc *.cls *.sty *.bst  \
              scr_new?.dvi scrnew*.dvi addrconv.* email.* birthday.* \
              example.* dir.tex phone.tex komascript.log adrguide.dvi

########################################################################

tar: 00README 00CONTEN $(SRC_FILES) Makefile.unx
	$(TARCREATE) koma-script.tar.gz 00CONTEN 00README $(SRC_FILES) \
                     Makefile.unx

srctar: $(SRC_FILES)
	$(TARCREATE) koma-script-src.tar.gz $(RSRC_FILES) \
	             scrguide.tex scrguide.ist liesmich.txt readme.txt

00CONTEN: 00README $(SRC_FILES) Makefile.unx
	$(LL) 00README $(SRC_FILES) Makefile.unx > 00CONTEN

00README:
	$(ECHO) $(GERMREADME) > 00README
	$(ECHO) $(ENGREADME) >> 00README

######################################################################## 
