# Makefile for ShowSort.

.PHONY: clean veryclean tar all install install_bin

#JAVAC      = javac
#JAVAC      = guavac
JAVAC       = gcj -C # The fastest Java compiler I've seen.
#JAVAC      = jikes  # The second-fastest
JCFLAGS     = 
CLASSDIR    = $(HOME)/classes
APPCLASSES  = InsertionSort.class SelectionSort.class QuickSort.class BubbleSort.class ShellSort.class \
              RadexchSort.class HeapSort.class MergeSort.class
BASECLASSES = ShowSort.class ShowSortFrame.class
MISCCLASSES = HLine.class DoNothing.class
CLASSES     = $(BASECLASSES) $(APPCLASSES) $(MISCCLASSES)
JSRCS       = $(CLASSES:.class=.java)
MISC        = index.html Makefile demo.html demo.css COPYING
BINDIR      = $(HOME)/bin

.SUFFIXES: .class .java

# JDK 1.1.7 uses JDK_HOME to find its classes.zip (even if $CLASSPATH is
# specified), but does not use it if we use -classpath.  The upshot of this
# is that, in order to allow this to work even when $CLASSPATH does not
# include classes.zip, we must add "." to the $CLASSPATH environment variable,
# not to the -classpath parameter.

.java.class:
	CLASSPATH=$(CLASSPATH):. $(JAVAC) $(JCFLAGS) $<

all: $(APPCLASSES) $(MISCCLASSES)
	chmod 0755 $(APPCLASSES)

InsertionSort.class: $(BASECLASSES)
SelectionSort.class: $(BASECLASSES)
QuickSort.class:     $(BASECLASSES)
BubbleSort.class:    $(BASECLASSES)
ShellSort.class:     $(BASECLASSES)
RadexchSort.class:   $(BASECLASSES)
HeapSort.class:      $(BASECLASSES)
MergeSort.class:     $(BASECLASSES)
ShowSortFrame.class: ShowSort.class


ShowSort.tar.gz: $(JSRCS) $(MISC)
	-mkdir ShowSort/
	cp -f $(JSRCS) $(MISC) ShowSort/
	tar cf ShowSort.tar ShowSort/
	gzip -f ShowSort.tar
	rm -rf ShowSort/

tar: ShowSort.tar.gz

install: $(CLASSES)
	install -d $(CLASSDIR)
	install -m 0755 $(APPCLASSES) $(CLASSDIR)
	install -m 0644 $(BASECLASSES) $(MISCCLASSES) $(CLASSDIR)

install_bin: install
	for x in $(APPCLASSES); do \
	    ln -sf $(CLASSDIR)/$$x $(BINDIR)/`basename $$x .class`; \
	done

clean:
	-rm *.class
	-rm -rf ShowSort/

veryclean: clean
	-rm ShowSort.tar.gz
