diff options
Diffstat (limited to 'other/docker/windows/build_toxcore.sh')
-rw-r--r-- | other/docker/windows/build_toxcore.sh | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/other/docker/windows/build_toxcore.sh b/other/docker/windows/build_toxcore.sh new file mode 100644 index 00000000..0f4c2731 --- /dev/null +++ b/other/docker/windows/build_toxcore.sh | |||
@@ -0,0 +1,164 @@ | |||
1 | #!/usr/bin/env sh | ||
2 | |||
3 | set -e -x | ||
4 | |||
5 | #=== Cross-Compile Toxcore === | ||
6 | |||
7 | build() | ||
8 | { | ||
9 | ARCH=${1} | ||
10 | |||
11 | echo "Building for ${ARCH} architecture" | ||
12 | |||
13 | # set some things | ||
14 | |||
15 | WINDOWS_TOOLCHAIN=${ARCH}-w64-mingw32 | ||
16 | |||
17 | # toxcore dependencies that we will copy to the user for static build of toxcore (e.g. vpx, opus, sodium) | ||
18 | DEP_PREFIX_DIR="/root/prefix/${ARCH}" | ||
19 | |||
20 | # toxcore dependencies that user doesn't need in build result (e.g. libcheck used for testing toxcore) | ||
21 | EXTRA_DEP_PREFIX_DIR="/root/extra-prefix/${ARCH}" | ||
22 | mkdir -p "${EXTRA_DEP_PREFIX_DIR}" | ||
23 | |||
24 | # where to put the result of this particular build | ||
25 | RESULT_PREFIX_DIR="/prefix/${ARCH}" | ||
26 | mkdir -p "${RESULT_PREFIX_DIR}" | ||
27 | |||
28 | # where to install static/shared toxcores before deciding whether they should be copied over to the user | ||
29 | STATIC_TOXCORE_PREFIX_DIR="/tmp/static_prefix" | ||
30 | SHARED_TOXCORE_PREFIX_DIR="/tmp/shared_prefix" | ||
31 | mkdir -p "${STATIC_TOXCORE_PREFIX_DIR}" "${SHARED_TOXCORE_PREFIX_DIR}" | ||
32 | |||
33 | export MAKEFLAGS=j$(nproc) | ||
34 | export CFLAGS=-O3 | ||
35 | |||
36 | echo | ||
37 | echo "=== Building toxcore ${ARCH} ===" | ||
38 | export PKG_CONFIG_PATH="${DEP_PREFIX_DIR}/lib/pkgconfig:${EXTRA_DEP_PREFIX_DIR}/lib/pkgconfig" | ||
39 | |||
40 | cp /toxcore /tmp/toxcore -R | ||
41 | cd /tmp/toxcore/build | ||
42 | echo " | ||
43 | SET(CMAKE_SYSTEM_NAME Windows) | ||
44 | |||
45 | SET(CMAKE_C_COMPILER ${WINDOWS_TOOLCHAIN}-gcc) | ||
46 | SET(CMAKE_CXX_COMPILER ${WINDOWS_TOOLCHAIN}-g++) | ||
47 | SET(CMAKE_RC_COMPILER ${WINDOWS_TOOLCHAIN}-windres) | ||
48 | |||
49 | SET(CMAKE_FIND_ROOT_PATH /usr/${WINDOWS_TOOLCHAIN} ${DEP_PREFIX_DIR} ${EXTRA_DEP_PREFIX_DIR}) | ||
50 | " > windows_toolchain.cmake | ||
51 | |||
52 | if [ "${ENABLE_TEST}" = "true" ]; then | ||
53 | echo "SET(CROSSCOMPILING_EMULATOR /usr/bin/wine)" >> windows_toolchain.cmake | ||
54 | fi | ||
55 | |||
56 | cmake -DCMAKE_TOOLCHAIN_FILE=windows_toolchain.cmake \ | ||
57 | -DCMAKE_INSTALL_PREFIX="${STATIC_TOXCORE_PREFIX_DIR}" \ | ||
58 | -DENABLE_SHARED=OFF \ | ||
59 | -DENABLE_STATIC=ON \ | ||
60 | ${EXTRA_CMAKE_FLAGS} \ | ||
61 | .. | ||
62 | cmake --build . --target install | ||
63 | |||
64 | if [ "${ENABLE_TEST}" = "true" ]; then | ||
65 | rm -rf /root/.wine | ||
66 | |||
67 | # setup wine | ||
68 | if [ "${ARCH}" = "i686" ]; then | ||
69 | export WINEARCH=win32 | ||
70 | else | ||
71 | export WINEARCH=win64 | ||
72 | fi | ||
73 | |||
74 | winecfg | ||
75 | export CTEST_OUTPUT_ON_FAILURE=1 | ||
76 | # add libgcc_s_sjlj-1.dll libwinpthread-1.dll libcheck-0.dll into PATH env var of wine | ||
77 | export WINEPATH=`cd /usr/lib/gcc/${WINDOWS_TOOLCHAIN}/*posix/ ; winepath -w $(pwd)`\;`winepath -w /usr/${WINDOWS_TOOLCHAIN}/lib/`\;`winepath -w ${EXTRA_DEP_PREFIX_DIR}/bin` | ||
78 | |||
79 | if [ "${ALLOW_TEST_FAILURE}" = "true" ]; then | ||
80 | set +e | ||
81 | fi | ||
82 | cmake --build . --target test | ||
83 | if [ "${ALLOW_TEST_FAILURE}" = "true" ]; then | ||
84 | set -e | ||
85 | fi | ||
86 | fi | ||
87 | |||
88 | # move static dependencies | ||
89 | cp "${STATIC_TOXCORE_PREFIX_DIR}"/* "${RESULT_PREFIX_DIR}" -R | ||
90 | cp "${DEP_PREFIX_DIR}"/* "${RESULT_PREFIX_DIR}" -R | ||
91 | |||
92 | # make libtox.dll | ||
93 | cd "${SHARED_TOXCORE_PREFIX_DIR}" | ||
94 | for archive in ${STATIC_TOXCORE_PREFIX_DIR}/lib/libtox*.a | ||
95 | do | ||
96 | ${WINDOWS_TOOLCHAIN}-ar xv ${archive} | ||
97 | done | ||
98 | ${WINDOWS_TOOLCHAIN}-gcc -Wl,--export-all-symbols \ | ||
99 | -Wl,--out-implib=libtox.dll.a \ | ||
100 | -shared \ | ||
101 | -o libtox.dll \ | ||
102 | *.obj \ | ||
103 | ${STATIC_TOXCORE_PREFIX_DIR}/lib/*.a \ | ||
104 | ${DEP_PREFIX_DIR}/lib/*.a \ | ||
105 | /usr/${WINDOWS_TOOLCHAIN}/lib/libwinpthread.a \ | ||
106 | -liphlpapi \ | ||
107 | -lws2_32 \ | ||
108 | -static-libgcc | ||
109 | cp libtox.dll.a ${RESULT_PREFIX_DIR}/lib | ||
110 | mkdir -p ${RESULT_PREFIX_DIR}/bin | ||
111 | cp libtox.dll ${RESULT_PREFIX_DIR}/bin | ||
112 | |||
113 | rm -rf /tmp/* | ||
114 | |||
115 | # remove everything from include directory except tox headers | ||
116 | mv ${RESULT_PREFIX_DIR}/include/tox ${RESULT_PREFIX_DIR}/tox | ||
117 | rm -rf ${RESULT_PREFIX_DIR}/include/* | ||
118 | mv ${RESULT_PREFIX_DIR}/tox ${RESULT_PREFIX_DIR}/include/tox | ||
119 | |||
120 | sed -i "s|^prefix=.*|prefix=${RESULT_PREFIX_DIR}|g" ${RESULT_PREFIX_DIR}/lib/pkgconfig/*.pc | ||
121 | sed -i "s|^libdir=.*|libdir=${RESULT_PREFIX_DIR}/lib|g" ${RESULT_PREFIX_DIR}/lib/*.la | ||
122 | } | ||
123 | |||
124 | #=== Test Supported vs. Enabled === | ||
125 | |||
126 | if [ "${ENABLE_ARCH_i686}" != "true" ] && [ "${ENABLE_ARCH_x86_64}" != "true" ]; then | ||
127 | echo "Error: No architecture specified. Set either ENABLE_ARCH_i686 or ENABLE_ARCH_x86_64 or both." | ||
128 | exit 1 | ||
129 | fi | ||
130 | |||
131 | if [ "${ENABLE_ARCH_i686}" = "true" ] && [ "${SUPPORT_ARCH_i686}" != "true" ]; then | ||
132 | echo "Error: Can't build for i686 architecture because the image was created without SUPPORT_ARCH_i686 set" | ||
133 | exit 1 | ||
134 | fi | ||
135 | |||
136 | if [ "${ENABLE_ARCH_x86_64}" = "true" ] && [ "${SUPPORT_ARCH_x86_64}" != "true" ]; then | ||
137 | echo "Error: Can't build for x86_64 architecture because the image was created without SUPPORT_ARCH_x86_64 set" | ||
138 | exit 1 | ||
139 | fi | ||
140 | |||
141 | if [ "${ENABLE_TEST}" = "true" ] && [ "${SUPPORT_TEST}" != "true" ]; then | ||
142 | echo "Error: Can't build with tests because the image was created without SUPPORT_TEST set" | ||
143 | exit 1 | ||
144 | fi | ||
145 | |||
146 | #=== Build === | ||
147 | |||
148 | if [ "${ENABLE_ARCH_i686}" = "true" ]; then | ||
149 | build i686 | ||
150 | fi | ||
151 | |||
152 | if [ "${ENABLE_ARCH_x86_64}" = "true" ]; then | ||
153 | build x86_64 | ||
154 | fi | ||
155 | |||
156 | |||
157 | tree -h /prefix | ||
158 | |||
159 | echo | ||
160 | echo "Built toxcore successfully!" | ||
161 | echo | ||
162 | |||
163 | # since we are building as root | ||
164 | chmod 777 /prefix -R | ||