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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
|
# Copyright (C) 2012-2020 SUSE Software Solutions Germany GmbH
#
# Author:
# Frank Sundermeyer <fsundermeyer at opensuse dot org>
#
# EPUB generation for DAPS
#
# Please submit feedback or patches to
# <fsundermeyer at opensuse dot org>
#
# includes are set in selector.mk
# include $(DAPSROOT)/make/setfiles.mk
# include $(DAPSROOT)/make/profiling.mk
# include $(DAPSROOT)/make/validate.mk
# include $(DAPSROOT)/make/images.mk
# include $(DAPSROOT)/make/misc.mk
# binary checks
ifeq "$(TARGET)" "epub"
ifeq "$(RESULTCHECK)" "1"
HAVE_ECHECK = $(shell which epubcheck 2>/dev/null)
ifeq "$(HAVE_ECHECK)" ""
$(error $(shell ccecho "error" "Error: epubcheck is not installed"))
endif
endif
endif
ifeq "$(TARGET)" "mobi"
HAVE_CALIBRE = $(shell which ebook-convert 2>/dev/null)
ifeq "$(HAVE_CALIBRE)" ""
$(error $(shell ccecho "error" "Error: ebook-convert (provided by calibre) is not installed"))
endif
endif
# Stylesheets
#
ifeq "$(EPUB3)" "1"
STYLEEPUB := $(firstword $(wildcard $(addsuffix \
/epub3/chunk.xsl, $(STYLE_ROOTDIRS))))
else
STYLEEPUB := $(firstword $(wildcard $(addsuffix \
/epub/docbook.xsl, $(STYLE_ROOTDIRS))))
endif
# Three scenarios:
#
# <STYLESHEETDIR>/xhtml/static
# |-css
# |-js
# |-images
#
# or
#
# <STYLESHEETDIR>/static
# |-css
# |-js
# |-images
#
#
# or we have the DocBook standard layout:
# <STYLESHEETDIR>/images
# <STYLESHEETDIR>/xhtml/<FOO>.css
#
# If <STYLESHEETDIR>/epub/static exists, it is used by default. If not,
# <STYLESHEETDIR>/static is used. Alternatively, a custom static directory
# can be specified with the --statdir parameter.
#
# IS_STATIC is used to determine
# whether we have a static dir (IS_STATIC=static) or not.
#
# Set the styleimage directory. If no custom directory is set with --statdir,
# it can either be <STYLEROOT>/epub/static, <STYLEROOT>/static or
# <STYLEROOT>/images. If more than one of these directories exist, they will
# be used in the order listed (firstword function)
#
ifneq "$(strip $(STATIC_DIR))" ""
STYLEIMG := $(STATIC_DIR)
IS_STATIC := static
else
STYLEIMG := $(firstword $(wildcard \
$(addsuffix static, $(dir $(STYLEEPUB)))\
$(addsuffix static,$(dir $(patsubst %/,%,$(dir $(STYLEEPUB)))))\
$(addsuffix images,$(dir $(patsubst %/,%,$(dir $(STYLEEPUB)))))))
IS_STATIC := $(notdir $(STYLEIMG))
endif
ifeq "$(strip $(STYLEIMG))" ""
$(error $(shell ccecho "error" "Fatal error: Could not find stylesheet images"))
endif
STYLEEPUB_BIGFILE := $(DAPSROOT)/daps-xslt/epub/db2db.xsl
EPUB_TMPDIR := $(TMP_DIR)/epub_$(DOCNAME)
EPUB_OEBPS := $(EPUB_TMPDIR)/OEBPS
EPUB_STATIC := $(EPUB_OEBPS)/static
EPUB_BIGFILE := $(TMP_DIR)/epub_$(DOCNAME).xml
# inline images
#
EPUB_INLINE_DIR := $(EPUB_OEBPS)
EPUB_INLINE_IMAGES := $(subst $(IMG_GENDIR)/color,$(EPUB_INLINE_DIR),$(ONLINE_IMAGES))
# Directories
#
EPUB_DIRECTORIES := $(EPUB_TMPDIR) $(EPUB_OEBPS) $(EPUB_STATIC)
EPUBSTRINGS := --param "show.comments=$(REMARKS)" \
--stringparam "epub.oebps.dir=OEBPS/" \
--stringparam "epub.metainf.dir=META-INF/"
ifeq "$(IS_STATIC)" "static"
EPUBSTRINGS += --stringparam "callout.graphics.path=static/images/" \
--stringparam "admon.graphics.path=static/images/"
else
EPUBSTRINGS += --stringparam "callout.graphics.path=static/callouts/" \
--stringparam "admon.graphics.path=static/"
endif
ifeq "$(EPUB3)" "1"
EPUB_CONTENT_FILE := OEBPS/package.opf
else
EPUB_CONTENT_FILE := OEBPS/content.opf
EPUBSTRINGS += --stringparam "base.dir=OEBPS/"
endif
EPUB_CONTENT_OPF := $(EPUB_TMPDIR)/$(EPUB_CONTENT_FILE)
ifneq "$(strip $(EPUB_CSS))" ""
ifneq "$(strip $(EPUB_CSS))" "none"
EPUBSTRINGS += --stringparam "html.stylesheet=$(notdir $(EPUB_CSS))"
EPUB_CSSFILE := $(EPUB_OEBPS)/$(notdir $(EPUB_CSS))
else
EPUBSTRINGS += --stringparam "html.stylesheet=\"\""
endif
endif
#--------------
# EPUB
#
# In order not to pack files that do not belong to the current ePUB build,
# we need to clear $(EPUB_TMPDIR) first. In order to avoid unwanted results
# with an unset $(EPUB_TMPDIR), we are adding a security check before
# deleting
#
.PHONY: epub
epub: $(shell if [[ $$(expr match "$(EPUB_TMPDIR)" "$(TMP_DIR)/epub_") -gt 0 && -d "$(EPUB_TMPDIR)" ]]; then rm -r "$(EPUB_TMPDIR)"; fi 2>&1 >/dev/null)
epub: list-images-missing
ifeq "$(RESULTCHECK)" "1"
epub: epub-check
endif
epub: $(EPUB_RESULT)
ifeq "$(TARGET)" "epub"
@ccecho "result" "Find the EPUB book at:\n$<"
endif
.PHONY: mobi
mobi: list-images-missing
mobi: $(MOBI_RESULT)
@ccecho "result" "Find the Amazon Kindle book (.mobi) at:\n$<"
#--------------
# Create Directories
#
$(EPUB_DIRECTORIES):
mkdir -p $@
#--------------
# generate EPUB-bigfile
#
$(EPUB_BIGFILE): $(PROFILES) $(PROFILEDIR)/.validate
ifeq "$(VERBOSITY)" "2"
@ccecho "info" " Generating EPUB-bigfile"
endif
$(XSLTPROC) --xinclude --output $@ $(ROOTSTRING) \
--stylesheet $(STYLEEPUB_BIGFILE) \
--file $(PROFILED_MAIN) $(XSLTPROCESSOR)
#--------------
# HTML from EPUB-bigfile
#
$(EPUB_CONTENT_OPF): | $(EPUB_TMPDIR)
$(EPUB_CONTENT_OPF): $(EPUB_BIGFILE)
ifeq "$(VERBOSITY)" "2"
@ccecho "info" " Creating HTML files for EPUB"
endif
(cd $(EPUB_TMPDIR) && $(XSLTPROC) $(EPUBSTRINGS) $(DAPSSTRINGS) \
$(PARAMS) $(XSLTPARAM) $(STRINGPARAMS) \
--stylesheet $(STYLEEPUB) --file $< $(XSLTPROCESSOR) \
$(DEVNULL) $(ERR_DEVNULL))
#---------------
# Inline Graphics
#
$(EPUB_INLINE_IMAGES): $(ONLINE_IMAGES) | $(EPUB_OEBPS)
$(EPUB_INLINE_DIR)/%.png: $(IMG_GENDIR)/color/%.png
ln -sf $(shell readlink -e $< 2>/dev/null) $@
$(EPUB_INLINE_DIR)/%.jpg: $(IMG_GENDIR)/color/%.jpg
ln -sf $(shell readlink -e $< 2>/dev/null) $@
$(EPUB_INLINE_DIR)/%.svg: $(IMG_GENDIR)/color/%.svg
ln -sf $(shell readlink -e $< 2>/dev/null) $@
#--------------
# mimetype file
#
$(EPUB_TMPDIR)/mimetype: | $(EPUB_TMPDIR)
@echo -n "application/epub+zip" > $@
#--------------
# Generate EPUB-file
#
$(EPUB_RESULT): | $(EPUB_OEBPS) $(EPUB_STATIC) $(RESULT_DIR)
ifneq "$(EPUB3)" "1"
$(EPUB_RESULT): $(EPUB_TMPDIR)/mimetype
endif
$(EPUB_RESULT): $(EPUB_CONTENT_OPF)
$(EPUB_RESULT): $(EPUB_INLINE_IMAGES)
ifeq "$(VERBOSITY)" "2"
@ccecho "info" " Creating EPUB"
endif
cp -rs --remove-destination $(STYLEIMG)/* $(EPUB_STATIC)
ifneq "$(strip $(EPUB_CSS))" ""
cp -s --remove-destination $(EPUB_CSS) $(EPUB_OEBPS)
endif
ifeq "$(IS_STATIC)" "static"
(cd $(EPUB_TMPDIR); zip -r -X $@ mimetype META-INF OEBPS $(DEVNULL))
else
(cd $(EPUB_TMPDIR); \
zip -r -X $@ mimetype META-INF $(EPUB_CONTENT_FILE) \
$(addprefix OEBPS/,$(shell xsltproc $(DAPSROOT)/daps-xslt/epub/get_manifest.xsl $(EPUB_CONTENT_OPF) 2>/dev/null)) $(DEVNULL))
endif
#--------------
# Check epub file
#
# Check the epub file
#
.PHONY: epub-check
epub-check: $(EPUB_RESULT)
@ccecho "result" "#################### BEGIN epubcheck report ####################"
epubcheck $< 2>&1 || true
@ccecho "result" "#################### END epubcheck report ####################"
#--------------
# mobi (Amazon Kindle)
#
# we are using calibre's ebook-convert to convert the epub file to mobi
# The format generated is MOBI 6, which is compatible to all Amazon devices
$(MOBI_RESULT):
$(MOBI_RESULT): $(EPUB_RESULT)
ebook-convert $< $@ --mobi-ignore-margins --no-inline-toc \
--pretty-print $(DEVNULL)
#Options to set metadata in the output
#
#--author-sort
#String to be used when sorting by author.
#
#--authors
#Set the authors. Multiple authors should be separated by ampersands.
#
#--book-producer
#Set the book producer.
#
#--comments
#Set the ebook description.
#
#--cover
#Set the cover to the specified file or URL
#
#--isbn
#Set the ISBN of the book.
#
#--language
#Set the language.
#
#--pubdate
#Set the publication date.
#
#--publisher
#Set the ebook publisher.
#
#--rating
#Set the rating. Should be a number between 1 and 5.
#
#--series
#Set the series this ebook belongs to.
#
#--series-index
#Set the index of the book in this series.
#
#--tags
#Set the tags for the book. Should be a comma separated list.
#
#--timestamp
#Set the book timestamp (no longer used anywhere)
#
#--title
#Set the title.
#
#--title-sort
#The version of the title to be used for sorting.
#
|