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