Make font selection be based on the definition of SERIES. The appropiate fontdir...
[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 the Lone wolf and Grey star 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 ifeq ($(SERIES), lw)
31 FONTDIR := $(AONROOTDIR)/../fontfiles/
32 endif
33 ifeq ($(SERIES), gs)
34 FONTDIR := $(AONROOTDIR)/../fontfiles/
35 endif
36
37 # Option 2 (to be used for Freway Warrior series builds) - Carlito font 
38 # ---------------------------------------------------------------------
39 # Use this when running builds of the Freeway Warrior series using the Carlito
40 # fonts.  This will build the documents using the fonts available in the SVN
41 # repository which (at the time of this writting) are the Carlito font, which
42 # is distributed with an Open Font license.
43
44 ifeq ($(SERIES), fw)
45 FONTDIR := $(AONROOTDIR)/common/fonts/
46 endif
47 # --------------------------------- END FONT SELECTION -----------------------------------------------------------
48
49 ifndef FONTDIR
50 $(info FONTDIR is not defined,  defauling to AONROOTDIR/common/fonts/)
51 FONTDIR := $(AONROOTDIR)/common/fonts/
52 endif
53
54 # Sanity checks before going further
55 ifndef SERIES
56 $(error WARNING: Book series is not defined, please define variable 'SERIES')
57 endif
58 ifndef BLANG
59 $(error WARNING: Book language is not defined, please define variable 'BLANG')
60 endif
61 ifndef BASENAME
62 $(error WARNING: Book basic name is not defined, please define variable 'BASENAME')
63 endif
64
65
66 EPUB=$(BASENAME).epub
67 MOBI=$(BASENAME).mobi
68 PDB=$(BASENAME).pdb
69 LRF=$(BASENAME).lrf
70 FB2=$(BASENAME).fb2
71 EBOOKS=$(EPUB) $(MOBI) $(PDB) $(LRF) $(FB2)
72 # To build only epub books:
73 # EBOOKS=$(EPUB)
74
75 # Formats we are compiling to
76 FORMATS=$(subst $(BASENAME).,,$(EBOOKS))
77
78 all: $(EBOOKS)
79
80 formats:
81         @echo $(FORMATS)
82
83 XMLFILE=$(patsubst %.epub,$(RELXMLDIR)/%.xml,$(BOOK))
84
85 # XSL files the ePubs depend on. If these are modified the
86 # ePub file needs to be regenerated
87 XSLFILES=$(RELXSLDIR)/epub-opf-metadata.xsl $(RELXSLDIR)/epub-xhtml.xsl  \
88         $(RELXSLDIR)/epub-ncx.xsl $(RELXSLDIR)/epub-opf-spine.xsl
89
90 # Generate the ePub file from the XML file
91 epub: $(EPUB)
92 $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/$(EPUB): $(XMLFILE) $(EPUBSCRIPT) $(XSLFILES)
93         cd $(AONROOTDIR) && perl $(EPUBSCRIPT) --language=$(BLANG) --font-files=$(FONTDIR) $(BASENAME) 
94
95 $(EPUB): $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/$(EPUB)
96         cp -p $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/$(EPUB) .
97 # Regenerate to include the covers properly within the Ebook and fix the EPUB
98         ebook-convert $(EPUB) regen_$(EPUB) --cover $(COVERIMAGE)
99         mv regen_$(EPUB) $(EPUB)
100         -rm -f cover.jpg $(BASENAME).opf  
101
102
103 # Convert to other formats. For a full list of format that we can convert to using 
104 # Calibre see http://manual.calibre-ebook.com/cli/ebook-convert.html
105
106 # Generate the mobi file from the ePub (Mobipocket format)
107 mobi: $(MOBI)
108 %.mobi: %.epub
109          ebook-convert $< $@
110
111 # Generate the pdb file from the ePub (eReader / Palm Media format)
112 %.pdb: %.epub
113          ebook-convert $< $@
114
115 # Generate the lrf file from the ePub (Broadband eBooks (BBeB) format)
116 %.lrf: %.epub
117          ebook-convert $< $@
118
119 # Generate the lit file from the ePub (Microsoft LIT format for Microsoft Reader)
120 %.lit: %.epub
121          ebook-convert $< $@
122
123 # Generate the pdf file from the ePub 
124 %.pdf: %.epub
125          ebook-convert $< $@
126
127 # Generate the snb file from the ePub 
128 %.snb: %.epub
129          ebook-convert $< $@
130
131 # Generate the pml file from the ePub 
132 %.pml: %.epub
133          ebook-convert $< $@
134
135 # Generate the fb2 file from the ePub  (Fictionbook format used by BeBook, PocketBook, Cybook, Papyre and others)
136 %.fb2: %.epub
137          ebook-convert $< $@
138
139
140 # Alternative build for the ePub format using open source tools instead
141 # of our script:
142 #
143 #DOCBOOK_XSL=/usr/share/xml/docbook/stylesheet/docbook-xsl/epub/docbook.xsl
144 #$(BOOK): $(XMLFILE) $(DOCBOOK_XSL)
145 #       if [ -x  /usr/bin/dbtoepub ] ; then  \
146 #               dbtoepub -o $(BOOK) $(XMLFILE) >$(BOOK).log 2>&1; \
147 #       else \
148 #               xsltproc $(DOCBOOK_XSL) $< >$(BOOK).log 2>&1; \
149 #               echo "application/epub+zip" > mimetype ; \
150 #               zip -0Xq  $@ mimetype; \
151 #               zip -Xr9D $@ META-INF/* OEBPS/* ; \
152 #       fi
153 # TODO:
154 # Embed font in dbtoepub using -f
155
156 epub-check: $(EPUB)
157         java -jar epubcheck.jar $<
158
159
160 # Final installation step of generate ebooks
161 install: $(INSTALLDIR) $(EBOOKS)
162         @for format in $(FORMATS); do \
163                 PUBLISHDIR="$(INSTALLDIR)/$$format/$(SERIES)" ; \
164                 file=$(BASENAME).$$format ; \
165                 [ ! -e "$$PUBLISHDIR" ] && \
166                         mkdir -p "$$PUBLISHDIR" ; \
167                 echo "Copying $$file to $$PUBLISHDIR" ; \
168                 cp -p $$file $$PUBLISHDIR && \
169                 chmod 664 $$PUBLISHDIR/$$file ;  \
170         done
171 publish: install
172
173 $(INSTALLDIR):
174         mkdir -p $@
175
176 clean: 
177         -rm -f $(EBOOKS) $(EPUB).log regen_$(EPUB) cover.jpg $(BASENAME).opf 
178
179 distclean: clean
180         -rm -rf $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/
181
182 .PHONY: all install publish clean distclean epub mobi