Newer
Older
Handbook / makefile-templates / Makefile.content
################################################################################
#
# Template makefile for building a particular content file for a document.
# Place a copy of this file in the directory containing the content file,
# and modify as appropriate. The makefile should be called with the name
# of a specific content file as target. It will then check whether there
# are any prerequisites to that file that may have changed, and rebuild
# them if necessary. Most of the work is done by the include files, and
# should cater for almost all cases. However, if custom rules are needed
# for a section, they can be appended to the end of the document's
# makefile.
#
# Note that the ONLY mode of operation for this makefile is to be called
# from the makefile for a particular document, with the name of a specific
# content file as the target. This makefile cannot be easily executed
# standalone! This is because the content directory can exist at a
# relatively arbitrary location within the paper's directory hierarchy. We
# therefore don't know where to look, relative to the current directory,
# to find the local include directory, and thus cannot provide a
# meaningful value for the variable LOCAL_HANDBOOK_INCLUDE. The value of
# LOCAL_HANDBOOK_INCLUDE must therefore be passed in from the calling
# environment.
#
################################################################################


SHELL=/bin/sh


################################################################################
#
# Get path to current Makefile so we can set up self-deleting temporary
# directory. Note that this MUST happen before the first include!
#
MAKEFILE:=$(CURDIR)/$(lastword $(MAKEFILE_LIST))


################################################################################
#
# Required Environment Variables
#
# TEACHING_SHARED
#	This variable specifies the path to the top level of the teaching
#	shared directory hierarchy (e.g., /path/to/Teaching/Shared).
#
TEACHING_SHARED?=$(error The required environment variable TEACHING_SHARED has not been defined. It should point to the root level of the shared teaching directory (e.g., /path/to/Teaching/Shared))


################################################################################
#
# Set up paths to makefile include directories.
#
# GLOBAL_HANDBOOK_INCLUDE is the global include directory in the "Shared"
# hierarchy, and is defined relative to the root of that hierarchy.
#
# LOCAL_HANDBOOK_INCLUDE is the local include directory for this
# particular paper, and is defined relative to the current execution
# directory. Since we don't know our current location in the paper's
# directory hierarchy, this has to be defined by the makefile's calling
# environment. It's an error not to define this variable.
#
GLOBAL_HANDBOOK_INCLUDE?=$(TEACHING_SHARED)/Authoring/Handbook/make-includes

LOCAL_HANDBOOK_INCLUDE?=$(error The environment variable LOCAL_HANDBOOK_INCLUDE has not been defined)


################################################################################
#
# Include local system-specific configuration.
#
include $(GLOBAL_HANDBOOK_INCLUDE)/local_configuration.make


################################################################################
#
# Set up global, self-deleting temporary directory. The first time through,
# TEMPDIR will be undefined, so the first part of the if will create the
# variable, then recursively call the makefile again with the appropriate
# targets, passing the temporary directory as an argument.
#
ifndef TEMPDIR

.PHONY: all

all:
	@TEMPDIR=$(shell $(MKTEMP) -d); \
	trap 'rm -rf "$$TEMPDIR"' EXIT; \
	$(MAKE) -f $(MAKEFILE) --no-print-directory TEMPDIR=$$TEMPDIR all

%:
	@TEMPDIR=$(shell $(MKTEMP) -d); \
	trap 'rm -rf "$$TEMPDIR"' EXIT; \
	$(MAKE) -f $(MAKEFILE) --no-print-directory TEMPDIR=$$TEMPDIR $@


################################################################################
#
# Normal makefile follows.
#
else


################################################################################
#
# Include standard variables and rules for building content files. (Mainly
# oriented towards graphics generation.)
#
include $(GLOBAL_HANDBOOK_INCLUDE)/build_content_rules.make


################################################################################
#
# Add custom rules below here, as necessary, BEFORE the endif. Rules should
# ensure that they at least touch their targets.
#


endif