/*   CrossFire, A Multiplayer game for X-windows
 *
 *   $Id: Imakefile,v 1.3 1993/12/18 03:18:53 kjetilho Exp $
 *
 *   Copyright (C) 1992 Frank Tore Johansen
 *
 *   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.
 *
 *   The author can be reached via e-mail to frankj@ifi.uio.no.
 */

#include "../../config/crossfire.tmpl"

FILES = Imakefile  monster-extract spells-extract stats-extract \
	arm-extract \
	helm-extract mag-extract shield-extract items-extract spoiler.tex \
	sorter makeps \
	empty.pbm bow-extract arche-extract weap-extract

TEX =	monput.tex spells.tex stats.tex weap.tex shield.tex helmet.tex \
	mag.tex arm.tex arche.tex bow.tex version.tex weapmag.tex

 CROSSRC = ../..
  INCDIR = $(CROSSRC)/include
  IMGDIR = $(CROSSRC)/doc/spoiler
CROSSBIN = $(CROSSRC)/server/crossfire

#define MAKEPS(in,out) $(AWK) -v libdir=$(CROSSRC)/lib \
	-v archdir=$(CROSSRC)/lib/ -v size=0.4 -v input=in \
	-f makeps $(C_LIBDIR)/archetypes > out

/*
CROSSBIN= $(C_BINDIR)/$(HOSTTYPE)/crossfire.`cat $(C_BINDIR)/$(HOSTTYPE)/last`
*/

spoiler:: ../spoiler.ps

../spoiler.ps: spoiler.dvi
	dvips -o ../spoiler.ps spoiler.dvi

all::

spoiler.dvi: spoiler.aux
	latex spoiler.tex

/* longtables requires one extra run to save alignment in spoiler.aux.
 */
spoiler.aux: spoiler.tex $(TEX)
	$(RM) spoiler.aux
	latex spoiler.tex

$(CROSSBIN):
	@$(RM) dump_switches
	@$(CROSSBIN) -m >/dev/null 2>&1 && touch dump_switches ||\
	(echo "You need to define DUMP_SWITCHES in include/config.h and";\
	echo "recompile before you can create the spoilers.")
	@$(MAKE) $(MFLAGS) check_ok

check_ok: dump_switches
	@$(RM) dump_switches

.bmaps: $(C_LIBDIR)/archetypes
	$(RM) *.ps
	touch .bmaps

items: .bmaps in_items makeps items.ps
	MAKEPS(in_items,items)

in_items: items-extract $(C_LIBDIR)/archetypes $(CROSSRC)/common/living.c
	$(AWK) -v living_c=$(CROSSRC)/common/living.c \
		-f items-extract $(C_LIBDIR)/archetypes > in_items

stats.tex: .bmaps in_stats makeps characters.ps
	MAKEPS(in_stats,stats.tex)

in_stats: stats-extract $(C_LIBDIR)/archetypes $(CROSSRC)/common/living.c
	$(AWK) -v living_c=$(CROSSRC)/common/living.c \
		-f stats-extract $(C_LIBDIR)/archetypes > in_stats

monput.tex: .bmaps in_monput makeps monsters.ps
	MAKEPS(in_monput,monput.tex)

in_monput: monster-extract $(CROSSBIN) $(C_LIBDIR)/treasures $(C_LIBDIR)/archetypes
	$(CROSSBIN) -m2 | tr A-Z a-z | sort | \
		$(AWK) -F'|' -f monster-extract > in_monput

spells.tex: .bmaps in_spells makeps spells.ps
	MAKEPS(in_spells,spells.tex)

in_spells: spells-extract sorter $(INCDIR)/spellist.h $(CROSSBIN) $(C_LIBDIR)/archetypes
	tr -d \" < $(INCDIR)/spellist.h | \
		$(AWK) -F, -v crosscmd="$(CROSSBIN) -m4" \
			-f spells-extract | sort > in_spells

version.tex: $(CROSSBIN)
	$(CROSSBIN) -v 2>&1 | grep "^This is" | \
		cut -d" " -f3- > version.tex

/* These dummy files are used to detect 'rm *.ps'
 */
characters.ps items.ps monsters.ps spells.ps:
	touch $@

weap.tex: items sorter
	egrep -e "^15 " items | $(AWK) -F'&' '{printf("%s &%s &%s &%.2f &%s\n",$$3,$$10,$$5,$$11,$$6)}' |\
	sort | $(AWK) -F'&' -f sorter -v lengde=`egrep -e "^15" items | \
	wc -l | tr -d ' ' ` | sort | cut -d'&' -f 2- > weap.tex

shield.tex: items shield-extract
	egrep -e "^33 " items | $(AWK) -F'&' -f shield-extract | sort > shield.tex

arm.tex: items arm-extract
	egrep -e "^16 " items | $(AWK) -F'&' -f arm-extract | sort -t'&' -n +4 -5 > arm.tex

helmet.tex: items helm-extract
	egrep -e "^34 " items | $(AWK) -F'&' -f helm-extract | \
		sort -t'&' -n +3 -4 | sed -e s/_/' '/g > helmet.tex

bow.tex: items bow-extract
	egrep -e "^14 " items | $(AWK) -F'&' -f bow-extract | sort > bow.tex

arche.tex: items arche-extract
	egrep -e "^915 " items | $(AWK) -F'&' -f arche-extract | sort > arche.tex

weapmag.tex: items weap-extract
	egrep -e "^15 " items | $(AWK) -F'&' -f weap-extract | sort > weapmag.tex

mag.tex: items mag-extract
	$(AWK) -F'&' -f mag-extract items | sort +0.9 -0.10 > mag.tex

install::

depend::

clean::
	$(RM) $(TEX)
	$(RM) items .bmaps in_monput in_items in_spells
	$(RM) *.ps *x*.ppm tmp.ppm work.ppm
	$(RM) spoiler.dvi spoiler.log spoiler.aux

InsertArchive($(FILES),doc/spoiler)

patchlist::
	echo $(FILES) > .patchlist

# Depends:
