150 lines
4.0 KiB
Makefile
150 lines
4.0 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
|
|
|
|
# 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
|
|
|
|
# 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
|
|
@# TODO: 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
|
|
|
|
#>
|
|
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
|