The hs-pkg-config package

[Tags:bsd3, library]

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

One of the possible usage examples of this library is generating .pc files from Shake build system.

For usage example see Data.PkgConfig module.

[Skip to Readme]


Change log
Dependencies base (>=4.6 && <5), data-default-class (==0.*), text (>=0.11 && <1.3) [details]
License BSD3
Copyright Copyright (c) 2014 Peter Trško
Author Peter Trško
Category Data, Development
Home page
Bug tracker
Source repository head: git clone git://
this: git clone git://
Uploaded Wed Dec 24 11:23:01 UTC 2014 by PeterTrsko
Updated Sun Mar 12 07:47:45 UTC 2017 by PeterTrsko to revision 2
Distributions NixOS:
Downloads 611 total (16 in the last 30 days)
0 []
Status Docs available [build log]
Last success reported on 2014-12-24 [all 1 reports]
Hackage Matrix CI




pedanticPass additional warning flags including -Werror to GHC during compilation.DisabledAutomatic

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info


Maintainer's Corner

For package maintainers and hackage trustees

Readme for hs-pkg-config

Readme for hs-pkg-config-


Hackage BSD3 License


Library for creating pkg-config configuration files from Haskell.

One of the possible usage examples of this library is generating .pc files from Shake build system.


Following Haskell code is able to generate package configuration file named foo.pc for library foo:

{-# LANGUAGE OverloadedStrings #-}
module Main (main)

import Data.String (IsString)

import Data.Default.Class (Default(def))
   -- From data-default-class library:

import Control.Lens
   -- From lens library:

import Data.PkgConfig

libraryBaseName :: IsString a => a
libraryBaseName = "foo"

main :: IO ()
main = writePkgConfig (libraryBaseName ++ ".pc") libPkgConfig
    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 foo.pc:


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

Now lets see if pkg-config would be able to tell us something about this library:

$ PKG_CONFIG_PATH=`pwd` pkg-config --modversion foo

Note that asking for --cflags or other options would result in error saying that it is unable to find bar and baz libraries. That is OK, it means that it is able to parse file correctly, we just hadn't provided bar.pc and baz.pc. If we delete lines that define Requires: field, then pkg-config would be able to give us --cflags, --libs, etc. You can try it.

Building options

  • -fpedantic (disabled by default)

    Pass additional warning flags including -Werror to GHC during compilation.