Newer
Older
Handbook / make-includes / build_lecture_rules.make
################################################################################
#
# Standard variables and rules for building a set of lecture files.
# Altering these definitions will affect ALL LECTURE MAKEFILES FOR ALL
# PAPERS!! If you need to do something specific for a particular paper,
# include a custom rule in its makefile. DON'T add it here!
#
################################################################################


################################################################################
#
# Add standard file suffixes.
#
include $(GLOBAL_HANDBOOK_INCLUDE)/standard_suffixes.make


################################################################################
#
# Standard directories.
#
IMGDIR=images


################################################################################
#
# Standard paths.
#
include $(GLOBAL_HANDBOOK_INCLUDE)/standard_paths.make


################################################################################
#
# Files to be cleaned by the various "clean" targets. Note that we don't
# "tidy" .aux files because they may be needed by the xr package for inter-
# document cross references, but won't get regenerated if the final target
# PDF files exist. They will be caught by by the "clean" target though.
#
TIDY_FILES+=*.tmp *.out *.log *.nav *.toc *.snm *.head *.dvi \
	slides-combined.pdf slides-notes.pdf
CLEAN_FILES+=*.aux *.pdf


################################################################################
#
# Various environment variables.
#
# Important: default font size for Beamer is 11pt. We need to define this before
# loading the standard environment. However, allow the user to override it!
ifndef FONT_SIZE
FONT_SIZE=11pt
endif

include $(GLOBAL_HANDBOOK_INCLUDE)/standard_environment.make
#
# Base file names for the various documents.
#
SLIDES?=Chapter$(CHAPTER)slides
FIGURES?=Chapter$(CHAPTER)figures
COMBINED?=Chapter$(CHAPTER)combined
NOTES?=Chapter$(CHAPTER)notes
#
# Standard files to be installed on the web server.
#
ifneq ($(strip $(SLIDES)),)
INSTALL_FILES+=$(SLIDES).pdf
endif
ifneq ($(strip $(FIGURES)),)
INSTALL_FILES+=$(FIGURES).pdf $(FIGURES)-reduced.pdf
endif
ifneq ($(strip $(COMBINED)),)
INSTALL_FILES+=$(COMBINED).pdf
endif
INSTALL_FILES+=$(wildcard *.mp3)
#
# List of standard "phony" build targets.
#
TARGETS+=slides notes slides-combined slides-notes figures figures2up combined
#
.PHONY: $(TARGETS)


################################################################################
#
# Display a message if someone tries to build a target that has been
# disabled (by setting the appropriate variable to empty in the makefile).
#
disabled_message=@$(ECHO) The \"$(1)\" target has been disabled for this chapter.


################################################################################
#
# Alternate LaTeXs for Unicode vs. non-Unicode processing.
#
ifdef UNICODE
LATEXCMD:=$(XELATEX)
else
LATEXCMD:=$(PDFLATEX)
endif


################################################################################
#
# Build everything.
#
all: slides notes figures figures2up combined


################################################################################
#
# Build presentation slides. If $(SLIDES) is empty, these rules are ignored.
#
ifneq ($(strip $(SLIDES)),)

#
# Set the prerequisites for the "slides" build target, depending on
# whether the figures document exists. If $(FIGURES) is non-empty, we need
# to include the figures .aux file for inter-document cross-references.
#
ifeq ($(strip $(FIGURES)),)
SLIDES_PREREQS:=$(SLIDES).pdf
else
SLIDES_PREREQS:=figures $(SLIDES).pdf
endif

#
# Build the slides for the presentation.
#
slides: $(SLIDES_PREREQS)

$(SLIDES).pdf: $(SLIDES).tex $(SLIDE_IMAGES) $(SLIDE_BACKGROUNDS) $(SLIDE_FILES)
	$(LATEXCMD) --jobname=$(SLIDES) '\documentclass[$(LATEX_OPTS)]{lectureslides}\input{$(SLIDES)}'
	$(LATEXCMD) --jobname=$(SLIDES) '\documentclass[$(LATEX_OPTS)]{lectureslides}\input{$(SLIDES)}'

else

slides:
	$(call disabled_message,$@)

endif


################################################################################
#
# Build the presentation notes. If $(NOTES) is empty, these rules are
# ignored.
#
ifneq ($(strip $(NOTES)),)

#
# Build the slides with notes.
#
slides-notes: slides-notes.pdf

slides-notes.pdf: $(SLIDES).tex $(SLIDE_IMAGES) $(SLIDE_BACKGROUNDS) $(SLIDE_FILES)
	$(LATEXCMD) --jobname=slides-notes '\documentclass[$(LATEX_OPTS),notes=onlyslideswithnotes]{lectureslides}\input{$(SLIDES)}'
	$(LATEXCMD) --jobname=slides-notes '\documentclass[$(LATEX_OPTS),notes=onlyslideswithnotes]{lectureslides}\input{$(SLIDES)}'

#
# Build the slides with notes, 6-up.
#
notes: $(NOTES).pdf

$(NOTES).pdf: $(NOTES).tex slides-notes.pdf
	$(LATEXCMD) $<
	$(LATEXCMD) $<

else

notes slides-notes:
	$(call disabled_message,$@)

endif


################################################################################
#
# Build the complete combined lecture document. If $(COMBINED) is empty,
# these rules are ignored.
#
ifneq ($(strip $(COMBINED)),)

#
# Set the prerequisites for the "combined" build target, depending on
# whether the figures document exists. If $(FIGURES) is empty, they are
# omitted from the combined document.
#
ifeq ($(strip $(FIGURES)),)
COMBINED_PREREQS:=$(COMBINED).tex slides-combined.pdf
else
COMBINED_PREREQS:=$(COMBINED).tex slides-combined.pdf $(FIGURES).pdf
endif

#
# Build the slides for the combined document.
#
slides-combined: slides-combined.pdf

slides-combined.pdf: $(SLIDES).tex $(SLIDE_IMAGES) $(SLIDE_BACKGROUNDS)
	$(LATEXCMD) --jobname=slides-combined '\documentclass[$(LATEX_OPTS),handout]{lectureslides}\input{$(SLIDES)}'
	$(LATEXCMD) --jobname=slides-combined '\documentclass[$(LATEX_OPTS),handout]{lectureslides}\input{$(SLIDES)}'

#
# Build the complete combined document.
#
combined: $(COMBINED).pdf

$(COMBINED).pdf: $(COMBINED_PREREQS) $(COMBI_IMAGES) $(COMBI_FILES)
	$(LATEXCMD) $<
	$(LATEXCMD) $<

else

combined slides-combined:
	$(call disabled_message,$@)

endif


################################################################################
#
# Build the figures and examples document. If $(FIGURES) is empty, these
# rules are ignored.
#
ifneq ($(strip $(FIGURES)),)

figures: $(FIGURES).pdf

$(FIGURES).pdf: $(FIGURES).tex $(FIG_IMAGES) $(FIG_FILES)
	$(LATEXCMD) $<
	$(LATEXCMD) $<

figures2up: $(FIGURES)-reduced.pdf

$(FIGURES)-reduced.pdf: $(FIGURES).pdf
	$(PDFNUP) $< --nup 2x1 --outfile $@

else

figures figures2up:
	$(call disabled_message,$@)

endif


################################################################################
#
# Build the test document.
#
test: test.pdf

test.pdf: test.tex


################################################################################
#
# Deploy the appropriate files into a shared folder, which is then synchronised
# with Blackbaord. This relies on the environment variable HANDBOOK_INSTALL_ROOT
# being defined, and (assuming that this variable points to a directory on the
# network) the appropriate share has been mounted.
#
# See build_document_rules.make for an explanation of why the install
# uses a foreach.
#
# Note that this won't do anything clever if you give it files that are
# in subdirectories of the current directory. Everything will be flattened
# at the other end. That is, something like "images/foo.pdf" will go into
# the installation directory as "foo.pdf", not "images/foo.pdf".
#
# If the variable NOSYNC is set (to anything), then files won't be synchronised
# with Blackboard.
#
install:
ifndef NOSYNC
	@$(LOCKFILE) -r0 $(HOME)/.sitecopy/Blackboard$(PAPER_NUMBER).lock && $(SITECOPY) --update --keep-going Blackboard$(PAPER_NUMBER) && $(RM) -f $(HOME)/.sitecopy/Blackboard$(PAPER_NUMBER).lock
	@$(LOCKFILE) -r0 $(HOME)/.sitecopy/Blackboard$(PAPER_NUMBER).lock && $(SITECOPY) --catchup Blackboard$(PAPER_NUMBER) && $(RM) -f $(HOME)/.sitecopy/Blackboard$(PAPER_NUMBER).lock
endif
	@$(ANNOUNCE) "Deploying files into $(INSTALL_DIRECTORY)"
	@$(TEST) -d $(HANDBOOK_INSTALL_ROOT)
	@$(MKDIR_P) $(INSTALL_DIRECTORY)
	@$(foreach f,$(INSTALL_FILES),if $(TEST) ! -f $(INSTALL_DIRECTORY)/`$(BASENAME) $(f)` -o $(f) -nt $(INSTALL_DIRECTORY)/`$(BASENAME) $(f)`; then $(ECHO) "Deploying $(f)"; $(CP) $(f) $(INSTALL_DIRECTORY); fi;)
ifndef NOSYNC
	@$(ANNOUNCE) "Synchronising with Blackboard"
	@$(LOCKFILE) -r0 $(HOME)/.sitecopy/Blackboard$(PAPER_NUMBER).lock && $(SITECOPY) --update Blackboard$(PAPER_NUMBER) && $(RM) -f $(HOME)/.sitecopy/Blackboard$(PAPER_NUMBER).lock
endif


################################################################################
#
# Debugging: print the values of the standard variables.
#
debug:
	@$(ANNOUNCE) Externally defined variables
	@$(ECHO) "TEACHING_SHARED = [$(TEACHING_SHARED)]"
	@$(ECHO) "HANDBOOK_INSTALL_ROOT = [$(HANDBOOK_INSTALL_ROOT)]"
	@$(ECHO) "CHAPTER = [$(CHAPTER)]"
	@$(ANNOUNCE) Internally defined variables
	@$(ECHO) "SUBJECT_CODE = [$(SUBJECT_CODE)]"
	@$(ECHO) "PAPER_NUMBER = [$(PAPER_NUMBER)]"
	@$(ECHO) "GLOBAL_HANDBOOK_INCLUDE = [$(GLOBAL_HANDBOOK_INCLUDE)]"
	@$(ECHO) "INSTALL_DIRECTORY = [$(INSTALL_DIRECTORY)]"
	@$(ECHO) "BUILD_DIR = [$(BUILD_DIR)]"
	@$(ECHO) "INSTALL_FILES = [$(INSTALL_FILES)]"
	@$(ECHO) "SLIDE_IMAGES = [$(SLIDE_IMAGES)]"
	@$(ECHO) "SLIDE_BACKGROUNDS = [$(SLIDE_BACKGROUNDS)]"
	@$(ECHO) "SLIDE_FILES = [$(SLIDE_FILES)]"
	@$(ECHO) "FIG_IMAGES = [$(FIG_IMAGES)]"
	@$(ECHO) "FIG_FILES = [$(FIG_FILES)]"
	@$(ECHO) "TIDY_FILES = [$(TIDY_FILES)]"
	@$(ECHO) "CLEAN_FILES = [$(CLEAN_FILES)]"
	@$(ECHO) "LATEXCMD = [$(LATEXCMD)]"
	@$(ECHO) "DRAFT = [$(DRAFT)]"
	@$(ECHO) "LATEX_OPTS = [$(LATEX_OPTS)]"
	@$(ECHO) "SLIDES = [$(SLIDES)]"
	@$(ECHO) "FIGURES = [$(FIGURES)]"
	@$(ECHO) "COMBINED = [$(COMBINED)]"
	@$(ECHO) "NOTES = [$(NOTES)]"
	@$(ECHO) "SLIDES_PREREQS = [$(SLIDES_PREREQS)]"
	@$(ECHO) "COMBINED_PREREQS = [$(COMBINED_PREREQS)]"
	@$(ECHO) "TARGETS = [$(TARGETS)]"


################################################################################
#
# Clean up: get rid of all the temporary files.
#
tidy:
	$(RM) -f $(TIDY_FILES)
#
# Clean up: get rid of everything except the original source.
#
clean: tidy
	$(RM) -f $(CLEAN_FILES)


################################################################################
#
# List all "phony" build targets.
#
targets:
	@$(ECHO) "targets: $(TARGETS)"


################################################################################
#
# Standard default rules.
#
include $(GLOBAL_HANDBOOK_INCLUDE)/standard_rules.make