| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Foreign.Hoppy.Setup
Description
Implementations of Cabal setup programs for use in packages of generated bindings.
Much like the default Setup.hs that Cabal recommends for packages,
import Distribution.Simple
main = defaultMain
this module provides simplified configuration of packages for generated bindings. Suppose you have a project named foobar that is composed of Cabal packages named "foobar-generator" for the code generator, "foobar-cpp" for the C++ gateway, and "foobar" for the Haskell gateway. The C++ gateway package can use the following code:
import Foreign.Hoppy.Setup (ProjectConfig(..),cppMain) main = cppMain $ ProjectConfig { generatorExecutableName = "foobar-generator" , cppPackageName = "foobar-cpp" , cppSourcesDir = "cpp" , hsSourcesDir = "src" }
The Haskell gateway uses the same code, except calling hsMain instead of
cppMain. This causes C++ sources to be generated in foobar-cpp/cpp and
(assuming the Haskell gateway is at foobar/) the Haskell sources to be
generated in foobar/src.
The gateway packages need to set build-type: Custom in their .cabal files
to use these setup files.
Synopsis
- data ProjectConfig = ProjectConfig {}
- cppMain :: ProjectConfig -> IO ()
- cppUserHooks :: ProjectConfig -> UserHooks
- hsMain :: ProjectConfig -> IO ()
- hsUserHooks :: ProjectConfig -> UserHooks
Documentation
data ProjectConfig Source #
Configuration parameters for a project using Hoppy.
Constructors
| ProjectConfig | |
Fields
| |
cppMain :: ProjectConfig -> IO () Source #
A main implementation to be used in the Setup.hs of a C++ gateway
package.
cppMain project =defaultMainWithHooks$cppUserHooksproject
cppUserHooks :: ProjectConfig -> UserHooks Source #
Cabal user hooks for a C++ gateway package. When overriding fields in the result, be sure to call the previous hook.
The following hooks are defined:
postConf: Runs the generator program to generate C++ sources. Checks if aconfigurescript exists in the C++ gateway root, and calls it if so (without arguments).buildHook: Runsmakewith no arguments from the C++ gateway root.copyHookandinstHook: Runsmake install libdir=$libdirwhere$libdiris the directory into which to install the built shared library.cleanHook: Removes files created by the generator, then callsmake clean.
hsMain :: ProjectConfig -> IO () Source #
A main implementation to be used in the Setup.hs of a Haskell gateway
package.
hsMain project =defaultMainWithHooks$hsUserHooksproject
hsUserHooks :: ProjectConfig -> UserHooks Source #
Cabal user hooks for a Haskell gateway package. When overriding fields in the result, be sure to call the previous hook.
The following hooks are defined:
postConf: Finds the shared library directory for the installed C++ gateway package, and writes this path to adist/build/hoppy-cpp-libdirfile. Runs the generator program to generate Haskell sources.preBuild,preTest,preCopy,preInst,preReg: Reads the C++ library directory fromdist/build/hoppy-cpp-libdirand adds it to the library search path (extraLibDirs).cleanHook: Removes files created by the generator.