#   Chaos:		    The Chess HAppening Organisation System	V5.1a
#   Copyright (C)   1993    Jochen Wiedmann
#
#   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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#   This is the Makefile (DMake 2.1)
#

VERSION=5_1a

REVISION=1


#   No special CFLAGS, except full error-checking and debugging
ALLCFLAGS=-c -Isrc -3.0 -r -ms
#ALLCFLAGS=-c -Isrc -2.0 -r -ms
CFLAGS=$(ALLCFLAGS) -Hsrc/Chaos.m=Chaos.h -proto

#   No special LFLAGS, except debugging
LFLAGS= -s -lm -lc -lamiga30


#   The binaries we use
CC=dcc
LN=dcc
CATCOMP=KitCat
CI=Ci
CO=Co
GTEX=GTeX
TEX=TeX
TEXINDEX=TexIndex
RM=Delete quiet
MAKEINFO=MakeInfo
LHA=LhA
CP=Copy
MV=Rename

#
#   You should not need to change anything below.
#

#   Some variables containing the lists of files to process

#   Object-files which are created manually
OBJ=src/main.o src/Project.o src/Tlnhmr.o src/Losen.o src/Runde.o \
    src/Out.o  src/OutSK.o src/OutDWZ.o

#   Object-files which are created automatically (using GadToolsBox or
#   KitCat alias CatComp or anything else)
AUTOOBJ=src/Chaos_Cat.o src/GadTools.o src/DWZtabs.o

#   Doc-files
DOC=doc/Chaos_deutsch.dvi doc/Chaos_deutsch.guide doc/Chaos_deutsch.doc \
    doc/Chaos_english.dvi doc/Chaos_english.guide doc/Chaos_english.doc

#   Files which RCS should look for
RCS=$(OBJ:*.o:%1.c) src/DWZtabs.c src/Chaos.h Chaos.info \
    doc.info COPYING.info COPYING src/Chaos.cd src/Deutsch.ct \
    src/Chaos.gui Install src/Chaos_Cat.c

RCSEXT=$(RCS) src/Chaos_d.texi src/Chaos_e.texi \
    s/Project.info Install_d.in Install_e.in src/DMakefile

#   Distribution-files
DIST0=Chaos.info Chaos/Chaos $(RCS:*:Chaos/%1)
DIST1=$(DOC:*:Chaos/%1) Chaos/Catalogs/Deutsch/Chaos.Catalog \
      Chaos/src/NewCatalog.ct Chaos/src/Chaos_deutsch.texinfo \
      Chaos/src/Chaos_english.texinfo $(DOC:*:Chaos/%1.info) \
      Chaos/s/Chaos_Project.info Chaos/src/GadTools.c Chaos/src/Chaos_Cat.c \
      Chaos/src/GadTools.h Chaos/src/Chaos_Cat.h \
      Chaos/READ_ME_FIRST Chaos/READ_ME_FIRST.info \
      Chaos/Install.Deutsch.info Chaos/Install.English.info \
      Chaos/DMakefile


#   Main targets: all clean dist doc ci
all: Chaos doc Catalogs/Deutsch/Chaos.catalog

clean: binclean
    $(RM) $(DOC) src/#?.aux src/#?.cp src/#?.ky src/#?.log \
	  src/#?.pg src/#?.toc src/#?.tp src/#?.vr src/#?.cps \
	  src/Chaos_Cat.?

binclean:
    $(RM) src/#?.o src/#?.sym src/#?.dbg src/#?.m

dist: all
	cd /
	$(RM) chaos$(VERSION).lha
	$(LHA) u -x chaos$(VERSION).lha $(DIST0) $(DIST1)
	cd chaos

doc:	$(DOC)

ci:
    $(MV) src/Chaos_deutsch.texinfo src/Chaos_d.texi
    $(MV) src/Chaos_english.texinfo src/Chaos_e.texi
    $(MV) s/Chaos_Project.info s/Project.info
    $(MV) Install.Deutsch.info Install_d.in
    $(MV) Install.English.info Install_e.in
    $(CP) DMakefile src/DMakefile
    $(CI) -l$(REVISION) $(RCSEXT)
    $(MV) src/Chaos_d.texi src/Chaos_deutsch.texinfo
    $(MV) src/Chaos_e.texi src/Chaos_english.texinfo
    $(MV) s/Project.info src/Chaos_Project.info
    $(MV) Install_d.in Install.Deutsch.info
    $(MV) Install_e.in Install.English.info
    $(RM) src/DMakefile

co:
    $(CO) -l$(REVISION) $(RCSEXT)
    $(MV) src/Chaos_d.texi src/Chaos_deutsch.texinfo
    $(MV) src/Chaos_e.texi src/Chaos_english.texinfo
    $(MV) s/Project.info src/Chaos_Project.info
    $(MV) Install_d.in Install.Deutsch.info
    $(MV) Install_e.in Install.English.info
    $(RM) src/DMakefile


freeze:
    rcs -nV$(VERSION): $(RCSEXT)


#   doc-Rules
$(DOC:*.guide): $(DOC:doc/*.guide:src/%1.texinfo)
    $(MAKEINFO) --amiga-39 --fill-column 76 --output %(left) %(right)

$(DOC:*.doc): $(DOC:doc/*.doc:src/%1.texinfo)
    $(MAKEINFO) --amiga-39 --fill-column 76 --no-headers --output %(left) \
		%(right)

doc/Chaos_deutsch.dvi: src/Chaos_deutsch.texinfo
    cd src
    $(GTEX) %(right:src/*:%1)
    $(TEXINDEX) %(right:src/*.texinfo:%1.cp)
    $(GTEX) %(right:src/*:%1)
    cd /
    $(CP) %(right:*.texinfo:%1.dvi) %(left)
    $(RM) %(right:*.texinfo:%1.dvi)

doc/Chaos_english.dvi: src/Chaos_english.texinfo
    cd src
    $(TEX) %(right:src/*:%1)
    $(TEXINDEX) %(right:src/*.texinfo:%1.cp)
    $(TEX) %(right:src/*:%1)
    cd /
    $(CP) %(right:*.texinfo:%1.dvi) %(left)
    $(RM) %(right:*.texinfo:%1.dvi)


#   source-Rules
Chaos: $(OBJ) $(AUTOOBJ)
    $(LN) $(LFLAGS) -o Chaos %(right:*.o)

$(OBJ): $(OBJ:*.o:%1.c)
    $(CC) $(CFLAGS) -o %(left) %(right)

$(AUTOOBJ): $(AUTOOBJ:*.o:%1.c)
    $(CC) $(ALLCFLAGS) -o %(left) %(right)

$(OBJ): src/Chaos.m

src/Chaos.m: src/Chaos.h src/GadTools.h src/Chaos_Cat.c
    rm %(left)

src/GadTools.c src/Chaos_Cat.c: src/GadTools.h src/Chaos_Cat.h

src/Chaos_Cat.c: src/Chaos.cd
    $(CATCOMP) %(right) CFILE=%(left) CTFILE=src/NewCatalog.ct

Catalogs/Deutsch/Chaos.catalog: src/Chaos.cd src/Deutsch.ct
    $(CATCOMP) %(right) CATALOG=%(left) L=Deutsch
