<commit_before>-------------------------------------------------------------------------
-- Copyright (c) 2007-2011, ETH Zurich.
-- All rights reserved.
--
-- This file is distributed under the terms in the attached LICENSE file.
-- If you do not find this file, copies can be found by writing to:-
-- ETH Zurich D-INFK CAB F.78, Universitaetstr 6, CH-8092 Zurich. 
-- Attn: Systems Group.
--
-- Basic Hake rule definitions and combinators
--
--------------------------------------------------------------------------

module RuleDefs where
import Data.List (intersect, isSuffixOf, union, (\\), nub, sortBy, elemIndex)
import Path
import qualified X86_64
import qualified X86_32
import qualified SCC
import qualified ARMv5
import qualified ARM11MP
import qualified XScale
import qualified ARMv7
import qualified ARMv7_M
import HakeTypes
import qualified Args
import qualified Config

import Debug.Trace
-- enable debug spew
-- should we move this to Config.hs? -AB
debugFlag = False

--
-- Is a token to be displayed in a rule?
--
inRule :: RuleToken -> Bool
inRule (Dep _ _ _) = False
inRule (PreDep _ _ _) = False
inRule (Target _ _) = False
inRule _ = True

--
-- Look for a set of files: this is called using the "find" combinator
--
withSuffix :: [String] -> String -> String -> [String]
withSuffix af tf arg =
    [ basename f | f <- af, f `isInSameDirAs` tf, isSuffixOf arg f ]
withSuffices :: [String] -> String -> [String] -> [String]
withSuffices af tf args =
    concat [ withSuffix af tf arg | arg <- args ]

--
-- Find files with a given suffix in a given dir
--
inDir :: [String] -> String -> String -> String -> [String]
inDir af tf dir suffix =
    -- Dummy is here so that we can find files in the same dir :-/
    let subdir = (if head dir == '/' then absdir else reldir) ./. "dummy"
        absdir = if head tf == '/' then dir else '.':dir
        reldir = (dirname tf) ./. dir
        files = withSuffix af subdir suffix
    in
        [ dir ./. f | f <- files ]

cInDir :: [String] -> String -> String -> [String]
cInDir af tf dir = inDir af tf dir ".c"
cxxInDir :: [String] -> String -> String -> [String]
cxxInDir af tf dir = inDir af tf dir ".cpp"
sInDir :: [String] -> String -> String -> [String]
sInDir af tf dir = inDir af tf dir ".S"

-------------------------------------------------------------------------
--
-- Architecture specific definitions
--
-------------------------------------------------------------------------

options :: String -> Options
options "x86_64" = X86_64.options
options "x86_32" = X86_32.options
options "scc" = SCC.options
options "armv5" = ARMv5.options
options "arm11mp" = ARM11MP.options
options "xscale" = XScale.options
options "armv7" = ARMv7.options
options "armv7-m" = ARMv7_M.options

kernelCFlags "x86_64" = X86_64.kernelCFlags
kernelCFlags "x86_32" = X86_32.kernelCFlags
kernelCFlags "scc" = SCC.kernelCFlags
kernelCFlags "armv5" = ARMv5.kernelCFlags
kernelCFlags "arm11mp" = ARM11MP.kernelCFlags
kernelCFlags "xscale" = XScale.kernelCFlags
kernelCFlags "armv7" = ARMv7.kernelCFlags
kernelCFlags "armv7-m" = ARMv7_M.kernelCFlags

kernelLdFlags "x86_64" = X86_64.kernelLdFlags
kernelLdFlags "x86_32" = X86_32.kernelLdFlags
kernelLdFlags "scc" = SCC.kernelLdFlags
kernelLdFlags "armv5" = ARMv5.kernelLdFlags
kernelLdFlags "arm11mp" = ARM11MP.kernelLdFlags
kernelLdFlags "xscale" = XScale.kernelLdFlags
kernelLdFlags "armv7" = ARMv7.kernelLdFlags
kernelLdFlags "armv7-m" = ARMv7_M.kernelLdFlags

archFamily :: String -> String
archFamily arch = optArchFamily (options arch)

-------------------------------------------------------------------------
--
-- Options for compiling the kernel, which is special
--
-------------------------------------------------------------------------

kernelIncludes arch = [ NoDep BuildTree arch f | f <- [
                    "/include",
                    "/include/dev" ]]
                 ++
                 [ NoDep SrcTree "src" f | f <- [
                    "/kernel/include/arch" ./. arch,
                    "/kernel/include/arch" ./. archFamily arch,
                    "/kernel/include",
                    "/include",
                    "/include/arch" ./. archFamily arch,
                    Config.libcInc,
                    "/include/c",
                    "/include/target" ./. archFamily arch]]

kernelOptions arch = Options {
            optArch = arch,
            optArchFamily = archFamily arch,
            optFlags = kernelCFlags arch,
            optCxxFlags = [],
            optDefines = (optDefines (options arch)) ++ [ Str "-DIN_KERNEL",
                Str ("-DCONFIG_SCHEDULER_" ++ (show Config.scheduler)),
                Str ("-DCONFIG_TIMESLICE=" ++ (show Config.timeslice)) ],
            optIncludes = kernelIncludes arch,
            optDependencies =
                [ Dep InstallTree arch "/include/errors/errno.h",
                  Dep InstallTree arch "/include/asmoffsets.h",
                  Dep InstallTree arch "/include/trace_definitions/trace_defs.h" ],
            optLdFlags = kernelLdFlags arch,
            optLdCxxFlags = [],
            optLibs = [],
            optCxxLibs = [],
            optSuffix = [],
            optInterconnectDrivers = [],
            optFlounderBackends = [],
            extraFlags = [],
            extraDefines = [],
            extraIncludes = [],
            extraDependencies = [],
            extraLdFlags = []
          }


-------------------------------------------------------------------------
--
-- IMPORTANT: This section contains extraction of functions from the
-- relevant architecture module.  The names and types should be
-- exactly the same as in the architecture.hs file.  This section<commit_msg>Added capbits dependency for kernel back in.<commit_after>-------------------------------------------------------------------------
-- Copyright (c) 2007-2011, ETH Zurich.
-- All rights reserved.
--
-- This file is distributed under the terms in the attached LICENSE file.
-- If you do not find this file, copies can be found by writing to:-
-- ETH Zurich D-INFK CAB F.78, Universitaetstr 6, CH-8092 Zurich. 
-- Attn: Systems Group.
--
-- Basic Hake rule definitions and combinators
--
--------------------------------------------------------------------------

module RuleDefs where
import Data.List (intersect, isSuffixOf, union, (\\), nub, sortBy, elemIndex)
import Path
import qualified X86_64
import qualified X86_32
import qualified SCC
import qualified ARMv5
import qualified ARM11MP
import qualified XScale
import qualified ARMv7
import qualified ARMv7_M
import HakeTypes
import qualified Args
import qualified Config

import Debug.Trace
-- enable debug spew
-- should we move this to Config.hs? -AB
debugFlag = False

--
-- Is a token to be displayed in a rule?
--
inRule :: RuleToken -> Bool
inRule (Dep _ _ _) = False
inRule (PreDep _ _ _) = False
inRule (Target _ _) = False
inRule _ = True

--
-- Look for a set of files: this is called using the "find" combinator
--
withSuffix :: [String] -> String -> String -> [String]
withSuffix af tf arg =
    [ basename f | f <- af, f `isInSameDirAs` tf, isSuffixOf arg f ]
withSuffices :: [String] -> String -> [String] -> [String]
withSuffices af tf args =
    concat [ withSuffix af tf arg | arg <- args ]

--
-- Find files with a given suffix in a given dir
--
inDir :: [String] -> String -> String -> String -> [String]
inDir af tf dir suffix =
    -- Dummy is here so that we can find files in the same dir :-/
    let subdir = (if head dir == '/' then absdir else reldir) ./. "dummy"
        absdir = if head tf == '/' then dir else '.':dir
        reldir = (dirname tf) ./. dir
        files = withSuffix af subdir suffix
    in
        [ dir ./. f | f <- files ]

cInDir :: [String] -> String -> String -> [String]
cInDir af tf dir = inDir af tf dir ".c"
cxxInDir :: [String] -> String -> String -> [String]
cxxInDir af tf dir = inDir af tf dir ".cpp"
sInDir :: [String] -> String -> String -> [String]
sInDir af tf dir = inDir af tf dir ".S"

-------------------------------------------------------------------------
--
-- Architecture specific definitions
--
-------------------------------------------------------------------------

options :: String -> Options
options "x86_64" = X86_64.options
options "x86_32" = X86_32.options
options "scc" = SCC.options
options "armv5" = ARMv5.options
options "arm11mp" = ARM11MP.options
options "xscale" = XScale.options
options "armv7" = ARMv7.options
options "armv7-m" = ARMv7_M.options

kernelCFlags "x86_64" = X86_64.kernelCFlags
kernelCFlags "x86_32" = X86_32.kernelCFlags
kernelCFlags "scc" = SCC.kernelCFlags
kernelCFlags "armv5" = ARMv5.kernelCFlags
kernelCFlags "arm11mp" = ARM11MP.kernelCFlags
kernelCFlags "xscale" = XScale.kernelCFlags
kernelCFlags "armv7" = ARMv7.kernelCFlags
kernelCFlags "armv7-m" = ARMv7_M.kernelCFlags

kernelLdFlags "x86_64" = X86_64.kernelLdFlags
kernelLdFlags "x86_32" = X86_32.kernelLdFlags
kernelLdFlags "scc" = SCC.kernelLdFlags
kernelLdFlags "armv5" = ARMv5.kernelLdFlags
kernelLdFlags "arm11mp" = ARM11MP.kernelLdFlags
kernelLdFlags "xscale" = XScale.kernelLdFlags
kernelLdFlags "armv7" = ARMv7.kernelLdFlags
kernelLdFlags "armv7-m" = ARMv7_M.kernelLdFlags

archFamily :: String -> String
archFamily arch = optArchFamily (options arch)

-------------------------------------------------------------------------
--
-- Options for compiling the kernel, which is special
--
-------------------------------------------------------------------------

kernelIncludes arch = [ NoDep BuildTree arch f | f <- [
                    "/include",
                    "/include/dev" ]]
                 ++
                 [ NoDep SrcTree "src" f | f <- [
                    "/kernel/include/arch" ./. arch,
                    "/kernel/include/arch" ./. archFamily arch,
                    "/kernel/include",
                    "/include",
                    "/include/arch" ./. archFamily arch,
                    Config.libcInc,
                    "/include/c",
                    "/include/target" ./. archFamily arch]]

kernelOptions arch = Options {
            optArch = arch,
            optArchFamily = archFamily arch,
            optFlags = kernelCFlags arch,
            optCxxFlags = [],
            optDefines = (optDefines (options arch)) ++ [ Str "-DIN_KERNEL",
                Str ("-DCONFIG_SCHEDULER_" ++ (show Config.scheduler)),
                Str ("-DCONFIG_TIMESLICE=" ++ (show Config.timeslice)) ],
            optIncludes = kernelIncludes arch,
            optDependencies =
                [ Dep InstallTree arch "/include/errors/errno.h",
                  Dep InstallTree arch "/include/barrelfish_kpi/capbits.h",
                  Dep InstallTree arch "/include/asmoffsets.h",
                  Dep InstallTree arch "/include/trace_definitions/trace_defs.h" ],
            optLdFlags = kernelLdFlags arch,
            optLdCxxFlags = [],
            optLibs = [],
            optCxxLibs = [],
            optSuffix = [],
            optInterconnectDrivers = [],
            optFlounderBackends = [],
            extraFlags = [],
            extraDefines = [],
            extraIncludes = [],
            extraDependencies = [],
            extraLdFlags = []
          }


-------------------------------------------------------------------------
--
-- IMPORTANT: This section contains extraction of functions from the
-- relevant architecture module.  The names and types should be
-- exactly the same as in the architecture.hs file.  This section
{'fraction_non_alphanumeric': 0.1896417107660276, 'fraction_numerical': 0.018391602324976143, 'mean_word_length': 1.813079551000488, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 47, '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': '5169019', 'n_tokens_mistral': 3404, 'n_tokens_neox': 3218, 'n_words': 1005}