changing how we add covers to EPUBs to fix errors reported by validators
[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         cd $(AONROOTDIR) && perl $(EPUBSCRIPT) --language=$(BLANG) --font-files=$(AONROOTDIR)/fontfiles/ $(BASENAME) 
44
45 $(EPUB): $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/$(EPUB)
46         cp -p $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/$(EPUB) .
47 # Regenerate to include the covers properly within the Ebook and fix the EPUB
48         ebook-convert $(EPUB) regen_$(EPUB) --cover $(COVERIMAGE)
49         mv regen_$(EPUB) $(EPUB)
50         -rm -f cover.jpg $(BASENAME).opf  
51
52
53 # Convert to other formats. For a full list of format that we can convert to using 
54 # Calibre see http://manual.calibre-ebook.com/cli/ebook-convert.html
55
56 # Generate the mobi file from the ePub (Mobipocket format)
57 mobi: $(MOBI)
58 %.mobi: %.epub
59          ebook-convert $< $@
60
61 # Generate the pdb file from the ePub (eReader / Palm Media format)
62 %.pdb: %.epub
63          ebook-convert $< $@
64
65 # Generate the lrf file from the ePub (Broadband eBooks (BBeB) format)
66 %.lrf: %.epub
67          ebook-convert $< $@
68
69 # Generate the lit file from the ePub (Microsoft LIT format for Microsoft Reader)
70 %.lit: %.epub
71          ebook-convert $< $@
72
73 # Generate the pdf file from the ePub 
74 %.pdf: %.epub
75          ebook-convert $< $@
76
77 # Generate the snb file from the ePub 
78 %.snb: %.epub
79          ebook-convert $< $@
80
81 # Generate the pml file from the ePub 
82 %.pml: %.epub
83          ebook-convert $< $@
84
85 # Generate the fb2 file from the ePub  (Fictionbook format used by BeBook, PocketBook, Cybook, Papyre and others)
86 %.fb2: %.epub
87          ebook-convert $< $@
88
89
90 # Alternative build for the ePub format using open source tools instead
91 # of our script:
92 #
93 #DOCBOOK_XSL=/usr/share/xml/docbook/stylesheet/docbook-xsl/epub/docbook.xsl
94 #$(BOOK): $(XMLFILE) $(DOCBOOK_XSL)
95 #       if [ -x  /usr/bin/dbtoepub ] ; then  \
96 #               dbtoepub -o $(BOOK) $(XMLFILE) >$(BOOK).log 2>&1; \
97 #       else \
98 #               xsltproc $(DOCBOOK_XSL) $< >$(BOOK).log 2>&1; \
99 #               echo "application/epub+zip" > mimetype ; \
100 #               zip -0Xq  $@ mimetype; \
101 #               zip -Xr9D $@ META-INF/* OEBPS/* ; \
102 #       fi
103 # TODO:
104 # Embed font in dbtoepub using -f
105
106 epub-check: $(EPUB)
107         java -jar epubcheck.jar $<
108
109
110 # Final installation step of generate ebooks
111 install: $(INSTALLDIR) $(EBOOKS)
112         @for format in $(FORMATS); do \
113                 PUBLISHDIR="$(INSTALLDIR)/$$format/$(SERIES)" ; \
114                 file=$(BASENAME).$$format ; \
115                 [ ! -e "$$PUBLISHDIR" ] && \
116                         mkdir -p "$$PUBLISHDIR" ; \
117                 echo "Copying $$file to $$PUBLISHDIR" ; \
118                 cp -p $$file $$PUBLISHDIR && \
119                 chmod 664 $$PUBLISHDIR/$$file ;  \
120         done
121 publish: install
122
123 $(INSTALLDIR):
124         mkdir -p $@
125
126 clean: 
127         -rm -f $(EBOOKS) $(EPUB).log regen_$(EPUB) cover.jpg $(BASENAME).opf 
128
129 distclean: clean
130         -rm -rf $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/
131
132 .PHONY: all install publish clean distclean epub mobi