########################################################################
# Creating a installed version of KOMA-Script
# Copyright (c) Markus Kohm, 1999-2004
#
#>>>> USE THIS ONLY, IF THERE IS A TDS-COMPATIBLE TEX-INSTALLATION! <<<<
#>>>>     DO NOT CHANGE ANYTHING BUT THE CUSTOMIZATION SECTION!     <<<<
#>>>>                 YOU NEED GNU-MAKE TO RUN THIS!                <<<<
#
# Defined rules for users:
#
#   all       default rule if make is called without parameter,
#             generates all KOMA-Script-files but not the guides
#   install   installs all files in a TDS-tree
#
#   guides    makes all the guides but ps-files 
#   optionalguides
#             like guides but does also make the ps-files
#
#   scrguide2p
#             generates a scrguide2p.ps, a postscript file with two
#             A5 pages together at A5 pages 
#             (doesn't need installation with unmodified maintainer 
#             distribution)
#   scrguide4p
#             generates a scrguide4p.ps, a postscript file with four
#             A5 pages aranged at A4 page for book printing 
#             (doesn't need installation with unmodified maintainer 
#             distribution)
#   scrguide4p16
#             generates a scrguide4p16.ps, a postscript file like 
#             scrguide4p.ps but with signature=16 (see psbook)
#             (doesn't need installation with unmodified maintainer 
#             distribution)
#
#   srcclean  deletes all generated files (but *tar.gz)
#   distclean deletes all generated files (but *tar.gz) not part of 
#             the distribution
#   clean     deletes all temporary files
#
#   dist      generates a tar file koma-script-<date>.tar.gz with all
#             files of the distribution
#             (needs unmodified maintainer distribution)
#
#   texlive   generates a directory structure, which may be copied to
#             TeXLive
########################################################################

########################################################################
#   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 one of following is used:
#INSTALLTEXMF ?= /usr/TeX/texmf
#INSTALLTEXMF ?= /usr/local/TeX/texmf
#INSTALLTEXMF ?= /usr/share/texmf
#INSTALLTEXMF ?= /usr/local/share/texmf
# user tree:
#INSTALLTEXMF ?= $(HOME)/texmf
# Try to use user's tree known by kpsewhich:
#INSTALLTEXMF ?= `kpsewhich --expand-var '$$HOMETEXMF'`
# Try to use the local tree known by kpsewhich:
INSTALLTEXMF ?= `kpsewhich --expand-var '$$TEXMFLOCAL'`
# But you may set INSTALLTEXMF to every directory you want. 
# Use following, if you only want to test the installation:
#INSTALLTEXMF ?= /tmp/texmf

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

# You should change following only, if you want to change defaults!

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

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

# The directory, where to install the sources
SRCDIR=$(INSTALLTEXMF)/source/latex/koma-script

# The directory, where to install demo-files
# If we have some, we have to add following 2 lines to install rule:
#	  $(MKDIR) $(DEMODIR); \
#	  $(INSTALL) $(DEMO_FILES) $(DEMODIR); \
DEMODIR=$(DOCDIR)/demo

# We need this, because the documentation needs the classes and packages
# It's not realy a good solution, but it's a working solution, if no
# KOMA-Script was installed.
TEXINPUTS := $(PWD):$(TEXINPUTS)

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

# Used command:
LATEX      = latex
PDFLATEX   = pdflatex
NONSTOPMODE = \\nonstopmode\\input
BATCHMODE   = \\batchmode\\input
RM         = rm -f
RMDIR      = rm -fr
CP         = cp -f
CPALL      = cp -Rpf
CD         = cd
MV         = mv -f
SYMLINK    = ln -sf
INSTALL    = install -m 644
MKDIR      = install -m 755 -d
MAKEINDEX  = makeindex -g -r -s scrguide.ist
MAKECHANGE = makeindex -g -r -s scrguide.gst -o 
MAKEIDX    = makeindex -g
GENINDEX   = $(PWD)/genindex.pl
BIBTEX     = bibtex
DVIPS      = dvips -Pwww
ECHO       = echo
ECHONONL   = echo -n
TARCREATE  = tar -zcvf
TARCREATEBZ = tar -jcvf
ZIPCREATE  = zip -9o
DIRNAME    = dirname
LL         = ls -l
LLL        = ls -sh1
SED        = sed
CUT        = cut
GREP       = grep
PSSELECT   = psselect
PSBOOK     = psbook
PSTOPS     = pstops
EVAL       = eval

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.'

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

# files needed only for generation of documentation files
RMEXT       = *.log *.aux *.toc *.lot *.lof *.out *.ilg *.idx *.ind \
              *.blg *.bbl *.glg *.glx *.glo *.gls

# documentation files
RMOUT       = *.pdf *.dvi *.ps

# class and package files
RMCLS       = *.cls *.sty

# sources of KOMA-Script News
NEWS_SRC    = 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 \
              scrnew18.tex \
              scrnew19.tex \
              scrnew20.tex \
	      scrnew21.tex

# folder with german manual
DE_GUIDE_DIR = scrguide

# source of german manual
DE_GUIDE_SRC = $(DE_GUIDE_DIR)/scrguide2.tex \
              $(DE_GUIDE_DIR)/einleit.tex \
              $(DE_GUIDE_DIR)/satzspgl.tex \
              $(DE_GUIDE_DIR)/hauptcls.tex \
              $(DE_GUIDE_DIR)/layout.tex \
              $(DE_GUIDE_DIR)/datmzeit.tex \
              $(DE_GUIDE_DIR)/brief.tex \
              $(DE_GUIDE_DIR)/adressen.tex \
              $(DE_GUIDE_DIR)/adrkonv.tex \
              $(DE_GUIDE_DIR)/datladen.tex \
              $(DE_GUIDE_DIR)/scrguide.bib \
              $(DE_GUIDE_DIR)/scrguide.bst \
              $(DE_GUIDE_DIR)/scrguide.dbj \
              $(DE_GUIDE_DIR)/scrguide.mbs \
              $(DE_GUIDE_DIR)/scrguide.ist \
	      $(DE_GUIDE_DIR)/scrguide.gst

# folder with english manual
EN_GUIDE_DIR = scrguide/english
EN_GUIDE_RELTO_BASE = ../..

# source of english manual
EN_GUIDE_SRC = $(EN_GUIDE_DIR)/main.tex \
               $(EN_GUIDE_DIR)/scrguide2.tex \
               $(EN_GUIDE_DIR)/introduc.tex \
	       $(EN_GUIDE_DIR)/pglayout.tex \
               $(EN_GUIDE_DIR)/maincls.tex \
               $(EN_GUIDE_DIR)/headfoot.tex \
               $(EN_GUIDE_DIR)/datetime.tex \
               $(EN_GUIDE_DIR)/letter.tex \
               $(EN_GUIDE_DIR)/addressf.tex \
               $(EN_GUIDE_DIR)/addrconv.tex \
	       $(EN_GUIDE_DIR)/loadfile.tex \
               $(EN_GUIDE_DIR)/scrguide.bib \
               $(EN_GUIDE_DIR)/scrguide-en.bst \
               $(EN_GUIDE_DIR)/scrguide-en.dbj \
               $(EN_GUIDE_DIR)/scrguide.mbs \
               $(EN_GUIDE_DIR)/scrguide.ist \
	       $(EN_GUIDE_DIR)/scrguide.gst

# other source files (unused)
MISC_SRC    = Makefile.unx \
	      genindex.pl

# source of all manuals
GUIDE_SRC   = koma-script.tex \
	      $(DE_GUIDE_SRC) $(EN_GUIDE_SRC)

# ready made KOMA-Script News
NEWS        = ${NEWS_SRC:.tex=.dvi}

# ready made german guides
DE_GUIDES   = scrguide.dvi \
              scrguide.pdf
# ready made german guides (optional)
O_DE_GUIDES = scrguide.ps

# ready made english guides
EN_GUIDES   = scrguien.dvi \
              scrguien.pdf
# ready made english guide (optional)
O_EN_GUIDES = scrguien.ps

# ready made guides
GUIDES      = koma-script.pdf \
              komascript.pdf \
              komascr.pdf \
	      $(DE_GUIDES) $(EN_GUIDES)
# ready made guide (optional)
OGUIDES    = $(O_DE_GUIDES) $(O_EN_GUIDES)

# primary dtx files
DTX_FILES   = scrclass.dtx \
	      scraddr.dtx \
	      scrlettr.dtx \
	      scrtime.dtx \
	      scrpage.dtx
#	      script20.dtx \

# dtx includes
DTX_INCLUDE = scrlogo.dtx

# batch files
INS_FILES   = komascr.ins \
	      scrclass.ins \
	      scrtime.ins \
	      scrpage.ins

# all sourced need to made classes and packages
CLS_SRC     = $(DTX_FILES) \
	      $(DTX_INCLUDE) \
	      $(INS_FILES) \
	      $(MISC_SRC)

# all files needed by generations
SRC_FILES   = $(CLS_SRC) \
	      $(GUIDE_SRC) \
	      $(NEWS_SRC)

# text files
TEXT_FILES  = ChangeLog      \
              liesmich.txt   \
              readme.txt     \
	      LEGAL.TXT      \
              LEGALDE.TXT    \
              INSTALL.TXT    \
              INSTALLD.TXT

# misc installation files
MISC_FILES  = komabug.tex

# files at distribution source
DIST_SRC    = $(TEXT_FILES)  \
	      $(SRC_FILES)   \
              $(MISC_FILES)

# files at distribution contents file
XDIST_FILES = 00README  \
              $(GUIDES) \
              $(DIST_SRC)

# files at distribution
DIST_FILES  = 00CONTEN \
	      komascript.md5 \
              $(XDIST_FILES)

# files to be installed at CLSDIR
CLS_FILES   = scrartcl.cls \
              scrreprt.cls \
              scrbook.cls  \
              typearea.sty \
	      scrlfile.sty \
              scrlettr.cls \
	      scrlttr2.cls \
	      scraddr.sty \
	      DIN.lco \
              DINmtext.lco \
              SNleft.lco \
	      SN.lco \
              KOMAold.lco \
              scrtime.sty  \
              scrdate.sty  \
              scrpage.sty  \
              scrpage2.sty

# files to be installed at DOCDIR
DOC_FILES   = $(GUIDES)     \
              $(TEXT_FILES) \
              $(NEWS)       \
              komabug.tex

# optional files to be installed at DOCDIR
ODOC_FILES  = $(OGUIDES)

# installation documentation files
IDOC_FILES  = ${DTX_FILES:.dtx=.dvi}

# installation documentation log files
ILOG_FILES  = ${DTX_FILES:.dtx=.log}

########################################################################
 
all: komascript.log #guides

guides: $(GUIDES)

optionalguides: guides $(OGUIDES)

komascript.log: Makefile $(CLS_SRC) $(NEWS)
	$(LATEX) komascr.ins
	$(ECHO) $(LOGMESSAGE) > komascript.log

Makefile: Makefile.unx
	@if test -r Makefile && test Makefile.unx -nt Makefile; then\
	  $(ECHO) "Makefile.unx is newer than Makefile!";\
	  $(ECHO) "Delete or Re-edit it!";\
	  exit 1;\
	fi 
	$(SYMLINK) Makefile.unx Makefile

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

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

scrguide: $(DE_GUIDES)

scrguide2p:	scrguide2p.ps

scrguide4p16:	scrguide4p16.ps

scrguide4p:	scrguide4p.ps

screnggu: scrguide-english

scrguien: scrguide-english

scrguide-english: $(EN_GUIDES)

scrguide.dvi:	$(DE_GUIDE_DIR)/scrguide2.dvi
	$(CP) $(DE_GUIDE_DIR)/scrguide2.dvi scrguide.dvi

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

scrguide2p.ps:	scrguide.ps
	$(PSSELECT) -p1,2,_,3- scrguide.ps tmp.ps
	$(PSTOPS) -w29.7cm -h21cm '2:0L(21cm,0)+1L(21cm,14.85cm)' \
	       tmp.ps tmp2.ps
	$(SED) 's/%%BoundingBox: 0 0 420 596/%%BoundingBox: 0 0 596 842/' \
	    tmp2.ps > scrguide2p.ps
	$(RM) tmp.ps tmp2.ps

scrguide4p16.ps:	scrguide.ps
	$(PSBOOK) -s16 scrguide.ps tmp.ps
	$(PSTOPS) '4:0L(21cm,0)+1L(21cm,14.85cm),2R(0,29.7cm)+3R(0,14.85cm)' \
	       tmp.ps tmp2.ps
	$(SED) 's/%%BoundingBox: 0 0 420 596/%%BoundingBox: 0 0 596 842/' \
	    tmp2.ps > scrguide4p16.ps
	$(RM) tmp.ps tmp2.ps

scrguide4p.ps:	scrguide.ps
	$(PSBOOK) scrguide.ps tmp.ps
	$(PSTOPS) '4:0L(21cm,0)+1L(21cm,14.85cm),2R(0,29.7cm)+3R(0,14.85cm)' \
	       tmp.ps tmp2.ps
	$(SED) 's/%%BoundingBox: 0 0 420 596/%%BoundingBox: 0 0 596 842/' \
	    tmp2.ps > scrguide4p.ps
	$(RM) tmp.ps tmp2.ps

scrguide.pdf:	$(DE_GUIDE_DIR)/scrguide2.pdf
	$(CP) $(DE_GUIDE_DIR)/scrguide2.pdf scrguide.pdf

scrguien.dvi: $(EN_GUIDE_DIR)/main.dvi
	$(CP) $(EN_GUIDE_DIR)/main.dvi scrguien.dvi

scrguien.ps:	scrguien.dvi
	$(DVIPS) scrguien.dvi -oscrguien.ps

scrguien.pdf:	$(EN_GUIDE_DIR)/main.pdf
	$(CP) $(EN_GUIDE_DIR)/main.pdf scrguien.pdf

screnggu.dvi:	$(EN_GUIDE_DIR)/screnggu.dvi
	$(CP) $(EN_GUIDE_DIR)/screnggu.dvi .

screnggu.ps:	screnggu.dvi
	$(DVIPS) screnggu.dvi -oscrenggu.ps

screnggu.pdf:	$(EN_GUIDE_DIR)/screnggu.pdf
	$(CP) $(EN_GUIDE_DIR)/screnggu.pdf .

koma-script.pdf: koma-script.tex
	$(PDFLATEX) $(NONSTOPMODE) koma-script.tex

komascript.pdf: koma-script.pdf
	$(SYMLINK) koma-script.pdf komascript.pdf

komascr.pdf: koma-script.pdf
	$(SYMLINK) koma-script.pdf komascr.pdf


ifneq ($(USEMULTIINDEX),false)
USEMULTIINDEX = test -x $(GENINDEX)
endif

$(DE_GUIDE_DIR)/scrguide2.dvi: komascript.log $(DE_GUIDE_SRC)
	$(CD) $(DE_GUIDE_DIR) && \
	$(RM) $(RMEXT) && \
	( oncemore=true; \
	  while $$oncemore; do \
	    $(LATEX) $(NONSTOPMODE) scrguide2.tex && \
	    $(BIBTEX) scrguide2 && \
	    $(MAKECHANGE) scrguide2.chn scrguide2.glo && \
	    $(MAKEINDEX) scrguide2 && \
	    ( ! $(USEMULTIINDEX) || $(GENINDEX) scrguide2 ); \
	    if test $$? != 0; then rm scrguide2.dvi; exit 1; fi;\
	    if $(GREP) Rerun scrguide2.log;\
	    then oncemore=true; else oncemore=false; fi;\
	  done;\
	)

$(DE_GUIDE_DIR)/scrguide2.pdf: komascript.log $(DE_GUIDE_SRC)
	$(CD) $(DE_GUIDE_DIR) && \
	$(RM) $(RMEXT) && \
	( oncemore=true; \
	  while $$oncemore; do \
	    $(PDFLATEX) $(NONSTOPMODE) scrguide2.tex && \
	    $(BIBTEX) scrguide2 && \
	    $(MAKECHANGE) scrguide2.chn scrguide2.glo && \
	    $(MAKEINDEX) scrguide2 && \
	    ( ! $(USEMULTIINDEX) || $(GENINDEX) scrguide2 ); \
	    if test $$? != 0; then rm scrguide2.pdf; exit 1; fi;\
	    if $(GREP) Rerun scrguide2.log;\
	    then oncemore=true; else oncemore=false; fi;\
	  done;\
	)

$(EN_GUIDE_DIR)/main.dvi: komascript.log $(EN_GUIDE_SRC)
	$(CD) $(EN_GUIDE_DIR) && \
	$(RM) $(RMEXT) && \
	( oncemore=true; \
	  while $$oncemore; do \
	    $(LATEX) $(NONSTOPMODE) main.tex && \
	    $(BIBTEX) main && \
	    $(MAKECHANGE) main.chn main.glo && \
	    $(MAKEINDEX) main && \
	    ( ! $(USEMULTIINDEX) || $(GENINDEX) main ); \
	    if test $$? != 0; then rm main.dvi; exit 1; fi;\
	    if $(GREP) Rerun main.log;\
	    then oncemore=true; else oncemore=false; fi;\
	  done;\
	)

$(EN_GUIDE_DIR)/main.pdf: komascript.log $(EN_GUIDE_SRC)
	$(CD) $(EN_GUIDE_DIR) && \
	$(RM) $(RMEXT) && \
	( oncemore=true; \
	  while $$oncemore; do \
	    $(PDFLATEX) $(NONSTOPMODE) main.tex && \
	    $(BIBTEX) main && \
	    $(MAKECHANGE) main.chn main.glo && \
	    $(MAKEINDEX) main && \
	    ( ! $(USEMULTIINDEX) || $(GENINDEX) main ); \
	    if test $$? != 0; then rm main.pdf; exit 1; fi;\
	    if $(GREP) Rerun main.log;\
	    then oncemore=true; else oncemore=false; fi;\
	  done;\
	)

$(EN_GUIDE_DIR)/scrguide2.tex: $(DE_GUIDE_DIR)/scrguide2.tex
	$(SYMLINK) $(EN_GUIDE_RELTO_BASE)/$(DE_GUIDE_DIR)/scrguide2.tex \
		$(EN_GUIDE_DIR)/scrguide2.tex

$(EN_GUIDE_DIR)/scrguide.bib: $(DE_GUIDE_DIR)/scrguide.bib
	$(SYMLINK) $(EN_GUIDE_RELTO_BASE)/$(DE_GUIDE_DIR)/scrguide.bib \
		 $(EN_GUIDE_DIR)/scrguide.bib

$(EN_GUIDE_DIR)/scrguide.ist: $(DE_GUIDE_DIR)/scrguide.ist
	$(SYMLINK) $(EN_GUIDE_RELTO_BASE)/$(DE_GUIDE_DIR)/scrguide.ist \
		$(EN_GUIDE_DIR)/scrguide.ist

$(EN_GUIDE_DIR)/scrguide.mbs: $(DE_GUIDE_DIR)/scrguide.mbs
	$(SYMLINK) $(EN_GUIDE_RELTO_BASE)/$(DE_GUIDE_DIR)/scrguide.mbs \
		$(EN_GUIDE_DIR)/scrguide.mbs

$(EN_GUIDE_DIR)/scrguide.gst: $(DE_GUIDE_DIR)/scrguide.gst
	$(SYMLINK) $(EN_GUIDE_RELTO_BASE)/$(DE_GUIDE_DIR)/scrguide.gst \
		$(EN_GUIDE_DIR)/scrguide.gst


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

install: clean komascript.log
	@if test "x" = "x$(INSTALLTEXMF)" || ! $(MKDIR) $(INSTALLTEXMF) \
	  || ! test -w "$(INSTALLTEXMF)"; then \
	  $(ECHO) "Not able to write to install directory \"$(INSTALLTEXMF)\"";\
	  $(ECHO) "Please edit INSTALLTEXMF at the Makefile first!"; \
	  exit 1 ; \
	fi
	@if test `pwd` = $(CLSDIR) -o `pwd` = $(SRCDIR) -o `pwd` = $(DOCDIR); \
	then \
	  $(CPALL) ./ /tmp/koma-script.tmp; \
	  $(CD) /tmp/koma-script.tmp; \
	  $(MAKE) install; \
	  $(RMDIR) /tmp/koma-script.tmp; \
	else \
	  $(ECHO) "Installation at $(INSTALLTEXMF):"; \
	  $(MKDIR) $(CLSDIR); \
	  $(ECHONONL) "  at $(CLSDIR): "; \
	  $(INSTALL) $(CLS_FILES) $(CLSDIR); \
	  $(ECHO) "."; \
	  $(MKDIR) $(DOCDIR); \
	  $(ECHONONL) "  at $(DOCDIR): "; \
	  $(INSTALL) $(DOC_FILES) $(DOCDIR); \
	  $(ECHONONL) "."; \
	  for file in "$(ODOC_FILES)"; do \
	    if test -r "$$file"; then \
	      $(ECHONONL) "."; \
	      $(INSTALL) $$file $(DOCDIR); \
	    fi; \
	  done; \
	  $(ECHO) "."; \
	  $(ECHONONL) "  at $(SRCDIR): "; \
	  for file in $(DIST_FILES); do \
	    dir=`dirname $$file`; \
	    if test "x$$dir" = "x"; \
	      then $(INSTALL) $$file $(SRCDIR); \
	      else $(ECHONONL) "."; \
	        $(MKDIR) $(SRCDIR)/$$dir; \
	        $(INSTALL) $$file $(SRCDIR)/$$dir; \
	    fi; \
	  done; \
	  $(ECHO) "."; \
	  $(INSTALL) komascript.log $(DOCDIR); \
	  $(ECHO) "done"; \
	fi
	@if test -z "$(TEXHASH)" ; then \
          $(ECHO) ;\
          $(ECHO) '>>> Maybe you have to run texhash or something else, now. <<<';\
          $(ECHO) ;\
        else \
          $(EVAL) $(TEXHASH); \
	fi

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

srcclean: distclean
	$(RM) $(RMOUT) 00*

distclean: clean
	$(RM) $(RMCLS) $(IDOC_FILES)
	$(CD) $(DE_GUIDE_DIR) && $(RM) $(RMOUT)
	$(CD) $(EN_GUIDE_DIR) && $(RM) $(RMOUT)

clean:
	$(RM) $(RMEXT)
	$(CD) $(DE_GUIDE_DIR) && $(RM) $(RMEXT)
	$(CD) $(EN_GUIDE_DIR) && $(RM) $(RMEXT)

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

.SUFFIXES: .dtx .dvi .log

.dtx.dvi:
	$(LATEX) $(NONSTOPMODE) $<
	$(LATEX) $(BATCHMODE) $<
	$(MAKEIDX) -r -s gind.ist $(<:.dtx=.idx)
	$(MAKEIDX) -r -s gglo.ist $(<:.dtx=.glo) -o $(<:.dtx=.gls)
	$(LATEX) $(BATCHMODE) $<

.dtx.log:
	$(LATEX) $(NONSTOPMODE) $<
	$(LATEX) $(BATCHMODE) $<
	$(MAKEIDX) -r -s gind.ist $(<:.dtx=.idx)
	$(MAKEIDX) -r -s gglo.ist $(<:.dtx=.glo) -o $(<:.dtx=.gls)
	$(LATEX) $(BATCHMODE) $<

ifeq ($(USER),mjk)
release:
	@for src in $(INS_FILES);do \
	  $(CP) $${src} $${src}.bak; \
	  $(SED) 's/\\let\\ifbeta\\iftrue/\\let\\ifbeta\\iffalse/1' \
	      <$${src}.bak >$${src}; \
	done
	@$(RM) Makefile
	$(SED) -e "s/^\(INSTALLTEXMF \?= \`kpsewhich .*HOME\)/#\1/" \
	       -e "s/^#\(INSTALLTEXMF \?= \`kpsewhich .*TEXMFLOCAL\)/\1/" \
	       <Makefile.unx >Makefile

beta:
	@for src in $(INS_FILES);do \
	  $(CP) $${src} $${src}.bak; \
	  $(SED) 's/\\let\\ifbeta\\iffalse/\\let\\ifbeta\\iftrue/1' \
	      <$${src}.bak >$${src}; \
	done
	@$(RM) Makefile
	$(SED) -e "s/^#\(INSTALLTEXMF \?= \`kpsewhich .*HOME\)/\1/" \
	       -e "s/^\(INSTALLTEXMF \?= \`kpsewhich .*TEXMFLOCAL\)/#\1/" \
	       <Makefile.unx >Makefile
endif

dist: komascript.log $(DIST_FILES) $(ILOG_FILES) $(IDOC_FILES)
	@if $(GREP) "Checksum not passed" *.log; then \
	  $(ECHO) "Cannot create tar because of checksum error" >&2; \
	else \
	  $(RM) koma-script-`date -I`.tar.gz; \
	  $(TARCREATE) koma-script-`date -I`.tar.gz $(DIST_FILES); \
	fi

check: dist-bzip
	$(RMDIR) /tmp/texmf/
	$(MKDIR) /tmp/texmf/source/latex/komascript
	$(CP) koma-script-`date -I`.tar.bz2 /tmp/texmf/source/latex/komascript
	cd /tmp/texmf/source/latex/komascript
	tar -xjf koma-script-`date -I`.tar.bz2
	$(RM) koma-script-`date -I`.tar.bz2
	$(eval export INSTALLTEXMF=/tmp/texmf)
	$(eval export TEXHASH=)
	$(MAKE) install 2>&1 | tee make.log
	echo "Test installation to /tmp/texmf was successfull."
	$(RMDIR) /tmp/texmf/source/latex/komascript
	tree /tmp/texmf

texlive: Makefile
	@if [ -z "$(TEXLIVE)" ]; then \
	  $(ECHO) "Error: You have to set up variable TEXLIVE!" >&2; \
	  exit 1; \
	fi
	$(eval export INSTALLTEXMF=$(TEXLIVE))
	$(eval export TEXHASH=)
	$(MAKE) install

dist-bzip: komascript.log $(DIST_FILES) $(ILOG_FILES) $(IDOC_FILES)
	@if $(GREP) "Checksum not passed" *.log; then \
	  $(ECHO) "Cannot create tar because of checksum error" >&2; \
	else \
	  $(RM) koma-script-`date -I`.tar.bz2; \
	  $(TARCREATEBZ) koma-script-`date -I`.tar.bz2 $(DIST_FILES); \
	fi

dist-zip: komascript.log $(DIST_FILES) $(ILOG_FILES) $(IDOC_FILES)
	@if $(GREP) "Checksum not passed" *.log; then \
	  $(ECHO) "Cannot create zip because of checksum error" >&2; \
	else \
	  $(RM) koma-script-`date -I`.zip; \
	  $(ZIPCREATE) koma-script-`date -I`.zip $(DIST_FILES); \
	fi

distsrc: komascript.log $(DIST_SRC) $(ILOG_FILES) $(IDOC_FILES)
	@if $(GREP) "Checksum not passed" *.log; then \
	  $(ECHO) "Cannot create tar because of checksum error" >&2; \
	else \
	  $(TARCREATE) koma-script-src-`date -I`.tar.gz $(DIST_SRC); \
	fi

komascript.md5: $(XDIST_FILES)
	$(MV) komascript.md5 komascript.md5.bak
	md5sum $(XDIST_FILES) > komascript.md5

00CONTEN: $(XDIST_FILES) komascript.md5
	$(LLL) $(XDIST_FILES) > 00CONTEN
	$(LLL) 00CONTEN >> 00CONTEN
	$(LLL) $(DIST_FILES) > 00CONTEN.TMP
	$(MV) 00CONTEN.TMP 00CONTEN

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

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