-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpaka
executable file
·90 lines (74 loc) · 1.72 KB
/
paka
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
#!/usr/bin/env bash
set -e
INDIR=$(pwd)
OUTFILE=$(basename "$1" .paka)
if test "$1" == ""
then
echo "please give this script a .paka file as an argument"
exit
fi
if test ! "$1"
then
echo "could not find input file: $1"
fi
if test "$SHACMD" == ""
then
SHACMD=$(which shasum)
fi
if test "$SHACMD" == ""
then
SHACMD=$(which sha1sum)
fi
if test "$SHACMD" == ""
then
echo "please install shasum or sha1sum command"
exit
fi
PCACHE=~/.paka-cache
mkdir -p "$PCACHE"
REPO="$PCACHE"/repo
mkdir -p "$REPO"
LOG="$PCACHE"/log
mkdir -p "$LOG"
if test ! -d "$REPO"/paka
then
git clone https://github.com/fastvm/paka --depth 1 "$REPO"/paka > "$LOG"/paka
cp "$REPO"/paka/bins/boot.bc "$PCACHE"/boot.bc
fi
if test ! -d "$REPO"/minivm
then
git clone https://github.com/fastvm/minivm --depth 1 "$REPO"/minivm > "$LOG"/paka
make -C "$REPO"/minivm HOST=D DC="ldc2" > "$LOG"/minivm
cp "$REPO"/minivm/minivm "$PCACHE"/minivm
fi
if test ! -f "$PCACHE"/pakac
then
ldc2 -O1 -i -I"$REPO"/minivm "$REPO"/minivm/vm/tod.d -of"$PCACHE"/pakac > "$LOG"/pakac
fi
RTCACHE="$PCACHE"/runs/"$("$SHACMD" "$1" | cut -d ' ' -f1)"
mkdir -p "$RTCACHE"
if test ! -f "$RTCACHE"/boot.bc
then
if test -f "$LOG"/paka
then
rm -f "$LOG"/paka
fi
"$PCACHE"/minivm "$PCACHE"/boot.bc "$INDIR"/"$1" -o "$RTCACHE"/boot.bc | tee "$LOG"/paka
fi
if test ! -f "$RTCACHE"/out.d
then
"$PCACHE"/pakac "$RTCACHE"/boot.bc > "$RTCACHE"/out.d
fi
if test ! -f "$RTCACHE"/out
then
ldc2 -betterC -O3 -release $DFLAGS "$RTCACHE"/out.d -c -of"$RTCACHE"/out.o > "$LOG"/exec
clang -flto=full "$RTCACHE"/out.o -o "$RTCACHE"/out
fi
shift
if test "$1" == "--"
then
shift
"$RTCACHE"/out $*
else
cp "$RTCACHE"/out "$OUTFILE"
fi