mako/curate.mk

114 lines
3.0 KiB
Makefile
Raw Normal View History

2023-09-14 13:39:45 -04:00
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
#> 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)
2023-09-20 11:45:11 -04:00
templates_expanded ::= $(addprefix ${STG_SECTION}/, ${templates:.gmi.m4=.gmi})
2023-09-14 13:39:45 -04:00
gemtext ::= $(wildcard *.gmi)
2023-09-20 11:45:11 -04:00
gemtext_copied ::= $(addprefix ${STG_SECTION}/, ${gemtext})
2023-09-14 13:39:45 -04:00
2023-09-19 15:24:44 -04:00
# Create list of potential dependencies of *.gmi.m4 templates
all ::= $(notdir $(filter-out %.gmi.m4 _% %~, $(wildcard *)))
2023-09-14 13:39:45 -04:00
#-----------------------------------------------------------------------------#
#
# 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}
2023-09-20 11:45:11 -04:00
@echo "✓ Completed processing ${SECTION}"
2023-09-14 13:39:45 -04:00
@echo
show: #> Show enironment variables with values
@echo "Key variables defined in ${self}:"
@echo
@echo "Makefile list: ${MAKEFILE_LIST}"
@echo
2023-09-20 11:45:11 -04:00
@echo "Content section .............................. ${SECTION}"
@echo "Staging space ................................ ${STG_SECTION}"
2023-09-14 13:39:45 -04:00
@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
2023-09-20 11:45:11 -04:00
@rm -rf ${STG_SECTION}
@echo "✓ Deleted ${STG_SECTION} and everything in it"
2023-09-14 13:39:45 -04:00
help: #> Display this help message
@awk -f ${AWKHELP} ${self}
#-----------------------------------------------------------------------------#
#
# File system interface
#
#-----------------------------------------------------------------------------#
2023-09-20 11:45:11 -04:00
${STG_SECTION}:
2023-09-14 13:39:45 -04:00
@mkdir -p $@
@echo "\t✓ Created staging space: $@"
2023-09-20 11:45:11 -04:00
${templates_expanded}: ${STG_SECTION}/%: %.m4 ${STG_SECTION} ${FENCE} ${all}
2023-09-14 13:39:45 -04:00
@m4 --include=${MAKO_DIR} $< > $@
@echo "\t✓ Generated $@"
2023-09-20 11:45:11 -04:00
${gemtext_copied}: ${STG_SECTION}/%: % ${STG_SECTION}
2023-09-14 13:39:45 -04:00
@cat $< > $@
@echo "\t✓ Copied $@"
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#