mako/environment.mk

150 lines
4.0 KiB
Makefile
Raw Normal View History

2023-09-14 13:39:45 -04:00
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
#> environment.mk
#>
#> Define global environment variables
#>
#> This file is typically included from the main Makefile rather called
#> directly. Its purpose is to keep the responsbility of the main Mainfile
#> compact. The responsbility of this Makefile is to define global
#> environment variables, some of which it read from a user created file.
#>
#
# © 2023 Andrew Stryker <axs@sdf.org>
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# Track file name of caller
ifdef self
2023-09-14 17:07:58 -04:00
caller ::= ${self}
2023-09-14 13:39:45 -04:00
endif
2023-09-20 11:45:58 -04:00
self ::= $(lastword ${MAKEFILE_LIST})
2023-09-14 13:39:45 -04:00
#-----------------------------------------------------------------------------#
#
# Configuration
#
#-----------------------------------------------------------------------------#
ifndef ENV_LOADED
# Track loading the environment
ENV_LOADED ::= 1
export ENV_LOADED
# Avoid an unexpected shell environment
SHELL = /bin/sh
export SHELL
# User-defined configuration file
SITE_ENV ?= content/site-env
2023-09-16 09:30:51 -04:00
SITE_ENV ::= $(strip ${SITE_ENV})
ifeq ($(strip $(shell [ -r ${SITE_ENV} ] && echo ${SITE_ENV})),)
$(info Generate a site configuration file first via `make configure`)
$(error Configuration file ${site_env} not readable.)
else
include ${SITE_ENV}
endif
2023-09-14 13:39:45 -04:00
# Base/root directory of the build system. Allows us to use absolute paths.
MAKO_DIR ?= ${CURDIR}
export MAKO_DIR
# Place for user content
CONTENT ?= ${MAKO_DIR}/content
CONTENT ::= $(strip ${CONTENT})
export CONTENT
# Place for intermediate files
WORKING ?= ${MAKO_DIR}/workspace
WORKING ::= $(strip ${WORKING})
export WORKING
# Place for site files ready to be transferred to the site
STAGING ?= ${MAKO_DIR}/staging
STAGING ::= $(strip ${STAGING})
export STAGING
# Define a macro that creates the section-specific directory variables
#
# NOTE: Make expand variables when they are exported, meaning that will not
# assume the values appropriate for the current section. This approach defines
# a macro that we can call when we recurse into each section
#
# TODO: Is it possible to simplify this?
define MAKE_SECTION_WORKING
working_section ::= ${WORKING}/$$(value $${1})
endef
export MAKE_SECTION_WORKING
define MAKE_SECTION_STAGING
staging_section ::= ${STAGING}/$${1}
endef
export MAKE_SECTION_STAGING
define MAKE_SECTION_VARS
section ::= $$(shell basename $${CURDIR})
$$(eval $$(call MAKE_SECTION_WORKING,$${section}))
$$(eval $$(call MAKE_SECTION_STAGING,$${section}))
endef
export MAKE_SECTION_VARS
2023-09-20 11:45:11 -04:00
2023-09-14 13:39:45 -04:00
# Makefiles
CURATE_MAKE ::= ${MAKO_DIR}/curate.mk
INDEX_MAKE ::= ${MAKO_DIR}/index.mk
# M4 fencing for raw text
FENCE ::= ${MAKO_DIR}/fence.m4
export FENCE
# Help generation
AWKHELP ::= ${MAKO_DIR}/generate-help.awk
export AWKHELP
endif
#-----------------------------------------------------------------------------#
#
# User interface targets
#
#> User facing targets:
#>
#-----------------------------------------------------------------------------#
# Only define targets if called directly
ifeq ($(firstword ${MAKEFILE_LIST}), ${self})
.PHONY: default show help
default: show
show: #> Show key variables
@echo "Key variables defined in ${self}:"
@echo
@echo "\tBase/root directory of the build system..... ${MAKO_DIR}"
2023-09-16 09:34:59 -04:00
@echo "\tUsef-defined configuration.................. ${SITE_ENV}"
2023-09-14 13:39:45 -04:00
@echo
@# TODO: future location for templates
2023-09-14 13:39:45 -04:00
@echo "\tLocation of user content.................... ${CONTENT}"
@echo "\tWorking area for intermediate files......... ${WORKING}"
@echo "\tStaging area for site....................... ${STAGING}"
@echo
@echo "\tM4 macro for raw text....................... ${FENCE}"
@echo "\tHelp generation AWK file.................... ${AWKHELP}"
help: #> Show this help message
@awk -f ${AWKHELP} ${self}
endif
#-----------------------------------------------------------------------------#
# Restore value of self to the caller's file name if possible
ifdef caller
self ::= ${caller}
endif
#>
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#