Skip to content
Browse files

Documentation

  • Loading branch information...
1 parent a11282d commit 0fbbf758e97b4813d72db5b09c102aaeced5d008 @avdi committed Feb 27, 2012
Showing with 60 additions and 7 deletions.
  1. +60 −7 orgpress.mk
View
67 orgpress.mk
@@ -1,13 +1,33 @@
ORGPRESS_VERSION := 0.0.1
+
+# Path to this file
ORGPRESS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
+
+# Path to the book makefile, containing book-specific customizations
+# to the rules and variables set up here.
+BOOK_MAKEFILE := $(CURDIR)/book.mk
+
+# The OrgPress root directory
ORGPRESS_ROOT := $(dir $(ORGPRESS_MAKEFILE))
+
+# Tell make to load this file in recursive invocations
MAKEFILES := $(ORGPRESS_MAKEFILE)
-# Tools
+### TOOLS ###
+
+# Where to find Emacs
EMACS = $(shell which emacs)
+
+# The Emacs version
EMACS_VERSION = $(shell $(EMACS) --version | head -n1)
-EMACS_INIT = $(ORGPRESS_ROOT)/init.el
+
+# ELisp files which should be loaded when Emacs is invoked
+EMACS_LOAD = $(ORGPRESS_ROOT)/init.el
+
+# The Calibre conversion command
CONVERT = ebook-convert
+
+# Flags for the Calibre conversion command
define CONVERTFLAGS
--authors "$(AUTHORS)" --book-producer "$(PRODUCER)"
--comments "$(COMMENTS)"
@@ -21,25 +41,49 @@ define CONVERTFLAGS
--level3-toc "//h:div[@class='outline-4']/h:h4"
--extra-css ".example { border: 1pt solid black; padding: 0.5ex; }"
endef
+
+# Calibre flags specific to Epub
define EPUBFLAGS
--output-profile ipad --preserve-cover-aspect-ratio
endef
# --cover "$(EPUBCOVER)"
+
+# Calibre flags specific to Mobi
define MOBIFLAGS
--output-profile kindle
endef
# --cover "$(MOBICOVER)"
+
+# The input HTML file for Calibre conversions
CALIBRE_INPUT = $(call flavor_file,calibre.html)
-# Book metadata
+### BOOK METADATA ###
+
+# The basename of the book, for use in filenames
BOOK_NAME = $(notdir $(CURDIR))
+
+# The main org-mode source file
SOURCE_FILE = $(BOOK_NAME).org
+
+# The book title
BOOK_TITLE = $(BOOK_NAME)
+
+# The author, or authors
AUTHORS = Unknown Author
+
+# The person or organization which produced the ebook file
PRODUCER = $(AUTHOR)
+
+# Misc. comments about the book
COMMENTS = $(BOOK_TITLE)
+
+# The language of the book
LANGUAGE = en-US
+
+# The book publisher
PUBLISHER = $(AUTHORS)
+
+# The publication date
PUBDATE = $(shell ls -ldc $(CURDIR) | cut -d' ' -f6)
# Org export customizations
@@ -58,8 +102,13 @@ CALIBRE_OUTPUTS = $(foreach flavor,$(CALIBRE_FLAVORS),$(call flavor_file,$(flav
export_target := $(BUILD_DIR)/$(BOOK_NAME).$(FLAVOR)
-# Functions
+### FUNCTIONS ###
+
+# Given a flavor name (e.g. "mobi"), return the path of the
+# corresponding output file
flavor_file = $(BUILD_DIR)/$(BOOK_NAME).$(1)
+
+# Convert a string to all-uppercase
uppercase = $(shell echo $(1) | tr a-z A-Z)
define export_plist_calibre_elisp
@@ -82,12 +131,16 @@ endef
$(info OrgPress version $(ORGPRESS_VERSION))
-include $(CURDIR)/book.mk
+include $(BOOK_MAKEFILE)
$(info Building $(BOOK_NAME))
default: $(BUNDLE_FLAVORS)
+# This sets up shortcut targets for flavors, e.g.:
+# make epub
+# Or:
+# make pdf
$(ALL_FLAVORS):
$(MAKE) $(call flavor_file,$@)
@@ -96,8 +149,8 @@ $(CALIBRE_OUTPUTS): FLAVORFLAGS = $($(call uppercase,$(FLAVOR))FLAGS)
$(CALIBRE_OUTPUTS): $(CALIBRE_INPUT) $(CURDIR)/book.mk $(ORGPRESS_MAKEFILE)
$(CONVERT) $< $@ $(strip $(CONVERTFLAGS)) $(strip $(FLAVORFLAGS))
-$(export_target): $(EMACS_INIT) $(SOURCE_FILE)
- $(EMACS) $(EMACS_INIT:%=-l %) \
+$(export_target): $(EMACS_LOAD) $(SOURCE_FILE)
+ $(EMACS) $(EMACS_LOAD:%=-l %) \
--user $(USER) \
--batch \
--file $(SOURCE_FILE) \

0 comments on commit 0fbbf75

Please sign in to comment.
Something went wrong with that request. Please try again.