Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 79 lines (63 sloc) 2.866 kb
07b6eb6 First steps towards cabalization
sven.panne@aedion.de authored
1 #!/usr/bin/runhaskell
2
3 \begin{code}
00e0242 More cabalization
sven.panne@aedion.de authored
4 module Main where
5
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new caba...
dcoutts authored
6 import Distribution.PackageDescription (PackageDescription(..))
7 import Distribution.Simple.Setup ( BuildFlags(..) )
b94acc4 Guess what? Fixed Cabal-induced breakage (in a totally wrong way)
sven.panne@aedion.de authored
8 import Distribution.Simple ( defaultMainWithHooks, defaultUserHooks, UserHooks(..) )
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new caba...
dcoutts authored
9 import Distribution.Simple.LocalBuildInfo ( LocalBuildInfo(..) )
10 import Distribution.Simple.Program
11
12 import System.FilePath ((</>))
83dc6ea Handle Cabal API changes regarding hooks
sven.panne@aedion.de authored
13 import System.IO.Error ( try )
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new caba...
dcoutts authored
14 import System.Directory (removeFile)
00e0242 More cabalization
sven.panne@aedion.de authored
15
16 main :: IO ()
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new caba...
dcoutts authored
17 main = defaultMainWithHooks defaultUserHooks{ hookedPrograms = [perlProgram],
18 postBuild = myPostBuild,
00e0242 More cabalization
sven.panne@aedion.de authored
19 postClean = myPostClean,
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new caba...
dcoutts authored
20 copyHook = myCopy,
21 instHook = myInstall }
22
23 perlProgram = simpleProgram "perl"
00e0242 More cabalization
sven.panne@aedion.de authored
24
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new caba...
dcoutts authored
25 -- hack to turn cpp-style '# 27 "GenericTemplate.hs"' into
26 -- '{-# LINE 27 "GenericTemplate.hs" #-}'.
27 crazy_perl_regexp =
28 "s/^#\\s+(\\d+)\\s+(\"[^\"]*\")/{-# LINE \\1 \\2 #-}/g;s/\\$(Id:.*)\\$/\\1/g"
c1a3075 sync Setup.lhs with Happy
Simon Marlow authored
29
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new caba...
dcoutts authored
30 myPostBuild _ flags _ lbi = do
31 let runProgram p = rawSystemProgramConf (buildVerbose flags) p (withPrograms lbi)
32 cpp_template src dst opts = do
33 runProgram ghcProgram (["-o", dst, "-E", "-cpp", "templates" </> src] ++ opts)
75f29b2 perl's -i option needs an argument on Windows
Simon Marlow authored
34 runProgram perlProgram ["-i.bak", "-pe", crazy_perl_regexp, dst]
00e0242 More cabalization
sven.panne@aedion.de authored
35
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new caba...
dcoutts authored
36 sequence_ ([ cpp_template "GenericTemplate.hs" dst opts | (dst,opts) <- templates ] ++
37 [ cpp_template "wrappers.hs" dst opts | (dst,opts) <- wrappers ])
00e0242 More cabalization
sven.panne@aedion.de authored
38
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new caba...
dcoutts authored
39 myPostClean _ _ _ _ = mapM_ (try . removeFile) all_template_files
00e0242 More cabalization
sven.panne@aedion.de authored
40
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new caba...
dcoutts authored
41 myInstall pkg_descr lbi hooks flags =
42 instHook defaultUserHooks pkg_descr' lbi hooks flags
43 where pkg_descr' = pkg_descr {
44 dataFiles = dataFiles pkg_descr ++ all_template_files
45 }
00e0242 More cabalization
sven.panne@aedion.de authored
46
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new caba...
dcoutts authored
47 myCopy pkg_descr lbi hooks copy_flags =
48 copyHook defaultUserHooks pkg_descr' lbi hooks copy_flags
49 where pkg_descr' = pkg_descr {
50 dataFiles = dataFiles pkg_descr ++ all_template_files
51 }
00e0242 More cabalization
sven.panne@aedion.de authored
52
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new caba...
dcoutts authored
53 all_template_files :: [FilePath]
54 all_template_files = map fst (templates ++ wrappers)
00e0242 More cabalization
sven.panne@aedion.de authored
55
56 templates :: [(FilePath,[String])]
57 templates = [
58 ("AlexTemplate", []),
59 ("AlexTemplate-ghc", ["-DALEX_GHC"]),
60 ("AlexTemplate-ghc-debug", ["-DALEX_GHC","-DALEX_DEBUG"]),
61 ("AlexTemplate-debug", ["-DALEX_DEBUG"])
62 ]
63
64 wrappers :: [(FilePath,[String])]
65 wrappers = [
66 ("AlexWrapper-basic", ["-DALEX_BASIC"]),
be78353 @dcoutts Add new ByteString wrappers
dcoutts authored
67 ("AlexWrapper-basic-bytestring", ["-DALEX_BASIC_BYTESTRING"]),
197317b @donsbot Add support for efficient lexing of strict bytestrings
donsbot authored
68 ("AlexWrapper-strict-bytestring", ["-DALEX_STRICT_BYTESTRING"]),
00e0242 More cabalization
sven.panne@aedion.de authored
69 ("AlexWrapper-posn", ["-DALEX_POSN"]),
be78353 @dcoutts Add new ByteString wrappers
dcoutts authored
70 ("AlexWrapper-posn-bytestring", ["-DALEX_POSN_BYTESTRING"]),
00e0242 More cabalization
sven.panne@aedion.de authored
71 ("AlexWrapper-monad", ["-DALEX_MONAD"]),
be78353 @dcoutts Add new ByteString wrappers
dcoutts authored
72 ("AlexWrapper-monad-bytestring", ["-DALEX_MONAD_BYTESTRING"]),
57d9d6d monadUserState
alcremi@pobox.com authored
73 ("AlexWrapper-monadUserState", ["-DALEX_MONAD", "-DALEX_MONAD_USER_STATE"]),
74 ("AlexWrapper-monadUserState-bytestring", ["-DALEX_MONAD_BYTESTRING", "-DALEX_MONAD_USER_STATE"]),
00e0242 More cabalization
sven.panne@aedion.de authored
75 ("AlexWrapper-gscan", ["-DALEX_GSCAN"])
76 ]
77
07b6eb6 First steps towards cabalization
sven.panne@aedion.de authored
78 \end{code}
Something went wrong with that request. Please try again.