#
#  PCC2 Plugins
#
#  This builds the PCC2 plugins from existing data (...outside the PCC2 source tree)
#

# Utilities
ZIP   = zip
UNZIP = unzip -o
TOUCH = touch
RM    = rm -f

# Original Files
CCSHIPS  = /dos/e/spool/www/phost.de/~stefan/planets/ccships.zip
CC256    = /dos/e/spool/www/phost.de/~stefan/planets/cc256.zip
PCCMEDIA = $(HOME)/planets-archiv/Media/PCC
SCRIPTS  = /dos/e/planets/cc/qlib
PHOST    = $(HOME)/src/phost

############################### Entry Points ##############################

PLUGINS = \
	shipimages.c2z \
	plist2images.c2z \
	plist3images.c2z \
	tlistimages.c2z \
	auto.c2z \
	checker.c2z \
	comment.c2z \
	exitgame.c2z \
	explmap.c2z \
	load.c2z \
	namer.c2z \
	phost4help.c2z \
	resetwp.c2z \
	revive.c2z \
	swapf4.c2z \
	updown.c2z \
	vis.c2z

all: $(PLUGINS)

clean:
	$(RM) $(PLUGINS)
	$(RM) -r tmp

test: $(PLUGINS)
	@../c2plugin test $(PLUGINS)
	@# Special test for namer:
	@perl -ne 'print "$$2\n" if /^(Script|)File *= *(.*)/' < namer.c2p | sort > tmp/namer1.lst
	@ls -1 namer | grep -vE '^CVS$$|~$$' > tmp/namer2.lst
	@diff tmp/namer1.lst tmp/namer2.lst
	@echo "+++ OK +++"

################################# Plugins #################################

# ShipImages
shipimages.c2z: shipimages.c2p tmp/ccships.res tmp/cc256.res
	$(RM) $@
	$(ZIP) -j $@ $^

tmp/ccships.res: $(CCSHIPS)
	$(UNZIP) -L $< ccships.res -d tmp/
	$(TOUCH) $@

tmp/cc256.res: $(CC256)
	$(UNZIP) -L $< cc256.res -d tmp/
	$(TOUCH) $@

# PList 2 Ships
plist2images.c2z: plist2images.c2p tmp/plist2.res
	$(RM) $@
	$(ZIP) -j $@ $^

tmp/plist2.res: $(PCCMEDIA)/pl2res103.zip
	$(UNZIP) -L $< plist2.res -d tmp/
	$(TOUCH) $@

# PList 3 Ships
plist3images.c2z: plist3images.c2p tmp/plist3.res
	$(RM) $@
	$(ZIP) -j $@ $^

tmp/plist3.res: $(PCCMEDIA)/pl3res103.zip
	$(UNZIP) -L $< plist3.res -d tmp/
	$(TOUCH) $@

# TList Ships
tlistimages.c2z: tlistimages.c2p tmp/tlist.res
	$(RM) $@
	$(ZIP) -j $@ $^

tmp/tlist.res: $(PCCMEDIA)/tlistres10.zip
	$(UNZIP) -L $< tlist.res -d tmp/
	$(TOUCH) $@

# Auto
auto.c2z: auto.c2p $(SCRIPTS)/auto.q
	$(RM) $@
	$(ZIP) -j $@ $^

# Checker
checker.c2z: checker.c2p $(SCRIPTS)/checker.q
	$(RM) $@
	$(ZIP) -j $@ $^

# Comment
comment.c2z: comment.c2p comment.q
	$(RM) $@
	$(ZIP) -j $@ $^

# ExitGame
exitgame.c2z: exitgame.c2p exitgame.q
	$(RM) $@
	$(ZIP) -j $@ $^

# ExplMap
explmap.c2z: explmap.c2p explmap.q
	$(RM) $@
	$(ZIP) -j $@ $^

# Load
load.c2z: load.c2p $(SCRIPTS)/load.q
	$(RM) $@
	$(ZIP) -j $@ $^

# PHost4 Help
phost4help.c2z: phost4help.c2p tmp/phost4help.xml
	$(RM) $@
	$(ZIP) -j $@ $^

tmp/phost4help.xml: $(PHOST)/doc4/*.xml $(PHOST)/doc4/macros.txt ../scripts/import_phost_help.pl ../scripts/SimpleXML.pm phost4help_extra.xml
	perl -I../scripts ../scripts/import_phost_help.pl --extra=phost4help_extra.xml --dir="$(PHOST)/doc4" > tmp/phost4help.xml

# Namer
namer.c2z: namer.c2p namer/*.txt namer/*.q
	$(RM) $@
	$(ZIP) -j $@ $^

# ResetWP
resetwp.c2z: resetwp.c2p resetwp.q
	$(RM) $@
	$(ZIP) -j $@ $^

# Revive
revive.c2z: revive.c2p revive.q
	$(RM) $@
	$(ZIP) -j $@ $^

# SwapF4
swapf4.c2z: swapf4.c2p $(SCRIPTS)/swapf4.q
	$(RM) $@
	$(ZIP) -j $@ $^

# Updown
updown.c2z: updown.c2p $(SCRIPTS)/updown.q
	$(RM) $@
	$(ZIP) -j $@ $^

# Vis
vis.c2z: vis.c2p $(SCRIPTS)/vis.q
	$(RM) $@
	$(ZIP) -j $@ $^

# Scripts      In PCC1 Library       Package?
# addres.q                           no
# auto.q             x               x
# autoexec.q         x               no
# bum-ori.q                          no, old version
# bum.q              x               LATER (not user-friendly, needs more hooks)
# cargo.q            x               LATER (script library)
# checker.q          x               x
# comment.q          x               x
# compat.q                           no
# explmap.q          x               x
# fborg.q            x
# fixtow.q           x               LATER (script library)
# goto-ori.q                         no, old version
# goto.q             x
# hidename.q         x
# load.q             x               x
# marker.q           x
# move.q             x
# namer.q                            x
# nextturn.q         x
# plist.q            x               no, not needed
# psmap.q            x
# qvs.q
# revive.q           x               x
# resetwp.q                          NEW (ex autoexec.q)
# savehost.q         x
# savemark.q         x
# scr-s-f.q          x
# scr-s-f1.q                         no, old version
# scr-s-o.q          x
# shadow.q           x
# starbase.q         x
# swapf4.q           x               x
# target.q           x
# taxes.q            x
# tty.q              x
# updown.q                           x
# vis.q              x               x
# wpmove.q           x
# xmms.q
