# -*- Mode: Makefile -*-
# Copyright (c) 2003-2013 Sid Steward
# This is part of pdftk
#
# Visit: www.pdftk.com for pdftk information and articles
# Permalink: http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
#
# Please email Sid Steward with questions or bug reports.
# Include "pdftk" in the subject line to ensure successful delivery:
# sid.steward at pdflabs dot com
#

JAVALIBPATH= $(CURDIR)

#
export GCJFLAGS+= --encoding=UTF-8 --classpath="$(LIBGCJ):$(JAVALIBPATH):."
export GCJHFLAGS+= --classpath="$(LIBGCJ):$(JAVALIBPATH):."

sources = $(wildcard pdftk/com/lowagie/text/*.java)
sources+= $(wildcard pdftk/com/lowagie/text/exceptions/*.java)
sources+= $(wildcard pdftk/com/lowagie/text/pdf/*.java)
sources+= $(wildcard pdftk/com/lowagie/text/pdf/crypto/*.java)
sources+= $(wildcard pdftk/com/lowagie/text/pdf/fonts/*.java)
sources+= $(wildcard pdftk/com/lowagie/text/pdf/interfaces/*.java)
sources+= $(wildcard pdftk/com/lowagie/text/pdf/internal/*.java)
#
sources+= $(wildcard pdftk/com/lowagie/text/markup/*.java)
sources+= $(wildcard pdftk/com/lowagie/text/xml/xmp/*.java)

# this isn't necessary for newer build tools
# regen Makefile.bc_sources after upgrading bouncycastle
include Makefile.bc_sources

headers= $(patsubst %.java, %.h, $(sources))

# for afm resources
afms= $(wildcard pdftk/com/lowagie/text/pdf/fonts/*.afm)

# don't automatically delete intermediate class files
.PRECIOUS : %.class

%.class : %.java
	$(GCJ) $(GCJFLAGS) -C $<

%.h : %.class
	$(GCJH) $(GCJHFLAGS) $*

# don't create class list from java filenames because it omits local classes
java_lib.o : $(headers) $(sources)
	$(GJAR) -cf java_lib.jar pdftk/com/lowagie/*/*/*/*.class pdftk/com/lowagie/*/*/*.class pdftk/com/lowagie/*/*.class pdftk/org/bouncycastle/*/*.class pdftk/org/bouncycastle/*/*/*.class $(afms)
	$(GCJ) $(GCJFLAGS) -c java_lib.jar

all : java_lib.o

clean : itext_clean

itext_clean :
	$(RM) $(RMFLAGS) java_lib.jar java_lib.o;
	$(RM) $(RMFLAGS) pdftk/com/lowagie/*/*/*/*.class pdftk/com/lowagie/*/*/*.class pdftk/com/lowagie/*/*.class pdftk/org/bouncycastle/*/*.class pdftk/org/bouncycastle/*/*/*.class;
	$(RM) $(RMFLAGS) $(headers);
