<commit_before>import Data.Maybe (fromJust)
import Distribution.PackageDescription
import Distribution.Simple
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Install
import Distribution.Simple.Setup
import System.Cmd (system)
import System.Directory
import System.FilePath

main :: IO ()
main = defaultMainWithHooks simpleUserHooks
         { confHook = libClangConfHook
         , cleanHook = libClangCleanHook
         , buildHook = libClangBuildHook
         }

libclangLibraries :: [String]
libclangLibraries =
  [ "-lclang_static"
  , "-lclangARCMigrate"
  , "-lclangAST"
  , "-lclangAnalysis"
  , "-lclangBasic"
  , "-lclangCodeGen"
  , "-lclangDriver"
  , "-lclangEdit"
  , "-lclangFormat"
  , "-lclangFrontend"
  , "-lclangFrontendTool"
  , "-lclangLex"
  , "-lclangParse"
  , "-lclangRewriteCore"
  , "-lclangRewriteFrontend"
  , "-lclangSema"
  , "-lclangSerialization"
  , "-lclangTooling"
  , "-lLLVMSupport"
  , "-lLLVMMCParser"
  , "-lLLVMMC"
  , "-lLLVMBitReader"
  , "-lLLVMCore"
  ]

libClangConfHook (pkg, pbi) flags = do
  lbi <- confHook simpleUserHooks (pkg, pbi) flags

  -- Compute some paths that need to be absolute.
  curDir <- getCurrentDirectory
  let clangRepoDir = curDir </> "clang"
  let llvmPrefixDir = curDir </> "build" </> "out"

  putStrLn "Ensuring the build directory exists..."
  system $ "mkdir -p build"

  putStrLn "Linking clang repository into llvm repository..."
  system $ "ln -sf " ++ (escape clangRepoDir) ++ " llvm/tools/clang"

  putStrLn "Configuring llvm and clang..."
  system $ "cd build && test -e Makefile || ../llvm/configure"
        ++ " --enable-optimized"
        ++ " --disable-clang-rewriter"
        ++ " --disable-clang-static-analyzer"
        ++ " --disable-clang-arcmt"
        ++ " --enable-keep-symbols"
        ++ " --disable-jit"
        ++ " --disable-docs"
        ++ " --enable-bindings=none"
        ++ " --disable-shared"
        ++ " --prefix=" ++ (escape llvmPrefixDir)

  let lpd   = localPkgDescr lbi
  let lib   = fromJust (library lpd)
  let libbi = libBuildInfo lib

  let libbi' = libbi
               { extraLibDirs = extraLibDirs libbi ++ [llvmPrefixDir </> "lib"]
               , includeDirs  = includeDirs  libbi ++ [".", llvmPrefixDir </> "include"]
               , ldOptions    = ldOptions    libbi ++ libclangLibraries
                                                   ++ ["-lstdc++"]
               }

  let lib' = lib { libBuildInfo = libbi' }
  let lpd' = lpd { library = Just lib' }

  return $ lbi { localPkgDescr = lpd' }

libClangBuildHook pkg lbi flags ppHandlers = do<commit_msg>Fix compilation issue on Ubuntu 13.10<commit_after>import Data.Maybe (fromJust)
import Distribution.PackageDescription
import Distribution.Simple
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Install
import Distribution.Simple.Setup
import System.Cmd (system)
import System.Directory
import System.FilePath

main :: IO ()
main = defaultMainWithHooks simpleUserHooks
         { confHook = libClangConfHook
         , cleanHook = libClangCleanHook
         , buildHook = libClangBuildHook
         }

libclangLibraries :: [String]
libclangLibraries =
  [ "-lclang_static"
  , "-lclangARCMigrate"
  , "-lclangAST"
  , "-lclangAnalysis"
  , "-lclangBasic"
  , "-lclangCodeGen"
  , "-lclangDriver"
  , "-lclangEdit"
  , "-lclangFormat"
  , "-lclangFrontend"
  , "-lclangFrontendTool"
  , "-lclangLex"
  , "-lclangParse"
  , "-lclangRewriteCore"
  , "-lclangRewriteFrontend"
  , "-lclangSema"
  , "-lclangSerialization"
  , "-lclangTooling"
  , "-lLLVMSupport"
  , "-lLLVMMCParser"
  , "-lLLVMMC"
  , "-lLLVMBitReader"
  , "-lLLVMCore"
  ]

libClangConfHook (pkg, pbi) flags = do
  lbi <- confHook simpleUserHooks (pkg, pbi) flags

  -- Compute some paths that need to be absolute.
  curDir <- getCurrentDirectory
  let clangRepoDir = curDir </> "clang"
  let llvmPrefixDir = curDir </> "build" </> "out"

  putStrLn "Ensuring the build directory exists..."
  system $ "mkdir -p build"

  putStrLn "Linking clang repository into llvm repository..."
  system $ "ln -sf " ++ (escape clangRepoDir) ++ " llvm/tools/clang"

  putStrLn "Configuring llvm and clang..."
  system $ "cd build && test -e Makefile || ../llvm/configure"
        ++ " --enable-optimized"
        ++ " --disable-clang-rewriter"
        ++ " --disable-clang-static-analyzer"
        ++ " --disable-clang-arcmt"
        ++ " --enable-keep-symbols"
        ++ " --disable-jit"
        ++ " --disable-docs"
        ++ " --enable-bindings=none"
        ++ " --disable-shared"
        ++ " --prefix=" ++ (escape llvmPrefixDir)

  let lpd   = localPkgDescr lbi
  let lib   = fromJust (library lpd)
  let libbi = libBuildInfo lib

  let libbi' = libbi
               { extraLibDirs = extraLibDirs libbi ++ [llvmPrefixDir </> "lib"]
               , includeDirs  = includeDirs  libbi ++ [".", llvmPrefixDir </> "include"]
               , ldOptions    = libclangLibraries  ++
                                ["-lstdc++"]       ++
                                ldOptions    libbi ++
                                libclangLibraries  ++
                                ["-lstdc++"]
               }

  let lib' = lib { libBuildInfo = libbi' }
  let lpd' = lpd { library = Just lib' }

  return $ lbi { localPkgDescr = lpd' }

libClangBuildHook pkg lbi flags ppHandlers = do
{'fraction_non_alphanumeric': 0.13293502613890965, 'fraction_numerical': 0.0007468259895444362, 'mean_word_length': 2.4628312863606983, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5224688', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1785, 'n_words': 378}