mako/curate.mk

114 lines
3.0 KiB
Makefile

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
#> content.makefile
#
#> Build
#>
#> This Makefile handles creating, building, and publishing posts for a Gemini
#> site.
#>
# The key challenge here is creating the index files.
# 1. Create a file with index entries
# 2. Extract a list of tags to file
# 3.
#
# © 2023 Andrew Stryker <axs@sdf.org>
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
#-----------------------------------------------------------------------------#
#
# Configuration
#
#-----------------------------------------------------------------------------#
# Record the name of this Makefile
self ::= $(lastword ${MAKEFILE_LIST})
# Load environment variables if needed--not the case when this is called from
# the main Makefile
ifndef ENV_LOADED
# Assume the base directory is two levels up if not defined
MAKO_DIR ?= ../..
include ${MAKO_DIR}/environment.mk
endif
# Gather file lists
templates ::= $(wildcard *.gmi.m4)
templates_expanded ::= $(addprefix ${STG_SECTION}/, ${templates:.gmi.m4=.gmi})
gemtext ::= $(wildcard *.gmi)
gemtext_copied ::= $(addprefix ${STG_SECTION}/, ${gemtext})
# Create list of potential dependencies of *.gmi.m4 templates
all ::= $(notdir $(filter-out %.gmi.m4 _% %~, $(wildcard *)))
#-----------------------------------------------------------------------------#
#
# User interface
#
#> This makefile supports the following targets:
#>
#-----------------------------------------------------------------------------#
.PHONY: default build clean show help create
# Define the default target explicitly
default: create
create: #> Create a new post (default)
@if [ -z $${EDITOR} ]; then \
python3 create-post.py; \
else \
python3 create-post.py --edit; \
fi
build: ${gemtext_copied} ${templates_expanded}
@echo "✓ Completed processing ${SECTION}"
@echo
show: #> Show enironment variables with values
@echo "Key variables defined in ${self}:"
@echo
@echo "Makefile list: ${MAKEFILE_LIST}"
@echo
@echo "Content section .............................. ${SECTION}"
@echo "Staging space ................................ ${STG_SECTION}"
@echo
@echo "Templates found:"
@for x in ${templates}; do echo "\t$$x"; done
@echo
@echo "Gemtext files found:"
@for x in ${gemtext}; do echo "\t\t$$x"; done
@echo
clean: #> Delete generated files
@rm -rf ${STG_SECTION}
@echo "✓ Deleted ${STG_SECTION} and everything in it"
help: #> Display this help message
@awk -f ${AWKHELP} ${self}
#-----------------------------------------------------------------------------#
#
# File system interface
#
#-----------------------------------------------------------------------------#
${STG_SECTION}:
@mkdir -p $@
@echo "\t✓ Created staging space: $@"
${templates_expanded}: ${STG_SECTION}/%: %.m4 ${STG_SECTION} ${FENCE} ${all}
@m4 --include=${MAKO_DIR} $< > $@
@echo "\t✓ Generated $@"
${gemtext_copied}: ${STG_SECTION}/%: % ${STG_SECTION}
@cat $< > $@
@echo "\t✓ Copied $@"
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#