aboutsummaryrefslogtreecommitdiff
path: root/v2/src/bin/makemake
blob: e95a040b9d73df39d606842e6efbcd5dd886598e (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/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.snippets \1.html: \1.conf \1.content/'
	printf '\n'
}


content_mds() {
	{
		if [ "$r" = 'pages' ]; then
			echo src/content/*.md
		else
			echo src/content/"$r"/*.md
		fi
	} | tr ' ' '\n'
}

RESOURCES='
pages
pastebins
tils
'

EXTENSIONS='
.md
.conf
.content
.html
.snippets
'

for r in $RESOURCES; do
	content_mds "$r" | varlist "$r".md
	for e in $EXTENSIONS; do
		if [ "$e" = '.md' ]; then
			continue
		fi
		# shellcheck disable=2016
		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
		# shellcheck disable=2016
		printf ' $(%s%s)' "$r" "$e"
	done
	printf '\n'
	html_deps content_mds "$r"
	printf '\n'
done


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

all_vars() {
	EXT="$1"
	# shellcheck disable=2016
	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'