hs-pkg-config-0.1.0.0: Create pkg-config configuration files

Copyright(c) 2014 Peter Trsko
LicenseBSD3
Maintainerpeter.trsko@gmail.com
Stabilityexperimental
PortabilityDeriveDataTypeable, NoImplicitPrelude
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.PkgConfig

Contents

Description

Create pkg-config configuration file from Haskell code using combinators specialized for this purpose.

Synopsis

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

Type Aliases

Serialization

toStrictText :: PkgConfig -> Text Source

Serialize PkgConfig in to strict Text.

I/O

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

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}

Queries

variables :: PkgTemplate -> [Text] Source

List all variables mentioned in PkgTemplate.