/*   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 spoiler.html spoiler.shtml\
	helm-extract mag-extract shield-extract items-extract \
	makeps makeps.pl empty.pbm bow-extract arche-extract weap-extract

HTML =	monput.html spells.html stats.html weap.html shield.html helmet.html \
	mag.html arm.html arche.html bow.html version.html weapmag.html

 CROSSRC = ../..
  INCDIR = $(CROSSRC)/include
  IMGDIR = $(CROSSRC)/doc/spoiler
  CROSSBIN = ../../server/crossfire
/*CROSSBIN = $(C_BINDIR)/crossfire*/
#if 0
#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
#else
#define MAKEPS(in,out) makeps.pl libdir=$(CROSSRC)/lib \
	archdir=$(CROSSRC)/lib/ size=0.4 input=in \
	inarch=$(C_LIBDIR)/archetypes > out
#endif
/*
CROSSBIN= $(C_BINDIR)/$(HOSTTYPE)/crossfire.`cat $(C_BINDIR)/$(HOSTTYPE)/last`
*/

spoiler.html:: $(HTML) spoiler.shtml
	../include_html.pl spoiler.shtml spoiler.html

all::

$(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) *.gif
	touch .bmaps

items: .bmaps in_items makeps items.gif
	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.html: .bmaps in_stats makeps stats.gif
	MAKEPS(in_stats,stats.html)

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.html: .bmaps in_monput makeps monsters.gif
	MAKEPS(in_monput,monput.html)

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

spells.html: .bmaps in_spells makeps spells.gif
	MAKEPS(in_spells,spells.html)

in_spells: spells-extract  $(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.html: $(CROSSBIN)
	$(CROSSBIN) -v 2>&1 | grep "^This is" | \
		cut -d" " -f3- > version.html

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


weap.html: items 
	egrep -e "^15 " items | $(AWK) -F'&' '{printf("<tr><th>%s</th><td>%s</td><td>%s</td><td>%.2f</td><td>%s</td></tr>\n",$$3,$$10,$$5,$$11,$$6)}' > weap.html

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

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

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

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

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

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

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

install::

depend::

clean::
	$(RM) items .bmaps in_monput in_items in_spells in_stats
	$(RM) *x*.ppm tmp.ppm work.ppm

InsertArchive($(FILES),doc/spoiler-html)

patchlist::
	echo $(FILES) > .patchlist

# Depends:
