#
# JTypist v3.1 - Java typing tutor program for UNIX systems
# Copyright (C) 2000  Simon Baldwin (simonb@sco.com)
#
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
# Makefile for typist 3.1 (Java version)
#

# fundamental release number
FULL_RELEASE       = 3.1h
# variations on release number
NDOTNA_RELEASE     = 3.1h
NDOTN_RELEASE      = 3.1
NNA_RELEASE        = 31h
NN_RELEASE         = 31

# application installation directories
APPLICATION_LIBDIR = /usr/local/lib/jtypist
APPLICATION_BINDIR = /usr/local/bin

# general temporary directory, and distribution directory
TEMPDIR            = tempdir
DISTDIR            = distribution

#-----------------------------------------------------------------------------

# compiler flags (debug, optimization...)
JAVAC = javac
#JAVAC = guavac
#JAVAC_FLAGS =
JAVAC_FLAGS = -deprecation
#JAVAC_FLAGS = -g -deprecation
#JAVAC_FLAGS = -O -deprecation

# suffixes and implicit rule to enable java compilations
.SUFFIXES:	.java .class

.java.class:
	$(JAVAC) $(JAVAC_FLAGS) $<

#-----------------------------------------------------------------------------

# default make target (first one in the file)
default: all

#-----------------------------------------------------------------------------

# reasonably complete dependency structure
#	Graphics reimplementations
ImageLabel.class: Xpm.class

ImageButton.class: ImageLabel.class Xpm.class

#	Key structures
KBNamespace.class: Finger.class GlyphGroup.class KeyCode.class \
	KeyShiftState.class

Glyph.class: Finger.class GlyphGroup.class KeyShiftState.class KeyCode.class

KBLayout.class: Glyph.class Finger.class GlyphGroup.class \
	KeyShiftState.class KeyCode.class

#	Lesson series
ExerciseLesson.class TutorialLesson.class: Lesson.class

DrillLesson.class ParagraphLesson.class: ExerciseLesson.class

LessonSeries.class: TutorialLesson.class DrillLesson.class \
	ParagraphLesson.class

#	Keystroke statistics
KBStatistics.class: KeyingStatistics.class KBLayout.class

#	GUI classes and doc classes
AboutGUI.class: Colour.class ImageLabel.class

PopupGUI.class: Colour.class ImageLabel.class

HelpGUI.class: Colour.class Tooltip.class

TutorialGUI.class: Colour.class TutorialLesson.class History.class

ExerciseGUIStats.class: Colour.class ExerciseLesson.class \
	KeyingStatistics.class KeyingRhythm.class

StatisticsGUI.class: Colour.class KBStatistics.class Gauge.class \
	ImageButton.class Tooltip.class

KeyIcon.class FingerIcon.class: KBIcon.class

KeyboardGUI.class: Colour.class Finger.class Glyph.class KBLayout.class \
	KeyIcon.class FingerIcon.class Tooltip.class

ExerciseGUI.class: Colour.class Lesson.class KeyingStatistics.class \
	KBStatistics.class ExerciseGUIStats.class StatisticsGUI.class \
	KeyboardGUI.class History.class KBTranslator.class ImageButton.class \
	Tooltip.class

ControlGUI.class: Colour.class PopupGUI.class TutorialGUI.class \
	ExerciseGUI.class HelpGUI.class AboutGUI.class StatisticsGUI.class \
	KeyboardGUI.class ImageButton.class Tooltip.class

InitProgressGUI.class: Colour.class Gauge.class

Typist.class: InitProgressGUI.class ControlGUI.class TutorialGUI.class \
	ExerciseGUI.class HelpGUI.class AboutGUI.class StatisticsGUI.class \
	KBStatistics.class KBLayout.class KBTranslator.class

#-----------------------------------------------------------------------------

# JtNNxxx.yyy files - documentation, and classes jar files
#	General documentation, and applet launcher HTML page
Jt$(NN_RELEASE)doc.html: HelpHTML.class HelpTextResource.properties
	java HelpHTML > Jt$(NN_RELEASE)doc.html

Jt$(NN_RELEASE)app.html Jt${NN_RELEASE}app.htm: TypistApplet.html
	sed -e 's;{NN_RELEASE};$(NN_RELEASE);g' \
		-e 's;{NDOTNA_RELEASE};$(NDOTNA_RELEASE);g' \
		-e 's;{NDOTN_RELEASE};$(NDOTN_RELEASE);g' \
		< TypistApplet.html > Jt$(NN_RELEASE)app.html

#	Classes and properties Jar file; note that this does not specify
#	dependencies on the actual class files and properties files that
#	it packages up - it works only with what's available. This is a
#	minor break in dependencies, but it does allow the make for
#	install_application to proceed in the absence of the .java files.
#	This is also where we flatten out the complete structure, so that
#	all of the classes and properties files come together.
Jt$(NN_RELEASE)cla.jar:
	make pstamp
	rm -rf $(TEMPDIR); mkdir $(TEMPDIR)
	ln lessons/*.properties keyboard/*.properties images/*.properties \
		*.properties *.class \
		$(TEMPDIR)
	cd $(TEMPDIR); jar -cf ../Jt$(NN_RELEASE)cla.jar *
	rm $(TEMPDIR)/*; rmdir $(TEMPDIR)

#	Tiny properties files that just notes the date and time of the
#	build; useful for debugging only
pstamp:
	@echo "Pstamp=`hostname` `date +%Y%m%d%H%M%S`" >Pstamp.properties

#-----------------------------------------------------------------------------

# selected entry points into dependencies
keyboards: pstamp KBLayout.class KBNamespace.class
lessons: pstamp LessonSeries.class
statistics: pstamp KBStatistics.class
gui: pstamp ControlGUI.class
main: pstamp Typist.class
doc: pstamp Jt$(NN_RELEASE)doc.html Jt$(NN_RELEASE)app.html
jar: pstamp Jt$(NN_RELEASE)cla.jar
typist: pstamp keyboards lessons statistics gui main doc jar

#-----------------------------------------------------------------------------

# all target; builds the whole thing
all: typist

#-----------------------------------------------------------------------------

# cleanup make targets
clean:
	rm -rf $(TEMPDIR) $(DISTDIR) *.class
	rm -rf Jt$(NN_RELEASE)doc.html Jt$(NN_RELEASE)app.html
	rm -rf Jt$(NN_RELEASE)cla.jar Pstamp.properties

clobber: clean

#-----------------------------------------------------------------------------

# install and uninstall are aliases for *_application
install: install_application

uninstall: uninstall_application

# (un)installation targets for a convenient form of the application
install_application: Jt$(NN_RELEASE)cla.jar wrapper
	-mkdir -p $(APPLICATION_LIBDIR)
	cp Jt$(NN_RELEASE)cla.jar $(APPLICATION_LIBDIR)

uninstall_application:
	-rm -rf $(APPLICATION_LIBDIR)/Jt$(NN_RELEASE)cla.jar
	-rmdir $(APPLICATION_LIBDIR)
	-rm -f $(APPLICATION_BINDIR)/jtypist
	-rmdir $(APPLICATION_BINDIR)

JTYPIST_WRAPPER=\
%!/bin/sh\
^%\
^% JTypist - Java typing tutor program for UNIX systems\
^% Copyright (C) 2000  Simon Baldwin (simonb@sco.com)\
^%\
^% Java typing tutor wrapper\
^%\
^\
^% some constants\
^JTYPIST_RELEASE="$(NN_RELEASE)"\
^JTYPIST_LIBRARY="$${JTYPIST_LIBRARY:-/usr/local/lib/jtypist}"\
^JTYPIST_JAR="$${JTYPIST_JAR:-Jt$${JTYPIST_RELEASE}cla.jar}"\
^JTYPIST_CLASS="$${JTYPIST_CLASS:-Typist}"\
^JTYPIST_JAVA="$${JTYPIST_JAVA:-java}"\
^ME="`basename $$0`"\
^\
^% run the Java application from the installed jar class library\
^if [ -f "$$JTYPIST_LIBRARY/$$JTYPIST_JAR" ]; then\
^	CLASSPATH="$$CLASSPATH:$$JTYPIST_LIBRARY/$$JTYPIST_JAR"\
^	export CLASSPATH\
^	$$JTYPIST_JAVA $$JTYPIST_CLASS "$$@"\
^	exit $$?\
^fi\
^\
^% not installed, apparently\
^echo "$$ME: ERROR: application $$JTYPIST_LIBRARY/$$JTYPIST_JAR not found" >&2\
^exit 1

wrapper:
	-mkdir -p $(APPLICATION_BINDIR)
	@echo '$(JTYPIST_WRAPPER)' | tr '%^' '#\n' | sed -e 's; *$$;;' \
			>$(APPLICATION_BINDIR)/jtypist
	chmod 755 $(APPLICATION_BINDIR)/jtypist

#-----------------------------------------------------------------------------

# target to make a distribution of the package
distribution: all
	rm -rf $(DISTDIR) $(TEMPDIR); mkdir $(DISTDIR) $(TEMPDIR)
	zip -q -9 $(TEMPDIR)/Jt$(NN_RELEASE)src.zip \
		README COPYING Makefile TypistApplet.html \
		*.java *.properties \
		images/*.properties keyboard/*.properties lessons/*.properties
	( echo "JTypist v$(NDOTNA_RELEASE) - Java typing tutor program"; \
	  echo "Copyright (C) 2000  Simon Baldwin (simonb@sco.com)" ) | \
	zip -z -j -q -9 -n .zip:.jar \
				$(DISTDIR)/jtypist-$(NDOTNA_RELEASE).zip \
		README COPYING Makefile \
		Jt$(NN_RELEASE)doc.html Jt$(NN_RELEASE)app.html \
		Jt$(NN_RELEASE)cla.jar $(TEMPDIR)/Jt$(NN_RELEASE)src.zip
	rm $(TEMPDIR)/*; rmdir $(TEMPDIR)

# target to create a floppy disk copy of the distribution
floppy: distribution
	cd $(DISTDIR); tar cvf /dev/fd0 jtypist-$(NDOTNA_RELEASE).zip

#-----------------------------------------------------------------------------
