# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

ROOT    = ..
SHELL   = /bin/sh

#
# Level number pushbutton gifs and zip file.
#
LGIFS	= \
	l1u.gif l2u.gif l3u.gif l4u.gif l5u.gif l6u.gif l7u.gif l8u.gif	\
	l1d.gif l2d.gif l3d.gif l4d.gif l5d.gif l6d.gif l7d.gif l8d.gif
LGIFZIP	= levels.zip

#
# White/black pushbutton gifs and zip file.
#
CGIFS	= \
	whiteu.gif blacku.gif whited.gif blackd.gif
CGIFZIP	= colors.zip

#
# Quit, New, Undo, Load, Save, and Busy pushbutton gifs and zip files.
#
QGIFS	= \
	quitu.gif quitd.gif
QGIFZIP	= quit.zip
NGIFS	= \
	newu.gif newd.gif
NGIFZIP	= new.zip
UGIFS	= \
	undou.gif undod.gif
UGIFZIP	= undo.zip
FGIFS	= \
	loadu.gif loadd.gif saveu.gif saved.gif
FGIFZIP	= file.zip
BGIFS	= \
	busyu.gif busyd.gif
BGIFZIP	= busy.zip

#
# Eight level radiobutton images.
#
LEVELS	= \
	l1.png l2.png l3.png l4.png l5.png l6.png l7.png l8.png

#
# Two white/black radiobutton images.
#
COLORS	= \
	cw.png cb.png

#
# Quit, New, Undo, Load, Save, and Busy images.
#
QFBNUNDO	= \
	qu.png qd.png nu.png nd.png uu.png ud.png lu.png ld.png su.png sd.png \
	bu.png bd.png

#
# Default make target.
#
default:	all

#
# Unpack level gifs.
#
$(LGIFS):	$(LGIFZIP)
	unzip -qquL $(LGIFZIP) $@

#
# Conversion macro for level buttons.  Fix the size to 32x32 (originals
# are 33x29), and antialias (using foreground antialiasing, rather than
# background, improves the look of the finished image).
#
LG	= giftopnm | pnmmargin -white 2				\
		| pnmalias -fonly -falias -fgcolor white	\
		| pnmcut -left 3 -top 1 -width 32 -height 32

#
# Intermediate pnm file dependencies.
#
l1u.pnm:	l1u.gif
	cat $< | $(LG) > $@	
l2u.pnm:	l2u.gif
	cat $< | $(LG) > $@	
l3u.pnm:	l3u.gif
	cat $< | $(LG) > $@	
l4u.pnm:	l4u.gif
	cat $< | $(LG) > $@	
l5u.pnm:	l5u.gif
	cat $< | $(LG) > $@	
l6u.pnm:	l6u.gif
	cat $< | $(LG) > $@	
l7u.pnm:	l7u.gif
	cat $< | $(LG) > $@	
l8u.pnm:	l8u.gif
	cat $< | $(LG) > $@	
l1d.pnm:	l1d.gif
	cat $< | $(LG) > $@	
l2d.pnm:	l2d.gif
	cat $< | $(LG) > $@	
l3d.pnm:	l3d.gif
	cat $< | $(LG) > $@	
l4d.pnm:	l4d.gif
	cat $< | $(LG) > $@	
l5d.pnm:	l5d.gif
	cat $< | $(LG) > $@	
l6d.pnm:	l6d.gif
	cat $< | $(LG) > $@	
l7d.pnm:	l7d.gif
	cat $< | $(LG) > $@	
l8d.pnm:	l8d.gif
	cat $< | $(LG) > $@	

#
# Level button dependencies and build commands.
#
l1.png:	l1d.pnm l2u.pnm l3u.pnm l4u.pnm l5u.pnm l6u.pnm l7u.pnm l8u.pnm
	pnmcat -lr l1d.pnm l2u.pnm l3u.pnm l4u.pnm	\
		   l5u.pnm l6u.pnm l7u.pnm l8u.pnm | pnmtopng >$@
l2.png:	l1u.pnm l2d.pnm l3u.pnm l4u.pnm l5u.pnm l6u.pnm l7u.pnm l8u.pnm
	pnmcat -lr l1u.pnm l2d.pnm l3u.pnm l4u.pnm	\
		   l5u.pnm l6u.pnm l7u.pnm l8u.pnm | pnmtopng >$@
l3.png:	l1u.pnm l2u.pnm l3d.pnm l4u.pnm l5u.pnm l6u.pnm l7u.pnm l8u.pnm
	pnmcat -lr l1u.pnm l2u.pnm l3d.pnm l4u.pnm	\
		   l5u.pnm l6u.pnm l7u.pnm l8u.pnm | pnmtopng >$@
l4.png:	l1u.pnm l2u.pnm l3u.pnm l4d.pnm l5u.pnm l6u.pnm l7u.pnm l8u.pnm
	pnmcat -lr l1u.pnm l2u.pnm l3u.pnm l4d.pnm	\
		   l5u.pnm l6u.pnm l7u.pnm l8u.pnm | pnmtopng >$@
l5.png:	l1u.pnm l2u.pnm l3u.pnm l4u.pnm l5d.pnm l6u.pnm l7u.pnm l8u.pnm
	pnmcat -lr l1u.pnm l2u.pnm l3u.pnm l4u.pnm	\
		   l5d.pnm l6u.pnm l7u.pnm l8u.pnm | pnmtopng >$@
l6.png:	l1u.pnm l2u.pnm l3u.pnm l4u.pnm l5u.pnm l6d.pnm l7u.pnm l8u.pnm
	pnmcat -lr l1u.pnm l2u.pnm l3u.pnm l4u.pnm	\
		   l5u.pnm l6d.pnm l7u.pnm l8u.pnm | pnmtopng >$@
l7.png:	l1u.pnm l2u.pnm l3u.pnm l4u.pnm l5u.pnm l6u.pnm l7d.pnm l8u.pnm
	pnmcat -lr l1u.pnm l2u.pnm l3u.pnm l4u.pnm	\
		   l5u.pnm l6u.pnm l7d.pnm l8u.pnm | pnmtopng >$@
l8.png:	l1d.pnm l2u.pnm l3u.pnm l4u.pnm l5u.pnm l6u.pnm l7u.pnm l8d.pnm
	pnmcat -lr l1u.pnm l2u.pnm l3u.pnm l4u.pnm	\
		   l5u.pnm l6u.pnm l7u.pnm l8d.pnm | pnmtopng >$@

#
# Build level buttons.
#
levels:	Makefile $(LGIFZIP) $(LEVELS)

#
# Unpack color gifs.
#
$(CGIFS):	$(CGIFZIP)
	unzip -qquL $(CGIFZIP) $@

#
# Conversion macro for non-level buttons.  Antialias, then fix the height
# at 32 pixels.
#
BG	= giftopnm | pnmmargin -white 2				\
		| pnmalias -fonly -falias -fgcolor white	\
		| pnmcut -top 1 -height 32

#
# Intermediate pnm file dependencies.
#
whiteu.pnm:	whiteu.gif
	cat $< | $(BG) > $@
whited.pnm:	whited.gif
	cat $< | $(BG) > $@
blacku.pnm:	blacku.gif
	cat $< | $(BG) > $@
blackd.pnm:	blackd.gif
	cat $< | $(BG) > $@

#
# Build the white/black buttons.
#
cw.png: whited.pnm blacku.pnm
	pnmcat -lr whited.pnm blacku.pnm | pnmtopng >$@

cb.png: whiteu.pnm blackd.pnm
	pnmcat -lr whiteu.pnm blackd.pnm | pnmtopng >$@

#
# Build the color buttons.
#
colors:	Makefile $(CGIFZIP) $(COLORS)

#
# Unpack gifs.
#
$(QGIFS):	$(QGIFZIP)
	unzip -qquL $(QGIFZIP) $@
$(NGIFS):	$(NGIFZIP)
	unzip -qquL $(NGIFZIP) $@
$(UGIFS):	$(UGIFZIP)
	unzip -qquL $(UGIFZIP) $@
$(FGIFS):	$(FGIFZIP)
	unzip -qquL $(FGIFZIP) $@
$(BGIFS):	$(FGIFZIP)
	unzip -qquL $(BGIFZIP) $@

#
# Build the Quit, New, Undo, Load, Save, and Busy button pngs.
#
qu.png: quitu.gif
	cat $< | $(BG) | pnmtopng >$@
qd.png: quitd.gif
	cat $< | $(BG) | pnmtopng >$@

nu.png: newu.gif
	cat $< | $(BG) | pnmtopng >$@
nd.png: newd.gif
	cat $< | $(BG) | pnmtopng >$@

uu.png: undou.gif
	cat $< | $(BG) | pnmtopng >$@
ud.png: undod.gif
	cat $< | $(BG) | pnmtopng >$@

lu.png: loadu.gif
	cat $< | $(BG) | pnmtopng >$@
ld.png: loadd.gif
	cat $< | $(BG) | pnmtopng >$@
su.png: saveu.gif
	cat $< | $(BG) | pnmtopng >$@
sd.png: saved.gif
	cat $< | $(BG) | pnmtopng >$@

bu.png: busyu.gif
	cat $< | $(BG) | pnmtopng >$@
bd.png: busyd.gif
	cat $< | $(BG) | pnmtopng >$@

#
# Build Quit, New, Undo, Load, Save, and Busy buttons.
#
qfbnundo:	Makefile $(QGIFZIP) $(UGIFZIP) $(QFBNUNDO)

#
# Targets.
#
all:	levels colors qfbnundo

clean:
	rm -f *.gif *.png *.pnm
