diff --git a/cabal.project b/cabal.project index 0f91c7f..414c121 100644 --- a/cabal.project +++ b/cabal.project @@ -1,10 +1,2 @@ packages: ./*.cabal -if os(windows) - package sdl2 - -- Disable searching with pkgconfig on Win, as a DLL is supplied instead - flags: -pkgconfig - - package text - -- Disable use of SIMD, which makes text fails to build on Win + GHC 8.8.4 - flags: -simdutf documentation: true diff --git a/dice_setup.sh b/dice_setup.sh new file mode 100644 index 0000000..cbb3310 --- /dev/null +++ b/dice_setup.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +# Don't run if the sdl2_dice folder or cabal.project.local already exists +if [ -d "sdl2_dice" ] || [ -f "cabal.project.local" ]; then + echo "sdl2_dice folder or cabal.project.local already exists." + echo "Please remove them before running this script." + exit 1 +fi + +# Download the SDL2 2.30.6 libraries +printf "\033[32minfo \033[0m Downloading SDL 2.30.6 libraries...\n" +curl -OLsS https://github.com/libsdl-org/SDL/releases/download/release-2.30.6/SDL2-2.30.6.tar.gz + +# Extract the SDL2 2.30.6 libraries +printf "\033[32minfo \033[0m Extracting SDL 2.30.6 libraries...\n" +tar -xzf SDL2-2.30.6.tar.gz + +# Remove the SDL2 2.30.6 tarball +printf "\033[32minfo \033[0m Removing downloaded SDL2-2.30.6.tar.gz file...\n" +rm SDL2-2.30.6.tar.gz + +# Create a build directory +printf "\033[32minfo \033[0m Temporarily changing dir to SDL source dir...\n" +cd SDL2-2.30.6 || (printf "\033[31mError: SDL2-2.30.6 folder not found.\033[0m\n" && exit 1) +mkdir build +cd build || (printf "\033[31mError: SDL2-2.30.6/build folder not found.\033[0m\n" && exit 1) + +printf "\033[32minfo \033[0m Configuring SDL2 to prepare build...\n" +if ! output=$(../configure --prefix="$(pwd)/../../sdl2_dice" 2>&1); then + printf "\033[31mError configuring SDL2. Check sdl_build_log.txt for more information.\033[0m\n" + echo "$output" >> sdl_build_log.txt + exit 1 +fi +printf "\033[32minfo \033[0m Building SDL2 libraries...\n" +if ! output=$(make 2>&1); then + printf "\033[31mError building SDL2. Check sdl_build_log.txt for more information.\033[0m\n" + echo "$output" >> sdl_build_log.txt + exit 1 +fi +printf "\033[32minfo \033[0m Copying built libraries to new sdl2_dice folder...\n" +if ! output=$(make install 2>&1); then + printf "\033[31mError copying SDL2. Check sdl_build_log.txt for more information.\033[0m\n" + echo "$output" >> sdl_build_log.txt + exit 1 +fi +# Remove log file if it exists because it was successful +rm sdl_build_log.txt 2>/dev/null + +printf "\033[32minfo \033[0m Removing extracted SDL2-2.30.6 directory...\n" +cd ../../ +rm -r SDL2-2.30.6 + +# Create a cabal.project.local file +printf "\033[32minfo \033[0m Creating cabal.project.local file...\n" +cat <> cabal.project.local +package sdl2 + flags: -pkgconfig + extra-lib-dirs: $(pwd)/sdl2_dice/lib + extra-include-dirs: $(pwd)/sdl2_dice/include/SDL2 +EOF + +printf "\033[32mSetup complete! Try running '\033[107m\033[30mcabal run\033[0m\033[32m' to build the project.\033[0m\n" +printf "If you encounter problems, try asking on Discord.\n" + + diff --git a/win_setup.bat b/win_setup.bat index 4561987..24e659e 100644 --- a/win_setup.bat +++ b/win_setup.bat @@ -42,8 +42,14 @@ rem Create a cabal.project.local file containing the path to the local SDL2 libr echo.info  Creating cabal.project.local file... ( echo.package sdl2 +echo. -- Disable pkg-config, as we instead supply the path to the SDL2 libraries manually +echo. flags: -pkgconfig +echo. -- Supply the path to the local SDL2 libraries (must be absolute path) echo. extra-lib-dirs: "%cd:\=\\%\\sdl2_win_mingw\\lib" echo. extra-include-dirs: "%cd:\=\\%\\sdl2_win_mingw\\include\\SDL2" +echo.package text +echo. -- Disable use of SIMD, which makes text fails to build on Win + GHC 8.8.4 +echo. flags: -simdutf )>"cabal.project.local" echo Setup complete! Try running 'cabal run' to build the project. -echo If you encounter problems, try asking Discord. +echo If you encounter problems, try asking on Discord.