mako/environment.mk

138 lines
3.6 KiB
Makefile

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
#> 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
caller ::= ${self}
endif
self ::= $(lastword ${MAKEFILE_LIST})
#-----------------------------------------------------------------------------#
#
# 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
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
# 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
# Place for section-specfic working and staging files as recurive variables
SECTION = $(shell basename ${CURDIR})
export SECTION
# Create shortcuts
STG_SECTION = ${STAGING}/${SECTION}
WRK_SECTION = ${WORKING}/${SECTION}
SECTION_DIRS = ${STG_SECTION} ${WRK_SECTION}
export STG_SECTION
export WRK_SECTION
export SECTION_DIRS
# 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}"
@echo "\tUsef-defined configuration.................. ${SITE_ENV}"
@echo
# future location for templates
@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
#>
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#