2017-01-31 01:00:38 +03:00
|
|
|
import Distribution.Simple
|
2017-01-31 20:45:09 +03:00
|
|
|
import Distribution.PackageDescription
|
|
|
|
import Distribution.Simple.Setup
|
|
|
|
import Distribution.Simple.Utils
|
2017-01-31 20:58:38 +03:00
|
|
|
import Distribution.Simple.LocalBuildInfo
|
|
|
|
import Data.Maybe
|
|
|
|
import System.Directory
|
2017-01-31 22:05:27 +03:00
|
|
|
import Distribution.System
|
2017-01-31 20:58:38 +03:00
|
|
|
import System.FilePath.Posix
|
|
|
|
|
|
|
|
main = defaultMainWithHooks simpleUserHooks {
|
2017-01-31 21:16:47 +03:00
|
|
|
preConf = makeScannerLib,
|
|
|
|
confHook = \a f -> confHook simpleUserHooks a f >>= updateExtraLibDirs,
|
|
|
|
postClean = cleanScannerLib
|
2017-01-31 20:58:38 +03:00
|
|
|
}
|
2017-01-31 20:45:09 +03:00
|
|
|
|
|
|
|
makeScannerLib :: Args -> ConfigFlags -> IO HookedBuildInfo
|
|
|
|
makeScannerLib _ flags = do
|
2017-01-31 21:16:47 +03:00
|
|
|
let verbosity = fromFlag $ configVerbosity flags
|
|
|
|
rawSystemExit verbosity "env" ["mkdir", "-p", "lib"]
|
2017-01-31 22:56:27 +03:00
|
|
|
rawSystemExit verbosity "env" ["g++", "-Ivendor/tree-sitter-ruby/src/", "-fPIC", "vendor/tree-sitter-ruby/src/scanner.cc", "-c", "-o", "lib/scanner.o"]
|
2017-01-31 21:16:47 +03:00
|
|
|
rawSystemExit verbosity "env" ["ar", "rcvs", "lib/libscanner.a", "lib/scanner.o"]
|
|
|
|
pure emptyHookedBuildInfo
|
2017-01-31 20:58:38 +03:00
|
|
|
|
|
|
|
updateExtraLibDirs :: LocalBuildInfo -> IO LocalBuildInfo
|
|
|
|
updateExtraLibDirs localBuildInfo = do
|
2017-01-31 21:16:47 +03:00
|
|
|
let packageDescription = localPkgDescr localBuildInfo
|
|
|
|
lib = fromJust $ library packageDescription
|
|
|
|
libBuild = libBuildInfo lib
|
|
|
|
dir <- getCurrentDirectory
|
|
|
|
pure localBuildInfo {
|
|
|
|
localPkgDescr = packageDescription {
|
|
|
|
library = Just $ lib {
|
|
|
|
libBuildInfo = libBuild {
|
|
|
|
extraLibDirs = (dir </> "lib") : extraLibDirs libBuild
|
2017-01-31 20:58:38 +03:00
|
|
|
}
|
2017-01-31 21:16:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanScannerLib :: Args -> CleanFlags -> PackageDescription -> () -> IO ()
|
|
|
|
cleanScannerLib _ flags _ _ = do
|
|
|
|
let verbosity = fromFlag $ cleanVerbosity flags
|
|
|
|
dir <- getCurrentDirectory
|
2017-01-31 21:26:58 +03:00
|
|
|
rawSystemExit verbosity "env" ["rm", "-rf", dir </> "lib"]
|