Newer
Older
Handbook / makefile-templates / Makefile.content
  1. ################################################################################
  2. #
  3. # Template makefile for building a particular content file for a document.
  4. # Place a copy of this file in the directory containing the content file,
  5. # and modify as appropriate. The makefile should be called with the name
  6. # of a specific content file as target. It will then check whether there
  7. # are any prerequisites to that file that may have changed, and rebuild
  8. # them if necessary. Most of the work is done by the include files, and
  9. # should cater for almost all cases. However, if custom rules are needed
  10. # for a section, they can be appended to the end of the document's
  11. # makefile.
  12. #
  13. # Note that the ONLY mode of operation for this makefile is to be called
  14. # from the makefile for a particular document, with the name of a specific
  15. # content file as the target. This makefile cannot be easily executed
  16. # standalone! This is because the content directory can exist at a
  17. # relatively arbitrary location within the paper's directory hierarchy. We
  18. # therefore don't know where to look, relative to the current directory,
  19. # to find the local include directory, and thus cannot provide a
  20. # meaningful value for the variable LOCAL_HANDBOOK_INCLUDE. The value of
  21. # LOCAL_HANDBOOK_INCLUDE must therefore be passed in from the calling
  22. # environment.
  23. #
  24. ################################################################################
  25.  
  26.  
  27. SHELL=/bin/sh
  28.  
  29.  
  30. ################################################################################
  31. #
  32. # Get path to current Makefile so we can set up self-deleting temporary
  33. # directory. Note that this MUST happen before the first include!
  34. #
  35. MAKEFILE:=$(CURDIR)/$(lastword $(MAKEFILE_LIST))
  36.  
  37.  
  38. ################################################################################
  39. #
  40. # Required Environment Variables
  41. #
  42. # TEACHING_SHARED
  43. # This variable specifies the path to the top level of the teaching
  44. # shared directory hierarchy (e.g., /path/to/Teaching/Shared).
  45. #
  46. 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))
  47.  
  48.  
  49. ################################################################################
  50. #
  51. # Set up paths to makefile include directories.
  52. #
  53. # GLOBAL_HANDBOOK_INCLUDE is the global include directory in the "Shared"
  54. # hierarchy, and is defined relative to the root of that hierarchy.
  55. #
  56. # LOCAL_HANDBOOK_INCLUDE is the local include directory for this
  57. # particular paper, and is defined relative to the current execution
  58. # directory. Since we don't know our current location in the paper's
  59. # directory hierarchy, this has to be defined by the makefile's calling
  60. # environment. It's an error not to define this variable.
  61. #
  62. GLOBAL_HANDBOOK_INCLUDE?=$(TEACHING_SHARED)/Authoring/Handbook/make-includes
  63.  
  64. LOCAL_HANDBOOK_INCLUDE?=$(error The environment variable LOCAL_HANDBOOK_INCLUDE has not been defined)
  65.  
  66.  
  67. ################################################################################
  68. #
  69. # Include local system-specific configuration.
  70. #
  71. include $(GLOBAL_HANDBOOK_INCLUDE)/local_configuration.make
  72.  
  73.  
  74. ################################################################################
  75. #
  76. # Set up global, self-deleting temporary directory. The first time through,
  77. # TEMPDIR will be undefined, so the first part of the if will create the
  78. # variable, then recursively call the makefile again with the appropriate
  79. # targets, passing the temporary directory as an argument.
  80. #
  81. ifndef TEMPDIR
  82.  
  83. .PHONY: all
  84.  
  85. all:
  86. @TEMPDIR=$(shell $(MKTEMP) -d); \
  87. trap 'rm -rf "$$TEMPDIR"' EXIT; \
  88. $(MAKE) -f $(MAKEFILE) --no-print-directory TEMPDIR=$$TEMPDIR all
  89.  
  90. %:
  91. @TEMPDIR=$(shell $(MKTEMP) -d); \
  92. trap 'rm -rf "$$TEMPDIR"' EXIT; \
  93. $(MAKE) -f $(MAKEFILE) --no-print-directory TEMPDIR=$$TEMPDIR $@
  94.  
  95.  
  96. ################################################################################
  97. #
  98. # Normal makefile follows.
  99. #
  100. else
  101.  
  102.  
  103. ################################################################################
  104. #
  105. # Include standard variables and rules for building content files. (Mainly
  106. # oriented towards graphics generation.)
  107. #
  108. include $(GLOBAL_HANDBOOK_INCLUDE)/build_content_rules.make
  109.  
  110.  
  111. ################################################################################
  112. #
  113. # Add custom rules below here, as necessary, BEFORE the endif. Rules should
  114. # ensure that they at least touch their targets.
  115. #
  116.  
  117.  
  118. endif