File: pdf.mk

package info (click to toggle)
daps 3.3.2%2Bcleaned1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,540 kB
  • sloc: xml: 9,773; sh: 3,059; python: 1,322; lisp: 380; makefile: 239
file content (271 lines) | stat: -rw-r--r-- 8,368 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# Copyright (C) 2012-2020 SUSE Software Solutions Germany GmbH
#
# Author:
# Frank Sundermeyer <fsundermeyer at opensuse dot org>
#
# FO/PDF generation for DAPS
#
# Please submit feedback or patches to
# <fsundermeyer at opensuse dot org>
#
# fs 2012-10-10
# TODO: --meta stuff not working in PDFs (Stlyesheet Issue??)

# Draft mode can be enabled for HTML, so we need to add the
# corresponding strings to the resulting filename
#
# Draft mode can be enabled for PDFs, so we need to add the
# corresponding strings to the resulting filename
#

# binary checks
ifeq "$(FORMATTER)" "xep"
  HAVE_XEP := $(shell which xep 2>/dev/null)
  ifndef HAVE_XEP
    $(error $(shell ccecho "error" "Error: PDF formatter xep is not installed"))
  endif
endif

STYLEFO    := $(firstword $(wildcard $(addsuffix \
	        /fo/docbook.xsl, $(STYLE_ROOTDIRS))))
STYLE_GENINDEX := $(DAPSROOT)/daps-xslt/index/xml2idx.xsl
STYLE_ISINDEX  := $(DAPSROOT)/daps-xslt/common/search4index.xsl

# Issue #419
# The upstream stylesheets set paths for admon, callout, and navig graphics
# to "images/" by default. However, DAPS' HTML builds require to set these
# paths to static/images/ regardless what the stylesheets set
# To ensure the same path ("static/images/") can be used for HTML and PDF
# we need to create "static/images/" relative to the FO file
# This is done by the target $(TMP_STATIC_IMG_DIR): by setting a link to the
# stylesheet image or static directory
# In addition to that, we will also create a link $(TMP_DIR)/images to ensure
# building PDFs without explicitly setting a path for admon/callouts works
# as well.
#
# First, determine whether we have <STYLEROOT>/static or <STYLEROOT>/images
# (for a detailed explanation see html.mk)
#
# If we have a static directory, we can create a link to it in $(TMP_DIR)
# If we have an image directory, $(TMP_DIR)/static needs to be created and
# then a link to images in $(TMP_DIR)/static
#
ifdef STATIC_DIR
  STYLEIMG  := $(STATIC_DIR)
  IS_STATIC := static
else
  STYLEIMG := $(firstword $(wildcard \
		$(addsuffix static, $(dir $(STYLEFO)))\
		$(addsuffix static,$(dir $(patsubst %/,%,$(dir $(STYLEFO)))))\
		$(addsuffix images,$(dir $(patsubst %/,%,$(dir $(STYLEFO)))))))
  IS_STATIC := $(notdir $(STYLEIMG))
endif

TMP_STATIC_DIR     := $(TMP_DIR)/static

# Draft mode can be enabled for PDFs, so we need to add the
# corresponding strings to the resulting filename
#
%DOCNAME := $(DOCNAME)$(DRAFT_STR)$(META_STR)

INDEX   := $(shell $(XSLTPROC) --xinclude $(ROOTSTRING) --stylesheet $(STYLE_ISINDEX) --file $(MAIN) $(XSLTPROCESSOR) 2>/dev/null)

ifeq "$(INDEX)" "Yes"
  INDEXSTRING := --stringparam "indexfile=$(DOCNAME).ind"
endif

#----------
# FO stringparams
#
FOSTRINGS := --param "show.comments=$(REMARKS)" \
             --param "generate.permalink=0"  \
	     --param "ulink.show=1" \
	     --stringparam "draft.mode=$(DRAFT)" \
             --stringparam "styleroot=$(dir $(STYLEIMG))"

#----------
# Settings depending on --grayscale and --cropmarks
#
# PDF_RESULT is set in filenames.mk

FOFILE     := $(TMP_DIR)/$(DOCNAME)-$(FORMATTER)

ifeq "$(GRAYSCALE)" "1"
  FOSTRINGS  += --param "format.print=1" \
	        --stringparam "img.src.path=$(IMG_GENDIR)/grayscale/"
  FOFILE     := $(FOFILE)_gray
else
  FOSTRINGS  += --param "format.print=0" \
	        --stringparam "img.src.path=$(IMG_GENDIR)/color/"
  FOFILE     := $(FOFILE)_color
endif

# cropmarks are currently only supported by XEP
ifeq "$(CROPMARKS)" "1"
  FOSTRINGS  += --param "use.xep.cropmarks=1" --param "crop.marks=1" 
  FOFILE     := $(FOFILE)_crop
endif

FOFILE := $(FOFILE)$(LANGSTRING).fo

# Formatter dependent stuff
#
# Command line options are set via variables in the config files
# and are processed in the wrapper files
#
ifeq "$(FORMATTER)" "fop"
  FOSTRINGS += --param "fop1.extensions=1" \
               --param "xep.extensions=0"
  FORMATTER_CMD := $(FOP_WRAPPER)
endif
ifeq "$(FORMATTER)" "xep"
  FOSTRINGS += --param "fop1.extensions=0" \
               --param "xep.extensions=1"
  FORMATTER_CMD := $(XEP_WRAPPER)
endif


# Issue #419 continued
# The links to image or static directories need to be removed once the PDF
# has been built, since we do not know which stylesheets (and therefore
# which image directories) will be used in the next build.
# Since $(TMP_DIR)/static/ can be a directory, INTERMEDIATE will not work
# (does not remove directories), therefor using an explicit
# rm in $(PDF_RESULT):

ifneq "$(IS_STATIC)" "static"
  #  
  # we have <STYLEROOT>/image
  # 1. create $(TMP_DIR)/static
  # 2. create link to images in $(TMP_DIR)/static
  # 3. create lilnk $(TMP_DIR)/images
  #
  TMP_IMG_DIR        := $(TMP_DIR)/images
  TMP_STATIC_IMG_DIR := $(TMP_STATIC_DIR)/images


  $(TMP_STATIC_DIR): | $(TMP_DIR)
	mkdir -p $@

  $(TMP_STATIC_IMG_DIR): | $(TMP_STATIC_DIR)
	(cd $(TMP_STATIC_DIR) && ln -sf $(STYLEIMG))

  $(TMP_IMG_DIR): | $(TMP_DIR)
	(cd $(TMP_DIR) && ln -sf $(STYLEIMG))

else
  #  
  # we have <STYLEROOT>/static
  # create link to static in $(TMP_DIR)
  #
  $(TMP_STATIC_DIR): | $(TMP_DIR)
	(cd $(TMP_DIR) && ln -sf $(STYLEIMG))

endif


#--------------
# PDF
#
# Including a workaround for failed FOP builds where FOP creates
# corrupt PDFs which are considered a successful build by make when
# run a second time (pdfinfo call)
#
.PHONY: pdf
pdf: list-images-multisrc list-images-missing
ifeq "$(LEAN)" "1"
  pdf: $(LEAN_PDF_RESULT)
else
  pdf: $(PDF_RESULT)
endif
	pdfinfo $(PDF_RESULT) > /dev/null 2>&1 || ( ccecho "error" "PDF $(PDF_RESULT) has a size of 0 bytes"; false )
  ifeq "$(TARGET)" "pdf"
	@ccecho "result" "PDF book built with REMARKS=$(REMARKS), DRAFT=$(DRAFT) and META=$(META):\n$<"
  endif

#--------------
# Generate fo
#
# the link to $(STYLEIMG) at the end of this rule is needed in case the
# paths to callouts, admonition and draft graphics are specified relatively
# in the stylesheets (which is the case in the DocBook stylesheets)
#
$(FOFILE): | $(TMP_DIR)
ifdef METASTRING
  $(FOFILE): $(PROFILEDIR)/METAFILE
endif
ifeq "$(INDEX)" "Yes"
  $(FOFILE): $(PROFILEDIR)/$(DOCNAME).ind
endif
ifeq "$(VERBOSITY)" "1"
  $(FOFILE): FONTDEBUG := --param "debug.fonts=0"
endif
$(FOFILE): $(PROFILES) $(PROFILEDIR)/.validate $(DOCFILES) $(STYLEFO)
  ifeq "$(VERBOSITY)" "2"
	@ccecho "info"  "   Creating fo-file..."
  endif
	  $(XSLTPROC) --xinclude $(FOSTRINGS) $(ROOTSTRING) $(METASTRING) \
	    $(INDEXSTRING) $(FONTDEBUG) $(DAPSSTRINGS) $(XSLTPARAM) $(PARAMS) \
	    $(STRINGPARAMS) --output $(FOFILE) --stylesheet $(STYLEFO) \
	    --file $(PROFILED_MAIN) $(XSLTPROCESSOR) $(DEVNULL) \
	    $(ERR_DEVNULL);
  ifeq "$(VERBOSITY)" "2"
	@ccecho "info" "Successfully created fo file $(FOFILE)"
  endif

#--------------
# Generate PDF
#

#
# If the FO file contains relative links (as is the case when using the
# original DocBook stylesheets) the formatter (well, at least FOP) must be
# run from the directory where the .do file is located. Therefore we do a 
# cd $(dir $(FOFILE)) before running the formatter.

$(PDF_RESULT): | $(BUILD_DIR) $(RESULT_DIR)
ifeq "$(GRAYSCALE)" "1"
  $(PDF_RESULT): $(GRAYSCALE_IMAGES)
else
  $(PDF_RESULT): $(COLOR_IMAGES)
endif
ifneq "$(IS_STATIC)" "static"
  $(PDF_RESULT): $(TMP_STATIC_IMG_DIR)
  $(PDF_RESULT): $(TMP_IMG_DIR)
else
  $(PDF_RESULT): $(TMP_STATIC_DIR)
endif
$(PDF_RESULT): $(FOFILE)
  ifeq "$(VERBOSITY)" "2"
	@ccecho "info" "   Creating PDF from fo-file..."
  endif
	(cd $(dir $(FOFILE)) && $(FORMATTER_CMD) $< $@ $(DEVNULL) $(ERR_DEVNULL))
	@rm -rf $(TMP_STATIC_DIR) $(TMP_IMG_DIR)
  ifeq "$(VERBOSITY)" "2"
	@pdffonts $@ | tail -n +3 | awk '{print $5}' | grep -v "yes" \
		>& /dev/null && \
		(ccecho "warn" "Not all fonts are embedded" >&2;) || :
  endif

#--------------
# Generate a lean PDF from the original one
# (PDF with reduced graphics quality and a considerable smaller file size)
#
$(LEAN_PDF_RESULT): $(PDF_RESULT)
  ifeq "$(VERBOSITY)" "2"
	@ccecho "info" "   Creating lean PDF from $(PDF_RESULT)..."
  endif
	gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook \
	  -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$@ $<

#--------------
# Generate Index
#
$(PROFILEDIR)/$(DOCNAME).ind: $(PROFILES)
  ifeq "$(VERBOSITY)" "2"
	 @ccecho "info" "   Creating Index..."
  endif
	$(XSLTPROC) $(ROOTSTRING) --xinclude --output $@ \
	  --stylesheet $(STYLE_GENINDEX) --file $(PROFILED_MAIN) \
	  $(XSLTPROCESSOR)