#!/bin/bash # Run in SDL 2 source directory on Linux. # Built libraries will be copied to ./ztm-libs/{win32,win64,macos-ub1,macos-ub2} # # Set up: # 1. Windows libaries: # Install mingw-w64 for i686 and x86_64 # # 2. macOS libraries: # Follow osxcross directions to set up macOS (11.3) SDK to build a Universal 2 (arm64/x86_64) dylib. # (I rename osxcross/target/ to osxcross/target-11.3/ but you could change OSXCROSS_TARGET_UB2 below instead.) # # Download rcodesign to ad-hoc sign macOS libraries. # I'm not entirely sure how necessary this is but it fixes broken signiture checksums after using strip. # Info: https://github.com/indygreg/PyOxidizer/tree/main/apple-codesign # Download page: https://github.com/indygreg/PyOxidizer/releases/tag/apple-codesign%2F0.17.0 # # 3. If building SDL < 2.24.0, you can also build Universal 1 dylib with ppc/x86/x86_64. # If you haven't yet, rename osxcross/target/ to osxcross/target-11.3/ # Repeat osxcross set up with macOS 10.13 SDK. Rename osxcross/target/ to osxcross/target-10.13/. # # For Universal 1, you need to extract the SDL 2.0.1 ppc build from ioq3. # git clone https://github.com/ioquake/ioq3 # mkdir ./ztm-libs-ioq3-prebuilt-ppc # x86_64-apple-darwin17-lipo -extract ppc ioq3/code/libs/macos-ub/libSDL2-2.0.0.dylib -o ./ztm-libs-ioq3-prebuilt-ppc/libSDL2-2.0.0.dylib # x86_64-apple-darwin17-lipo -extract ppc ioq3/code/libs/macos-ub/libSDL2main.a -o ./ztm-libs-ioq3-prebuilt-ppc/libSDL2main.a # For building macOS libraries; change for your system. OSXCROSS_TARGET_UB1=$HOME/tools/osxcross/target-10.13 OSXCROSS_TARGET_UB2=$HOME/tools/osxcross/target-11.3 RCODESIGN=$HOME/tools/apple-codesign-0.17.0-x86_64-unknown-linux-musl/rcodesign # You can set this to 0 and then enable one BUILD_* manually below. BUILD_DEFAULT=1 # Build Windows x86 (SDL2.dll). BUILD_WIN32=$BUILD_DEFAULT # Build Windows x86_64 (SDL2.dll). BUILD_WIN64=$BUILD_DEFAULT # Build Windows x86_64 (SDL264.dll). # Renames SDL2.dll to SDL264.dll to match ioquake3 naming convension. BUILD_WIN64_SDL264=$BUILD_DEFAULT # Build macOS Universal Binary 1 (macOS 10.6+, x86, x86_64) # - Merged with pre-built powerpc (macOS 10.5+, ppc) # - Only for SDL < 2.24.0 BUILD_MACOS_UB1=0 # Build macOS Universal Binary 2 (macOS 10.9+, x86_64, arm64) # I'm not sure what the oldest version that works on macOS arm64 is (2.0.14 works). BUILD_MACOS_UB2=$BUILD_DEFAULT if [ -n "$BUILD_WIN32" ] && [ "$BUILD_WIN32" -eq 1 ]; then mkdir -p ztm-mingw-x86 cd ztm-mingw-x86 if [ ! -f ./config.log ]; then ../configure --host=i686-w64-mingw32 --prefix=$(pwd)/prefix fi make -j$(nproc) make install i686-w64-mingw32-strip -x $(pwd)/prefix/bin/*.dll $(pwd)/prefix/lib/*.a mkdir -p ../ztm-libs/win32/ cp $(pwd)/prefix/bin/*.dll $(pwd)/prefix/lib/*.a ../ztm-libs/win32/ cd .. fi if [ -n "$BUILD_WIN64" ] && [ "$BUILD_WIN64" -eq 1 ]; then mkdir -p ztm-mingw-x86_64 cd ztm-mingw-x86_64 if [ ! -f ./config.log ]; then ../configure --host=x86_64-w64-mingw32 --prefix=$(pwd)/prefix fi make -j$(nproc) make install x86_64-w64-mingw32-strip -x $(pwd)/prefix/bin/*.dll $(pwd)/prefix/lib/*.a mkdir -p ../ztm-libs/win64/ cp $(pwd)/prefix/bin/*.dll $(pwd)/prefix/lib/*.a ../ztm-libs/win64/ cd .. fi if [ -n "$BUILD_WIN64_SDL264" ] && [ "$BUILD_WIN64_SDL264" -eq 1 ]; then mkdir -p ztm-mingw-x86_64-sdl264 cd ztm-mingw-x86_64-sdl264 if [ ! -f ./config.log ]; then ../configure --host=x86_64-w64-mingw32 --prefix=$(pwd)/prefix sed -i -s "s/libSDL2/libSDL264/g" Makefile fi make -j$(nproc) make install x86_64-w64-mingw32-strip -x $(pwd)/prefix/bin/*.dll $(pwd)/prefix/lib/*.a mkdir -p ../ztm-libs/win64/ cp $(pwd)/prefix/bin/*.dll $(pwd)/prefix/lib/*.a ../ztm-libs/win64/ cd .. fi if [ -n "$BUILD_MACOS_UB1" ] && [ "$BUILD_MACOS_UB1" -eq 1 ]; then # This needs to be added to PATH for macOS configure and make. export PATH="${OSXCROSS_TARGET_UB1}/bin/:$PATH" # Build macOS x86 (10.13 SDK) mkdir -p ztm-macos-x86-darwin17 cd ztm-macos-x86-darwin17 if [ ! -f ./config.log ]; then ../configure --prefix=$(pwd)/prefix --host=i386-apple-darwin17 CC=i386-apple-darwin17-cc fi make -j$(nproc) make install i386-apple-darwin17-install_name_tool -id "@executable_path/libSDL2-2.0.0.dylib" $(pwd)/prefix/lib/libSDL2-2.0.0.dylib i386-apple-darwin17-strip -x $(pwd)/prefix/lib/libSDL2-2.0.0.dylib $(pwd)/prefix/lib/*.a #mkdir -p ../ztm-libs/x86/ #cp $(pwd)/prefix/lib/*.dylib $(pwd)/prefix/lib/*.a ../ztm-libs/x86/ cd .. # Build macOS x86_64 (10.13 SDK) mkdir -p ztm-macos-x86_64-darwin17 cd ztm-macos-x86_64-darwin17 if [ ! -f ./config.log ]; then ../configure --prefix=$(pwd)/prefix --host=x86_64-apple-darwin17 CC=x86_64-apple-darwin17-cc fi make -j$(nproc) make install x86_64-apple-darwin17-install_name_tool -id "@executable_path/libSDL2-2.0.0.dylib" $(pwd)/prefix/lib/libSDL2-2.0.0.dylib x86_64-apple-darwin17-strip -x $(pwd)/prefix/lib/libSDL2-2.0.0.dylib $(pwd)/prefix/lib/*.a #mkdir -p ../ztm-libs/x86_64/ #cp $(pwd)/prefix/lib/*.dylib $(pwd)/prefix/lib/*.a ../ztm-libs/x86_64/ cd .. # Merge x86, x86_64, and SDL 2.0.1 PPC build from ioquake3. mkdir -p ./ztm-libs/macos-ub1 x86_64-apple-darwin17-lipo -create -o ./ztm-libs/macos-ub1/libSDL2-2.0.0.dylib ./ztm-libs-ioq3-prebuilt-ppc/libSDL2-2.0.0.dylib ./ztm-macos-{x86,x86_64}-darwin17/prefix/lib/libSDL2-2.0.0.dylib x86_64-apple-darwin17-lipo -create -o ./ztm-libs/macos-ub1/libSDL2main.a ./ztm-libs-ioq3-prebuilt-ppc/libSDL2main.a ./ztm-macos-{x86,x86_64}-darwin17/prefix/lib/libSDL2main.a # Ad-hoc sign $RCODESIGN sign ./ztm-libs/macos-ub1/libSDL2-2.0.0.dylib fi if [ -n "$BUILD_MACOS_UB2" ] && [ "$BUILD_MACOS_UB2" -eq 1 ]; then # This needs to be added to PATH for macOS configure and make. export PATH="${OSXCROSS_TARGET_UB2}/bin/:$PATH" # Build macOS x86_64 (11.3 SDK) mkdir -p ztm-macos-x86_64 cd ztm-macos-x86_64 if [ ! -f ./config.log ]; then ../configure --prefix=$(pwd)/prefix --host=x86_64-apple-darwin20.4 CC=x86_64-apple-darwin20.4-cc fi make -j$(nproc) make install x86_64-apple-darwin20.4-install_name_tool -id "@executable_path/libSDL2-2.0.0.dylib" $(pwd)/prefix/lib/libSDL2-2.0.0.dylib x86_64-apple-darwin20.4-strip -x $(pwd)/prefix/lib/libSDL2-2.0.0.dylib $(pwd)/prefix/lib/*.a #mkdir -p ../ztm-libs/x86_64/ #cp $(pwd)/prefix/lib/*.dylib $(pwd)/prefix/lib/*.a ../ztm-libs/x86_64/ cd .. # Build macOS Apple Silicon (11.3 SDK) mkdir -p ztm-macos-aarch64 cd ztm-macos-aarch64 if [ ! -f ./config.log ]; then ../configure --prefix=$(pwd)/prefix --host=aarch64-apple-darwin20.4 CC=aarch64-apple-darwin20.4-cc fi make -j$(nproc) make install aarch64-apple-darwin20.4-install_name_tool -id "@executable_path/libSDL2-2.0.0.dylib" $(pwd)/prefix/lib/libSDL2-2.0.0.dylib aarch64-apple-darwin20.4-strip -x $(pwd)/prefix/lib/libSDL2-2.0.0.dylib $(pwd)/prefix/lib/*.a #mkdir -p ../ztm-libs/aarch64/ #cp $(pwd)/prefix/lib/*.dylib $(pwd)/prefix/lib/*.a ../ztm-libs/aarch64/ cd .. # Merge x86_64 and aarch64 libraries. mkdir -p ./ztm-libs/macos-ub2 aarch64-apple-darwin20.4-lipo -create -o ./ztm-libs/macos-ub2/libSDL2-2.0.0.dylib ./ztm-macos-{x86_64,aarch64}/prefix/lib/libSDL2-2.0.0.dylib aarch64-apple-darwin20.4-lipo -create -o ./ztm-libs/macos-ub2/libSDL2main.a ./ztm-macos-{x86_64,aarch64}/prefix/lib/libSDL2main.a # Ad-hoc sign $RCODESIGN sign ./ztm-libs/macos-ub2/libSDL2-2.0.0.dylib fi