3 # Xonotic DLL automatic cross-compile script
7 cjobs=$(($(nproc) + 1))
8 echo "Working directory is $d0"
11 if ! dpkg -s "$1" >/dev/null 2>&1 ; then
12 echo "$1 package is required. Please install it."
20 win64) ARCH="x86_64" ;;
21 *) echo "Invalid arch (win32 or win64)." && exit -1 ;;
25 src_dir="$buildpath/src"
26 work_dir="$buildpath/work/$target_arch"
27 pkg_dir="$buildpath/pkg/$target_arch"
28 out_dir="$buildpath/out/$target_arch"
31 CHOST="$ARCH-w64-mingw32"
32 toolchain_file="$d0/toolchain-$CHOST.cmake"
34 # Fix for Debian package missing the Windows resource file
35 zlib1rc_file="$d0/zlib1.rc"
37 export LDFLAGS="-L$pkg_dir/lib"
38 export CPPFLAGS="-I$pkg_dir/include"
55 dir=$(find . -maxdepth 1 -type d -print | grep -m1 "^\./$1") || return 1
56 this_src="$src_dir/$dir"
63 if get_this_src "$1"; then
64 echo "Source for $1 already exists."
67 echo "Getting source for $1..."
75 printf '%s\n%s' "$1" "$2" | sort -C -V
88 if fetch_source zlib ; then
89 echo "Fixing zlib prefix..."
90 sed -i '/zlib PROPERTIES SUFFIX/i set_target_properties(zlib PROPERTIES PREFIX "")' "$this_src/CMakeLists.txt"
92 # Debian source package is missing the win32 resource file for some reason,
93 # so we add it ourselves.
94 echo "Fixing zlib1.rc..."
95 mkdir -p "$this_src/win32"
96 cp "$zlib1rc_file" "$this_src/win32"
100 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file"\
101 -DBUILD_SHARED_LIBS=ON \
102 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
103 -G"Unix Makefiles" "$this_src"
109 fetch_source gmp || true
112 "$this_src/configure" --prefix="$pkg_dir" \
123 if [[ -d "$src_dir/d0_blind_id" ]] ; then
124 echo "Sources already exist."
126 echo "Getting git sources for libd0..."
128 git clone https://gitlab.com/xonotic/d0_blind_id.git
131 sed -i '/libd0_blind_id_la_LDFLAGS/ s/$/ -no-undefined/' Makefile.am
132 sed -i '/libd0_rijndael_la_LDFLAGS/ s/$/ -no-undefined/' Makefile.am
135 mkcd "$work_dir/libd0"
136 "$src_dir/d0_blind_id/configure" --with-pic \
137 --prefix="$pkg_dir" \
144 if fetch_source libogg ; then
145 echo "Fixing win32 def files..."
146 sed -i 's/^LIBRARY ogg$/LIBRARY libogg/' "$this_src/win32/ogg.def"
149 mkcd "$work_dir/libogg"
150 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
151 -DBUILD_SHARED_LIBS=ON \
152 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
153 -G"Unix Makefiles" "$this_src"
159 if fetch_source libvorbis ; then
160 echo "Fixing win32 def files..."
161 sed -i 's/^LIBRARY$/LIBRARY libvorbis/' "$this_src/win32/vorbis.def"
162 sed -i 's/^LIBRARY$/LIBRARY libvorbisenc/' "$this_src/win32/vorbisenc.def"
163 sed -i 's/^LIBRARY$/LIBRARY libvorbisfile/' "$this_src/win32/vorbisfile.def"
166 mkcd "$work_dir/libvorbis"
167 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
168 -DBUILD_SHARED_LIBS=ON \
169 -DOGG_INCLUDE_DIR="$pkg_dir/include" \
170 -DOGG_LIBRARY="$pkg_dir/lib/libogg.dll.a" \
171 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
172 -G"Unix Makefiles" "$this_src"
178 if fetch_source libtheora ; then
179 echo "Fixing mingw32 defs..."
180 sed -i '1iLIBRARY libtheoradec' "$this_src/win32/xmingw32/libtheoradec-all.def"
181 sed -i '1iLIBRARY libtheoraenc' "$this_src/win32/xmingw32/libtheoraenc-all.def"
182 sed -i '/TH_VP31_QUANT_INFO/d' "$this_src/win32/xmingw32/libtheoraenc-all.def"
183 sed -i '/TH_VP31_HUFF_CODES/d' "$this_src/win32/xmingw32/libtheoraenc-all.def"
186 mkcd "$work_dir/libtheora"
187 "$this_src/autogen.sh"
188 "$this_src/configure" --host="$CHOST" \
189 --prefix="$pkg_dir" \
190 --with-ogg="$pkg_dir" \
191 --with-vorbis="$pkg_dir" \
195 --disable-vorbistest \
202 fetch_source freetype || true
204 mkcd "$work_dir/freetype"
205 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
206 -DBUILD_SHARED_LIBS=ON \
207 -DCMAKE_BUILD_TYPE=Release \
208 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
209 -G"Unix Makefiles" "$this_src"
215 fetch_source "libpng1.6" || true
217 mkcd "$work_dir/libpng1.6"
218 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
221 -DZLIB_INCLUDE_DIR="$pkg_dir/include" \
222 -DZLIB_LIBRARY="$pkg_dir/lib/libzlib.dll.a" \
223 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
224 -G"Unix Makefiles" "$this_src"
230 fetch_source libjpeg-turbo || true
232 mkcd "$work_dir/libjpeg"
233 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
234 -DCMAKE_SYSTEM_PROCESSOR="$ARCH" \
235 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
237 -DENABLE_STATIC=OFF \
238 -DWITH_TURBOJPEG=OFF \
239 -G"Unix Makefiles" "$this_src"
245 fetch_source curl || true
247 # curl versions older than 7.81.0 used CMAKE instead of CURL for
248 # private USE identifiers
249 verlt $this_ver 7.81.0 && PARAM="CMAKE" || PARAM="CURL"
251 mkcd "$work_dir/curl"
252 cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
253 -DCMAKE_INSTALL_PREFIX="$pkg_dir" \
254 -DZLIB_INCLUDE_DIR="$pkg_dir/include" \
255 -DZLIB_LIBRARY="$pkg_dir/lib/libzlib.dll.a" \
256 -D${PARAM}_USE_SCHANNEL=ON \
257 -DBUILD_SHARED_LIBS=ON \
258 -DBUILD_CURL_EXE=OFF \
260 -G"Unix Makefiles" "$this_src"
281 cp -v "$pkg_dir/bin/libgmp-10.dll" "$out_dir"
282 cp -v "$pkg_dir/bin/libd0_blind_id-0.dll" "$out_dir"
283 cp -v "$pkg_dir/bin/libd0_rijndael-0.dll" "$out_dir"
284 cp -v "$pkg_dir/bin/libogg.dll" "$out_dir"
285 cp -v "$pkg_dir/bin/libvorbis.dll" "$out_dir"
286 cp -v "$pkg_dir/bin/libvorbisenc.dll" "$out_dir"
287 cp -v "$pkg_dir/bin/libvorbisfile.dll" "$out_dir"
288 cp -v "$pkg_dir/bin/libtheora-0.dll" "$out_dir"
289 cp -v "$pkg_dir/bin/libfreetype.dll" "$out_dir/libfreetype-6.dll"
290 cp -v "$pkg_dir/bin/zlib1.dll" "$out_dir"
291 cp -v "$pkg_dir/bin/libpng16.dll" "$out_dir"
292 cp -v "$pkg_dir/bin/libjpeg-62.dll" "$out_dir/libjpeg.dll"
293 cp -v "$pkg_dir/bin/libcurl.dll" "$out_dir/libcurl-4.dll"
296 ${CHOST}-strip -s *.dll
300 rm -rf "$buildpath/src"
301 rm -rf "$buildpath/work"
302 rm -rf "$buildpath/pkg"
303 rm -rf "$buildpath/out"
307 echo "Compilable libraries:"
322 echo "Experimental Windows DLL cross-compiling for Xonotic"
325 echo "usage: $0 <step> [build path] [arch]"
327 echo "available steps (require arch):"
328 echo " <library name>: build specified library"
329 echo " build_all: build all libraries"
330 echo " install: copy built DLLs into output directory"
331 echo " all: do all the previous steps in order"
333 echo "steps without arch:"
334 echo " list: list all compilable libraries"
335 echo " clean: delete all work"
347 gmp) prepare && build_gmp ;;
348 libd0) prepare && build_libd0 ;;
349 libogg) prepare && build_libogg ;;
350 libvorbis) prepare && build_libvorbis ;;
351 libtheora) prepare && build_libtheora ;;
352 freetype) prepare && build_freetype ;;
353 zlib) prepare && build_zlib ;;
354 libpng16) prepare && build_libpng16 ;;
355 libjpeg) prepare && build_libjpeg ;;
356 curl) prepare && build_curl ;;
357 build_all) prepare && build_all ;;
358 install) prepare && install ;;
359 all) prepare && build_all && install ;;