aboutsummaryrefslogtreecommitdiff
path: root/v2/src/bin/makemake
blob: 665bb846bf26c024981695de6fd2876f8e4b8f85 (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/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'
}


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

COLL_EXTENSIONS='
.sortref
.xmlentry
'

page_ext_filter="^($(echo "$COLL_EXTENSIONS" |
	tr ' ' '\n' |
	grep . |
	paste -sd'|'
))\$"


extensions() {
	echo "$EXTENSIONS" "$COLL_EXTENSIONS" "$@" |
		tr ' ' '\n' |
		grep .
}


printf '.POSIX:\n\n\n'
for lang in $(langs); do
	for c in pages $(collections); do
		if [ "$c" = 'pages' ]; then
			filter="$page_ext_filter"
			dir="$CONTENT_PREFIX/$lang"
		else
			filter='^$'
			dir="$CONTENT_PREFIX/$lang/$c"
		fi

		mds() {
			find "$dir"/*.md 2>/dev/null
		}

		exts() {
			extensions | grep -Ev "$filter"
		}

		mds | varlist "$c.$lang.md"
		exts | sed "s|^\(.*\)\$|$c.$lang\1 = \$($c.$lang.md:.md=\1)|"
		exts | sed "s|^\(.*\)\$|\$($c.$lang\1)|" | varlist "$c.$lang"

		mds | sed 's/^\(.*\)\.md$/\1.conf \1.content: \1.md/'
		mds | sed 's/^\(.*\)\.md$/\1.snippets \1.htmlbody \1.html: \1.conf \1.content/'
		if [ "$c" = 'pages' ]; then
			continue
		fi

		mds | sed 's/^\(.*\)\.md$/\1.sortref: \1.md/'
		mds | sed 's/^\(.*\)\.md$/\1.xmlentry: \1.html/'

		echo "$CONTENT_PREFIX/$lang/feeds/$c.xml: \$($c.$lang.xmlentry)"

		printf '\n\n'
	done

	for e in $(extensions); do
		{
			if ! printf '%s\n' "$e" | grep -qE "$page_ext_filter"; then
				echo pages
			fi
			collections
		} |
		sed "s|^\(.*\)\$|\$(\1.$lang$e)|" |
		varlist "all-generated.$lang$e"
	done

	collections |
		sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/feeds/\1.xml|" |
		varlist "all-generated.$lang.xml"

	extensions '.xml' |
		sed "s|^\(.*\)\$|\$(all-generated.$lang\1)|" |
		varlist "all-generated.$lang"

	printf '\n'
done

for e in $(extensions .xml); do
	langs |
		sed "s|^\(.*\)\$|\$(all-generated.\1$e)|" |
		varlist "all-generated$e"
done

# shellcheck disable=2016
langs |
	sed 's|^\(.*\)$|$(all-generated.\1)|' |
	varlist 'all-generated'


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

git ls-files "$CONTENT_PREFIX"/ |
	grep -v '\.md$' |
	varlist 'static-content'