diff --git a/make-includes/build_misc_rules.make b/make-includes/build_misc_rules.make index 068267b..eeab387 100755 --- a/make-includes/build_misc_rules.make +++ b/make-includes/build_misc_rules.make @@ -28,18 +28,41 @@ # BASE_NAMES # The base name(s) of the document source file(s). It may be a list, which # enables multiple different documents to be built by the one Makefile. -# BASE_PDF -# BASE_PDF_2UP -# BASE_TEX -# BASE_HTML -# Lists of various source and target files, all derived from BASE_NAMES. # BASE_NAMES?=$(error The required make variable BASE_NAMES has not been defined. Please set it to the base name(s) of the document source file(s)) -BASE_PDF:=$(foreach n,$(BASE_NAMES),$(n).pdf) -BASE_PDF_2UP:=$(foreach n,$(BASE_NAMES),$(n)-2up.pdf) -BASE_TEX:=$(foreach n,$(BASE_NAMES),$(n).tex) -BASE_HTML:=$(foreach n,$(BASE_NAMES),$(n).html) +################################################################################ +# +# Set up the context for the current document. +# +# SOURCE_XML is the original source XML, from which DERIVED_XML is +# generated (the derived source has the includes for questions, etc., +# inserted). +# +SOURCE_XML:=$(foreach n,$(BASE_NAMES),$(n).xml) +DERIVED_XML:=$(SOURCE_XML:.xml=-derived.xml) + +# +# Define the names of the output files. +# +ifdef HAS_ANSWERS +WEB_QUESTIONS_HTML:=$(SOURCE_XML:.xml=-questions.html) +WEB_ANSWERS_HTML:=$(SOURCE_XML:.xml=-answers.html) + +PRINT_QUESTIONS_TEX:=$(WEB_QUESTIONS_HTML:.html=.tex) +PRINT_ANSWERS_TEX:=$(WEB_ANSWERS_HTML:.html=.tex) + +PRINT_QUESTIONS_PDF_1UP:=$(PRINT_QUESTIONS_TEX:.tex=.pdf) +PRINT_ANSWERS_PDF_1UP:=$(PRINT_ANSWERS_TEX:.tex=.pdf) +PRINT_QUESTIONS_PDF_2UP:=$(PRINT_QUESTIONS_TEX:.tex=-2up.pdf) +PRINT_ANSWERS_PDF_2UP:=$(PRINT_ANSWERS_TEX:.tex=-2up.pdf) +else +WEB_HTML:=$(SOURCE_XML:.xml=.html) + +PRINT_TEX:=$(SOURCE_XML:.xml=.tex) +PRINT_PDF_1UP:=$(SOURCE_XML:.xml=.pdf) +PRINT_PDF_2UP:=$(SOURCE_XML:.xml=-2up.pdf) +endif ################################################################################ @@ -71,8 +94,8 @@ # PDF files exist. They will be caught by by the "clean" target though. # TIDY_FILES+=*.tmp *.out *.log *.nav *.toc *.snm *.head *.dvi \ - *-derived.xml -CLEAN_FILES+=*.aux *.pdf *.html + *-derived.xml *.tex +CLEAN_FILES+=*.aux *.pdf *.html $(IMGDIR)/*-print.pdf $(IMGDIR)/*-web.png ################################################################################ @@ -81,9 +104,15 @@ # include $(GLOBAL_HANDBOOK_INCLUDE)/standard_environment.make # -# List of standard "phony" build targets. +# List of standard "phony" build targets. Varies depending on whether +# answers are enabled. # -TARGETS+=web print print2up $(BASE_NAMES) +TARGETS+=web print $(BASE_NAMES) +ifdef HAS_ANSWERS +TARGETS+=web-questions web-answers \ + print-questions print-answers \ + questions answers +endif # .PHONY: $(TARGETS) @@ -92,33 +121,66 @@ # # Build everything. # -all: web print print2up - -$(BASE_NAMES): %: %.pdf %-2up.pdf %.html +all: web print ################################################################################ # -# Build print version, 1-up or 2-up. +# Build questions or answers only. # -print: $(BASE_PDF) +ifdef HAS_ANSWERS +questions: web-questions print-questions -$(BASE_PDF): %.pdf: %.tex $(PRINT_IMAGES) $(PRINT_FILES) - -$(BASE_TEX): %.tex: %-derived.xml - -print2up: $(BASE_PDF_2UP) - -$(BASE_PDF_2UP): %-2up.pdf: %.pdf +answers: web-answers print-answers +endif ################################################################################ # -# Build web version. +# Build web version only. # -web: $(BASE_HTML) +ifdef HAS_ANSWERS +web: web-questions web-answers -$(BASE_HTML): %.html: %-derived.xml $(WEB_IMAGES) $(WEB_FILES) +web-questions: $(WEB_QUESTIONS_HTML) $(WEB_IMAGES) $(WEB_FILES) + +$(WEB_QUESTIONS_HTML): %-questions.html: %-derived.xml + $(call xslt,$<,xml2html.xsl,$(call xslt_parameter,department,'$(SUBJECT_CODE)'),$(call xslt_parameter,paper,'$(PAPER_NUMBER)'),$(call xslt_parameter,standalone,'yes'),$(call xslt_parameter,showanswers,'no'),$(call xslt_parameter,base-path,'.'),$(call xslt_parameter,image-format,'png')) > $@ + +web-answers: $(WEB_ANSWERS_HTML) $(WEB_IMAGES) $(WEB_FILES) + +$(WEB_ANSWERS_HTML): %-answers.html: %-derived.xml + $(call xslt,$<,xml2html.xsl,$(call xslt_parameter,department,'$(SUBJECT_CODE)'),$(call xslt_parameter,paper,'$(PAPER_NUMBER)'),$(call xslt_parameter,standalone,'yes'),$(call xslt_parameter,showanswers,'yes'),$(call xslt_parameter,base-path,'.'),$(call xslt_parameter,image-format,'png')) > $@ +else +web: $(WEB_HTML) $(WEB_IMAGES) $(WEB_FILES) +endif + + +################################################################################ +# +# Build print version only. +# +ifdef HAS_ANSWERS +print: print-questions print-answers + +print-questions: $(PRINT_QUESTIONS_PDF_1UP) $(PRINT_QUESTIONS_PDF_2UP) + +$(PRINT_QUESTIONS_PDF_1UP): $(PRINT_IMAGES) $(PRINT_FILES) + +$(PRINT_QUESTIONS_TEX): %-questions.tex: %-derived.xml + $(call xslt,$<,xml2latex.xsl,$(call xslt_parameter,department,'$(SUBJECT_CODE)'),$(call xslt_parameter,paper,'$(PAPER_NUMBER)'),$(call xslt_parameter,standalone,'yes'),$(call xslt_parameter,showanswers,'no'),$(call xslt_parameter,base-path,'.'),$(call xslt_parameter,image-format,'pdf')) >> $@ + +print-answers: $(PRINT_ANSWERS_PDF_1UP) $(PRINT_ANSWERS_PDF_2UP) + +$(PRINT_ANSWERS_PDF_1UP): $(PRINT_IMAGES) $(PRINT_FILES) + +$(PRINT_ANSWERS_TEX): %-answers.tex: %-derived.xml + $(call xslt,$<,xml2latex.xsl,$(call xslt_parameter,department,'$(SUBJECT_CODE)'),$(call xslt_parameter,paper,'$(PAPER_NUMBER)'),$(call xslt_parameter,standalone,'yes'),$(call xslt_parameter,showanswers,'yes'),$(call xslt_parameter,base-path,'.'),$(call xslt_parameter,image-format,'pdf')) >> $@ +else +print: $(PRINT_PDF_1UP) $(PRINT_PDF_2UP) + +$(PRINT_PDF_1UP): $(PRINT_IMAGES) $(PRINT_FILES) +endif ################################################################################ @@ -140,10 +202,25 @@ @announce Internally defined variables @echo "GLOBAL_HANDBOOK_INCLUDE = [$(GLOBAL_HANDBOOK_INCLUDE)]" @echo "BASE_NAMES = [$(BASE_NAMES)]" - @echo "BASE_PDF = [$(BASE_PDF)]" - @echo "BASE_PDF_2UP = [$(BASE_PDF_2UP)]" - @echo "BASE_TEX = [$(BASE_TEX)]" - @echo "BASE_HTML = [$(BASE_HTML)]" + @echo "SOURCE_XML = [$(SOURCE_XML)]" + @echo "DERIVED_XML = [$(DERIVED_XML)]" +ifdef HAS_ANSWERS + @echo "WEB_QUESTIONS_HTML = [$(WEB_QUESTIONS_HTML)]" + @echo "WEB_ANSWERS_HTML = [$(WEB_ANSWERS_HTML)]" + @echo "PRINT_QUESTIONS_TEX = [$(PRINT_QUESTIONS_TEX)]" + @echo "PRINT_ANSWERS_TEX = [$(PRINT_ANSWERS_TEX)]" + @echo "PRINT_QUESTIONS_PDF_1UP = [$(PRINT_QUESTIONS_PDF_1UP)]" + @echo "PRINT_ANSWERS_PDF_1UP = [$(PRINT_ANSWERS_PDF_1UP)]" + @echo "PRINT_QUESTIONS_PDF_2UP = [$(PRINT_QUESTIONS_PDF_2UP)]" + @echo "PRINT_ANSWERS_PDF_2UP = [$(PRINT_ANSWERS_PDF_2UP)]" +else + @echo "WEB_HTML = [$(WEB_HTML)]" + @echo "PRINT_TEX = [$(PRINT_TEX)]" + @echo "PRINT_PDF_1UP = [$(PRINT_PDF_1UP)]" + @echo "PRINT_PDF_2UP = [$(PRINT_PDF_2UP)]" +endif + @echo "DERIVED_WEB_FILES = [$(DERIVED_WEB_FILES)]" + @echo "DERIVED_PRINT_FILES = [$(DERIVED_PRINT_FILES)]" @echo "PRINT_IMAGES = [$(PRINT_IMAGES)]" @echo "PRINT_FILES = [$(PRINT_FILES)]" @echo "WEB_IMAGES = [$(WEB_IMAGES)]"