-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.sh
322 lines (275 loc) · 7.38 KB
/
generate.sh
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/bin/sh
# Copyright (c) 2010-2025
# Frank Terbeck <[email protected]>, All rights reserved.
# Terms for redistribution and use can be found in `LICENCE'.
# This identifies version 0.1; used to check if we're building from a working
# dewi git repository.
v01id='2475066cebe843978e38cdff9dd3b3a253c24c5b'
die() {
printf '%s\n' "$1"
exit 1
}
find_binary() {
prog="$1"
[ -z "$prog" ] && return 1
case "$prog" in
/*)
if [ -x "$prog" ]; then
printf '%s' "$prog"
return 0
fi
;;
esac
ret=1
oifs="$IFS"
IFS=:
for dir in $PATH; do
[ -z "$dir" ] && continue
if [ -x "$dir/$prog" ]; then
printf '%s' "$dir/$prog"
ret=0
break
fi
done
IFS="$oifs"
unset oifs
return "$ret"
}
resolv_path() {
[ -d "$1" ] || return 1
(
cd "$1" || exit 1
printf '%s' "$(pwd)"
exit 0
)
return $?
}
cli_version='2014-04-06#001'
posix_sh_unres=sh
perl_unres=perl
data_unres=.
mode=
__set_mode() {
if [ x"${mode}" != x ]; then
printf 'mode already set to `%s'\''\n' "${mode}"
exit 1
fi
mode="$1"
}
while [ $# -gt 0 ]; do
case "$1" in
sh=*)
posix_sh_unres=${1#sh=}
;;
perl=*)
perl_unres=${1#perl=}
;;
data=*)
data_unres=${1#data=}
;;
here)
__set_mode here
;;
sys)
__set_mode sys
;;
*)
printf 'unknown parameter: `%s'\''\n' "$1"
exit 1
;;
esac
shift
done
die_not_found() {
rv=$1
name=$2
unres_value=$3
[ "$rv" = 0 ] && return 0
die '`'"$name"\'' not found: '"$unres_value"
# does not return
}
got_perl_module() {
perl -e 'eval {require '"$1"';}; if ($@) { exit 1; } else { exit 0;}'
}
is_git_repository () {
if ! git rev-parse --is-inside-worktree > /dev/null 2>&1; then
return 1
fi
thisv01=$(git log -1 --pretty=%H v0.1 2> /dev/null)
if test "$v01id" = "$thisv01"; then
return 0
fi
printf '\n This is a git repository, but the v0.1 tag checksums do not match!\n'
printf ' Expected: [%s]\n' "$v01id"
printf ' Retrieved: [%s]\n' "$thisv01"
printf ' Falling back to static version information!\n\n'
return 1
}
get_git_version () {
base_="$(git describe --abbrev=12)"
[ -z "$base_" ] && base_="noversion-$(git show -s --pretty='%h')"
dirty_=""
git update-index -q --refresh
[ -z "$(git diff-index --name-only HEAD --)" ] || dirty_="-dirty"
REPLY="${base_#v}${dirty_}"
}
get_major_version () {
REPLY="${1%%.*}"
REPLY="${REPLY#v}"
}
get_minor_version () {
REPLY="${1#*.}"
REPLY="${REPLY%%-*}"
}
get_patch_level () {
REPLY="${1#*-}"
REPLY="${REPLY%%-*}"
}
get_git_dirty () {
case "$1" in
*-dirty) REPLY="dirty" ;;
*) REPLY="clean" ;;
esac
}
get_check_sum () {
REPLY="$(git log -1 --pretty=%H)"
}
get_git_description () {
REPLY=$(git show -s --pretty="%s")
}
get_git_date () {
REPLY=$(git show -s --pretty="%ai")
REPLY="${REPLY%% *}"
}
posix_sh=$(find_binary "$posix_sh_unres")
die_not_found "$?" posix_sh "$posix_sh_unres"
perl=$(find_binary "$perl_unres")
die_not_found "$?" perl "$perl_unres"
case "$data_unres" in
/*)
datadir="$data_unres"
;;
*)
datadir=$(resolv_path "$data_unres")
die_not_found "$?" datadir "$data_unres"
;;
esac
if got_perl_module "IPC::Run3"; then
ipcrun3='gotit'
else
printf '
This system does not appear to have the IPC::Run3 Perl module installed.
`dewi'\'' uses that module to implement external filter functionality.\n\n'
ipcrun3='sorry, buddy.'
fi
if got_perl_module "Template"; then
perltemplate='gotit'
else
printf '
This system does not appear to have the Template Perl module installed.
`dewi'\'' uses that module to implement `template'\'' method.\n\n'
perltemplate='sorry, buddy.'
fi
if is_git_repository; then
version_source="Git Repository"
get_git_version
full_version="v$REPLY"
get_major_version "$full_version"
major_version="$REPLY"
get_minor_version "$full_version"
minor_version="$REPLY"
get_git_dirty "$full_version"
work_dir_state="$REPLY"
get_patch_level "$full_version"
patch_level="${REPLY:-0}"
get_check_sum
check_sum="$REPLY"
get_git_description
git_description="$REPLY"
get_git_date
git_date="$REPLY"
if ! test "$patch_level" = 0; then
version_suffix='+git'
fi
source_source='git'
else
version_source="VERSION File"
. ./VERSION
check_sum=undef
git_description=undef
patch_level=undef
git_date="$release_date"
full_version="${major_version}.${minor_version}${version_suffix}"
work_dir_state='undef'
source_source='tarball'
fi
printf '%s\n' "Version:"
printf ' source: %s\n' "$version_source"
printf ' major: %s\n' "$major_version"
printf ' minor: %s\n' "$minor_version"
printf ' patch-level: %s\n' "$patch_level"
printf ' version-suffix: %s\n' "$version_suffix"
printf ' work-dir-state: %s\n' "$work_dir_state"
printf ' check-sum: %s\n' "$check_sum"
printf ' description: %s\n' "$git_description"
printf ' date: %s\n' "$git_date"
printf ' full-version: %s\n' "$full_version"
printf '\n%s\n' "Configuration:"
printf ' perl: %s\n' "$perl"
printf ' posix_sh: %s\n' "$posix_sh"
printf ' datadir: %s\n' "$datadir"
if [ "$ipcrun3" = 'gotit' ]; then
printf ' IPC::Run3: found\n'
else
printf ' IPC::Run3: not found\n'
fi
if [ "$perltemplate" = 'gotit' ]; then
printf ' Template: found\n'
else
printf ' Template: not found\n'
fi
printf '\n'
__generate() {
"$perl" -e '
%replaces=( q{@@DATADIR@@} => q{'"$datadir"'},
q{@@PERL5@@} => q{'"$perl"'},
q{@@PERL5_QUOTED@@} => q{'"$perl"'},
q{@@POSIX_SH@@} => q{'"$posix_sh"'},
q{@@MAJOR_VERSION@@} => q{'"$major_version"'},
q{@@MINOR_VERSION@@} => q{'"$minor_version"'},
q{@@VERSION_SUFFIX@@} => q{'"$version_suffix"'},
q{@@VERSION_DESCRIPTION@@} => q{'"$git_description"'},
q{@@VERSION_DATE@@} => q{'"$git_date"'},
q{@@VERSION_CHECKSUM@@} => q{'"$check_sum"'},
q{@@WORK_DIR_STATE@@} => q{'"$work_dir_state"'},
q{@@PATCH_LEVEL@@} => q{'"$patch_level"'},
q{@@SOURCE_CODE_SOURCE@@} => q{'"$source_source"'},
q{@@FULL_VERSION@@} => q{'"$full_version"'},
q{@@DOC_VERSION@@} => q{'"${full_version#v}"'} );
while(<>) {
foreach $key (keys %replaces) {
$data = $replaces{$key};
$data = "q{" . $data . "}" unless ($data eq "undef"
|| $key eq q{@@PERL5@@}
|| $key eq q{@@DOC_VERSION@@});
s{$key}{$data};
}
} continue {
print or die "-p destination: $!\n";
}
'
}
printf '%s\n' "Generating files:"
for file in "dewi.in" "Dewifile.in"; do
gen_file=${file%.in}
printf ' %s\n' "$gen_file"
__generate < "$file" > "$gen_file"
done
chmod +x "./dewi"
for file in dewi_1.mdwn dewi_7.mdwn dewifile_5.mdwn; do
in_file="doc/in_$file"
file="doc/$file"
printf ' %s\n' "$file"
__generate < "$in_file" > "$file"
done
exit 0