#
# $Id: Makefile,v 1.12 2005/08/03 17:00:27 robo Exp $
#
# RabbIT .java Makefile
#

#
# Compiler path and flags
#
#JAVAC = /usr/lib/java/bin/javac
JAVAC = javac
JCFLAGS = -O -Xlint:unchecked -Xmaxerrs 200

#
# JavaDoc path and flags
#
#JAVADOC = /usr/lib/java/bin/javadoc
JAVADOC = javadoc
JDFLAGS =

#
# Classpath
#
include classpath

#
# Source file base directory
#
SRCDIR := src

#
# Class file destination base directory
#
CLASSDIR := .

#
# Documentation destination base directory
#
DOCDIR := htdocs/doc

#
# Fully qualified packages to compile in the
# SRCDIR defined above. This implies that the
# source directories have the same structure
# as the standard class file hierarchy.
#
PACKAGES := \
	rabbit.awt \
	rabbit.cache \
	rabbit.filter \
	rabbit.handler \
	rabbit.html \
	rabbit.http \
	rabbit.installer \
	rabbit.io \
	rabbit.linkchecker \
	rabbit.meta \
	rabbit.proxy \
	rabbit.spider \
	rabbit.util \
	rabbit.webserver

#
# Automatic package list generation, hopefully not too slow
# Dang, it's broken. Wait another day or two. /EA
#
#PACKAGES := `find src/rabbit/ -type d | grep -v RCS$$ | \
# grep -v CVS$$ | sed -e 's/\\//\\./g' | sed -e 's/^src\\.//g'`

###########################################################
# Don't change anything below
###########################################################
SRCDIRS := $(addprefix $(SRCDIR)/,$(subst .,/,$(PACKAGES)))
SRCDIRS := $(addsuffix /,$(SRCDIRS))
VPATH := $(SRCDIR)
SOURCES := $(wildcard $(addsuffix *.java,$(SRCDIRS)))
CLASSES := $(patsubst $(SRCDIR)/%,%,$(SOURCES))
CLASSES := $(CLASSES:.java=.class)
DOCS := $(patsubst $(SRCDIR)/%,$(DOCDIR)/%,$(SOURCES))
DOCS := $(DOCS:.java=.html)
$empty=

% : %,v

% : RCS/%,v

%.class : %.java	
	@echo $<
	@$(JAVAC) $(JCFLAGS) -classpath $(CLASSPATH) -sourcepath $(SRCDIR) -d $(CLASSDIR) $<

all:
	@echo " - RabbIT somewhat generic Java makefile -"
	@echo "Usage: make [code|doc|packages|<packagename>]"
	@echo "       default package(s) for code and doc targets: $(PACKAGES)"


test:
	@echo sources: $(SOURCES)
	@echo classes: $(CLASSES)
	@echo cs: $(CS)

clean:
	@echo " - If you really want to do this manually remove the rabbit directory. -"

ifeq ($(SOURCES),$(empty))

code: nosource

doc: nosource

else

code: $(CLASSES)
	@echo "All done"

everything: 
	@$(JAVAC) $(JCFLAGS) -classpath $(CLASSPATH) -sourcepath $(SRCDIR) -d $(CLASSDIR) $(SOURCES)
	@echo "All done"	

doc:  $(SOURCES)
	$(JAVADOC) $(JDFLAGS) -sourcepath $(SRCDIR):$(CLASSPATH) -d $(DOCDIR) $(PACKAGES)

endif


ifeq ($(MAKELEVEL),0)

%::
	@make --no-print-directory PACKAGES=$* code

endif

nosource:
	@echo Sources for package $(PACKAGES) not found
	@exit 42

