#
# 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.1f
# variations on release number
NUNDERNA_RELEASE   = 3_1f
NDOTN_RELEASE      = 3.1
NN_RELEASE         = 31

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

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

# 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
#	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

PopupGUI.class: Colour.class

HelpGUI.class: Colour.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

KeyIcon.class FingerIcon.class: KBIcon.class

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

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

ControlGUI.class: Colour.class PopupGUI.class TutorialGUI.class \
	ExerciseGUI.class HelpGUI.class AboutGUI.class StatisticsGUI.class \
	KeyboardGUI.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

Typist$(NN_RELEASE).html: HelpHTML.class HelpTextResource.properties
	java Typist -d > Typist$(NN_RELEASE).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 class files.
Jtypist$(NDOTN_RELEASE).jar:
	make pstamp
	jar -cf Jtypist$(NDOTN_RELEASE).jar *.class *.properties

#	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 Typist$(NN_RELEASE).html
jar: pstamp Jtypist$(NDOTN_RELEASE).jar
typist: pstamp keyboards lessons statistics gui main doc jar

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

# all target; builds the whole thing
all: typist

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

# cleanup make targets
clean:
	rm -rf distribution *.class
	rm -rf Typist$(NN_RELEASE).html
	rm -rf Jtypist$(NDOTN_RELEASE).jar Pstamp.properties

clobber: clean

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

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

uninstall_application:
	-rm -rf $(APPLICATION_LIBDIR)/Jtypist$(NDOTN_RELEASE).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="$(NDOTN_RELEASE)"\
^JTYPIST_LIBRARY="$${JTYPIST_LIBRARY:-/usr/local/lib/jtypist}"\
^JTYPIST_JAR="$${JTYPIST_JAR:-Jtypist$$JTYPIST_RELEASE.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 distribution; mkdir distribution
	ln -s . ./typist$(NN_RELEASE)
	zip -q -9 distribution/typist-$(NUNDERNA_RELEASE)_bin.zip \
		typist$(NN_RELEASE)/README \
		typist$(NN_RELEASE)/COPYING \
		typist$(NN_RELEASE)/Makefile \
		typist$(NN_RELEASE)/Typist$(NN_RELEASE).html \
		typist$(NN_RELEASE)/TypistApplet.html \
		typist$(NN_RELEASE)/Jtypist$(NDOTN_RELEASE).jar
	zip -q -9 distribution/typist-$(NUNDERNA_RELEASE)_src.zip \
		typist$(NN_RELEASE)/README \
		typist$(NN_RELEASE)/COPYING \
		typist$(NN_RELEASE)/Makefile \
		typist$(NN_RELEASE)/TypistApplet.html \
		typist$(NN_RELEASE)/*.java \
		typist$(NN_RELEASE)/*.properties
	cp README distribution
	cd distribution; zip -q -n zip typist-$(NUNDERNA_RELEASE).zip \
		README \
		typist-$(NUNDERNA_RELEASE)_bin.zip \
		typist-$(NUNDERNA_RELEASE)_src.zip
	cd distribution; rm \
		README \
		typist-$(NUNDERNA_RELEASE)_bin.zip \
		typist-$(NUNDERNA_RELEASE)_src.zip
	rm typist$(NN_RELEASE)

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