-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBuildLua.sh
executable file
·35 lines (29 loc) · 1010 Bytes
/
BuildLua.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
#!/bin/bash
if [ -z $2 ]; then
echo "Usage: $0 input_file output_file [input2 output2 ...]"
echo "e.g.: $0 'threaded-libcurl/DownloadManager.moon' 'DownloadManager.lua'"
exit 0
fi
while [[ "$#" -ge 2 ]]; do
moonInput="$1"
moonInputBase=`basename "$moonInput"`
moduleName=${moonInputBase%.moon}
sourceDir=`dirname "$moonInput"`
headerInput="$sourceDir/${moduleName}C.h"
headerOutput="$sourceDir/${moduleName}C.processed.h"
moonOutput="${moonInput%.moon}.processed.moon"
luaOutput="$2"
if [[ -r $headerInput ]]; then
# clean up excess newlines for aesthetics.
cpp -P "$headerInput" | perl -pe "s/^\n$//g" > "$headerOutput"
# drop the processed header into the moonscript file.
cat "$moonInput" | perl -pe "s/___INCLUDE___/`cat "$headerOutput"`/" > "$moonOutput"
# clean up preprocessed header
# compile the moonscript file.
moonc -o "$luaOutput" "$moonOutput" 2>/dev/null
rm "$headerOutput" "$moonOutput"
else
moonc -o "$luaOutput" "$moonInput" 2>/dev/null
fi
shift 2
done