<commit_before>{-# LANGUAGE NoImplicitPrelude #-}
module Package.Compile (buildPackageCompile) where

import Package.Base
import Development.Shake.Util

{- "inplace/bin/ghc-stage1.exe" -hisuf hi -osuf  o -hcsuf hc
-static  -H32m -O
-this-package-key deeps_FT5iVCELxOr62eHY0nbvnU -hide-all-packages
-i -ilibraries/deepseq/. -ilibraries/deepseq/dist-install/build
-ilibraries/deepseq/dist-install/build/autogen
-Ilibraries/deepseq/dist-install/build
-Ilibraries/deepseq/dist-install/build/autogen
-Ilibraries/deepseq/.    
-optP-include -optPlibraries/deepseq/dist-install/build/autogen/cabal_macros.h
-package-key <KEY>
-package-key <KEY>
-package-key <KEY>
-Wall -XHaskell2010 -O2  -no-user-package-db -rtsopts      
-odir libraries/deepseq/dist-install/build
-hidir libraries/deepseq/dist-install/build
-stubdir libraries/deepseq/dist-install/build
-split-objs 
-c libraries/deepseq/./Control/DeepSeq.hs
-o libraries/deepseq/dist-install/build/Control/DeepSeq.o -}

suffixArgs :: Way -> Args
suffixArgs way = arg ["-hisuf", hisuf way]
              <> arg [ "-osuf",  osuf way]
              <> arg ["-hcsuf", hcsuf way]

oRule :: Package -> TodoItem -> Rules ()
oRule (Package name path _) (stage, dist, settings) =
    let buildDir = path </> dist </> "build"
        pkgData  = path </> dist </> "package-data.mk"
        depFile  = buildDir </> name <.> "m"
    in
    (buildDir <//> "*o") %> \out -> do
        let way  = detectWay $ tail $ takeExtension out
        need ["shake/src/Package/Compile.hs"]
        need [depFile]
        depContents <- parseMakefile <$> (liftIO $ readFile depFile)
        let deps = concat $ snd $ unzip $ filter ((== out) . fst) depContents
            srcs = filter ("//*hs" ?==) deps -- TODO: handle *.c sources
        need deps
        terseRun (Ghc stage) $ suffixArgs way
            <> wayHcArgs way
            <> arg SrcHcOpts
            <> packageArgs stage pkgData
            <> includeArgs path dist
            <> concatArgs ["-optP"] (CppOpts pkgData) 
            -- TODO: now we have both -O and -O2
            <> arg ["-Wall", "-XHaskell2010", "-O2"]
            <> productArgs ["-odir", "-hidir", "-stubdir"] buildDir
            <> when (splitObjects stage) (arg "-split-objs")
            <> arg ("-c":srcs)
            <> arg ["-o", toStandard out]

-- TODO: This rule looks hacky... combine it with the above?
hiRule :: Package -> TodoItem -> Rules ()
hiRule (Package name path _) (stage, dist, settings) =
    let buildDir = path </> dist </> "build"
    in
    (buildDir <//> "*hi") %> \out -> do
        let way  = detectWay $ tail $ takeExtension out
            oFile = out -<.> osuf way
        need [oFile]

buildPackageCompile :: Package -> TodoItem -> Rules ()
buildPackageCompile = oRule <> hiRule<commit_msg>Add toStandard.<commit_after>{-# LANGUAGE NoImplicitPrelude #-}
module Package.Compile (buildPackageCompile) where

import Package.Base
import Development.Shake.Util

{- "inplace/bin/ghc-stage1.exe" -hisuf hi -osuf  o -hcsuf hc
-static  -H32m -O
-this-package-key deeps_FT5iVCELxOr62eHY0nbvnU -hide-all-packages
-i -ilibraries/deepseq/. -ilibraries/deepseq/dist-install/build
-ilibraries/deepseq/dist-install/build/autogen
-Ilibraries/deepseq/dist-install/build
-Ilibraries/deepseq/dist-install/build/autogen
-Ilibraries/deepseq/.    
-optP-include -optPlibraries/deepseq/dist-install/build/autogen/cabal_macros.h
-package-key <KEY>
-package-key <KEY>
-package-key <KEY>
-Wall -XHaskell2010 -O2  -no-user-package-db -rtsopts      
-odir libraries/deepseq/dist-install/build
-hidir libraries/deepseq/dist-install/build
-stubdir libraries/deepseq/dist-install/build
-split-objs 
-c libraries/deepseq/./Control/DeepSeq.hs
-o libraries/deepseq/dist-install/build/Control/DeepSeq.o -}

suffixArgs :: Way -> Args
suffixArgs way = arg ["-hisuf", hisuf way]
              <> arg [ "-osuf",  osuf way]
              <> arg ["-hcsuf", hcsuf way]

oRule :: Package -> TodoItem -> Rules ()
oRule (Package name path _) (stage, dist, settings) =
    let buildDir = toStandard $ path </> dist </> "build"
        pkgData  = toStandard $ path </> dist </> "package-data.mk"
        depFile  = buildDir </> name <.> "m"
    in
    (buildDir <//> "*o") %> \out -> do
        let way  = detectWay $ tail $ takeExtension out
        need ["shake/src/Package/Compile.hs"]
        need [depFile]
        depContents <- parseMakefile <$> (liftIO $ readFile depFile)
        let deps = concat $ snd $ unzip $ filter ((== out) . fst) depContents
            srcs = filter ("//*hs" ?==) deps -- TODO: handle *.c sources
        need deps
        terseRun (Ghc stage) $ suffixArgs way
            <> wayHcArgs way
            <> arg SrcHcOpts
            <> packageArgs stage pkgData
            <> includeArgs path dist
            <> concatArgs ["-optP"] (CppOpts pkgData) 
            -- TODO: now we have both -O and -O2
            <> arg ["-Wall", "-XHaskell2010", "-O2"]
            <> productArgs ["-odir", "-hidir", "-stubdir"] buildDir
            <> when (splitObjects stage) (arg "-split-objs")
            <> arg ("-c":srcs)
            <> arg ["-o", toStandard out]

-- TODO: This rule looks hacky... combine it with the above?
hiRule :: Package -> TodoItem -> Rules ()
hiRule (Package name path _) (stage, dist, settings) =
    let buildDir = toStandard $ path </> dist </> "build"
    in
    (buildDir <//> "*hi") %> \out -> do
        let way  = detectWay $ tail $ takeExtension out
            oFile = out -<.> osuf way
        need [oFile]

buildPackageCompile :: Package -> TodoItem -> Rules ()
buildPackageCompile = oRule <> hiRule
{'fraction_non_alphanumeric': 0.1469067569976823, 'fraction_numerical': 0.006418256373685149, 'mean_word_length': 2.473684210526316, 'pattern_counts': {'":': 2, '<': 61, '<?xml version=': 0, '>': 81, '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': '1321499', 'n_tokens_mistral': 1932, 'n_tokens_neox': 1859, 'n_words': 467}