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