Do not make epub generation depend on the gbtoepub script. Otherwise, minor changes...
[project-aon.git] / common / epub / Makefile.common
index e998a28..633416f 100644 (file)
@@ -11,7 +11,62 @@ RELSCRIPT := $(AONROOTDIR)/common/scripts
 # Relative location of the xsl files
 RELXSLDIR := $(AONROOTDIR)/common/xsl
 EPUBSCRIPT := $(RELSCRIPT)/gbtoepub.pl
+COVERSCRIPT := $(RELSCRIPT)/create-epub-cover.pl
 COVERIMAGE := $(AONROOTDIR)/$(BLANG)/jpeg/$(SERIES)/$(BASENAME)/skins/ebook/cover.jpg
+ALTCOVERIMAGE := $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/OEBPS/cover.jpg 
+
+# -------------------------------- BEGIN FONT SELECTION -----------------------------------------------------------
+# Location of the font files, this is adjustable here in order to make it possible to run
+# the build scripts as not all developers might have the Souvernir fonts.
+
+# Option 1 (to be used for the Lone wolf and Grey star series) - Souvenir font 
+# ---------------------------------------------------------------------------
+# Use this when buidling Lone Wolf books, using Souvenir fonts and make sure
+# the font is available in the directory you configure here.  Note that the
+# fontfiles are *not* available in Project Aon's SVN repository as they are not
+# under a free license. For more information see /common/fonts/README.txt
+#
+# If using this configure, please make sure the following fonts are available in this directory:
+# SouvenirStd-DemiItalic.otf  SouvenirStd-Demi.otf  SouvenirStd-LightItalic.otf  SouvenirStd-Light.otf
+
+ifeq ($(SERIES), lw)
+FONTDIR := $(AONROOTDIR)/../fontfiles/
+endif
+ifeq ($(SERIES), ls)
+FONTDIR := $(AONROOTDIR)/../fontfiles/
+endif
+ifeq ($(SERIES), gs)
+FONTDIR := $(AONROOTDIR)/../fontfiles/
+endif
+
+# Option 2 (to be used for Freway Warrior series builds) - Carlito font 
+# ---------------------------------------------------------------------
+# Use this when running builds of the Freeway Warrior series using the Carlito
+# fonts.  This will build the documents using the fonts available in the SVN
+# repository which (at the time of this writting) are the Carlito font, which
+# is distributed with an Open Font license.
+
+ifeq ($(SERIES), fw)
+FONTDIR := $(AONROOTDIR)/common/fonts/
+endif
+# --------------------------------- END FONT SELECTION -----------------------------------------------------------
+
+ifndef FONTDIR
+$(info FONTDIR is not defined,  defauling to AONROOTDIR/common/fonts/)
+FONTDIR := $(AONROOTDIR)/common/fonts/
+endif
+
+# Sanity checks before going further
+ifndef SERIES
+$(error WARNING: Book series is not defined, please define variable 'SERIES')
+endif
+ifndef BLANG
+$(error WARNING: Book language is not defined, please define variable 'BLANG')
+endif
+ifndef BASENAME
+$(error WARNING: Book basic name is not defined, please define variable 'BASENAME')
+endif
+
 
 EPUB=$(BASENAME).epub
 MOBI=$(BASENAME).mobi
@@ -39,18 +94,27 @@ XSLFILES=$(RELXSLDIR)/epub-opf-metadata.xsl $(RELXSLDIR)/epub-xhtml.xsl  \
 
 # Generate the ePub file from the XML file
 epub: $(EPUB)
-$(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/$(EPUB): $(XMLFILE) $(EPUBSCRIPT) $(XSLFILES)
-# Use this when using Souvenir fonts (cannot be distributed in Project Aon's SVN repository)
-# make sure the font is available in the fontfiles directory *one level before* the SVN repo
-#      cd $(AONROOTDIR) && perl $(EPUBSCRIPT) --language=$(BLANG) --font-files=$(AONROOTDIR)/../fontfiles/ $(BASENAME) 
-# Use this when using the fonts provided in the Carlito font (distributed with an Open Font license)
-# which is available in the Project Aon's SVN repository
-       cd $(AONROOTDIR) && perl $(EPUBSCRIPT) --language=$(BLANG) --font-files=$(AONROOTDIR)/common/fonts/ $(BASENAME) 
-
-$(EPUB): $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/$(EPUB)
+$(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/$(EPUB): $(XMLFILE) $(XSLFILES)
+       cd $(AONROOTDIR) && perl $(EPUBSCRIPT) --language=$(BLANG) --font-files=$(FONTDIR) $(BASENAME) 
+# Create cover page if not existing
+       @if [ ! -e $(COVERIMAGE) ] ; then \
+               cd $(AONROOTDIR) && perl  $(COVERSCRIPT) --language=$(BLANG) --font-files=$(FONTDIR) $(BASENAME) ; \
+       fi
+
+$(EPUB): $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/$(EPUB)  
+       @[ -x  `which ebook-convert` ] || { echo "ERROR: Cannot find 'ebook-convert', please install Calibre" >&2; exit 1;  }
        cp -p $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/$(EPUB) .
 # Regenerate to include the covers properly within the Ebook and fix the EPUB
-       ebook-convert $(EPUB) regen_$(EPUB) --cover $(COVERIMAGE)
+       @if [ -e $(ALTCOVERIMAGE) ] && [ ! -e $(COVERIMAGE) ]  ; then \
+               ebook-convert $(EPUB) regen_$(EPUB) --cover $(ALTCOVERIMAGE) ; \
+       fi
+       @if [ -e $(COVERIMAGE) ]  ; then \
+               ebook-convert $(EPUB) regen_$(EPUB) --cover $(COVERIMAGE) ; \
+       fi
+       @if [ ! -e $(ALTCOVERIMAGE) ] && [ ! -e $(COVERIMAGE) ]  ; then \
+               ebook-convert $(EPUB) regen_$(EPUB) ; \
+       fi
+               
        mv regen_$(EPUB) $(EPUB)
        -rm -f cover.jpg $(BASENAME).opf  
 
@@ -61,44 +125,54 @@ $(EPUB): $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/$(EPUB)
 # Generate the mobi file from the ePub (Mobipocket format)
 mobi: $(MOBI)
 %.mobi: %.epub
+       @[ -x  `which ebook-convert` ] || { echo "ERROR: Cannot find 'ebook-convert', please install Calibre" >&2; exit 1;  }
         ebook-convert $< $@
 
 # Generate the pdb file from the ePub (eReader / Palm Media format)
 %.pdb: %.epub
+       @[ -x  `which ebook-convert` ] || { echo "ERROR: Cannot find 'ebook-convert', please install Calibre" >&2; exit 1;  }
         ebook-convert $< $@
 
 # Generate the lrf file from the ePub (Broadband eBooks (BBeB) format)
 %.lrf: %.epub
+       @[ -x  `which ebook-convert` ] || { echo "ERROR: Cannot find 'ebook-convert', please install Calibre" >&2; exit 1;  }
         ebook-convert $< $@
 
 # Generate the lit file from the ePub (Microsoft LIT format for Microsoft Reader)
 %.lit: %.epub
+       @[ -x  `which ebook-convert` ] || { echo "ERROR: Cannot find 'ebook-convert', please install Calibre" >&2; exit 1;  }
         ebook-convert $< $@
 
 # Generate the pdf file from the ePub 
 %.pdf: %.epub
+       @[ -x  `which ebook-convert` ] || { echo "ERROR: Cannot find 'ebook-convert', please install Calibre" >&2; exit 1;  }
         ebook-convert $< $@
 
 # Generate the snb file from the ePub 
 %.snb: %.epub
+       @[ -x  `which ebook-convert` ] || { echo "ERROR: Cannot find 'ebook-convert', please install Calibre" >&2; exit 1;  }
         ebook-convert $< $@
 
 # Generate the pml file from the ePub 
 %.pml: %.epub
+       @[ -x  `which ebook-convert` ] || { echo "ERROR: Cannot find 'ebook-convert', please install Calibre" >&2; exit 1;  }
         ebook-convert $< $@
 
 # Generate the fb2 file from the ePub  (Fictionbook format used by BeBook, PocketBook, Cybook, Papyre and others)
-%.fb2: %.epub
+%.fb2: %.epub 
+       @[ -x  `which ebook-convert` ] || { echo "ERROR: Cannot find 'ebook-convert', please install Calibre" >&2; exit 1;  }
         ebook-convert $< $@
 
 
 # Alternative build for the ePub format using open source tools instead
-# of our script:
+# of our script.
+# Sample Makefile code:
 #
 #DOCBOOK_XSL=/usr/share/xml/docbook/stylesheet/docbook-xsl/epub/docbook.xsl
-#$(BOOK): $(XMLFILE) $(DOCBOOK_XSL)
+#$(EPUB): $(XMLFILE) $(DOCBOOK_XSL)
+#      @[ -x  `which dbtoepub` ] || { echo "ERROR: Cannot find 'dbtoepub', please install this package" >&2; exit 1;  }
 #      if [ -x  /usr/bin/dbtoepub ] ; then  \
-#              dbtoepub -o $(BOOK) $(XMLFILE) >$(BOOK).log 2>&1; \
+#              dbtoepub -o $(EPUB) $(XMLFILE) >$(BOOK).log 2>&1; \
 #      else \
 #              xsltproc $(DOCBOOK_XSL) $< >$(BOOK).log 2>&1; \
 #              echo "application/epub+zip" > mimetype ; \
@@ -134,4 +208,4 @@ clean:
 distclean: clean
        -rm -rf $(AONROOTDIR)/$(BLANG)/epub/$(SERIES)/$(BASENAME)/
 
-.PHONY: all install publish clean distclean epub mobi
+.PHONY: all install publish clean distclean epub mobi ebook-convert