| 1 | # Copyright (C) 2003-2004 Doug Gregor and Dave Abrahams. Distributed |
|---|
| 2 | # under the Boost Software License, Version 1.0. (See accompanying |
|---|
| 3 | # file LICENSE_1_0.txt or copy at |
|---|
| 4 | # http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 5 | # |
|---|
| 6 | # This module defines rules to handle generation of PDF and |
|---|
| 7 | # PostScript files from XSL Formatting Objects via Apache FOP |
|---|
| 8 | |
|---|
| 9 | import os ; |
|---|
| 10 | import generators ; |
|---|
| 11 | import common ; |
|---|
| 12 | import errors ; |
|---|
| 13 | |
|---|
| 14 | generators.register-standard fop.render.pdf : FO : PDF ; |
|---|
| 15 | generators.register-standard fop.render.ps : FO : PS ; |
|---|
| 16 | |
|---|
| 17 | rule init ( fop-command ? : java-home ? : java ? ) |
|---|
| 18 | { |
|---|
| 19 | fop-command = [ common.get-invocation-command fop : fop : $(fop-command) |
|---|
| 20 | : [ modules.peek : FOP_DIR ] ] ; |
|---|
| 21 | |
|---|
| 22 | if $(.initialized) |
|---|
| 23 | { |
|---|
| 24 | if $(.FOP_COMMAND) != $(fop-command) || $(JAVA_HOME) != $(java-home) |
|---|
| 25 | || $(JAVACMD) != $(java) |
|---|
| 26 | { |
|---|
| 27 | errors.user-error "fop: reinitialization with different options" ; |
|---|
| 28 | } |
|---|
| 29 | } |
|---|
| 30 | else |
|---|
| 31 | { |
|---|
| 32 | .initialized = true ; |
|---|
| 33 | .FOP_COMMAND = $(fop-command) ; |
|---|
| 34 | # What is the meaning of this logic? Needs more comments!! --DWA |
|---|
| 35 | java-home ?= $(java) ; |
|---|
| 36 | .FOP_SETUP = [ common.variable-setting-command JAVA_HOME : $(java-home) ] ; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | # Make sure the fop command is executed from within the directory where it's located. |
|---|
| 40 | |
|---|
| 41 | # DPG: I can't see how this could ever be correct, because it |
|---|
| 42 | # messes up path names that are used in the command. |
|---|
| 43 | |
|---|
| 44 | # if $(.FOP_COMMAND:D) |
|---|
| 45 | # { |
|---|
| 46 | # .FOP_SETUP = $(.FOP_SETUP)" |
|---|
| 47 | # cd "$(.FOP_COMMAND:D) ; |
|---|
| 48 | # } |
|---|
| 49 | |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | local rule find-by-absolute-path ( target ) |
|---|
| 53 | { |
|---|
| 54 | # Mask off any vars by these names that may be hanging around in |
|---|
| 55 | # outer dynamic scopes. |
|---|
| 56 | local LOCATE SEARCH ; |
|---|
| 57 | |
|---|
| 58 | # simulate the target binding process to find the target |
|---|
| 59 | |
|---|
| 60 | local found = [ on $(target) GLOB $(LOCATE) (SEARCH) : $(target:G=) ] ; |
|---|
| 61 | |
|---|
| 62 | if $(found) |
|---|
| 63 | { |
|---|
| 64 | # Re-LOCATE the target with an absolute path if it isn't |
|---|
| 65 | # already absolute. |
|---|
| 66 | local found-dir = $(found[1]:D) ; |
|---|
| 67 | local cwd = [ PWD ] ; |
|---|
| 68 | local absolute-dir = $(found-dir:R=$(cwd)) ; |
|---|
| 69 | |
|---|
| 70 | # Translate cygwin paths to Windows iff the user is running on |
|---|
| 71 | # cygwin but using a Windows FOP. We detect a Windows FOP by |
|---|
| 72 | # looking to see if FOP_COMMAND ends with ".bat" |
|---|
| 73 | if [ os.name ] = CYGWIN && [ MATCH .*\\.([Bb][Aa][Tt])$ : $(.FOP_COMMAND) ] |
|---|
| 74 | { |
|---|
| 75 | absolute-dir = "`cygpath --windows '$(absolute-dir)'`" ; |
|---|
| 76 | } |
|---|
| 77 | LOCATE on $(target) = $(absolute-dir) ; |
|---|
| 78 | } |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | rule render.pdf ( source : target : properties * ) |
|---|
| 82 | { |
|---|
| 83 | find-by-absolute-path $(source) ; |
|---|
| 84 | find-by-absolute-path $(target) ; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | rule render.ps ( source : target : properties * ) |
|---|
| 88 | { |
|---|
| 89 | find-by-absolute-path $(source) ; |
|---|
| 90 | find-by-absolute-path $(target) ; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | actions render.pdf |
|---|
| 95 | { |
|---|
| 96 | $(.FOP_SETUP) $(.FOP_COMMAND) $(>) $(<) |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | actions render.ps |
|---|
| 100 | { |
|---|
| 101 | $(.FOP_SETUP) $(.FOP_COMMAND) $(>) -ps $(<) |
|---|
| 102 | } |
|---|