/*   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 mwedel@pyramid.com
 */

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

FILES = Imakefile \
	bonus-extract char-extract items-extract generic-extract \
	gods-extract levels-extract local.sty\
	skills-extract skills2-extract spellpath-extract statskmod-extract \
	treas1-extract treas2-extract $(TEX) handbook.idx \
	sorter makeps make_index.pl empty.pbm

TEX   =	handbook.tex title.tex chap1.tex chap2.tex chap3.tex chap4.tex \
	chap5.tex chap6.tex chap7.tex appA.tex appB.tex appC.tex 

TABLES=	bonus.tex char.tex equip.tex index.tex gods.tex levels.tex skills.tex \
	skill_stat.tex statskmod.tex spellpath.tex version.tex 

ICONS =	altar.tex arm_mail.tex br_wall.tex \
	books.tex bows.tex cauldron.tex corpse.tex dir_spin.tex \
	flesh.tex food.tex foodone.tex \
	fr_wall.tex gatedoor.tex gems.tex gravestone.tex \
	guild.tex holysymbol.tex handbutt.tex horns.tex id_altar.tex \
	keys.tex lockpicks.tex lighter.tex money.tex \
	pit.tex potion.tex potions.tex rings.tex rods.tex \
	runeblast.tex runedeath.tex runefire.tex runefrost.tex \
	runeshock.tex runemark.tex runegen.tex savebed.tex \
	scrolls.tex shops.tex shopmat.tex sign.tex \
	talisman.tex wands.tex

 CROSSRC = ../..
  INCDIR = $(CROSSRC)/include
  IMGDIR = $(CROSSRC)/doc/playbook
CROSSBIN = $(CROSSRC)/server/crossfire
   INDEX = 1

#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

handbook:: ../handbook.ps

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

all::

handbook.dvi: handbook.aux
	latex handbook.tex

/* Indexing, crossrefs and longtables requires one extra run */
handbook.aux: handbook.tex $(TABLES) $(ICONS)
	$(RM) handbook.aux
	latex handbook.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 handbook.")
	@$(MAKE) $(MFLAGS) check_ok

check_ok: dump_switches
	@$(RM) dump_switches

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

index.tex: make_index.pl
	touch handbook.idx
	./make_index.pl handbook.idx > index.tex;\

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

in_items: items-extract $(C_LIBDIR)/archetypes
	$(AWK) -f items-extract $(C_LIBDIR)/archetypes > in_items

bonus.tex:
	$(AWK) -v living_c=../../common/living.c \
	-f bonus-extract > bonus.tex

char.tex: .bmaps in_char makeps characters.ps
	MAKEPS(in_char,char.tex)

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

equip.tex: in_equip treas2-extract
	$(AWK) -v eqitems=in_equip -f treas2-extract \
	../../lib/treasures > equip.tex

in_equip: treas1-extract $(C_LIBDIR)/archetypes $(CROSSRC)/common/living.c
	$(AWK) -v living_c=$(CROSSRC)/common/living.c \
		-f treas1-extract $(C_LIBDIR)/archetypes | sort -d > in_equip
 
gods.tex: gods-extract $(CROSSBIN)
	$(AWK) -F, -v crosscmd="$(CROSSBIN) -m8" -f gods-extract > gods.tex

levels.tex:
	$(AWK) -v living_c=../../common/living.c \
	-f levels-extract > levels.tex

skills.tex: in_equip skills-extract
	$(AWK) -v eqitems=in_equip -f skills-extract \
	../../lib/treasures > skills.tex

skill_stat.tex: skills2-extract $(CROSSBIN)
		$(AWK) -F, -v crosscmd="$(CROSSBIN) -m5" \
			-f skills2-extract | sort > skill_stat.tex

statskmod.tex:
	$(AWK) -v living_c=../../server/skill_util.c \
	-f statskmod-extract > statskmod.tex

spellpath.tex:
	$(AWK) -v living_c=../../include/spellist.h \
	-f spellpath-extract |sort > spellpath.tex

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

/* just a few mega-tex thingies for ease of compilation */

sp_item.tex: handbutt.tex gatedoor.tex pit.tex br_wall.tex fr_wall.tex dir_spin.tex

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

/* proceedures for extracting various icons */

/* THESE are PROBLEMATIC TO EXTRACT */

cauldron.tex:
	egrep -e "^122 " items | grep "cauldron" | $(AWK) -F'&' \
	-f generic-extract | sort > cauldron.tex

guild.tex:
	egrep -e "^66 " items | grep "guild" | $(AWK) -F'&' \
	-f generic-extract | sort > guild.tex

holysymbol.tex:
	egrep -e "^43 " items | grep "holy" | $(AWK) -F'&' \
	-f generic-extract | sort > holysymbol.tex

lockpicks.tex:
	egrep -e "^43 " items | grep "lockpicks" | $(AWK) -F'&' \
	-f generic-extract | sort > lockpicks.tex

potion.tex:
	egrep -e "^5 " items | grep "potiongen" | $(AWK) -F'&' \
	-f generic-extract | sort > potion.tex

runeblast.tex: items sorter 
	egrep -e "^154 " items | grep "rune-blast" | \
	$(AWK) -F'&' -f generic-extract | sort > runeblast.tex
 
runedeath.tex: items sorter
	egrep -e "^154 " items | grep "rune-death" | \
	$(AWK) -F'&' -f generic-extract | sort > runedeath.tex

runegen.tex: items sorter 
	egrep -e "^154 " items | grep "generic-rune" | \
	$(AWK) -F'&' -f generic-extract | sort > runegen.tex

runefrost.tex: items sorter 
	egrep -e "^154 " items | grep "rune-frost." | \
	$(AWK) -F'&' -f generic-extract | sort > runefrost.tex
 
runefire.tex: items sorter
	egrep -e "^154 " items | grep "rune-fire." | \
	$(AWK) -F'&' -f generic-extract | sort > runefire.tex

runemark.tex: items sorter 
	egrep -e "^98 " items | grep "rune-mark." | \
	$(AWK) -F'&' -f generic-extract | sort > runemark.tex

runeshock.tex: items sorter 
	egrep -e "^154 " items | grep "rune-shock." | \
	$(AWK) -F'&' -f generic-extract | sort > runeshock.tex
 
shops.tex:
	egrep -e "^66 " items | grep "store" | $(AWK) -F'&' \
	-f generic-extract | sort > shops.tex
 
talisman.tex: 
	egrep -e "^43 " items | grep "talisman" | $(AWK) -F'&' \
	-f generic-extract | sort > talisman.tex

/* these are algorthms for extracting all of certain type */
altar.tex: items sorter 
	egrep -e "^18 " items | $(AWK) -F'&' -f generic-extract | sort > altar.tex

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

br_wall.tex: items sorter 
	egrep -e "^45 " items | $(AWK) -F'&' -f generic-extract | sort > br_wall.tex

books.tex: items sorter 
	egrep -e "^8 " items | $(AWK) -F'&' -f generic-extract | sort > books.tex

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

corpse.tex: items sorter 
	egrep -e "^157 " items | $(AWK) -F'&' -f generic-extract | sort > corpse.tex

dir_spin.tex: items sorter 
	egrep -e "^90 " items | $(AWK) -F'&' -f generic-extract | sort > dir_spin.tex 
	egrep -e "^112 " items | $(AWK) -F'&' -f generic-extract | sort >> dir_spin.tex 

flesh.tex: items sorter 
	egrep -e "^72 " items | $(AWK) -F'&' -f generic-extract | sort > flesh.tex

food.tex: items sorter 
	egrep -e "^6 " items | $(AWK) -F'&' -f generic-extract | sort > food.tex

foodone.tex: items sorter 
	egrep -e "^6 " items | $(AWK) -F'&' -f generic-extract | grep "food" > foodone.tex

fr_wall.tex: items sorter 
	egrep -e "^62 " items | $(AWK) -F'&' -f generic-extract | sort > fr_wall.tex

gatedoor.tex: items sorter 
	egrep -e "^20 " items | $(AWK) -F'&' -f generic-extract | sort > gatedoor.tex
	egrep -e "^23 " items | $(AWK) -F'&' -f generic-extract | sort >> gatedoor.tex
	egrep -e "^91 " items | $(AWK) -F'&' -f generic-extract | sort >> gatedoor.tex

gems.tex: items sorter 
	egrep -e "^60 " items | $(AWK) -F'&' -f generic-extract | sort > gems.tex
 
gravestone.tex: items sorter 
	egrep -e "^38 " items | $(AWK) -F'&' -f generic-extract | sort > gravestone.tex

handbutt.tex: items sorter 
	egrep -e "^92 " items | $(AWK) -F'&' -f generic-extract | sort > handbutt.tex 
	egrep -e "^93 " items | $(AWK) -F'&' -f generic-extract | sort >> handbutt.tex

horns.tex: items sorter 
	egrep -e "^35 " items | $(AWK) -F'&' -f generic-extract | sort > horns.tex 

id_altar.tex: items sorter 
	egrep -e "^139 " items | $(AWK) -F'&' -f generic-extract | sort > id_altar.tex 

keys.tex: items sorter 
	egrep -e "^21 " items | $(AWK) -F'&' -f generic-extract | sort > keys.tex
	egrep -e "^24 " items | $(AWK) -F'&' -f generic-extract | sort >> keys.tex

lighter.tex: items sorter 
	egrep -e "^75 " items | $(AWK) -F'&' -f generic-extract | sort > lighter.tex

money.tex: items sorter 
	egrep -e "^36 " items | $(AWK) -F'&' -f generic-extract | sort > money.tex

pit.tex: items sorter 
	egrep -e "^95 " items | $(AWK) -F'&' -f generic-extract | sort > pit.tex

potions.tex: items sorter 
	egrep -e "^5 " items | $(AWK) -F'&' -f generic-extract | sort > potions.tex

rings.tex: items sorter 
	egrep -e "^70 " items | $(AWK) -F'&' -f generic-extract | sort > rings.tex 

rods.tex: items sorter 
	egrep -e "^3 " items | $(AWK) -F'&' -f generic-extract | sort > rods.tex 

savebed.tex: items sorter 
	egrep -e "^106 " items | $(AWK) -F'&' -f generic-extract | sort > savebed.tex

scrolls.tex: items sorter 
	egrep -e "^111 " items | $(AWK) -F'&' -f generic-extract | sort > scrolls.tex

shopmat.tex: items sorter 
	egrep -e "^69 " items | $(AWK) -F'&' -f generic-extract | sort > shopmat.tex

sign.tex: items sorter 
	egrep -e "^98 " items | $(AWK) -F'&' -f generic-extract | sort > sign.tex

wands.tex: items sorter 
	egrep -e "^109 " items | $(AWK) -F'&' -f generic-extract | sort > wands.tex 


install::

depend::

clean::
	$(RM) $(TABLES) $(ICONS)
	$(RM) items .bmaps in_*
	$(RM) *.ps *x*.ppm tmp.ppm work.ppm
	$(RM) handbook.toc handbook.lot handbook.dvi handbook.log handbook.aux

InsertArchive($(FILES),doc/playbook)
InsertArchive(fig/screen_dia.ps,doc/playbook/fig)

patchlist::
	echo $(FILES) > .patchlist

# Depends:
