File: Setup.hs

package info (click to toggle)
haskell-pango 0.13.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 304 kB
  • sloc: haskell: 77; ansic: 35; makefile: 10
file content (56 lines) | stat: -rw-r--r-- 2,262 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{-# LANGUAGE CPP, ViewPatterns #-}
-- Adjustments specific to this package,
-- all Gtk2Hs-specific boilerplate is kept in
-- gtk2hs-buildtools:Gtk2HsSetup
--
import Distribution.Simple ( defaultMainWithHooks, UserHooks(postConf),
                             PackageIdentifier(..), PackageName(..) )
import Gtk2HsSetup ( gtk2hsUserHooks, getPkgConfigPackages)
import Distribution.Simple.Setup ( ConfigFlags(configVerbosity), fromFlag)
import Distribution.Simple.LocalBuildInfo ( LocalBuildInfo(..) )
import Distribution.Simple.BuildPaths ( autogenPackageModulesDir )
import Distribution.Text ( display )
import Distribution.Version ( Version(..) )
import Distribution.Verbosity
import Distribution.Simple.Utils hiding (die)
import System.FilePath
import System.Exit (die)

#if MIN_VERSION_Cabal(2,0,0)
import Distribution.Version ( versionNumbers )
import Distribution.Types.PackageName ( unPackageName )
#endif

main =
  defaultMainWithHooks gtk2hsUserHooks {

    postConf = \args cf pd lbi -> do
      let verb = (fromFlag (configVerbosity cf))
      cPkgs <- getPkgConfigPackages verb lbi pd
      let [pangoVersion] = [ v | PackageIdentifier (unPackageName -> "pango") v <- cPkgs ]
      writePangoVersionHeaderFile verb lbi pangoVersion
      postConf gtk2hsUserHooks args cf pd lbi
  }

------------------------------------------------------------------------------
-- Generate CPP defines for version of C libs.
------------------------------------------------------------------------------

writePangoVersionHeaderFile :: Verbosity -> LocalBuildInfo -> Version -> IO ()
#if MIN_VERSION_Cabal(2,0,0)
writePangoVersionHeaderFile verbosity lbi (versionNumbers -> (major:minor:micro:_)) = do
#else
writePangoVersionHeaderFile verbosity lbi (Version (major:minor:micro:_) []) = do
#endif
  createDirectoryIfMissingVerbose verbosity True targetDir
  rewriteFileEx verbosity targetFile $ unlines
    [ "#define PANGO_VERSION_MAJOR " ++ show major
    , "#define PANGO_VERSION_MINOR " ++ show minor
    , "#define PANGO_VERSION_MICRO " ++ show micro
    ]
  where
    targetDir  = autogenPackageModulesDir lbi
    targetFile = targetDir </> "hspangoversion.h"

writeVersionHeaderFile _ _ version =
  die $ "unexpected pango version number: " ++ display version