Copyright | (c) 2014 Peter Trsko |
---|---|
License | BSD3 |
Maintainer | peter.trsko@gmail.com |
Stability | experimental |
Portability | DeriveDataTypeable, NoImplicitPrelude |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Create pkg-config configuration file from Haskell code using combinators specialized for this purpose.
- data PkgConfig
- pkgVariables :: Functor f => ([PkgVariable] -> f [PkgVariable]) -> PkgConfig -> f PkgConfig
- pkgName :: Functor f => (Text -> f Text) -> PkgConfig -> f PkgConfig
- pkgDescription :: Functor f => (Text -> f Text) -> PkgConfig -> f PkgConfig
- pkgUrl :: Functor f => (Text -> f Text) -> PkgConfig -> f PkgConfig
- pkgVersion :: Functor f => (PkgTemplate -> f PkgTemplate) -> PkgConfig -> f PkgConfig
- pkgRequires :: Functor f => (PkgTemplate -> f PkgTemplate) -> PkgConfig -> f PkgConfig
- pkgRequiresPrivate :: Functor f => (PkgTemplate -> f PkgTemplate) -> PkgConfig -> f PkgConfig
- pkgConflicts :: Functor f => (PkgTemplate -> f PkgTemplate) -> PkgConfig -> f PkgConfig
- pkgCflags :: Functor f => (PkgTemplate -> f PkgTemplate) -> PkgConfig -> f PkgConfig
- pkgLibs :: Functor f => (PkgTemplate -> f PkgTemplate) -> PkgConfig -> f PkgConfig
- pkgLibsPrivate :: Functor f => (PkgTemplate -> f PkgTemplate) -> PkgConfig -> f PkgConfig
- type PkgDescription = Text
- type PkgName = Text
- type PkgUrl = Text
- type PkgVariable = (Text, PkgTemplate)
- type PkgVersion = PkgTemplate
- toStrictText :: PkgConfig -> Text
- writePkgConfig :: FilePath -> PkgConfig -> IO ()
- type PkgTemplate = Template
- var :: Text -> PkgTemplate
- lit :: Text -> PkgTemplate
- strLit :: String -> PkgTemplate
- singletonLit :: Char -> PkgTemplate
- (</>) :: PkgTemplate -> PkgTemplate -> PkgTemplate
- (<.>) :: PkgTemplate -> PkgTemplate -> PkgTemplate
- version :: [Word] -> PkgTemplate
- (~=) :: Text -> [Word] -> PkgTemplate
- (~/=) :: Text -> [Word] -> PkgTemplate
- (~<) :: Text -> [Word] -> PkgTemplate
- (~>) :: Text -> [Word] -> PkgTemplate
- (~<=) :: Text -> [Word] -> PkgTemplate
- (~>=) :: Text -> [Word] -> PkgTemplate
- includes :: [PkgTemplate] -> PkgTemplate
- libraries :: [PkgTemplate] -> PkgTemplate
- libraryPath :: [PkgTemplate] -> PkgTemplate
- list :: [PkgTemplate] -> PkgTemplate
- options :: [PkgTemplate] -> PkgTemplate
- separatedBy :: Text -> [PkgTemplate] -> PkgTemplate
- variables :: PkgTemplate -> [Text]
Usage
Following code is able to generate foo.pc
, a pkg-config configuration
file for library foo
:
{-# LANGUAGE OverloadedStrings #-} module Main (main) where import Data.Default.Class (Default
(def
)) import Data.String (IsString
) import Control.Lens import Data.PkgConfig libraryBaseName ::IsString
a => a libraryBaseName = "foo" main :: IO () main =writePkgConfig
(libraryBaseName++
".pc") libPkgConfig where libPkgConfig =def
&pkgVariables
.~
[ ("prefix", "/usr/local" ) , ("includedir",var
"prefix"</>
"include") , ("libdir",var
"prefix"</>
"lib" ) , ("arch", "i386" ) ] &pkgName
.~
libraryBaseName &pkgDescription
.~
"Example pkg-config." &pkgVersion
.~
version
[1, 2, 3] &pkgCflags
.~
includes
[var
"includedir"] &pkgRequires
.~
list
[ "bar"~>
[0], "bar"~<=
[3, 1] , "baz"~=
[1, 2, 3] ] &pkgLibs
.~
options [libraryPath
[var
"libdir",var
"libdir"</>
var
"arch"] ,libraries
[libraryBaseName] ]
Content of generated foo.pc
:
prefix=/usr/local includedir=${prefix}/include libdir=${prefix}/lib arch=i386 Name: foo Description: Example pkg-config. Version: 1.2.3 Requires: bar > 0, bar <= 3.1, baz = 1.2.3 Cflags: -I${includedir} Libs: -L${libdir} -L${libdir}/${arch} -lfoo
PkgConfig
Lenses
pkgVariables :: Functor f => ([PkgVariable] -> f [PkgVariable]) -> PkgConfig -> f PkgConfig Source
pkgVersion :: Functor f => (PkgTemplate -> f PkgTemplate) -> PkgConfig -> f PkgConfig Source
pkgRequires :: Functor f => (PkgTemplate -> f PkgTemplate) -> PkgConfig -> f PkgConfig Source
pkgRequiresPrivate :: Functor f => (PkgTemplate -> f PkgTemplate) -> PkgConfig -> f PkgConfig Source
pkgConflicts :: Functor f => (PkgTemplate -> f PkgTemplate) -> PkgConfig -> f PkgConfig Source
pkgCflags :: Functor f => (PkgTemplate -> f PkgTemplate) -> PkgConfig -> f PkgConfig Source
pkgLibs :: Functor f => (PkgTemplate -> f PkgTemplate) -> PkgConfig -> f PkgConfig Source
pkgLibsPrivate :: Functor f => (PkgTemplate -> f PkgTemplate) -> PkgConfig -> f PkgConfig Source
Type Aliases
type PkgDescription = Text Source
type PkgVariable = (Text, PkgTemplate) Source
type PkgVersion = PkgTemplate Source
Serialization
I/O
writePkgConfig :: FilePath -> PkgConfig -> IO () Source
PkgTemplate
type PkgTemplate = Template Source
Template consists of variables and literal strings. All special characters ('$', '#', '\' and end-of-line sequences) contained in literals are escaped when serialized.
Smart Constructors
var :: Text -> PkgTemplate Source
Construct variable fragment of template.
>>>
var "prefix" <> lit "/bin"
$prefix/bin
lit :: Text -> PkgTemplate Source
Construct literal fragment of template. This is useful if language extension OverloadedStrings is not enabled.
>>>
var "prefix" <> lit "/bin"
$prefix/bin
strLit :: String -> PkgTemplate Source
Create PkgTemplate
literal from String
by packing it in to strict
Text
first.
singletonLit :: Char -> PkgTemplate Source
Crate one character long PkgTemplate
literal.
File Path Combinators
(</>) :: PkgTemplate -> PkgTemplate -> PkgTemplate Source
Put literal "/" between two templates.
>>>
var "prefix" </> lit "foo" <.> lit "pc"
${prefix}/foo.pc
(<.>) :: PkgTemplate -> PkgTemplate -> PkgTemplate Source
Put literal "." between two templates.
>>>
var "prefix" </> lit "foo" <.> lit "pc"
${prefix}/foo.pc>>>
var "major" <.> var "minor" <.> var "patch"
${major}.${minor}.${patch}
Version Combinators
version :: [Word] -> PkgTemplate Source
Treat list of integers as version number and construct template literal out of it.
>>>
version [1, 2, 3]
1.2.3>>>
version [] == mempty
True
(~=) :: Text -> [Word] -> PkgTemplate Source
(~/=) :: Text -> [Word] -> PkgTemplate Source
(~<) :: Text -> [Word] -> PkgTemplate Source
(~>) :: Text -> [Word] -> PkgTemplate Source
(~<=) :: Text -> [Word] -> PkgTemplate Source
(~>=) :: Text -> [Word] -> PkgTemplate Source
Options Combinators
includes :: [PkgTemplate] -> PkgTemplate Source
Take list of templates and make compiler include options.
>>>
let d = var "prefix" </> "include" in includes [d, d </> var "arch"]
-I${prefix}/include -I${prefix}/include/${arch}
libraries :: [PkgTemplate] -> PkgTemplate Source
Take list of templates and make compiler library options.
>>>
libraries ["m", "rt", "foo"]
-lm -lrt -lfoo
libraryPath :: [PkgTemplate] -> PkgTemplate Source
Take list of templates and make compiler library path options.
>>>
let l = var "prefix" </> lit "lib" in libraryPath [l, l </> var "arch"]
-L${prefix}/lib -L${prefix}/lib/${arch}
Specialized Folds
list :: [PkgTemplate] -> PkgTemplate Source
Concatenate templates by inserting coma (',') in between.
>>>
list ["foo" .= [1,2,3], "bar" .> [0], "bar" .< [3,1]]
foo = 1.2.3, bar > 0, bar < 3.1
options :: [PkgTemplate] -> PkgTemplate Source
Concatenate templates by inserting space (' ') in between.
>>>
options ["-I" <> var "prefix" </> "lib", "-I" <> var "extra"]
-I${prefix}/lib -I${extra}
separatedBy :: Text -> [PkgTemplate] -> PkgTemplate Source
Queries
variables :: PkgTemplate -> [Text] Source
List all variables mentioned in PkgTemplate
.