mako/curate.mk

113 lines
3.1 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
# Compute definitions for the section, working, and staging directories
$(eval ${MAKE_SECTION_VARS})
# Gather file lists
templates ::= $(wildcard *.gmi.m4)
templates_expanded ::= $(addprefix ${staging_section}/, ${templates:.gmi.m4=.gmi})
gemtext ::= $(wildcard *.gmi)
gemtext_copied ::= $(addprefix ${staging_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 ................................ ${staging_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 ${staging_section}
@echo "✓ Deleted ${staging_section} and everything in it"
help: #> Display this help message
@awk -f ${AWKHELP} ${self}
#-----------------------------------------------------------------------------#
#
# File system interface
#
#-----------------------------------------------------------------------------#
${templates_expanded}: ${staging_section}/%: %.m4 ${all}
@mkdir -p ${staging_section}
@m4 --include=${MAKO_DIR} $< > $@
@echo "\t✓ Generated $@"
${gemtext_copied}: ${staging_section}/%: %
@mkdir -p ${staging_section}
@cat $< > $@
@echo "\t✓ Copied $@"
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#