<commit_before>module Settings.Builders.Ghc (
    ghcBuilderArgs, ghcMBuilderArgs, commonGhcArgs, gmpLibNameCache
    ) where

import Base
import Expression
import GHC
import Oracles
import Predicates hiding (way, stage)
import Settings
import Settings.Builders.GhcCabal (bootPackageDbArgs)
import Settings.Builders.Common (cIncludeArgs)

-- TODO: add support for -dyno
-- $1/$2/build/%.$$($3_o-bootsuf) : $1/$4/%.hs-boot
--     $$(call cmd,$1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -c $$< -o $$@
--     $$(if $$(findstring YES,$$($1_$2_DYNAMIC_TOO)),-dyno
--     $$(addsuffix .$$(dyn_osuf)-boot,$$(basename $$@)))
ghcBuilderArgs :: Args
ghcBuilderArgs = stagedBuilder Ghc ? do
    output <- getOutput
    stage  <- getStage
    way    <- getWay
    let buildObj  = ("//*." ++  osuf way) ?== output || ("//*." ++  obootsuf way) ?== output
        buildHi   = ("//*." ++ hisuf way) ?== output || ("//*." ++ hibootsuf way) ?== output
        buildProg = not (buildObj || buildHi)
    libs    <- getPkgDataList DepExtraLibs
    gmpLibs <- if stage > Stage0 && buildProg
               then lift $ readFileLines gmpLibNameCache -- TODO: use oracles
               else return []
    libDirs <- getPkgDataList DepLibDirs
    mconcat [ commonGhcArgs
            , arg "-H32m"
            , stage0    ? arg "-O"
            , notStage0 ? arg "-O2"
            , arg "-Wall"
            , arg "-fwarn-tabs"
            , splitObjectsArgs
            , buildProg ? arg "-no-auto-link-packages"
            , buildProg ? append [ "-optl-l" ++ lib | lib <- libs ++ gmpLibs ]
            , buildProg ? append [ "-optl-L" ++ dir | dir <- libDirs ]
            , not buildProg ? arg "-c"
            , append =<< getInputs
            , buildHi ? append ["-fno-code", "-fwrite-interface"]
            , not buildHi ? mconcat [ arg "-o", arg =<< getOutput ] ]

splitObjectsArgs :: Args
splitObjectsArgs = splitObjects ? do
    lift $ need [ghcSplit]
    arg "-split-objs"

ghcMBuilderArgs :: Args
ghcMBuilderArgs = stagedBuilder GhcM ? do
    ways <- getLibraryWays
    mconcat [ arg "-M"
            , commonGhcArgs
            , arg "-include-pkg-deps"
            , arg "-dep-makefile", arg =<< getOutput
            , append $ concat [ ["-dep-suffix", wayPrefix w] | w <- ways ]
            , append =<< getInputs ]<commit_msg>Need touchy when calling ghc-stageN, N > 0, on Windows.<commit_after>module Settings.Builders.Ghc (
    ghcBuilderArgs, ghcMBuilderArgs, commonGhcArgs, gmpLibNameCache
    ) where

import Base
import Expression
import GHC
import Oracles
import Predicates hiding (way, stage)
import Settings
import Settings.Builders.GhcCabal (bootPackageDbArgs)
import Settings.Builders.Common (cIncludeArgs)

-- TODO: add support for -dyno
-- $1/$2/build/%.$$($3_o-bootsuf) : $1/$4/%.hs-boot
--     $$(call cmd,$1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -c $$< -o $$@
--     $$(if $$(findstring YES,$$($1_$2_DYNAMIC_TOO)),-dyno
--     $$(addsuffix .$$(dyn_osuf)-boot,$$(basename $$@)))
ghcBuilderArgs :: Args
ghcBuilderArgs = stagedBuilder Ghc ? do
    output <- getOutput
    stage  <- getStage
    way    <- getWay
    when (stage > Stage0) . lift $ needTouchy
    let buildObj  = ("//*." ++  osuf way) ?== output || ("//*." ++  obootsuf way) ?== output
        buildHi   = ("//*." ++ hisuf way) ?== output || ("//*." ++ hibootsuf way) ?== output
        buildProg = not (buildObj || buildHi)
    libs    <- getPkgDataList DepExtraLibs
    gmpLibs <- if stage > Stage0 && buildProg
               then lift $ readFileLines gmpLibNameCache -- TODO: use oracles
               else return []
    libDirs <- getPkgDataList DepLibDirs
    mconcat [ commonGhcArgs
            , arg "-H32m"
            , stage0    ? arg "-O"
            , notStage0 ? arg "-O2"
            , arg "-Wall"
            , arg "-fwarn-tabs"
            , splitObjectsArgs
            , buildProg ? arg "-no-auto-link-packages"
            , buildProg ? append [ "-optl-l" ++ lib | lib <- libs ++ gmpLibs ]
            , buildProg ? append [ "-optl-L" ++ dir | dir <- libDirs ]
            , not buildProg ? arg "-c"
            , append =<< getInputs
            , buildHi ? append ["-fno-code", "-fwrite-interface"]
            , not buildHi ? mconcat [ arg "-o", arg =<< getOutput ] ]

needTouchy :: Action ()
needTouchy = whenM windowsHost $ need [fromJust $ programPath Stage0 touchy ]

splitObjectsArgs :: Args
splitObjectsArgs = splitObjects ? do
    lift $ need [ghcSplit]
    arg "-split-objs"

ghcMBuilderArgs :: Args
ghcMBuilderArgs = stagedBuilder GhcM ? do
    ways <- getLibraryWays
    mconcat [ arg "-M"
            , commonGhcArgs
            , arg "-include-pkg-deps"
            , arg "-dep-makefile", arg =<< getOutput
            , append $ concat [ ["-dep-suffix", wayPrefix w] | w <- ways ]
            , append =<< getInputs ]
{'fraction_non_alphanumeric': 0.14951133291744645, 'fraction_numerical': 0.008109794135995009, 'mean_word_length': 2.258807588075881, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5498037', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1597, 'n_words': 385}