-
Notifications
You must be signed in to change notification settings - Fork 0
/
m.sh
executable file
·159 lines (158 loc) · 4.27 KB
/
m.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
#!/bin/sh
# m.sh: in-tree build script for convenience
cd "$(dirname "$0")"
set -ex
case "$1" in
"c")
# clean artifacts
rm -rf build compile_commands.json
;;
"doc")
VERSION="dev"
if git rev-parse --git-dir >/dev/null 2>&1; then
VERSION="$(git tag --points-at HEAD)"
if [ -z "${VERSION}" ]; then
VERSION="git-$(git rev-parse --short HEAD)"
fi
if ! git diff --quiet HEAD --; then
VERSION="${VERSION}+"
fi
fi
mkdir -p build/doc
cp -r neosocksd.lua libruleset.lua agent.lua example build/doc/
sed "s/^Version: dev$/Version: ${VERSION}/g" API.md >build/doc/API.md
;;
"x")
# cross compiling, environment vars need to be set
rm -rf build && mkdir -p build && cd build
cmake \
-DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_SYSROOT="${SYSROOT}" \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
-DCMAKE_SKIP_RPATH=ON \
..
cmake --build .
ls -lh bin/neosocksd
;;
"posix")
# rebuild for strict POSIX compliance
rm -rf build && mkdir -p build && cd build
cmake \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_BUILD_TYPE="Release" \
-DFORCE_POSIX=ON \
..
cp compile_commands.json ../
cmake --build .
ls -lh bin/neosocksd
;;
"clang")
# rebuild with Linux clang/lld
rm -rf build && mkdir -p build && cd build
cmake \
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
-DCMAKE_C_COMPILER="clang" \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld --rtlib=compiler-rt" \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
..
cmake --build .
(cd bin && llvm-objdump -drwS neosocksd >neosocksd.S)
ls -lh bin/neosocksd
;;
"msys2")
# rebuild with MSYS 2
rm -rf build && mkdir -p build && cd build
cmake \
-DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_EXE_LINKER_FLAGS="-static-libgcc" \
..
cmake --build .
HOST="$(cc -dumpmachine)"
zip -9j "neosocksd-win32.${HOST}.zip" \
"/usr/bin/msys-2.0.dll" \
"/usr/bin/msys-cares-2.dll" \
"bin/neosocksd.exe"
ls -lh "neosocksd-win32.${HOST}.zip"
;;
"ndk")
# rebuild with Android NDK
rm -rf build && mkdir -p build && cd build
cmake \
-DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_SYSTEM_NAME="Android" \
-DCMAKE_SYSTEM_VERSION="${ANDROID_API_LEVEL}" \
-DCMAKE_ANDROID_NDK="${ANDROID_NDK_ROOT}" \
-DCMAKE_ANDROID_ARCH_ABI="${ABI_NAME}" \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
-DENABLE_MIMALLOC=ON \
-DLINK_STATIC_LIBS=ON \
..
cmake --build .
ls -lh bin/neosocksd
;;
"san")
# rebuild with clang & sanitizers
rm -rf build && mkdir -p build && cd build
cmake \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_BUILD_TYPE="Debug" \
-DCMAKE_C_COMPILER="clang" \
-DENABLE_SANITIZERS=ON \
..
cp compile_commands.json ../
cmake --build .
ls -lh bin/neosocksd
;;
"min")
# rebuild for minimized size
rm -rf build && mkdir -p build && cd build
cmake \
-DCMAKE_BUILD_TYPE="MinSizeRel" \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
..
cmake --build .
ls -lh bin/neosocksd
;;
"p")
# rebuild for profiling
rm -rf build && mkdir -p build && cd build
cmake \
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
..
cmake --build .
(cd bin && objdump -drwS neosocksd >neosocksd.S)
ls -lh bin/neosocksd
;;
"r")
# rebuild for release
rm -rf build && mkdir -p build && cd build
cmake \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_BUILD_TYPE="Release" \
..
cp compile_commands.json ../
cmake --build .
ls -lh bin/neosocksd
;;
"d")
# rebuild for debug
if command -v clang-format >/dev/null; then
find src -type f -regex '.*\.[hc]' -exec clang-format -i {} +
fi
rm -rf build && mkdir -p build && cd build
cmake \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_BUILD_TYPE="Debug" \
-DENABLE_SANITIZERS=ON \
..
cp compile_commands.json ../
cmake --build .
ls -lh bin/neosocksd
;;
*)
cd build
cmake --build .
ls -lh bin/neosocksd
;;
esac