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 "$this_src/configure" --prefix="$pkg_dir" \
121 if [[ -d "$src_dir/d0_blind_id" ]] ; then
122 echo "Sources already exist."
124 echo "Getting git sources for libd0..."
126 git clone https://gitlab.com/xonotic/d0_blind_id.git
129 sed -i '/libd0_blind_id_la_LDFLAGS/ s/$/ -no-undefined/' Makefile.am
130 sed -i '/libd0_rijndael_la_LDFLAGS/ s/$/ -no-undefined/' Makefile.am
133 mkcd "$work_dir/libd0"
134 "$src_dir/d0_blind_id/configure" --with-pic \
135 --prefix="$pkg_dir" \
142 if fetch_source libogg ; then
143 echo "Fixing win32 def files..."
144 sed -i 's/^LIBRARY ogg$/LIBRARY libogg/' "$this_src/win32/ogg.def"
147 mkcd "$work_dir/libogg"
148 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
149 -DBUILD_SHARED_LIBS=ON \
150 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
151 -G"Unix Makefiles" "$this_src"
157 if fetch_source libvorbis ; then
158 echo "Fixing win32 def files..."
159 sed -i 's/^LIBRARY$/LIBRARY libvorbis/' "$this_src/win32/vorbis.def"
160 sed -i 's/^LIBRARY$/LIBRARY libvorbisenc/' "$this_src/win32/vorbisenc.def"
161 sed -i 's/^LIBRARY$/LIBRARY libvorbisfile/' "$this_src/win32/vorbisfile.def"
164 mkcd "$work_dir/libvorbis"
165 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
166 -DBUILD_SHARED_LIBS=ON \
167 -DOGG_INCLUDE_DIR="$pkg_dir/include" \
168 -DOGG_LIBRARY="$pkg_dir/lib/libogg.dll.a" \
169 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
170 -G"Unix Makefiles" "$this_src"
176 if fetch_source libtheora ; then
177 echo "Fixing mingw32 defs..."
178 sed -i '1iLIBRARY libtheoradec' "$this_src/win32/xmingw32/libtheoradec-all.def"
179 sed -i '1iLIBRARY libtheoraenc' "$this_src/win32/xmingw32/libtheoraenc-all.def"
180 sed -i '/TH_VP31_QUANT_INFO/d' "$this_src/win32/xmingw32/libtheoraenc-all.def"
181 sed -i '/TH_VP31_HUFF_CODES/d' "$this_src/win32/xmingw32/libtheoraenc-all.def"
184 mkcd "$work_dir/libtheora"
185 "$this_src/autogen.sh"
186 "$this_src/configure" --host="$CHOST" \
187 --prefix="$pkg_dir" \
188 --with-ogg="$pkg_dir" \
189 --with-vorbis="$pkg_dir" \
193 --disable-vorbistest \
200 fetch_source freetype || true
202 mkcd "$work_dir/freetype"
203 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
204 -DBUILD_SHARED_LIBS=ON \
205 -DCMAKE_BUILD_TYPE=Release \
206 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
207 -G"Unix Makefiles" "$this_src"
213 fetch_source "libpng1.6" || true
215 mkcd "$work_dir/libpng1.6"
216 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
219 -DZLIB_INCLUDE_DIR="$pkg_dir/include" \
220 -DZLIB_LIBRARY="$pkg_dir/lib/libzlib.dll.a" \
221 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
222 -G"Unix Makefiles" "$this_src"
228 fetch_source libjpeg-turbo || true
230 mkcd "$work_dir/libjpeg"
231 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
232 -DCMAKE_SYSTEM_PROCESSOR="$ARCH" \
233 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
235 -DENABLE_STATIC=OFF \
236 -DWITH_TURBOJPEG=OFF \
237 -G"Unix Makefiles" "$this_src"
243 fetch_source curl || true
245 # curl versions older than 7.81.0 used CMAKE instead of CURL for
246 # private USE identifiers
247 verlt $this_ver 7.81.0 && PARAM="CMAKE" || PARAM="CURL"
249 mkcd "$work_dir/curl"
250 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
251 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
252 -DZLIB_INCLUDE_DIR="$pkg_dir/include" \
253 -DZLIB_LIBRARY="$pkg_dir/lib/libzlib.dll.a" \
254 -D${PARAM}_USE_SCHANNEL=ON \
255 -DBUILD_SHARED_LIBS=ON \
256 -DBUILD_CURL_EXE=OFF \
258 -G"Unix Makefiles" "$this_src"
279 cp -v "$pkg_dir/bin/libgmp-10.dll" "$out_dir"
280 cp -v "$pkg_dir/bin/libd0_blind_id-0.dll" "$out_dir"
281 cp -v "$pkg_dir/bin/libd0_rijndael-0.dll" "$out_dir"
282 cp -v "$pkg_dir/bin/libogg.dll" "$out_dir"
283 cp -v "$pkg_dir/bin/libvorbis.dll" "$out_dir"
284 cp -v "$pkg_dir/bin/libvorbisenc.dll" "$out_dir"
285 cp -v "$pkg_dir/bin/libvorbisfile.dll" "$out_dir"
286 cp -v "$pkg_dir/bin/libtheora-0.dll" "$out_dir"
287 cp -v "$pkg_dir/bin/libfreetype.dll" "$out_dir/libfreetype-6.dll"
288 cp -v "$pkg_dir/bin/zlib1.dll" "$out_dir"
289 cp -v "$pkg_dir/bin/libpng16.dll" "$out_dir"
290 cp -v "$pkg_dir/bin/libjpeg-62.dll" "$out_dir/libjpeg.dll"
291 cp -v "$pkg_dir/bin/libcurl.dll" "$out_dir/libcurl-4.dll"
293 # Required for win32 builds
294 if [ "$ARCH" = "i686" ]; then
295 cp -v "/usr/lib/gcc/i686-w64-mingw32/10-win32/libgcc_s_dw2-1.dll" "$out_dir"
299 ${CHOST}-strip -s *.dll
303 rm -rf "$buildpath/src"
304 rm -rf "$buildpath/work"
305 rm -rf "$buildpath/pkg"
306 rm -rf "$buildpath/out"
310 echo "Compilable libraries:"
325 echo "Experimental Windows DLL cross-compiling for Xonotic"
328 echo "usage: $0 <step> [build path] [arch]"
330 echo "available steps (require arch):"
331 echo " <library name>: build specified library"
332 echo " build_all: build all libraries"
333 echo " install: copy built DLLs into output directory"
334 echo " all: do all the previous steps in order"
336 echo "steps without arch:"
337 echo " list: list all compilable libraries"
338 echo " clean: delete all work"
350 gmp) prepare && build_gmp ;;
351 libd0) prepare && build_libd0 ;;
352 libogg) prepare && build_libogg ;;
353 libvorbis) prepare && build_libvorbis ;;
354 libtheora) prepare && build_libtheora ;;
355 freetype) prepare && build_freetype ;;
356 zlib) prepare && build_zlib ;;
357 libpng16) prepare && build_libpng16 ;;
358 libjpeg) prepare && build_libjpeg ;;
359 curl) prepare && build_curl ;;
360 build_all) prepare && build_all ;;
361 install) prepare && install ;;
362 all) prepare && build_all && install ;;