3 # Xonotic DLL automatic cross-compile script
9 if ! dpkg -s "$1" >/dev/null 2>&1 ; then
10 echo "$1 package is required. Please install it."
18 win64) ARCH="x86_64" ;;
19 *) echo "Invalid arch (win32 or win64)." && exit -1 ;;
23 src_dir="$buildpath/src"
24 work_dir="$buildpath/work/$target_arch"
25 pkg_dir="$buildpath/pkg/$target_arch"
26 out_dir="$buildpath/out/$target_arch"
29 CHOST="$ARCH-w64-mingw32"
30 toolchain_file="$d0/toolchain-$CHOST.cmake"
32 # Fix for Debian package missing the Windows resource file
33 zlib1rc_file="$d0/zlib1.rc"
35 export LDFLAGS="-L$pkg_dir/lib"
36 export CPPFLAGS="-I$pkg_dir/include"
53 dir=$(find . -maxdepth 1 -type d -print | grep -m1 "^\./$1") || return 1
54 this_src="$src_dir/$dir"
61 if get_this_src "$1"; then
62 echo "Source for $1 already exists."
65 echo "Getting source for $1..."
66 apt-get source -t=stable "$1"
73 printf '%s\n%s' "$1" "$2" | sort -C -V
86 if fetch_source zlib ; then
87 echo "Fixing zlib prefix..."
88 sed -i '/zlib PROPERTIES SUFFIX/i set_target_properties(zlib PROPERTIES PREFIX "")' "$this_src/CMakeLists.txt"
90 # Debian source package is missing the win32 resource file for some reason,
91 # so we add it ourselves.
92 echo "Fixing zlib1.rc..."
93 mkdir -p "$this_src/win32"
94 cp "$zlib1rc_file" "$this_src/win32"
98 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file"\
99 -DBUILD_SHARED_LIBS=ON \
100 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
101 -G"Unix Makefiles" "$this_src"
107 fetch_source gmp || true
110 autoreconf -i "$this_src"
111 "$this_src/configure" --prefix="$pkg_dir" \
122 if [[ -d "$src_dir/d0_blind_id" ]] ; then
123 echo "Sources already exist."
125 echo "Getting git sources for libd0..."
127 git clone https://gitlab.com/xonotic/d0_blind_id.git
130 sed -i '/libd0_blind_id_la_LDFLAGS/ s/$/ -no-undefined/' Makefile.am
131 sed -i '/libd0_rijndael_la_LDFLAGS/ s/$/ -no-undefined/' Makefile.am
134 mkcd "$work_dir/libd0"
135 "$src_dir/d0_blind_id/configure" --with-pic \
136 --prefix="$pkg_dir" \
143 if fetch_source libogg ; then
144 echo "Fixing win32 def files..."
145 sed -i 's/^LIBRARY ogg$/LIBRARY libogg/' "$this_src/win32/ogg.def"
148 mkcd "$work_dir/libogg"
149 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
150 -DBUILD_SHARED_LIBS=ON \
151 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
152 -G"Unix Makefiles" "$this_src"
158 if fetch_source libvorbis ; then
159 echo "Fixing win32 def files..."
160 sed -i 's/^LIBRARY$/LIBRARY libvorbis/' "$this_src/win32/vorbis.def"
161 sed -i 's/^LIBRARY$/LIBRARY libvorbisenc/' "$this_src/win32/vorbisenc.def"
162 sed -i 's/^LIBRARY$/LIBRARY libvorbisfile/' "$this_src/win32/vorbisfile.def"
165 mkcd "$work_dir/libvorbis"
166 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
167 -DBUILD_SHARED_LIBS=ON \
168 -DOGG_INCLUDE_DIR="$pkg_dir/include" \
169 -DOGG_LIBRARY="$pkg_dir/lib/libogg.dll.a" \
170 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
171 -G"Unix Makefiles" "$this_src"
177 if fetch_source libtheora ; then
178 echo "Fixing mingw32 defs..."
179 sed -i '1iLIBRARY libtheoradec' "$this_src/win32/xmingw32/libtheoradec-all.def"
180 sed -i '1iLIBRARY libtheoraenc' "$this_src/win32/xmingw32/libtheoraenc-all.def"
181 sed -i '/TH_VP31_QUANT_INFO/d' "$this_src/win32/xmingw32/libtheoraenc-all.def"
182 sed -i '/TH_VP31_HUFF_CODES/d' "$this_src/win32/xmingw32/libtheoraenc-all.def"
185 mkcd "$work_dir/libtheora"
186 "$this_src/autogen.sh"
187 "$this_src/configure" --host="$CHOST" \
188 --prefix="$pkg_dir" \
189 --with-ogg="$pkg_dir" \
190 --with-vorbis="$pkg_dir" \
194 --disable-vorbistest \
201 fetch_source freetype || true
203 mkcd "$work_dir/freetype"
204 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
205 -DBUILD_SHARED_LIBS=ON \
206 -DCMAKE_BUILD_TYPE=Release \
207 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
208 -G"Unix Makefiles" "$this_src"
214 fetch_source "libpng1.6" || true
216 mkcd "$work_dir/libpng1.6"
217 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
220 -DZLIB_INCLUDE_DIR="$pkg_dir/include" \
221 -DZLIB_LIBRARY="$pkg_dir/lib/libzlib.dll.a" \
222 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
223 -G"Unix Makefiles" "$this_src"
229 fetch_source libjpeg-turbo || true
231 mkcd "$work_dir/libjpeg"
232 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
233 -DCMAKE_SYSTEM_PROCESSOR="$ARCH" \
234 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
236 -DENABLE_STATIC=OFF \
237 -DWITH_TURBOJPEG=OFF \
238 -G"Unix Makefiles" "$this_src"
244 fetch_source curl || true
246 # curl versions older than 7.81.0 used CMAKE instead of CURL for
247 # private USE identifiers
248 verlt $this_ver 7.81.0 && PARAM="CMAKE" || PARAM="CURL"
250 mkcd "$work_dir/curl"
251 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
252 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
253 -DZLIB_INCLUDE_DIR="$pkg_dir/include" \
254 -DZLIB_LIBRARY="$pkg_dir/lib/libzlib.dll.a" \
255 -D${PARAM}_USE_SCHANNEL=ON \
256 -DBUILD_SHARED_LIBS=ON \
257 -DBUILD_CURL_EXE=OFF \
259 -G"Unix Makefiles" "$this_src"
266 fetch_source libsdl2 || true
268 # this subdir will be made available to DP's linker
269 mkdir -p "$pkg_dir/sdl"
271 mkcd "$work_dir/libsdl2"
272 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
273 -DCMAKE_SYSTEM_PROCESSOR="$ARCH" \
274 -DCMAKE_INSTALL_PREFIX="$pkg_dir/sdl" \
275 -G"Unix Makefiles" "$this_src"
297 cp -v "$pkg_dir/bin/libgmp-10.dll" "$out_dir"
298 cp -v "$pkg_dir/bin/libd0_blind_id-0.dll" "$out_dir"
299 cp -v "$pkg_dir/bin/libd0_rijndael-0.dll" "$out_dir"
300 cp -v "$pkg_dir/bin/libogg.dll" "$out_dir"
301 cp -v "$pkg_dir/bin/libvorbis.dll" "$out_dir"
302 cp -v "$pkg_dir/bin/libvorbisenc.dll" "$out_dir"
303 cp -v "$pkg_dir/bin/libvorbisfile.dll" "$out_dir"
304 cp -v "$pkg_dir/bin/libtheora-0.dll" "$out_dir"
305 cp -v "$pkg_dir/bin/libfreetype.dll" "$out_dir/libfreetype-6.dll"
306 cp -v "$pkg_dir/bin/zlib1.dll" "$out_dir"
307 cp -v "$pkg_dir/bin/libpng16.dll" "$out_dir"
308 cp -v "$pkg_dir/bin/libjpeg-62.dll" "$out_dir/libjpeg.dll"
309 cp -v "$pkg_dir/bin/libcurl.dll" "$out_dir/libcurl-4.dll"
310 # cp -v "$pkg_dir/sdl/bin/SDL2.dll" "$out_dir"
312 # Required for win32 builds
313 if [ "$ARCH" = "i686" ]; then
314 cp -v /usr/lib/gcc/i686-w64-mingw32/[0-9][0-9]-win32/libgcc_s_dw2-1.dll "$out_dir"
318 ${CHOST}-strip -s *.dll
322 rm -rf "$buildpath/src"
323 rm -rf "$buildpath/work"
324 rm -rf "$buildpath/pkg"
325 rm -rf "$buildpath/out"
329 echo "Compilable libraries:"
345 echo "Experimental Windows DLL cross-compiling for Xonotic"
348 echo "usage: $0 <step> [build path] [arch]"
350 echo "available steps (require arch):"
351 echo " <library name>: build specified library"
352 echo " build_all: build all libraries"
353 echo " install: copy built DLLs into output directory"
354 echo " all: do all the previous steps in order"
356 echo "steps without arch:"
357 echo " list: list all compilable libraries"
358 echo " clean: delete all work"
370 gmp) prepare && build_gmp ;;
371 libd0) prepare && build_libd0 ;;
372 libogg) prepare && build_libogg ;;
373 libvorbis) prepare && build_libvorbis ;;
374 libtheora) prepare && build_libtheora ;;
375 freetype) prepare && build_freetype ;;
376 zlib) prepare && build_zlib ;;
377 libpng16) prepare && build_libpng16 ;;
378 libjpeg) prepare && build_libjpeg ;;
379 curl) prepare && build_curl ;;
380 libsdl2) prepare && build_libsdl2 ;;
381 build_all) prepare && build_all ;;
382 install) prepare && install ;;
383 all) prepare && build_all && install ;;