# Licensed under the LGPL v2 or later license.
# Copyright Frank Edwards, <frank@eec.com>
#
# This script reads the HTML in the '1-spells/' subdirectory and
# eventually creates a series of MapTool macro sets that can be imported
# into MapTool for use with lmarkus' D&D3.5/PF campaign framework.
#
# Essentially, this makefile controls the operation.  First, all HTML is
# processed through an XSL that strips out all unwanted data (this has
# the side effect of converting Unicode characters to their \u####
# equivalents).  These new files are read and a list of spell names and
# class/level pairs is generated.  The output is a Perl script.  (The
# first script could actually do the next two steps itself, but I wanted
# separate steps so that I could break into the process and tweak things
# at each stage, if necessary.  Also easier for debugging in some cases.)
#
# This last Perl script is executed in a subdirectory.  It uses the list
# of spell names compiled earlier.  This list is merged with a template XML
# document to form the required XML for a single macro.  All of this XML
# for a single character class is written to a single XML file with the
# correct wrapping element.  This allows the MapTool RPTOK to be
# generated and then drag/drop'd onto a map. :)
#
# Expectations:
#    The directory '1-spells/' contains each of the spell pages from the
#    SRD web site at www.d20srd.org.
#
#    The file 'example.rptok' is the result of saving a MapTool token.
#    The contents are unimportant as they will be replaced, but the rest
#    of the data is used as a template.
#
# Things generated by this makefile:
#    A directory called '2-macro/' to contain each spell converted to a
#    macro as a separate file.
#
#    A script called 'createMacroXML.pl'.  Executed to convert the
#    individual macro files into full HTML form for use in MapTool.
#
#    A directory called 'tmp/' will be created to hold the results of
#    the following steps.
#
#    The 'createMacroXML.pl' script is executed and the output
#    redirected to 'generateByClassXML.sh'.
#
#    The 'generateByClassXML.sh' script will be executed.
.PHONY: cleanup raw1 raw2 xml checkin
all: cleanup raw1 raw2 xml

clean:
	rm -rf 2-macro tmp
	rm -f createMacroXML.pl

cleanup:
	rm -f 1-spells/lesserSpellName.htm 1-spells/massSpellName.htm
	rm -rf tmp

raw1: createMacroXML.pl
createMacroXML.pl: Makefile _convert.sh _exemplar.xsl 1-spells/*
	./_convert.sh 2-macro 1-spells/*
	./_cleanup.pl 2-macro/* > createMacroXML.pl

raw2: generateByClassXML.sh
generateByClassXML.sh: createMacroXML.pl
	-mkdir tmp
	cd tmp; \
	    ln -s ../2-macro .; \
	    perl ../createMacroXML.pl > generateByClassXML.sh

xml:
	cd tmp; bash generateByClassXML.sh
	# We no longer bother with macrosets since we build tokens directly.
	# cd tmp; bash ../packageMTMacroset.sh
	cd tmp; perl ../packageTokens.pl


FILES=Makefile _cleanup.pl _convert.sh _exemplar.xsl \
    downloadSpells.sh makeSpellURLs.pl mb2ascii.pl packageTokens.pl

checkin:
	ci -l $(FILES)

zip:
	zip -r9 spellMacros $(FILES)
