# Makefile
#
# Makefile for resumes
#
# Copyright (c) 2002 Bruce Christensen
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the
#    distribution.
# 
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#------------------------------------------------------------------------------
# To create example.html, example.txt, example.fo, and example.pdf from
# example.xml, with Italian localization and a4 paper size, use this command:
#
# 	gmake resume=example country=it papersize=a4
#
# To generate just the html version of cv.xml with UK localization, use this
# command:
#
# 	gmake html resume=cv country=uk
#
# To remove all generated files, run:
#
# 	gmake clean
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# Basename (filename minus .xml extension) of resume to process
# For example, put "myresume" here to process "myresume.xml".
#------------------------------------------------------------------------------
resume = res

#------------------------------------------------------------------------------
# Stylesheets
#------------------------------------------------------------------------------
# Options: br de fr it nl uk us es
country = us
# Options: letter for country=us, a4 for others
papersize = letter

#xsl_base = http://xmlresume.sourceforge.net/xsl
xsl_base = /usr/local/share/xsl/resume
#xsl_base = ../xsl
#xsl_base = ../src/www/xsl
xml_base = /usr/local/share/xml/resume

upload_location=alfred@freefall.freebsd.org:www/resume
rcp=scp

pwd=$(shell pwd)

ifneq '$(wildcard $(country)-html.xsl.in)' ''
html_style = $(country)-html.xsl
overrides+= $(html_style)
else
html_style = $(xsl_base)/output/$(country)-html.xsl
endif

ifneq '$(wildcard $(country)-text.xsl.in)' ''
text_style = $(country)-text.xsl
overrides+= $(text_style)
else
text_style = $(xsl_base)/output/$(country)-text.xsl
endif

#fo_style =  $(country)-$(papersize).xsl
#upgrade_13x_140_style = 13x-140.xsl

sedflags+=-e 's@%%XSL_BASE%%@$(xsl_base)@'
sedflags+=-e 's@%%WARNING%%@GENERATED FILE DO NOT EDIT@'
sedflags+=-e 's@%%CURDIR%%@$(pwd)@'
sedflags+=-e 's@%%DTDLOCATION%%@$(xml_base)/resume.dtd@'


fo_style = $(xsl_base)/output/$(country)-$(papersize).xsl
upgrade_13x_140_style = $(xsl_base)/misc/13x-140.xsl

#------------------------------------------------------------------------------
# Processing software
#------------------------------------------------------------------------------
make = gmake

# requires:
# java
# textproc/xalan-j
# textproc/fop
# textproc/xerces-j

fop_path?=/usr/local/share/fop
jar_files+= \
	$(fop_path)/lib/avalon-framework-4.2.0.jar \
	$(fop_path)/lib/batik-all-1.6.jar \
	$(fop_path)/lib/commons-io-1.1.jar \
	$(fop_path)/lib/commons-logging-1.0.4.jar \
	$(fop_path)/lib/serializer-2.7.0.jar \
	$(fop_path)/lib/servlet-2.2.jar \
	$(fop_path)/lib/xalan-2.7.0.jar \
	$(fop_path)/lib/xercesImpl-2.7.1.jar \
	$(fop_path)/lib/xml-apis-1.3.02.jar \
	$(fop_path)/lib/xmlgraphics-commons-1.1.jar 

#jar_files+=	\
	$(fop_path)/lib/xalan-2.7.0.jar  \
	$(fop_path)/lib/xercesImpl-2.7.1.jar \
	/usr/local/share/fop/build/fop.jar

#jar_files+=$(fop_path)/build/fop-transcoder-allinone.jar
#jar_files+= \
	$(fop_path)/build/fop-hyph.jar \
	$(fop_path)/build/fop-sandbox.jar \
	$(fop_path)/build/fop-transcoder-allinone.jar \
	$(fop_path)/build/fop-transcoder.jar \
	$(fop_path)/build/fop.jar 

#jar_files+=$(fop_path)/build/fop.war
#jar_files+=$(fop_path)/build/fop.jar
#jar_files+=$(fop_path)/build/fop-transcoder-allinone.jar
#jar_files+=$(fop_path)/build/fop-transcoder.jar

#jar_files+=$(fop_path)/lib/ant-1.5.1.jar
#jar_files+=$(fop_path)/lib/avalon-framework-cvs-20020806.jar
#jar_files+=$(fop_path)/lib/batik.jar
#jar_files+=$(fop_path)/lib/xalan-2.4.1.jar
#jar_files+=$(fop_path)/lib/xercesImpl-2.2.1.jar
#jar_files+=$(fop_path)/lib/xml-apis.jar
#jar_files+=$(fop_path)/build/fop.jar

classpath?= $(shell echo $(strip $(jar_files)) | tr ' ' ':')
java?=java
javaflags?= -classpath $(classpath)


xsl_proc = $(java) $(javaflags) org.apache.xalan.xslt.Process $(xsl_flags) -in $(in) -xsl $(xsl) -out $(out)
#xsl_proc = $(java) $(javaflags) com.icl.saxon.StyleSheet $(xsl_flags) -o $(out) $(in) $(xsl) $(xsl_params)

pdf_proc = fop -fo $(fo_flags) $(in) -pdf $(out)
#pdf_proc = $(java) $(javaflags) org.apache.fop.apps.Fop -fo $(fo_flags) $(in) -pdf $(out)
#pdf_proc = ~/bin/xep/run.sh $(fo_flags) $(in) $(out)

# RTF generation currently requires you download a separate, closed source jar 
# file and add it to your java classpath: 	
# http://www.xmlmind.com/foconverter/downloadperso.shtml
rtf_proc = $(java) $(javaflags) com.xmlmind.fo.converter.Driver $(in) $(out)
#rtf_proc = $(java) $(javaflags) ch.codeconsult.jfor.main.CmdLineConverter $(in) $(out)

# Element filtering allows you to create targeted resumes.  
# You can create your own targets; just specify them in your resume.xml 
# file with the "targets" attribute.  In this example, the foodservice
# AND carpentry elements will be included in the output, but not the 
# elements targeted to other jobs.  Untargeted elements (those with no 
# "targets" attribute) are always included.  
# Take a look at example2.xml and try changing the filter targets to get a 
# feel for how the filter works.
filter_targets = foodservice carpentry
filter_proc = $(java) $(javaflags) net.sourceforge.xmlresume.filter.Filter -in $(in) -out $(out) $(filter_targets)

#------------------------------------------------------------------------------
# End configurable parameters
#------------------------------------------------------------------------------

# /usr/local/share/java/classes/xalan.jar:/usr/local/j2sdkee1.3.1/lib/j2ee.jar

.PHONY: all html text fo pdf clean 13x-140

final_targets=$(addprefix $(resume)., html txt fo pdf)
all: $(final_targets)

ifdef overrides
cleanfiles+= $(overrides)
$(overrides): %: %.in
	@echo using $@ as an override.
	-rm -f $@
	sed $(sedflags)	$< >> $@
	chmod 444 $@
endif

13x-140: $(resume)-140.xml
rtf: $(resume).rtf
filter: $(resume)-filtered.xml

cleanfiles+= \
	$(resume).xml \
	$(resume).html $(resume).html.pre \
	$(resume).txt \
	$(resume).fo $(resume).pdf \
	$(resume).rtf \
	$(resume)-filtered.xml $(resume)-filtered.html	\
	$(resume)-filtered.txt $(resume)-filtered.pdf \
	$(resume)-filtered.fo $(resume)-filtered.rtf

clean:
	rm -f $(cleanfiles)

$(resume).xml: %: %.in
	-rm -f $@
	sed $(sedflags)	$< >> $@
	chmod 444 $@

$(resume).html.pre: in = $(resume).xml
$(resume).html.pre: out = $(resume).html.pre
$(resume).html.pre: xsl = $(html_style)
$(resume).html.pre: $(resume).xml $(html_style) test.css
	$(xsl_proc)

$(resume).html:	$(resume).html.pre
	cp $< $@
	-tidy -i -m $@

$(resume).txt: in = $(resume).xml
$(resume).txt: out = $(resume).txt
$(resume).txt: xsl = $(text_style)
$(resume).txt: $(resume).xml $(text_style)
	$(xsl_proc)

$(resume).fo: in = $(resume).xml
$(resume).fo: out = $(resume).fo
$(resume).fo: xsl = $(fo_style)
$(resume).fo: $(resume).xml
	$(xsl_proc)

$(resume).pdf: in = $(resume).fo
$(resume).pdf: out = $(resume).pdf
$(resume).pdf: $(resume).fo
	$(pdf_proc)

$(resume).rtf: in = $(resume).fo
$(resume).rtf: out = $(resume).rtf
$(resume).rtf: $(resume).fo
	$(rtf_proc)

$(resume)-140.xml: in = $(resume).xml
$(resume)-140.xml: out = $(resume)-140.xml
$(resume)-140.xml: xsl = $(upgrade_13x_140_style)
$(resume)-140.xml: $(resume).xml
	$(xsl_proc)

$(resume)-filtered.xml: in = $(resume).xml
$(resume)-filtered.xml: out = $(resume)-filtered.xml
$(resume)-filtered.xml: $(resume).xml
	$(filter_proc)
	$(make) all resume=$(resume)-filtered

upload: all
	$(rcp) $(final_targets) $(resume).xml.in Makefile $(upload_location)

tidy:
	-tidy -i -xml -m -wrap 78 $(resume).xml.in

commit: tidy
	cvs commit
