Skip to content

Commit

Permalink
Create setup script for Windows SDL as cabal flags don't support rela…
Browse files Browse the repository at this point in the history
…tive paths
  • Loading branch information
yutotakano committed Aug 9, 2024
1 parent b4f3eeb commit 7c65fa2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
5 changes: 4 additions & 1 deletion HaskellGameJamTemplate.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ maintainer: changeme@ed.ac.uk
-- copyright:

category: Game
build-type: Simple
if os(windows)
build-type: Custom
else
build-type: Simple

executable Game
ghc-options: -Wall
Expand Down
49 changes: 49 additions & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Distribution.PackageDescription
( GenericPackageDescription
, HookedBuildInfo
, extraLibDirs
, includeDirs
, libBuildInfo
, library
)
import Distribution.Simple
( Args
, UserHooks
, confHook
, defaultMainWithHooks
, simpleUserHooks
)
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo
, localPkgDescr
)
import Distribution.Simple.Setup
( ConfigFlags
)
import Data.Maybe
( fromJust
)
import System.Directory
( getCurrentDirectory
)

main :: IO ()
main = defaultMainWithHooks simpleUserHooks { confHook = sdlConfHook }

sdlConfHook :: (GenericPackageDescription, HookedBuildInfo) -> ConfigFlags -> IO LocalBuildInfo
sdlConfHook (description, buildInfo) flags = do
localBuildInfo <- confHook simpleUserHooks (description, buildInfo) flags
let packageDescription = localPkgDescr localBuildInfo
library = fromJust $ library packageDescription
libraryBuildInfo = libBuildInfo library
dir <- getCurrentDirectory
return localBuildInfo {
localPkgDescr = packageDescription {
library = Just $ library {
libBuildInfo = libraryBuildInfo {
includeDirs = (dir ++ "/sdl/include"):(includeDirs libraryBuildInfo),
extraLibDirs = (dir ++ "/sdl/lib"):(extraLibDirs libraryBuildInfo)
}
}
}
}
2 changes: 0 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ if os(windows)
-- is found in the system package manager.
-- On Linux, run: apt-get install libsdl2-dev
-- On OSX, run: brew install sdl2
extra-include-dirs: sdl/include
extra-lib-dirs: sdl/lib

package text
-- Disable use of SIMD, which makes text fails to build on Win + GHC 8.8.4
Expand Down

0 comments on commit 7c65fa2

Please sign in to comment.