# source directories
htmlparser_src := ../htmlparser/src
htmlparser_test := ../htmlparser/test-src
cni_src := src
# java sources
htmlparser_sources := $(shell find $(htmlparser_src) -name '*.java' | \
grep -v 'xom')
# dependencies
chardet := ../dependencies/mozilla/intl/chardet/java/dist/lib/chardet.jar
icu4j := ../dependencies/icu4j-4_0.jar
jaxp := /usr/share/java/jaxp-1.3.jar
gcj_jar := /usr/share/java/libgcj.jar
# work directories
build = build
headers = headers
classes = classes
# link main program
objects = \
$(build)/HTML2XML.o \
$(build)/SystemErrErrorHandler_j.o \
$(build)/SystemErrErrorHandler_c.o
HTML2XML: $(objects) $(build)/libhtmlparser.so
g++ -o $@ -lhtmlparser -L$(build) $(objects)
# compile main program
$(build)/HTML2XML.o: $(cni_src)/HTML2XML.c \
$(headers)/org/xml/sax/ContentHandler.h \
$(headers)/org/xml/sax/InputSource.h \
$(headers)/nu/validator/htmlparser/common/XmlViolationPolicy.h \
$(headers)/nu/validator/htmlparser/sax/XmlSerializer.h \
$(headers)/nu/validator/htmlparser/sax/HtmlParser.h \
$(headers)/nu/validator/htmlparser/test/SystemErrErrorHandler.h
@test -d $(dir $@) || mkdir -p $(dir $@)
g++ -c -Iheaders -o $@ $<
# compile error handler - java interface
$(build)/SystemErrErrorHandler_j.o: $(cni_src)/SystemErrErrorHandler.java
@test -d $(dir $@) || mkdir -p $(dir $@)
gcj -c -I$(htmlparser_src) -I$(htmlparser_test) \
--classpath=$(classpath) -o $@ $<
# compile error handler - c++ implementation
$(build)/SystemErrErrorHandler_c.o: $(cni_src)/SystemErrErrorHandler.c \
$(headers)/javax/xml/transform/TransformerException.h \
$(headers)/javax/xml/transform/SourceLocator.h \
$(headers)/org/xml/sax/SAXException.h \
$(headers)/org/xml/sax/SAXParseException.h
@test -d $(dir $@) || mkdir -p $(dir $@)
g++ -c -Iheaders -o $@ $<
# link html parser library
$(build)/libhtmlparser.so: \
$(build)/htmlparser.o \
$(build)/icu4j.o \
$(build)/chardet.o
gcj -shared -o $@ $^
# compile html parser library
$(build)/htmlparser.o: $(chardet) $(icu4j) $(htmlparser_sources)
@test -d $(dir $@) || mkdir -p $(dir $@)
gcj -c -fPIC --classpath=$(chardet):$(icu4j) $(htmlparser_sources) -o $@
# dependencies: icu4j
$(build)/icu4j.o: $(icu4j)
@test -d $(dir $@) || mkdir -p $(dir $@)
gcj -c -fPIC -o $@ $<
# dependencies: chardet
$(build)/chardet.o: $(chardet)
@test -d $(dir $@) || mkdir -p $(dir $@)
gcj -c -fPIC -o $@ $<
# sax headers
$(headers)/org/xml/sax/%.h:
gcjh -cp $(jaxp):$(gcj_jar) \
-o $@ $(subst /,.,$(subst $(headers)/,,$(@:.h=)))
# sax headers
$(headers)/javax/xml/%.h:
gcjh -cp $(jaxp):$(gcj_jar) \
-o $@ $(subst /,.,$(subst $(headers)/,,$(@:.h=)))
# htmlparser headers (test)
$(headers)/nu/validator/htmlparser/test/%.h: $(cni_src)/%.java
@test -d $(classes) || mkdir -p $(classes)
javac -d $(classes) -classpath $(chardet):$(icu4j) $<
gcjh -cp $(classes):$(gcj_jar) \
-o $@ $(subst /,.,$(subst $(headers)/,,$(@:.h=)))
# htmlparser headers (src)
$(headers)/nu/validator/htmlparser/%.h:
@test -d $(classes) || mkdir -p $(classes)
javac -d $(classes) -classpath $(chardet):$(icu4j) \
-sourcepath $(htmlparser_src) \
$(htmlparser_src)/$(subst $(headers)/,,$(@:.h=.java))
gcjh -cp $(classes):$(gcj_jar) \
-o $@ $(subst /,.,$(subst $(headers)/,,$(@:.h=)))
# and, of course, a clean target
clean:
rm -rf $(build)
rm -rf $(headers)
rm -rf $(classes)
rm -f HTML2XML