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