From 2958eecabbe790abec8d9ae7b6d1db556f940edf Mon Sep 17 00:00:00 2001 From: Alexander Bondarenko Date: Sat, 14 Nov 2020 12:45:29 +0300 Subject: [PATCH] Make OpenGL dependency conditional Use types from Tensor package as a replacement. --- OpenAL.cabal | 15 +++++++++++++-- src/Sound/OpenAL.hs | 9 +++++++-- src/Sound/OpenAL/AL/Listener.hs | 4 ++++ src/Sound/OpenAL/AL/Source.hs | 6 +++++- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/OpenAL.cabal b/OpenAL.cabal index dd1fc75..67725af 100644 --- a/OpenAL.cabal +++ b/OpenAL.cabal @@ -49,6 +49,10 @@ flag BuildExamples description: Build various OpenAL examples. default: False +flag UseOpenGL + description: Use OpenGL-provided Vertex and Vector types. + default: True + library exposed-modules: Sound.OpenAL @@ -87,8 +91,7 @@ library base >= 3 && < 5, transformers >= 0.2 && < 0.6, ObjectName >= 1.1 && < 1.2, - StateVar >= 1.1 && < 1.3, - OpenGL >= 2.12 && < 3.1 + StateVar >= 1.1 && < 1.3 default-language: Haskell2010 ghc-options: -Wall if impl(ghc > 8) @@ -101,6 +104,14 @@ library frameworks: OpenAL else extra-libraries: openal + if flag(UseOpenGL) + build-depends: + OpenGL >= 2.12 && < 3.1 + cpp-options: + -DUSEOPENGL + else + build-depends: + Tensor >= 1 && < 2 executable TestDevice if !flag(BuildExamples) diff --git a/src/Sound/OpenAL.hs b/src/Sound/OpenAL.hs index 33a19da..1b788f9 100644 --- a/src/Sound/OpenAL.hs +++ b/src/Sound/OpenAL.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} -------------------------------------------------------------------------------- -- | -- Module : Sound.OpenAL @@ -39,7 +40,7 @@ module Sound.OpenAL ( -- * Convenience Re-exports , module Data.ObjectName , module Data.StateVar - , module Graphics.Rendering.OpenGL.GL.Tensor + , module Tensor ) where import Sound.OpenAL.AL @@ -47,7 +48,11 @@ import Sound.OpenAL.ALC import Data.ObjectName import Data.StateVar -import Graphics.Rendering.OpenGL.GL.Tensor ( Vector3(..), Vertex3(..) ) +#ifdef USEOPENGL +import Graphics.Rendering.OpenGL.GL.Tensor as Tensor ( Vector3(..), Vertex3 (..) ) +#else +import Data.Tensor as Tensor ( Vector3(..), Vertex3 (..) ) +#endif -------------------------------------------------------------------------------- -- $ABriefHistoryOfOpenAL diff --git a/src/Sound/OpenAL/AL/Listener.hs b/src/Sound/OpenAL/AL/Listener.hs index bb187ca..6e3c9a7 100644 --- a/src/Sound/OpenAL/AL/Listener.hs +++ b/src/Sound/OpenAL/AL/Listener.hs @@ -42,7 +42,11 @@ import Foreign.Marshal.Array ( allocaArray, withArray ) import Foreign.Marshal.Utils ( with ) import Foreign.Ptr ( Ptr ) import Foreign.Storable ( Storable ) +#ifdef USEOPENGL import Graphics.Rendering.OpenGL.GL.Tensor ( Vector3(..), Vertex3 (..) ) +#else +import Data.Tensor ( Vector3(..), Vertex3 (..) ) +#endif import Sound.OpenAL.AL.BasicTypes import Sound.OpenAL.AL.PeekPoke diff --git a/src/Sound/OpenAL/AL/Source.hs b/src/Sound/OpenAL/AL/Source.hs index bcc040d..a2a2338 100644 --- a/src/Sound/OpenAL/AL/Source.hs +++ b/src/Sound/OpenAL/AL/Source.hs @@ -92,7 +92,11 @@ import Foreign.Marshal.Array ( allocaArray, peekArray, withArrayLen ) import Foreign.Marshal.Utils ( with ) import Foreign.Ptr ( Ptr, castPtr ) import Foreign.Storable ( Storable(..) ) -import Graphics.Rendering.OpenGL.GL.Tensor ( Vector3(..), Vertex3(..) ) +#ifdef USEOPENGL +import Graphics.Rendering.OpenGL.GL.Tensor ( Vector3(..), Vertex3 (..) ) +#else +import Data.Tensor ( Vector3(..), Vertex3 (..) ) +#endif import Sound.OpenAL.AL.ALboolean import Sound.OpenAL.AL.BasicTypes