JAVAC = @JAVAC@
JAVACFLAGS = @JAVACFLAGS@
JAR = jar
JAVADEBUGFLAGS = #-Xlint:deprecation -Xlint:unchecked

LUCENE_VER = 4.7.2


LUCENE3_JAR = ./lib/lucene-core-3.3.0.jar
#LUCENE3_JAR = ./lib/lucene-core-3.6.0.jar

# To have a manifest file that lists the jar dependencies for a jar file:

# http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
# https://blogs.oracle.com/olaf/entry/jdev_including_a_classpath_in
# http://www.coderanch.com/t/482185/java/java/classpath
# http://todayguesswhat.blogspot.co.nz/2011/03/jar-manifestmf-class-path-referencing.html
# http://stackoverflow.com/questions/9684737/class-not-found-despite-of-classpath-in-manifest
# http://stackoverflow.com/questions/219585/setting-multiple-jars-in-java-classpath
# JAVA 6 JVM and later allows use of wildcards in classpath 
# http://stackoverflow.com/questions/11607873/escape-wildcard-processing-in-java-classpath/11608165#comment15368871_11608165
# http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html


LUCENE4_WRAPPER_OBJECTS = \
	classes4/org/greenstone/LuceneWrapper4/GSLuceneConstants.class \
	classes4/org/greenstone/LuceneWrapper4/GSLuceneUtil.class \
	classes4/org/greenstone/LuceneWrapper4/GS2Analyzer.class \
	classes4/org/greenstone/LuceneWrapper4/GS2LuceneDelete.class \
	classes4/org/greenstone/LuceneWrapper4/GS2LuceneEditor.class \
	classes4/org/greenstone/LuceneWrapper4/GS2LuceneIndexer.class \
	classes4/org/greenstone/LuceneWrapper4/GS2LuceneQuery.class \
	classes4/org/greenstone/LuceneWrapper4/LuceneQueryResult.class \
	classes4/org/greenstone/LuceneWrapper4/SharedSoleneQuery.class \
	classes4/org/greenstone/LuceneWrapper4/SharedSoleneQueryResult.class

LUCENE4_WRAPPER_JAR = LuceneWrapper4.jar


LUCENE3_WRAPPER_OBJECTS = \
	classes3/org/greenstone/LuceneWrapper3/GS2Analyzer.class \
	classes3/org/greenstone/LuceneWrapper3/GS2IndexModifier.class \
	classes3/org/greenstone/LuceneWrapper3/GS2LuceneDelete.class \
	classes3/org/greenstone/LuceneWrapper3/GS2LuceneEditor.class \
	classes3/org/greenstone/LuceneWrapper3/GS2LuceneIndexer.class \
	classes3/org/greenstone/LuceneWrapper3/GS2LuceneQuery.class \
	classes3/org/greenstone/LuceneWrapper3/LuceneQueryResult.class \
	classes3/org/greenstone/LuceneWrapper3/SharedSoleneQuery.class \
	classes3/org/greenstone/LuceneWrapper3/SharedSoleneQueryResult.class

LUCENE3_WRAPPER_JAR = LuceneWrapper3.jar

classes4/org/greenstone/LuceneWrapper4/%.class: src/org/greenstone/LuceneWrapper4/%.java
ifeq ($(GSDLOS),windows)
	mkdir -p classes4 && $(JAVAC) $(JAVACFLAGS) $(JAVADEBUGFLAGS) -classpath "lib/lucene4/*;classes4;." -d classes4 -sourcepath src/ src/org/greenstone/LuceneWrapper4/$*.java
else
	mkdir -p classes4 && $(JAVAC) $(JAVACFLAGS) $(JAVADEBUGFLAGS) -classpath "lib/lucene4/*:classes4:." -d classes4 -sourcepath src/ src/org/greenstone/LuceneWrapper4/$*.java
endif

LuceneWrapper4.jar: $(LUCENE4_WRAPPER_OBJECTS)
	cd classes4 && for jar in ../lib/lucene4/*$(LUCENE_VER).jar; do \
		jar xf $$jar; \
	done
	cp LICENSE.txt classes4/META-INF/LICENSE-LUCENE_WRAPPER.txt
	cp LICENSE-GPLv2.txt classes4/META-INF/.
	cp LICENSE-GPLv3.txt classes4/META-INF/.
	$(JAR) cf $(LUCENE4_WRAPPER_JAR) -C classes4 .


classes3/org/greenstone/LuceneWrapper3/%.class: src/org/greenstone/LuceneWrapper3/%.java
ifeq ($(GSDLOS),windows)
	mkdir -p classes3 && $(JAVAC) $(JAVACFLAGS) -classpath "$(LUCENE3_JAR);classes3;." -d classes3 -sourcepath src/ src/org/greenstone/LuceneWrapper3/$*.java
else
	mkdir -p classes3 && $(JAVAC) $(JAVACFLAGS) -classpath $(LUCENE3_JAR):classes3:. -d classes3 -sourcepath src/ src/org/greenstone/LuceneWrapper3/$*.java
endif

LuceneWrapper3.jar: $(LUCENE3_WRAPPER_OBJECTS)
	cd classes3 && jar xf ../$(LUCENE3_JAR)
	$(JAR) cf $(LUCENE3_WRAPPER_JAR) -C classes3 .


all: $(LUCENE4_WRAPPER_JAR)
# $(LUCENE3_WRAPPER_JAR)
install: all

clean:
	/bin/rm -f $(LUCENE4_WRAPPER_OBJECTS) $(LUCENE4_WRAPPER_JAR)
	/bin/rm -f classes4/org/greenstone/LuceneWrapper4/*.class
	/bin/rm -f $(LUCENE3_WRAPPER_OBJECTS) $(LUCENE3_WRAPPER_JAR)
	/bin/rm -f classes3/org/greenstone/LuceneWrapper3/*.class	

distclean: clean
	if test -e classes4; then /bin/rm -r classes4; fi
	if test -e $(LUCENE4_WRAPPER_JAR); then /bin/rm -r $(LUCENE4_WRAPPER_JAR); fi
	if test -e classes3; then /bin/rm -r classes3; fi
	if test -e $(LUCENE3_WRAPPER_JAR); then /bin/rm -r $(LUCENE3_WRAPPER_JAR); fi
