aboutsummaryrefslogblamecommitdiff
path: root/v2/src/bin/makemake
blob: f4ab87a4ad336354e3c0107e36785dcc551c57f1 (plain) (tree)








































































































































                                                                            
#!/bin/sh
set -eu


usage() {
	cat <<-'EOF'
		Usage:
		  makemake
		  makemake -h
	EOF
}

help() {
	cat <<-'EOF'

		Options:
		  -h, --help    show this message


		Generate make(1) code for later evaluation by make(1).  What
		this scripts does is fill the gap where make(1) can't handle
		globs and dynamic dependencies, and uses some ad-hoc scripts
		to generate those.
	EOF
}

for flag in "$@"; do
	case "$flag" in
		--)
			break
			;;
		--help)
			usage
			help
			exit
			;;
		*)
			;;
	esac
done

while getopts 'h' flag; do
	case "$flag" in
		h)
			usage
			help
			exit
			;;
		*)
			usage >&2
			exit 2
			;;
	esac
done
shift $((OPTIND - 1))



varlist() {
	printf '%s = \\\n' "$1"
	sed \
		-e 's/^/	/' \
		-e 's/$/ \\/'
	printf '\n'
}

html_deps() {
	"$@" | sed 's/^\(.*\)\.md$/\1.conf \1.content: \1.md/'
	"$@" | sed 's/^\(.*\)\.md$/\1.html: \1.conf \1.content/'
	printf '\n'
}


content_mds() {
	find src/content/"$1"/ -type f -name '*.md'
}

RESOURCES='
pastebins
tils
'

EXTENSIONS='
.md
.conf
.content
.prehtml
.posthtml
.html
'

for r in $RESOURCES; do
	content_mds "$r" | varlist "$r".md
	for e in $EXTENSIONS; do
		if [ "$e" = '.md' ]; then
			continue
		fi
		printf '%s%s = $(%s.md:.md=%s)\n' "$r" "$e" "$r" "$e"
	done
	printf '%s =' "$r"
	for e in $EXTENSIONS; do
		if [ "$e" = '.md' ]; then
			continue
		fi
		printf ' $(%s%s)' "$r" "$e"
	done
	printf '\n'
	html_deps content_mds "$r"
	printf '\n'
done

all_resources() {
	echo $RESOURCES | tr ' ' '\n'
}

all_vars() {
	EXT="$1"
	all_resources |
		sed 's|^|$(|' |
		sed "s|$|$EXT)|" |
		varlist all-generated"$EXT"
}

for e in $EXTENSIONS; do
	all_vars "$e"
done
all_vars ''


git ls-files |
	grep -v '^src/content/' |
	varlist 'non-content'

git ls-files src/content/ |
	grep -v '\.md$' |
	grep -Ev "src/content/($(all_resources | paste -sd'|'))/" |
	varlist 'static-content'