-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild
executable file
·153 lines (144 loc) · 2.96 KB
/
build
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
#!/bin/bash
set -e
C_OPTS="-fwrapv -Werror"
pushd "$(dirname "$0")" > /dev/null
SCRIPT_DIR="$(pwd)"
popd > /dev/null
SRC_DIR=$SCRIPT_DIR/src
TGT_DIR=$SCRIPT_DIR/tgt
DIST_DIR=$TGT_DIR/dist
LIB_DIR=$SCRIPT_DIR/lib
DIST_DIR=$SCRIPT_DIR/dist
BUILD_TS=0
BUILD_C=0
BUILD_DEBUG=0
BUILD_MEM=0
case "$1" in
"all")
BUILD_TS=1
BUILD_C=1
if [ "$2" = "debug" ]; then
BUILD_DEBUG=1
fi
;;
"ts")
BUILD_TS=1
if [ "$2" = "debug" ]; then
BUILD_DEBUG=1
fi
;;
"c")
BUILD_C=1
if [ "$2" = "debug" ]; then
BUILD_DEBUG=1
fi
;;
"debug")
BUILD_TS=1
BUILD_C=1
BUILD_DEBUG=1
;;
"mem")
BUILD_C=1
BUILD_MEM=1
;;
"clean")
echo Cleaning...
rm -rf "$TGT_DIR"
echo Done
exit 0
;;
"dist")
echo Publishing builds to ./dist
find dist -type f -maxdepth 1 -delete
mkdir -p "$DIST_DIR"/windows
mkdir -p "$DIST_DIR"/mac
mkdir -p "$DIST_DIR"/posix
cp "$LIB_DIR/require.js" "$DIST_DIR"
cp "$SRC_DIR/cmd.ts" "$DIST_DIR"
cp "$SRC_DIR/repl.html" "$DIST_DIR"
cp "$SRC_DIR/sink.ts" "$DIST_DIR"
cp "$SRC_DIR/sink_shell.ts" "$DIST_DIR"
cp "$TGT_DIR/cmd.d.ts" "$DIST_DIR"
cp "$TGT_DIR/cmd.js" "$DIST_DIR"
cp "$TGT_DIR/driver.js" "$DIST_DIR"
cp "$TGT_DIR/sink.d.ts" "$DIST_DIR"
cp "$TGT_DIR/sink.js" "$DIST_DIR"
cp "$TGT_DIR/sink_shell.d.ts" "$DIST_DIR"
cp "$TGT_DIR/sink_shell.js" "$DIST_DIR"
echo 'You must copy the correct executables yourself, from tgt/ to dist/<platform>'
;;
*)
echo './build <command> [debug]'
echo ''
echo 'Commands:'
echo ' all Build everything'
echo ' ts Build the TypeScript sources (node + browser)'
echo ' c Build the C source'
echo ' mem Build the C source with memory leak detection'
echo ' clean Delete the tgt directory'
echo ' dist Publish builds to ./dist'
echo ''
echo 'If "debug" is specified, then builds will be debug versions'
exit 0
;;
esac
EXIT=0
#
# TypeScript build
#
if [ "$BUILD_TS" = "1" ]; then
echo Building TypeScript...
mkdir -p $TGT_DIR
pushd "$SRC_DIR" > /dev/null
set +e
npm run tsc
status=$?
set -e
popd > /dev/null
if [ "$status" != "0" ]; then
echo 'TypeScript errors'
exit 1
fi
cp $SRC_DIR/driver.js $TGT_DIR/driver.js
chmod +x $TGT_DIR/driver.js
fi
#
# C build
#
if [ "$BUILD_C" = "1" ]; then
echo Building C...
mkdir -p $TGT_DIR
if which clang > /dev/null; then
if [ "$BUILD_MEM" = "1" ]; then
C_OPTS="$C_OPTS -DSINK_MEMTEST"
echo Memory Test
elif [ "$BUILD_DEBUG" = "1" ]; then
C_OPTS="$C_OPTS -g -DSINK_DEBUG"
echo Debug Build
else
C_OPTS="$C_OPTS -O2"
fi
clang $C_OPTS \
-lm \
-o $TGT_DIR/sink \
$SRC_DIR/sink.c \
$SRC_DIR/sink_shell.c \
$SRC_DIR/cmd.c
else
echo ''
echo 'ERROR:'
echo 'Missing "clang" which is required for building.'
echo ''
echo 'Skipping C build.'
echo ''
echo 'You can install "clang" by visiting:'
echo ' http://llvm.org/'
echo ''
EXIT=1
fi
fi
if [ "$EXIT" = "1" ]; then
exit 1
fi
echo Done