-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·153 lines (138 loc) · 3.97 KB
/
build.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
#!/bin/bash
# TODO: makefile and vs solution?
OPTIMZE="-Os -s"
get_platform () {
"$1" --version | grep -q "clang" && IS_CLANG=1 || IS_CLANG=0
DUMPMACHINE=$($1 -dumpmachine) # sometimes *-pc-linux-gnu, sometimes *-linux-gnu
OS=$($1 -dumpmachine | cut -d'-' -f3)
ARCH=$($1 -dumpmachine | cut -d'-' -f1)
if [[ "$OS" == "gnu" ]]; then
OS="linux"
fi
if [[ "$OS" == darwin* ]]; then
# macos
PLATFORM="macos-$ARCH"
DLL_EXT=".dylib"
elif [[ "$OS" == "mingw32" ]] || [[ "$OS" == "windows" ]]; then
# windows
if [[ "$ARCH" == "x86_64" ]] || [[ "$ARCH" == "amd64" ]]; then
PLATFORM="win64"
else
PLATFORM="win32"
fi
DLL_EXT=".dll"
EXE_EXT=".exe"
EXTRA_LIBS="-Wl,-Bdynamic -lcrypt32 -lws2_32"
if [ "$IS_CLANG" -ne 0 ]; then
EXTRA_LIBS="-lc++ $EXTRA_LIBS"
fi
else
# other
PLATFORM="$OS-$ARCH"
DLL_EXT=".so"
fi
}
needs_build () {
if [ ! -f $1 ]; then
return 0 # true
fi
for f in src/*; do
if [ $f -nt $DEST ]; then
return 0 # true
fi
done
for f in include/*; do
if [ $f -nt $DEST ]; then
return 0 # true
fi
done
return 1 # false
}
# native / local lib
get_platform g++
mkdir -p build/$PLATFORM/lib
DEST=build/$PLATFORM/lib/c-wspp$DLL_EXT
# try static linking first, then dynamic
if needs_build $DEST; then
echo "Building lib for $PLATFORM ($DUMPMACHINE)"
set -x
g++ -o "$DEST" \
-shared -fpic $OPTIMZE \
-Wno-deprecated-declarations \
src/c-wspp.cpp \
-Iinclude -Isubprojects/websocketpp -Isubprojects/asio/include \
-Wl,-Bstatic \
-lssl -lcrypto \
$EXTRA_LIBS \
-Wno-deprecated 2>/dev/null || \
g++ -o "$DEST" \
-shared -fpic $OPTIMIZE \
-Wno-deprecated-declarations \
src/c-wspp.cpp \
-Iinclude -Isubprojects/websocketpp -Isubprojects/asio/include \
-lssl -lcrypto \
$EXTRA_LIBS \
-Wno-deprecated
set +x
else
echo "lib for $PLATFORM is up to date"
fi
#native / local test binary
mkdir -p build/$PLATFORM/bin
DEST=build/$PLATFORM/bin/c-wspp$EXE_EXT
if needs_build $DEST; then
echo "Building test for $PLATFORM"
set -x
g++ -o "$DEST" \
-Wno-deprecated-declarations $OPTIMZE \
src/test.c src/c-wspp.cpp \
-Iinclude -Isubprojects/websocketpp -Isubprojects/asio/include \
-lssl -lcrypto \
$EXTRA_LIBS \
-Wno-deprecated
set +x
else
echo "test for $PLATFORM is up to date"
fi
if [ -x "$(which x86_64-w64-mingw32-g++)" ]; then
# cross build win64
get_platform x86_64-w64-mingw32-g++
mkdir -p build/$PLATFORM/lib
DEST=build/$PLATFORM/lib/c-wspp$DLL_EXT
if needs_build $DEST; then
echo "Building lib for $PLATFORM"
set -x
x86_64-w64-mingw32-g++ -o "$DEST" \
-shared -fpic $OPTIMZE \
-Wno-deprecated-declarations \
src/c-wspp.cpp \
-Iinclude -Isubprojects/websocketpp -Isubprojects/asio/include \
-lssl -lcrypto -lcrypt32 -lws2_32 \
-Wl,-Bstatic \
-Wno-deprecated
set +x
else
echo "lib for $PLATFORM is up to date"
fi
fi
if [ -x "$(which i686-w64-mingw32-g++)" ]; then
# cross build win32
get_platform i686-w64-mingw32-g++
mkdir -p build/$PLATFORM/lib
DEST=build/$PLATFORM/lib/c-wspp$DLL_EXT
if needs_build $DEST; then
echo "Building lib for $PLATFORM"
set -x
i686-w64-mingw32-g++ -o "$DEST" \
-shared -fpic $OPTIMZE \
-Wno-deprecated-declarations \
src/c-wspp.cpp \
-Iinclude -Isubprojects/websocketpp -Isubprojects/asio/include \
-lssl -lcrypto -lcrypt32 -lws2_32 \
-Wl,-Bstatic \
-Wno-deprecated
set +x
else
echo "lib for $PLATFORM is up to date"
fi
fi