Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 95 lines (79 sloc) 3.688 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
0885497 @drull95 eliminated compiler warnings by updating cabal file, underscoring unu…
drull95 authored
6 import Distribution.Verbosity
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new c…
dcoutts authored
7 import Distribution.PackageDescription (PackageDescription(..))
0885497 @drull95 eliminated compiler warnings by updating cabal file, underscoring unu…
drull95 authored
8 import Distribution.Simple.Setup ( BuildFlags(..), buildVerbosity, fromFlagOrDefault )
9 import Distribution.Simple ( defaultMainWithHooks, simpleUserHooks, UserHooks(..) )
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new c…
dcoutts authored
10 import Distribution.Simple.LocalBuildInfo ( LocalBuildInfo(..) )
11 import Distribution.Simple.Program
12
13 import System.FilePath ((</>))
0885497 @drull95 eliminated compiler warnings by updating cabal file, underscoring unu…
drull95 authored
14 import Control.Exception ( IOException, try )
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new c…
dcoutts authored
15 import System.Directory (removeFile)
00e0242 More cabalization
sven.panne@aedion.de authored
16
17 main :: IO ()
0885497 @drull95 eliminated compiler warnings by updating cabal file, underscoring unu…
drull95 authored
18 main = defaultMainWithHooks simpleUserHooks{ postBuild = myPostBuild,
19 postClean = myPostClean,
20 copyHook = myCopy,
21 instHook = myInstall }
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new c…
dcoutts authored
22
23 -- hack to turn cpp-style '# 27 "GenericTemplate.hs"' into
24 -- '{-# LINE 27 "GenericTemplate.hs" #-}'.
962336d @simonmar Drop dependency on Perl
authored
25 mungeLinePragma line = case symbols line of
26 ["#", number, string] | length string >= 2
27 && head string == '"'
28 && last string == '"'
29 -> case reads number of
30 [(n, "")] -> "{-# LINE " ++ show (n :: Int) ++ " " ++ string ++ " #-}"
31 _ -> line
32 -- Also convert old-style CVS lines, no idea why we do this...
33 ("--":"$":"Id":":":_) -> filter (/='$') line
34 ( "$":"Id":":":_) -> filter (/='$') line
35 _ -> line
36
37 symbols :: String -> [String]
38 symbols cs = case lex cs of
39 (sym, cs'):_ | not (null sym) -> sym : symbols cs'
40 _ -> []
c1a3075 sync Setup.lhs with Happy
Simon Marlow authored
41
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new c…
dcoutts authored
42 myPostBuild _ flags _ lbi = do
0885497 @drull95 eliminated compiler warnings by updating cabal file, underscoring unu…
drull95 authored
43 let verbosity = fromFlagOrDefault normal (buildVerbosity flags)
44 runProgram p = rawSystemProgramConf verbosity p (withPrograms lbi)
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new c…
dcoutts authored
45 cpp_template src dst opts = do
962336d @simonmar Drop dependency on Perl
authored
46 let tmp = dst ++ ".tmp"
47 runProgram ghcProgram (["-o", tmp, "-E", "-cpp", "templates" </> src] ++ opts)
48 writeFile dst . unlines . map mungeLinePragma . lines =<< readFile tmp
49 removeFile tmp
00e0242 More cabalization
sven.panne@aedion.de authored
50
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new c…
dcoutts authored
51 sequence_ ([ cpp_template "GenericTemplate.hs" dst opts | (dst,opts) <- templates ] ++
52 [ cpp_template "wrappers.hs" dst opts | (dst,opts) <- wrappers ])
00e0242 More cabalization
sven.panne@aedion.de authored
53
0885497 @drull95 eliminated compiler warnings by updating cabal file, underscoring unu…
drull95 authored
54 myPostClean _ _ _ _ = let try' = try :: IO a -> IO (Either IOException a)
55 in mapM_ (try' . removeFile) all_template_files
00e0242 More cabalization
sven.panne@aedion.de authored
56
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new c…
dcoutts authored
57 myInstall pkg_descr lbi hooks flags =
0885497 @drull95 eliminated compiler warnings by updating cabal file, underscoring unu…
drull95 authored
58 instHook simpleUserHooks pkg_descr' lbi hooks flags
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new c…
dcoutts authored
59 where pkg_descr' = pkg_descr {
60 dataFiles = dataFiles pkg_descr ++ all_template_files
61 }
00e0242 More cabalization
sven.panne@aedion.de authored
62
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new c…
dcoutts authored
63 myCopy pkg_descr lbi hooks copy_flags =
0885497 @drull95 eliminated compiler warnings by updating cabal file, underscoring unu…
drull95 authored
64 copyHook simpleUserHooks pkg_descr' lbi hooks copy_flags
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new c…
dcoutts authored
65 where pkg_descr' = pkg_descr {
66 dataFiles = dataFiles pkg_descr ++ all_template_files
67 }
00e0242 More cabalization
sven.panne@aedion.de authored
68
532e918 @dcoutts Use configurations to allow to build with old ghc, but requires new c…
dcoutts authored
69 all_template_files :: [FilePath]
70 all_template_files = map fst (templates ++ wrappers)
00e0242 More cabalization
sven.panne@aedion.de authored
71
72 templates :: [(FilePath,[String])]
73 templates = [
74 ("AlexTemplate", []),
75 ("AlexTemplate-ghc", ["-DALEX_GHC"]),
76 ("AlexTemplate-ghc-debug", ["-DALEX_GHC","-DALEX_DEBUG"]),
77 ("AlexTemplate-debug", ["-DALEX_DEBUG"])
78 ]
79
80 wrappers :: [(FilePath,[String])]
81 wrappers = [
82 ("AlexWrapper-basic", ["-DALEX_BASIC"]),
be78353 @dcoutts Add new ByteString wrappers
dcoutts authored
83 ("AlexWrapper-basic-bytestring", ["-DALEX_BASIC_BYTESTRING"]),
197317b @donsbot Add support for efficient lexing of strict bytestrings
donsbot authored
84 ("AlexWrapper-strict-bytestring", ["-DALEX_STRICT_BYTESTRING"]),
00e0242 More cabalization
sven.panne@aedion.de authored
85 ("AlexWrapper-posn", ["-DALEX_POSN"]),
be78353 @dcoutts Add new ByteString wrappers
dcoutts authored
86 ("AlexWrapper-posn-bytestring", ["-DALEX_POSN_BYTESTRING"]),
00e0242 More cabalization
sven.panne@aedion.de authored
87 ("AlexWrapper-monad", ["-DALEX_MONAD"]),
be78353 @dcoutts Add new ByteString wrappers
dcoutts authored
88 ("AlexWrapper-monad-bytestring", ["-DALEX_MONAD_BYTESTRING"]),
57d9d6d monadUserState
alcremi@pobox.com authored
89 ("AlexWrapper-monadUserState", ["-DALEX_MONAD", "-DALEX_MONAD_USER_STATE"]),
90 ("AlexWrapper-monadUserState-bytestring", ["-DALEX_MONAD_BYTESTRING", "-DALEX_MONAD_USER_STATE"]),
00e0242 More cabalization
sven.panne@aedion.de authored
91 ("AlexWrapper-gscan", ["-DALEX_GSCAN"])
92 ]
93
07b6eb6 First steps towards cabalization
sven.panne@aedion.de authored
94 \end{code}
Something went wrong with that request. Please try again.