2
0

buildwin32.sh 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #!/bin/bash
  2. set -e
  3. CORE_GIT=https://github.com/minetest/minetest
  4. CORE_BRANCH=master
  5. CORE_NAME=minetest
  6. GAME_GIT=https://github.com/minetest/minetest_game
  7. GAME_BRANCH=master
  8. GAME_NAME=minetest_game
  9. topdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  10. if [ $# -ne 1 ]; then
  11. echo "Usage: $0 <build directory>"
  12. exit 1
  13. fi
  14. builddir=$1
  15. mkdir -p $builddir
  16. builddir="$( cd "$builddir" && pwd )"
  17. libdir=$builddir/libs
  18. # Test which win32 compiler is present
  19. command -v i686-w64-mingw32-gcc >/dev/null &&
  20. compiler=i686-w64-mingw32-gcc
  21. command -v i686-w64-mingw32-gcc-posix >/dev/null &&
  22. compiler=i686-w64-mingw32-gcc-posix
  23. if [ -z "$compiler" ]; then
  24. echo "Unable to determine which MinGW compiler to use"
  25. exit 1
  26. fi
  27. toolchain_file=$topdir/toolchain_${compiler/-gcc/}.cmake
  28. echo "Using $toolchain_file"
  29. # Try to find runtime DLLs in various paths (varies by distribution, sigh)
  30. tmp=$(dirname "$(command -v $compiler)")/..
  31. runtime_dlls=
  32. for name in lib{gcc_,stdc++-,winpthread-}'*'.dll; do
  33. for dir in $tmp/i686-w64-mingw32/{bin,lib} $tmp/lib/gcc/i686-w64-mingw32/*; do
  34. [ -d "$dir" ] || continue
  35. file=$(echo $dir/$name)
  36. [ -f "$file" ] && { runtime_dlls+="$file;"; break; }
  37. done
  38. done
  39. [ -z "$runtime_dlls" ] &&
  40. echo "The compiler runtime DLLs could not be found, they might be missing in the final package."
  41. # Get stuff
  42. irrlicht_version=$(cat $topdir/../../misc/irrlichtmt_tag.txt)
  43. ogg_version=1.3.5
  44. openal_version=1.21.1
  45. vorbis_version=1.3.7
  46. curl_version=7.81.0
  47. gettext_version=0.20.1
  48. freetype_version=2.11.1
  49. sqlite3_version=3.37.2
  50. luajit_version=2.1.0-beta3
  51. leveldb_version=1.23
  52. zlib_version=1.2.11
  53. zstd_version=1.5.2
  54. mkdir -p $libdir
  55. download () {
  56. local url=$1
  57. local filename=$2
  58. [ -z "$filename" ] && filename=${url##*/}
  59. local foldername=${filename%%[.-]*}
  60. local extract=$3
  61. [ -z "$extract" ] && extract=unzip
  62. [ -d "./$foldername" ] && return 0
  63. wget "$url" -c -O "./$filename"
  64. if [ "$extract" = "unzip" ]; then
  65. unzip -o "$filename" -d "$foldername"
  66. elif [ "$extract" = "unzip_nofolder" ]; then
  67. unzip -o "$filename"
  68. else
  69. return 1
  70. fi
  71. }
  72. # 'dw2' just points to rebuilt versions after a toolchain change
  73. # this distinction should be gotten rid of next time
  74. cd $libdir
  75. download "https://github.com/minetest/irrlicht/releases/download/$irrlicht_version/win32.zip" irrlicht-$irrlicht_version.zip
  76. download "http://minetest.kitsunemimi.pw/dw2/zlib-$zlib_version-win32.zip"
  77. download "http://minetest.kitsunemimi.pw/zstd-$zstd_version-win32.zip"
  78. download "http://minetest.kitsunemimi.pw/libogg-$ogg_version-win32.zip"
  79. download "http://minetest.kitsunemimi.pw/dw2/libvorbis-$vorbis_version-win32.zip"
  80. download "http://minetest.kitsunemimi.pw/curl-$curl_version-win32.zip"
  81. download "http://minetest.kitsunemimi.pw/dw2/gettext-$gettext_version-win32.zip"
  82. download "http://minetest.kitsunemimi.pw/freetype2-$freetype_version-win32.zip" freetype-$freetype_version.zip
  83. download "http://minetest.kitsunemimi.pw/sqlite3-$sqlite3_version-win32.zip"
  84. download "http://minetest.kitsunemimi.pw/dw2/luajit-$luajit_version-win32.zip"
  85. download "http://minetest.kitsunemimi.pw/dw2/libleveldb-$leveldb_version-win32.zip" leveldb-$leveldb_version.zip
  86. download "http://minetest.kitsunemimi.pw/openal-soft-$openal_version-win32.zip"
  87. # Set source dir, downloading Minetest as needed
  88. if [ -n "$EXISTING_MINETEST_DIR" ]; then
  89. sourcedir="$( cd "$EXISTING_MINETEST_DIR" && pwd )"
  90. else
  91. cd $builddir
  92. sourcedir=$PWD/$CORE_NAME
  93. [ -d $CORE_NAME ] && { pushd $CORE_NAME; git pull; popd; } || \
  94. git clone -b $CORE_BRANCH $CORE_GIT $CORE_NAME
  95. if [ -z "$NO_MINETEST_GAME" ]; then
  96. cd $sourcedir
  97. [ -d games/$GAME_NAME ] && { pushd games/$GAME_NAME; git pull; popd; } || \
  98. git clone -b $GAME_BRANCH $GAME_GIT games/$GAME_NAME
  99. fi
  100. fi
  101. git_hash=$(cd $sourcedir && git rev-parse --short HEAD)
  102. # Build the thing
  103. cd $builddir
  104. [ -d build ] && rm -rf build
  105. irr_dlls=$(echo $libdir/irrlicht/lib/*.dll | tr ' ' ';')
  106. vorbis_dlls=$(echo $libdir/libvorbis/bin/libvorbis{,file}-*.dll | tr ' ' ';')
  107. gettext_dlls=$(echo $libdir/gettext/bin/lib{intl,iconv}-*.dll | tr ' ' ';')
  108. cmake -S $sourcedir -B build \
  109. -DCMAKE_TOOLCHAIN_FILE=$toolchain_file \
  110. -DCMAKE_INSTALL_PREFIX=/tmp \
  111. -DVERSION_EXTRA=$git_hash \
  112. -DBUILD_CLIENT=1 -DBUILD_SERVER=0 \
  113. -DEXTRA_DLL="$runtime_dlls" \
  114. \
  115. -DENABLE_SOUND=1 \
  116. -DENABLE_CURL=1 \
  117. -DENABLE_GETTEXT=1 \
  118. -DENABLE_LEVELDB=1 \
  119. \
  120. -DCMAKE_PREFIX_PATH=$libdir/irrlicht \
  121. -DIRRLICHT_DLL="$irr_dlls" \
  122. \
  123. -DZLIB_INCLUDE_DIR=$libdir/zlib/include \
  124. -DZLIB_LIBRARY=$libdir/zlib/lib/libz.dll.a \
  125. -DZLIB_DLL=$libdir/zlib/bin/zlib1.dll \
  126. \
  127. -DZSTD_INCLUDE_DIR=$libdir/zstd/include \
  128. -DZSTD_LIBRARY=$libdir/zstd/lib/libzstd.dll.a \
  129. -DZSTD_DLL=$libdir/zstd/bin/libzstd.dll \
  130. \
  131. -DLUA_INCLUDE_DIR=$libdir/luajit/include \
  132. -DLUA_LIBRARY=$libdir/luajit/libluajit.a \
  133. \
  134. -DOGG_INCLUDE_DIR=$libdir/libogg/include \
  135. -DOGG_LIBRARY=$libdir/libogg/lib/libogg.dll.a \
  136. -DOGG_DLL=$libdir/libogg/bin/libogg-0.dll \
  137. \
  138. -DVORBIS_INCLUDE_DIR=$libdir/libvorbis/include \
  139. -DVORBIS_LIBRARY=$libdir/libvorbis/lib/libvorbis.dll.a \
  140. -DVORBIS_DLL="$vorbis_dlls" \
  141. -DVORBISFILE_LIBRARY=$libdir/libvorbis/lib/libvorbisfile.dll.a \
  142. \
  143. -DOPENAL_INCLUDE_DIR=$libdir/openal/include/AL \
  144. -DOPENAL_LIBRARY=$libdir/openal/lib/libOpenAL32.dll.a \
  145. -DOPENAL_DLL=$libdir/openal/bin/OpenAL32.dll \
  146. \
  147. -DCURL_DLL=$libdir/curl/bin/libcurl-4.dll \
  148. -DCURL_INCLUDE_DIR=$libdir/curl/include \
  149. -DCURL_LIBRARY=$libdir/curl/lib/libcurl.dll.a \
  150. \
  151. -DGETTEXT_MSGFMT=`command -v msgfmt` \
  152. -DGETTEXT_DLL="$gettext_dlls" \
  153. -DGETTEXT_INCLUDE_DIR=$libdir/gettext/include \
  154. -DGETTEXT_LIBRARY=$libdir/gettext/lib/libintl.dll.a \
  155. \
  156. -DFREETYPE_INCLUDE_DIR_freetype2=$libdir/freetype/include/freetype2 \
  157. -DFREETYPE_INCLUDE_DIR_ft2build=$libdir/freetype/include/freetype2 \
  158. -DFREETYPE_LIBRARY=$libdir/freetype/lib/libfreetype.dll.a \
  159. -DFREETYPE_DLL=$libdir/freetype/bin/libfreetype-6.dll \
  160. \
  161. -DSQLITE3_INCLUDE_DIR=$libdir/sqlite3/include \
  162. -DSQLITE3_LIBRARY=$libdir/sqlite3/lib/libsqlite3.dll.a \
  163. -DSQLITE3_DLL=$libdir/sqlite3/bin/libsqlite3-0.dll \
  164. \
  165. -DLEVELDB_INCLUDE_DIR=$libdir/leveldb/include \
  166. -DLEVELDB_LIBRARY=$libdir/leveldb/lib/libleveldb.dll.a \
  167. -DLEVELDB_DLL=$libdir/leveldb/bin/libleveldb.dll
  168. cmake --build build -j$(nproc)
  169. [ -z "$NO_PACKAGE" ] && cmake --build build --target package
  170. exit 0
  171. # EOF