mako/Makefile

167 lines
4.8 KiB
Makefile

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
#> Makefile
#>
#> Build a Gemini site
#>
#> This Makefile manages the building and publishing of the Gemini site:
#> 1. Delegating content directories to other makefiles
#> 2. Building the site index page
#> 3. Copying the site to the hosting location
#>
#> Run `make -f environment.mk show' to display the key global varibles.
#>
#
# © 2023 Andrew Stryker <axs@sdf.org>
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
#-----------------------------------------------------------------------------#
#
# Configuation
#
#-----------------------------------------------------------------------------#
# Record the name of this Makefile
self ::= $(lastword ${MAKEFILE_LIST})
# Define the Makefiles
env_make ::= environment.mk
curate_make ::= curate.mk
index_make ::= index.mk
# load environment variables
include ${env_make}
# build lists of content directories
# TODO: do we need the quoted variables?
curate ?= about stuff
curate_dirs ::= $(addprefix ${CONTENT}/, ${curate})
#curate_quoted ::= $(shell echo ${curate} | sed -e "s/ /, /g")
index ?= posts staff
index_dirs ::= $(addprefix ${CONTENT}/, ${index})
#index_quoted ::= $(shell echo ${index} | sed -e "s/ /, /g")
# files that this file builds directly
banner_template ::= ${CONTENT}/banner.gmi.m4
banner ::= ${WORKING}/banner.gmi
site_index_template ::= ${CONTENT}/index.gmi.m4
site_index ::= ${STAGING}/index.gmi
BUILD_DATE_MSG ::= This page was built on $$(date).
export BUILD_DATE_MSG
#-----------------------------------------------------------------------------#
#
# User interface
#
#> User facing targets:
#>
#-----------------------------------------------------------------------------#
.PHONY: default all configure build publish help clean about posts show test
default: all # make the default target explicit
all: build # follow convention of using `all` as the default target
configure: #> Configure the site
@bash configure
build: ${site_index} #> Build the site (default)
@echo Built local site in this directory: ${STAGING}
publish: #> Publish Gemini files to site
@# rsync options:
@# verbose: show each operation
@# links: preserve symlinks
@# times: preserve modification times
@# delete: delete extraneous files, i.e., files on destination
@# chmod: set permsions
@echo Publishing in ${STAGING} to ${GEMINI_SITE}
@rsync \
--verbose \
--recursive \
--links \
--times \
--delete \
--chmod=D755,F644 \
${STAGING} \
${GEMINI_SITE}
@echo "\t✓ Publising complete"
@echo "\nThe site should be available on ${GEMINI_URL}"
show: #> Display key variables
@echo "Key variables defined in ${self}:"
@echo
@echo "Gemini site .................................. ${GEMINI_SITE}"
@echo "Genini site URL .............................. ${GEMINI_URL}"
@echo
@echo "\tSite index template ........................ ${site_index_template}"
@echo "\tBanner template ............................ ${banner_template}"
@echo
@echo "\tCurated content directories:"
@echo "\t\t${curate}"
@echo
@echo "\tDynamically indexed content directories:"
@echo "\t\t${index}"
@echo
@echo "Build message: ${BUILD_DATE_MSG}"
@${MAKE} -f ${env_make}
@echo
@#${MAKE} -f ${curate.mk} show
@echo
@#${MAKE} -f ${index_make} show
@#echo
@#cd tests && ${MAKE} show
clean: #> Delete generated files
@rm -rf ${WORKING} ${STAGING}
@echo "✓ Deleted all intermediate and generated files"
@cd tests && ${MAKE} clean
test: #> Run the test suite
@cd tests && ${MAKE} test
help: #> Display this help message
@awk -f ${AWKHELP} ${self}
#-----------------------------------------------------------------------------#
#
# File system interface
#
#-----------------------------------------------------------------------------#
# Isolating the directory making logic here so that we are not repeatedly
# building directories and changing timestamps--let's have Make deal with this
${WORKING} ${STAGING}: %:
@mkdir -p $@
@echo "\t✓Created $@"
${banner}: ${banner_template} ${WORKING}
@m4 --include=${MAKO_DIR} $< > $@
@echo "\t✓ Generated site banner"
${site_index}: ${site_index_template} ${banner} ${curate_dirs} ${index_dirs}
@m4 --include=${MAKO_DIR} --define=WORKING=${WORKING} $< > $@
@echo ${BUILD_DATE_MSG} >> $@
@echo "\t✓ Generated site index file"
${curate_dirs}: %: ${WORKING} ${STAGING}
@echo
@echo "Entering section: $@"
@echo
@mkdir -p ${WORKING}/$@ ${STAGING}/$@
@cd $@ && ${MAKE} -f ${CURATE_MAKE} build
@echo "✓ Completed $@ section"
${index_dirs}: %: ${WORKING} ${STAGING}
@echo
@echo "Entering section: $@"
@echo
@mkdir -p ${WORKING}/$@ ${STAGING}/$@
@#cd ${CONTENT}/$@ && ${MAKE} -f ${index_make} build
@echo "✓ Completed $@ section"
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#