#
# 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.1 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 Lesser 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

#
# Icon image and blorbtar locations, and PNG distribution file.
#
ICONS	= ./Icons
TOOLS	= ./Tools
IMAGEZIP= images.zip

#
# Compilation options for inform.
#
INFORM_OPTS	= '$$MAX_STATIC_DATA=40000'

#
# Standard method to compile .inf files.
#
GLULX_INFORM    = ../inform630/inform -G $(INFORM_OPTS)
GLULX_FLAGS     = -~S
#GLULX_FLAGS    = -D
.SUFFIXES:
.SUFFIXES:      .inf .ulx
.inf.ulx:
	$(GLULX_INFORM) $(GLULX_FLAGS) $<

#
# Distribution file.
#
DISTFILE= glkebook_src.zip

#
# Executable files.
#
GLKEBOOK= glkebook.blb
GLKEBULX= glkebook.ulx

#
# Blorbtar tool.
#
BLORBTAR= $(TOOLS)/blorbtar

#
# List of all image resources required.
#
IMAGES	=  PIC1  PIC2  PIC3  PIC4  PIC5  PIC6  PIC7  PIC8  PIC9  PIC10	\
	   PIC11 PIC12 PIC13 PIC14 PIC15 PIC16 PIC17 PIC18

#
# Default make target.
#
default:	all

#
# Extract image resources.
#
$(ICONS)/$(IMAGEZIP):
	cd $(ICONS) && $(MAKE) all
$(IMAGEZIP):	$(ICONS)/$(IMAGEZIP)
	cp $< $@
$(IMAGES):	$(IMAGEZIP)
	unzip -qqu $(IMAGEZIP) $@ && touch $@

#
# Build targets.
#
all:	$(GLKEBOOK)

STORY0:		$(GLKEBULX)
	cp $< $@

$(GLKEBOOK):	STORY0 $(IMAGES) $(BLORBTAR)
	$(BLORBTAR) cv $(GLKEBOOK) STORY0 $(IMAGES)

$(BLORBTAR):
	cd $(TOOLS) && $(MAKE) all

clean:
	cd $(ICONS) && $(MAKE) clean
	cd $(TOOLS) && $(MAKE) clean
	rm -f STORY0 PIC* $(GLKEBULX) $(GLKEBOOK) GLKEBOOK.BMK

distclean:	clean
	cd $(ICONS) && $(MAKE) distclean

maintainer-clean:	distclean
	cd $(ICONS) && $(MAKE) maintainer-clean
	rm -f $(DISTFILE) $(IMAGEZIP)

#
# Distribution target.
#
dist:
	$(MAKE) maintainer-clean $(IMAGEZIP)
	$(MAKE) distclean
	zip -9 -r $(DISTFILE) * -x $(DISTFILE)
