Newer
Older
Handbook / make-includes / standard_rules.make
  1. ################################################################################
  2. #
  3. # Standard rules for a variety of situations. Includes standard suffixes and
  4. # paths.
  5. #
  6. #
  7. ################################################################################
  8.  
  9.  
  10. ################################################################################
  11. #
  12. # Required make variables. These should be defined by the calling makefile.
  13. #
  14. # PAPER_NUMBER
  15. # The paper number for the current paper, e.g., 212.
  16. #
  17. PAPER_NUMBER?=$(error The required make variable PAPER_NUMBER has not been defined. Please set it to the correct value)
  18. #
  19. # IMGDIR
  20. # The path to the directory that contains images, e.g., images.
  21. #
  22. IMGDIR?=$(error The required make variable IMGDIR has not been defined. Please set it to the directory in which images are located)
  23.  
  24.  
  25. ################################################################################
  26. #
  27. # Default rules.
  28. #
  29. #
  30. # PDF from LaTeX, typically for images drawn using PSTricks.
  31. #
  32. %.pdf %-print.pdf: $(IMGDIR)/%.tex
  33. ifdef UNICODE
  34. $(XELATEX) --jobname=$(IMGDIR)/$* $<
  35. $(XELATEX) --jobname=$(IMGDIR)/$* $<
  36. $(PDFCROP) $(IMGDIR)/$@ $(IMGDIR)/$*-crop.pdf
  37. -$(MV) $(IMGDIR)/$*-crop.pdf $(IMGDIR)/$@
  38. else
  39. $(LATEX) --jobname=$(IMGDIR)/$* $<
  40. $(LATEX) --jobname=$(IMGDIR)/$* $<
  41. $(DVIPS) -q -f $(IMGDIR)/$* | $(PS2EPS) --quiet --loose | $(EPSTOPDF) --filter --outfile=$(IMGDIR)/$@
  42. endif
  43. #
  44. # PDF from LaTeX.
  45. #
  46. %.pdf: %.tex
  47. ifdef UNICODE
  48. $(XELATEX) $<
  49. $(XELATEX) $<
  50. else
  51. $(PDFLATEX) $<
  52. $(PDFLATEX) $<
  53. endif
  54. #
  55. # 2-up PDF from 1-up PDF.
  56. #
  57. %-2up.pdf: %.pdf
  58. $(PDFNUP) $< --nup 2x1 --outfile $@
  59. #
  60. # Derived XML with inclusions from source XML without inclusions.
  61. #
  62. # This is done by simply running the original source through xmllint
  63. # with the --xinclude option to process any xi:include elements.
  64. # The result of this could just be piped into the XSLT processor,
  65. # except that (a) not all of the processors support input from stdin,
  66. # and (b) combining both xmllint and XSLT processing into one command
  67. # means that make won't stop if there's any errors from xmllint.
  68. #
  69. # Sed is used to add a comment to the derived XML file, warning that this
  70. # is generated and shouldn't be edited. Sed was used because the <?xml?>
  71. # processing instruction MUST be on the first line. The implication here
  72. # is that all input source files have an <?xml?> processing instruction
  73. # (which they should anyway).
  74. #
  75. %-derived.xml: %.xml
  76. $(XMLLINT) --xinclude $< > $@
  77. @$(SED) --in-place --expression='1a <!-- THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT! -->' $@
  78. #
  79. # LaTeX from derived XML.
  80. #
  81. %.tex: %-derived.xml
  82. ifdef UNICODE
  83. $(call xslt,$<,xml2xelatex.xsl,$(call xslt_parameter,subject-code,'$(SUBJECT_CODE)'),$(call xslt_parameter,paper-number,'$(PAPER_NUMBER)'),$(call xslt_parameter,paper-year,'$(PAPER_YEAR)'),$(call xslt_parameter,period-code,'$(PAPER_PERIOD)'),$(call xslt_parameter,paper-include-path,'$(ALL_PAPERS_ROOT)/$(SUBJECT_CODE)$(PAPER_NUMBER)')) > $@
  84. else
  85. $(call xslt,$<,xml2latex.xsl,$(call xslt_parameter,subject-code,'$(SUBJECT_CODE)'),$(call xslt_parameter,paper-number,'$(PAPER_NUMBER)'),$(call xslt_parameter,paper-year,'$(PAPER_YEAR)'),$(call xslt_parameter,period-code,'$(PAPER_PERIOD)'),$(call xslt_parameter,paper-include-path,'$(ALL_PAPERS_ROOT)/$(SUBJECT_CODE)$(PAPER_NUMBER)')) > $@
  86. endif
  87. #
  88. # HTML from derived XML.
  89. #
  90. %.html: %-derived.xml
  91. ifdef UNICODE
  92. $(call xslt,$<,xml2xhtml.xsl,$(call xslt_parameter,subject-code,'$(SUBJECT_CODE)'),$(call xslt_parameter,paper-number,'$(PAPER_NUMBER)'),$(call xslt_parameter,paper-year,'$(PAPER_YEAR)'),$(call xslt_parameter,period-code,'$(PAPER_PERIOD)')) > $@
  93. else
  94. $(call xslt,$<,xml2html.xsl,$(call xslt_parameter,subject-code,'$(SUBJECT_CODE)'),$(call xslt_parameter,paper-number,'$(PAPER_NUMBER)'),$(call xslt_parameter,paper-year,'$(PAPER_YEAR)'),$(call xslt_parameter,period-code,'$(PAPER_PERIOD)')) > $@
  95. endif
  96. #
  97. # Image rules can be a bit messy, because the prerequisite might be in any one
  98. # of several different formats, but we want to apply the same commands anyway
  99. # (e.g., ImageMagick convert) to generate the target. It would be nice if we
  100. # could specify variable file types in a prerequisite of a pattern rule (e.g.,
  101. # %-foo.png: %.png %.jpg %.tif), but unfortunately we can't :(. The solution is
  102. # to create a make function to refactor the commands, and then specify as many
  103. # rules as required depending on the number of file formats. We still end up
  104. # repeating the rule actions, but at least the guts of the action is coded only
  105. # once in the function.
  106. #
  107. # PNG from TIFF, JPEG, PICT (normal image)
  108. # Note: PNG prerequisites are dealt with further down.
  109. #
  110. convert_normal = $(CONVERT) "$(1)" "$(2)"
  111.  
  112. %.png %-print.png %-web.png: %.tif
  113. $(call convert_normal,$<,$(IMGDIR)/$@)
  114.  
  115. %.png %-print.png %-web.png: %.jpg
  116. $(call convert_normal,$<,$(IMGDIR)/$@)
  117.  
  118. %.png %-print.png %-web.png: %.pict
  119. $(call convert_normal,$<,$(IMGDIR)/$@)
  120. #
  121. # PNG from PNG, TIFF, JPEG, PICT (slide background)
  122. #
  123. # We lighten these so that they don't overwhelm the text. Note that 15% is
  124. # too light for most data projectors, so let's try 33% and see what
  125. # happens... (this looks far too much on screen, but data projectors tend
  126. # to wash things out much, much more).
  127. #
  128. # Includes both blurred and unblurred versions, use as required.
  129. #
  130. # Unblurred:
  131. convert_bg = $(CONVERT) "$(1)" -threshold "-1" -depth 16 - | $(COMPOSITE) -dissolve 33% "$(1)" - "$(2)"
  132.  
  133. %-BG.png: %.tif
  134. $(call convert_bg,$<,$(IMGDIR)/$@)
  135.  
  136. %-BG.png: %.png
  137. $(call convert_bg,$<,$(IMGDIR)/$@)
  138.  
  139. %-BG.png: %.jpg
  140. $(call convert_bg,$<,$(IMGDIR)/$@)
  141.  
  142. %-BG.png: %.pict
  143. $(call convert_bg,$<,$(IMGDIR)/$@)
  144. #
  145. # Blurred:
  146. convert_bg_blur = $(CONVERT) -blur 0.5 "$(1)" "$(2)"; $(CONVERT) "$(2)" -threshold "-1" -depth 16 - | $(COMPOSITE) -dissolve 33% "$(2)" - "$(3)"; rm -f "$(2)"
  147.  
  148. %-BG-blur.png: %.tif
  149. $(call convert_bg_blur,$<,$(IMGDIR)/$*-tmp.png,$(IMGDIR)/$@)
  150.  
  151. %-BG-blur.png: %.png
  152. $(call convert_bg_blur,$<,$(IMGDIR)/$*-tmp.png,$(IMGDIR)/$@)
  153.  
  154. %-BG-blur.png: %.jpg
  155. $(call convert_bg_blur,$<,$(IMGDIR)/$*-tmp.png,$(IMGDIR)/$@)
  156.  
  157. %-BG-blur.png: %.pict
  158. $(call convert_bg_blur,$<,$(IMGDIR)/$*-tmp.png,$(IMGDIR)/$@)
  159. #
  160. # PNG from XCF.
  161. #
  162. %.png: %.xcf
  163. $(XCF2PNG) -o $(IMGDIR)/$@ $<
  164. #
  165. # PNG from EPS.
  166. #
  167. %.png %-print.png %-web.png: %.eps
  168. $(PS2EPS) --ignoreBB --nohires --loose --gsbbox < $< | \
  169. $(GS) -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=png16m -dEPSCrop -r96 \
  170. -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile=$(IMGDIR)/$@ -
  171.  
  172. %-web-zoom.png: %.eps
  173. $(PS2EPS) --ignoreBB --nohires --loose --gsbbox < $< | \
  174. $(GS) -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=png16m -dEPSCrop -r144 \
  175. -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile=$(IMGDIR)/$@ -
  176. #
  177. # PNG from PS.
  178. #
  179. %-web.png: %.ps
  180. @$(PS2EPS) --ignoreBB --nohires --loose --gsbbox < $< | \
  181. $(GS) -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=png16m -dEPSCrop -r96 \
  182. -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile=$(IMGDIR)/$@ -
  183.  
  184. %-web-zoom.png: %.ps
  185. @$(PS2EPS) --ignoreBB --nohires --loose --gsbbox < $< | \
  186. $(GS) -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=png16m -dEPSCrop -r144 \
  187. -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile=$(IMGDIR)/$@ -
  188. #
  189. # PNG from PDF.
  190. #
  191. %-web.png: %.pdf
  192. $(GS) -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=png16m -r96 \
  193. -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile=$(IMGDIR)/$@ $<
  194.  
  195. %-web-zoom.png: %.pdf
  196. $(GS) -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=png16m -r144 \
  197. -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile=$(IMGDIR)/$@ $<
  198. #
  199. # PDF from Ploticus.
  200. #
  201. %.pdf %-print.pdf: %.plo
  202. $(PLOTICUS) -eps -tightcrop -o stdout $< | $(SHIFTBBOX) | $(EPSTOPDF) --filter --outfile=$(IMGDIR)/$@
  203. #
  204. # PDF from R.
  205. # This assumes that the first argument to the R script is the output filename
  206. # for the resultant PDF.
  207. #
  208. %.pdf %-print.pdf: %.R
  209. $(R) --slave --file=$< --args "$(IMGDIR)/$@"
  210. $(PDFCROP) $(IMGDIR)/$@ $(IMGDIR)/$*-crop.pdf
  211. -$(MV) $(IMGDIR)/$*-crop.pdf $(IMGDIR)/$@
  212. #
  213. # PDF from PS
  214. #
  215. %.pdf %-print.pdf: %.ps
  216. $(PS2EPS) --quiet --ignoreBB --nohires --loose < $< | $(EPSTOPDF) --filter --outfile=$(IMGDIR)/$@
  217. #
  218. # PDF from EPS
  219. #
  220. %.pdf %-print.pdf: %.eps
  221. $(EPSTOPDF) --outfile=$(IMGDIR)/$@ $<
  222. # $(PS2EPS) --ignoreBB --nohires --loose < $< | $(PS2PDF) -dEPSCrop - $(IMGDIR)/$@
  223. #
  224. # PDF from SVG (via Inkscape)
  225. # The --export-area-drawing option now appears to behave correctly with
  226. # PDFs (previously it over-cropped slightly).
  227. #
  228. %.pdf %-print.pdf: %.svg
  229. $(INKSCAPE) --file=$< --without-gui --export-area-drawing --export-text-to-path --export-pdf=$(IMGDIR)/$@
  230. #
  231. # PNG from SVG (via Inkscape)
  232. #
  233. %.png %-print.png %-web.png: %.svg
  234. $(INKSCAPE) --file=$< --without-gui --export-area-drawing --export-background-opacity=1.0 --export-dpi=96 --export-png=$(IMGDIR)/$@
  235.  
  236. %-web-zoom.png: %.svg
  237. $(INKSCAPE) --file=$< --without-gui --export-area-drawing --export-background-opacity=1.0 --export-dpi=144 --export-png=$(IMGDIR)/$@
  238.  
  239. %-print-zoom.png: %.svg
  240. $(INKSCAPE) --file=$< --without-gui --export-area-drawing --export-background-opacity=1.0 --export-dpi=300 --export-png=$(IMGDIR)/$@
  241.  
  242. %-print-zoom-transparent.png: %.svg
  243. $(INKSCAPE) --file=$< --without-gui --export-area-drawing --export-background-opacity=0 --export-dpi=300 --export-png=$(IMGDIR)/$@
  244.  
  245. %-transparent.png: %.svg
  246. $(INKSCAPE) --file=$< --without-gui --export-area-drawing --export-background-opacity=0 --export-dpi=96 --export-png=$(IMGDIR)/$@
  247. #
  248. # PNG from PNG (change the name).
  249. # These appear to need to be separate rules. If both variants need to be
  250. # created (i.e., both %-web.png and %-print.png), it only generates one of
  251. # them (most likely %-web.png as it's first in the rule) if the rules are
  252. # combined into one. This is Kind of Weird.
  253. #
  254. %-print.png: %.png
  255. $(CP) $< $(IMGDIR)/$@
  256.  
  257. %-web.png: %.png
  258. $(CP) $< $(IMGDIR)/$@
  259. #
  260. # PDF from PDF (change the name).
  261. # Only need a print rule for this one, as the web version is handled by the
  262. # PDF to PNG rules above.
  263. #
  264. %-print.pdf: %.pdf
  265. $(CP) $< $(IMGDIR)/$@
  266. #
  267. # CSS from Sass (both syntaxes).
  268. #
  269. %.css: %.sass
  270. $(SASS) $< $@
  271.  
  272. %.css: %.scss
  273. $(SASS) $< $@