Adjust the description based on a review of changes by Klaatu, now it is more accurate
[project-aon.git] / common / epub / Makefile.common
1 #
2 # Root directory
3 AONROOTREL := ../../../
4 AONROOTDIR = $(realpath $(AONROOTREL))
5 # Base directory we will install into
6 INSTALLDIR := $(AONROOTDIR)/../PUBLISH/$(BLANG)/
7 # Relative location of the XML files
8 RELXMLDIR := $(AONROOTDIR)/$(BLANG)/xml/
9 # Relative location of the scripts
10 RELSCRIPT := $(AONROOTDIR)/common/scripts
11 # Relative location of the xsl files
12 RELXSLDIR := $(AONROOTDIR)/common/xsl
13 EPUBSCRIPT := $(RELSCRIPT)/gbtoepub.pl
14 COVERIMAGE := $(AONROOTDIR)/$(BLANG)/jpeg/$(SERIES)/$(BASENAME)/skins/ebook/cover.jpg
15
16 # -------------------------------- BEGIN FONT SELECTION -----------------------------------------------------------
17 # Location of the font files, this is adjustable here in order to make it possible to run
18 # the build scripts as not all developers might have the Souvernir fonts.
19
20 # Option 1 (to be used for Lone wolf series) - Souvenir font 
21 # ---------------------------------------------------------
22 # Use this when buidling Lone Wolf books, using Souvenir fonts and make sure
23 # the font is available in the directory you configure here.  Note that the
24 # fontfiles are *not* available in Project Aon's SVN repository as they are not
25 # under a free license. For more information see /common/fonts/README.txt
26 #
27 # If using this configure, please make sure the following fonts are available in this directory:
28 # SouvenirStd-DemiItalic.otf  SouvenirStd-Demi.otf  SouvenirStd-LightItalic.otf  SouvenirStd-Light.otf
29
30 # FONTDIR := $(AONROOTDIR)/../fontfiles/
31
32 # Option 2 (to be used for Freway Warrior series builds) - Carlito font 
33 # ---------------------------------------------------------------------
34 # Use this when running builds of the Freeway Warrior series using the Carlito
35 # fonts.  This will build the documents using the fonts available in the SVN
36 # repository which (at the time of this writting) are the Carlito font, which
37 # is distributed with an Open Font license.
38
39 FONTDIR := $(AONROOTDIR)/common/fonts/
40
41 # --------------------------------- END FONT SELECTION -----------------------------------------------------------
42
43 EPUB=$(BASENAME).epub
44 MOBI=$(BASENAME).mobi
45 PDB=$(BASENAME).pdb
46 LRF=$(BASENAME).lrf
47 FB2=$(BASENAME).fb2
48 EBOOKS=$(EPUB) $(MOBI) $(PDB) $(LRF) $(FB2)
49 # To build only epub books:
50 # EBOOKS=$(EPUB)
51
52 # Formats we are compiling to
53 FORMATS=$(subst $(BASENAME).,,$(EBOOKS))
54
55 all: $(EBOOKS)
56
57 formats:
58         @echo $(FORMATS)
59
60 XMLFILE=$(patsubst %.epub,$(RELXMLDIR)/%.xml,$(BOOK))
61
62 # XSL files the ePubs depend on. If these are modified the
63 # ePub file needs to be regenerated
64 XSLFILES=$(RELXSLDIR)/epub-opf-metadata.xsl $(RELXSLDIR)/epub-xhtml.xsl  \
65         $(RELXSLDIR)/epub-ncx.xsl $(RELXSLDIR)/epub-opf-spine.xsl
66
67 # Generate the ePub file from the XML file
68 epub: $(EPUB)
69 $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/$(EPUB): $(XMLFILE) $(EPUBSCRIPT) $(XSLFILES)
70         cd $(AONROOTDIR) && perl $(EPUBSCRIPT) --language=$(BLANG) --font-files=$(FONTDIR) $(BASENAME) 
71
72 $(EPUB): $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/$(EPUB)
73         cp -p $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/$(EPUB) .
74 # Regenerate to include the covers properly within the Ebook and fix the EPUB
75         ebook-convert $(EPUB) regen_$(EPUB) --cover $(COVERIMAGE)
76         mv regen_$(EPUB) $(EPUB)
77         -rm -f cover.jpg $(BASENAME).opf  
78
79
80 # Convert to other formats. For a full list of format that we can convert to using 
81 # Calibre see http://manual.calibre-ebook.com/cli/ebook-convert.html
82
83 # Generate the mobi file from the ePub (Mobipocket format)
84 mobi: $(MOBI)
85 %.mobi: %.epub
86          ebook-convert $< $@
87
88 # Generate the pdb file from the ePub (eReader / Palm Media format)
89 %.pdb: %.epub
90          ebook-convert $< $@
91
92 # Generate the lrf file from the ePub (Broadband eBooks (BBeB) format)
93 %.lrf: %.epub
94          ebook-convert $< $@
95
96 # Generate the lit file from the ePub (Microsoft LIT format for Microsoft Reader)
97 %.lit: %.epub
98          ebook-convert $< $@
99
100 # Generate the pdf file from the ePub 
101 %.pdf: %.epub
102          ebook-convert $< $@
103
104 # Generate the snb file from the ePub 
105 %.snb: %.epub
106          ebook-convert $< $@
107
108 # Generate the pml file from the ePub 
109 %.pml: %.epub
110          ebook-convert $< $@
111
112 # Generate the fb2 file from the ePub  (Fictionbook format used by BeBook, PocketBook, Cybook, Papyre and others)
113 %.fb2: %.epub
114          ebook-convert $< $@
115
116
117 # Alternative build for the ePub format using open source tools instead
118 # of our script:
119 #
120 #DOCBOOK_XSL=/usr/share/xml/docbook/stylesheet/docbook-xsl/epub/docbook.xsl
121 #$(BOOK): $(XMLFILE) $(DOCBOOK_XSL)
122 #       if [ -x  /usr/bin/dbtoepub ] ; then  \
123 #               dbtoepub -o $(BOOK) $(XMLFILE) >$(BOOK).log 2>&1; \
124 #       else \
125 #               xsltproc $(DOCBOOK_XSL) $< >$(BOOK).log 2>&1; \
126 #               echo "application/epub+zip" > mimetype ; \
127 #               zip -0Xq  $@ mimetype; \
128 #               zip -Xr9D $@ META-INF/* OEBPS/* ; \
129 #       fi
130 # TODO:
131 # Embed font in dbtoepub using -f
132
133 epub-check: $(EPUB)
134         java -jar epubcheck.jar $<
135
136
137 # Final installation step of generate ebooks
138 install: $(INSTALLDIR) $(EBOOKS)
139         @for format in $(FORMATS); do \
140                 PUBLISHDIR="$(INSTALLDIR)/$$format/$(SERIES)" ; \
141                 file=$(BASENAME).$$format ; \
142                 [ ! -e "$$PUBLISHDIR" ] && \
143                         mkdir -p "$$PUBLISHDIR" ; \
144                 echo "Copying $$file to $$PUBLISHDIR" ; \
145                 cp -p $$file $$PUBLISHDIR && \
146                 chmod 664 $$PUBLISHDIR/$$file ;  \
147         done
148 publish: install
149
150 $(INSTALLDIR):
151         mkdir -p $@
152
153 clean: 
154         -rm -f $(EBOOKS) $(EPUB).log regen_$(EPUB) cover.jpg $(BASENAME).opf 
155
156 distclean: clean
157         -rm -rf $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/
158
159 .PHONY: all install publish clean distclean epub mobi