-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.sh
executable file
·76 lines (61 loc) · 1.47 KB
/
compile.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
#!/bin/bash
# Repository information.
URL="https://github.com/shacknetisp/crawl-rc"
# Root directory.
ROOT="$(dirname "$0")"
# Output this line to "reset lua". This is a workaround for < > blocks not firing.
reset_lua() {
echo ": --"
}
# Information.
echo "#-#-# Automatically Compiled Units"
echo "#-#-# Generated from $URL"
# Begin units.
echo
echo "#-#-# Units Begin"
# Process and output a file.
process_file() {
file="$1"
# With dot.
dext=${file##*.}
# Without dot.
ext=${dext#.}
# Set exported variables.
export CRC_FILE="$file"
export CRC_DIR="$(basename "$(dirname "$file")")"
export CRC_NAME="$(basename "$file" .$ext)"
# Unit header.
echo
echo "#-#-# Unit: $CRC_NAME ($CRC_DIR/$CRC_NAME.$ext)"
# Test handler for ext.
test -e "$ROOT/handlers/$ext" && {
reset_lua
# Run handler (with exported variables above).
. "$ROOT/handlers/$ext"
} || echo "No handler for extension: $ext" > /dev/stderr
}
# Recursively find and process a directory.
process_dir() {
dir="$1"
for file in "$dir"/*; do
test -e "$file" || continue
if test -d "$file"; then
process_dir "$file"
else
process_file "$file"
fi
done
}
# Header before all other units.
process_dir "$ROOT/core/header"
# Process all paths in arguments.
for path in "$@"; do
test -e "$path" || { echo "Does not exist: $path" > /dev/stderr; exit 1; }
if test -d "$path"; then
process_dir "$path"
else
process_file "$path"
fi
done
# Footer after all other units.
process_dir "$ROOT/core/footer"