Skip to content

Commit

Permalink
Add DICE setup script, move conditional cabal.project entries to setu…
Browse files Browse the repository at this point in the history
…p script
  • Loading branch information
yutotakano committed Aug 10, 2024
1 parent c00da81 commit 07669e8
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 9 deletions.
8 changes: 0 additions & 8 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -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
65 changes: 65 additions & 0 deletions dice_setup.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF >> 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"


8 changes: 7 additions & 1 deletion win_setup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 07669e8

Please sign in to comment.