1 --------------------------------------------------------------------------
2 -- Copyright (c) 2007-2010, ETH Zurich.
3 -- All rights reserved.
5 -- This file is distributed under the terms in the attached LICENSE file.
6 -- If you do not find this file, copies can be found by writing to:
7 -- ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
9 -- Default architecture-specific definitions for Barrelfish
11 --------------------------------------------------------------------------
13 module ArchDefaults where
18 import qualified Config
20 commonFlags = [ Str s | s <- [ "-fno-builtin",
26 "-Wmissing-declarations",
27 "-Wmissing-field-initializers",
31 ++ [ NoDep SrcTree "src" "/include/deputy/nodeputy.h" ]
33 commonCFlags = [ Str s | s <- [ "-std=c99",
34 "-Wstrict-prototypes",
35 "-Wold-style-definition",
36 "-Wmissing-prototypes" ] ]
37 ++ [ ContStr Config.use_fp "-fno-omit-frame-pointer" ""]
39 commonCxxFlags = [ Str s | s <- [ "-nostdinc++",
43 ++ [ NoDep SrcTree "src" "/include/cxx" ]
44 ++ [ ContStr Config.use_fp "-fno-omit-frame-pointer" ""]
46 cFlags = [ Str s | s <- [ "-Wno-packed-bitfield-compat" ] ]
49 cxxFlags = [ Str s | s <- [ "-Wno-packed-bitfield-compat" ] ]
52 cDefines options = [ Str ("-D"++s) | s <- [ "BARRELFISH" ]]
54 ++ Config.arch_defines options
56 cStdIncs arch archFamily =
57 [ NoDep SrcTree "src" "/include",
58 NoDep SrcTree "src" ("/include/arch" ./. archFamily),
59 NoDep SrcTree "src" ("/include/target" ./. archFamily),
60 NoDep SrcTree "src" "/include/ipv4", -- XXX
61 NoDep InstallTree arch "/include",
62 NoDep InstallTree arch "/include/dev",
63 NoDep SrcTree "src" ".",
64 NoDep BuildTree arch "." ]
67 [ Str Config.cOptFlags,
68 In InstallTree arch "/lib/crt0.o",
69 In InstallTree arch "/lib/crtbegin.o",
74 [ Str Config.cOptFlags,
75 In InstallTree arch "/lib/crt0.o",
76 In InstallTree arch "/lib/crtbegin.o",
81 [ In InstallTree arch "/lib/libbarrelfish.a",
82 In InstallTree arch "/lib/libdist_parser.a", -- dist_read() in nameservice_client.c
83 In InstallTree arch "/errors/errno.o",
84 In InstallTree arch "/lib/libc.a",
85 In InstallTree arch "/lib/crtend.o" ,
86 In InstallTree arch "/lib/libcollections.a"]
89 [ In InstallTree arch "/lib/libcxx.a",
93 options arch archFamily = Options {
95 optArchFamily = archFamily,
97 optCxxFlags = cxxFlags,
98 optDefines = [ Str "-DBARRELFISH" ] ++ Config.defines,
99 optIncludes = cStdIncs arch archFamily,
101 [ PreDep InstallTree arch "/include/errors/errno.h",
102 PreDep InstallTree arch "/include/barrelfish_kpi/capbits.h",
103 PreDep InstallTree arch "/include/asmoffsets.h" ],
104 optLdFlags = ldFlags arch,
105 optLdCxxFlags = ldCxxFlags arch,
106 optLibs = stdLibs arch,
107 optCxxLibs = stdCxxLibs arch,
108 optInterconnectDrivers = ["lmp", "ump", "multihop"],
109 optFlounderBackends = ["lmp", "ump", "multihop"],
113 extraDependencies = [],
118 ------------------------------------------------------------------------
120 -- Now, commands to actually do something
122 ------------------------------------------------------------------------
127 cCompiler arch compiler opts phase src obj =
128 let incls = (optIncludes opts) ++ (extraIncludes opts)
129 flags = (optFlags opts)
131 ++ [ Str f | f <- extraFlags opts ]
132 ++ [ Str f | f <- extraDefines opts ]
133 deps = (optDependencies opts) ++ (extraDependencies opts)
135 [ Str compiler ] ++ flags ++ [ Str Config.cOptFlags ]
136 ++ concat [ [ NStr "-I", i ] | i <- incls ]
137 ++ [ Str "-o", Out arch obj,
138 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src ]
141 -- the C preprocessor, like C compiler but with -E
143 cPreprocessor arch compiler opts phase src obj =
144 let incls = (optIncludes opts) ++ (extraIncludes opts)
145 flags = (optFlags opts)
147 ++ [ Str f | f <- extraFlags opts ]
148 ++ [ Str f | f <- extraDefines opts ]
149 deps = (optDependencies opts) ++ (extraDependencies opts)
150 cOptFlags = unwords ((words Config.cOptFlags) \\ ["-g"])
152 [ Str compiler ] ++ flags ++ [ Str cOptFlags ]
153 ++ concat [ [ NStr "-I", i ] | i <- incls ]
154 ++ [ Str "-o", Out arch obj,
155 Str "-E", In (if phase == "src" then SrcTree else BuildTree) phase src ]
161 cxxCompiler arch cxxcompiler opts phase src obj =
162 let incls = (optIncludes opts) ++ (extraIncludes opts)
163 flags = (optCxxFlags opts)
165 ++ [ Str f | f <- extraFlags opts ]
166 ++ [ Str f | f <- extraDefines opts ]
167 deps = (optDependencies opts) ++ (extraDependencies opts)
169 [ Str cxxcompiler ] ++ flags ++ [ Str Config.cOptFlags ]
170 ++ concat [ [ NStr "-I", i ] | i <- incls ]
171 ++ [ Str "-o", Out arch obj,
172 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src ]
176 -- Create C file dependencies
178 makeDepend arch compiler opts phase src obj depfile =
179 let incls = (optIncludes opts) ++ (extraIncludes opts)
180 flags = (optFlags opts)
182 ++ [ Str f | f <- extraFlags opts ]
183 ++ [ Str f | f <- extraDefines opts ]
185 [ Str ('@':compiler) ] ++ flags
186 ++ concat [ [ NStr "-I", i ] | i <- incls ]
187 ++ (optDependencies opts) ++ (extraDependencies opts)
190 Str "-MQ", NoDep BuildTree arch obj,
191 Str "-MQ", NoDep BuildTree arch depfile,
192 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src
196 -- Create C++ file dependencies
198 makeCxxDepend arch cxxcompiler opts phase src obj depfile =
199 let incls = (optIncludes opts) ++ (extraIncludes opts)
200 flags = (optCxxFlags opts)
202 ++ [ Str f | f <- extraFlags opts ]
203 ++ [ Str f | f <- extraDefines opts ]
205 [ Str ('@':cxxcompiler) ] ++ flags
206 ++ concat [ [ NStr "-I", i ] | i <- incls ]
207 ++ (optDependencies opts) ++ (extraDependencies opts)
210 Str "-MQ", NoDep BuildTree arch obj,
211 Str "-MQ", NoDep BuildTree arch depfile,
212 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src
216 -- Compile a C program to assembler
218 cToAssembler :: String -> String -> Options -> String -> String -> String -> String -> [ RuleToken ]
219 cToAssembler arch compiler opts phase src afile objdepfile =
220 let incls = (optIncludes opts) ++ (extraIncludes opts)
221 flags = (optFlags opts)
223 ++ [ Str f | f <- extraFlags opts ]
224 ++ [ Str f | f <- extraDefines opts ]
225 deps = [ Dep BuildTree arch objdepfile ] ++ (optDependencies opts) ++ (extraDependencies opts)
227 [ Str compiler ] ++ flags ++ [ Str Config.cOptFlags ]
228 ++ concat [ [ NStr "-I", i ] | i <- incls ]
229 ++ [ Str "-o ", Out arch afile,
230 Str "-S ", In (if phase == "src" then SrcTree else BuildTree) phase src ]
234 -- Assemble an assembly language file
236 assembler :: String -> String -> Options -> String -> String -> [ RuleToken ]
237 assembler arch compiler opts src obj =
238 let incls = (optIncludes opts) ++ (extraIncludes opts)
239 flags = (optFlags opts)
241 ++ [ Str f | f <- extraFlags opts ]
242 ++ [ Str f | f <- extraDefines opts ]
243 deps = (optDependencies opts) ++ (extraDependencies opts)
245 [ Str compiler ] ++ flags ++ [ Str Config.cOptFlags ]
246 ++ concat [ [ NStr "-I", i ] | i <- incls ]
247 ++ [ Str "-o ", Out arch obj, Str "-c ", In SrcTree "src" src ]
251 -- Create a library from a set of object files
253 archive :: String -> Options -> [String] -> String -> [ RuleToken ]
254 archive arch opts objs libname =
255 [ Str "rm -f ", Out arch libname ]
257 [ NL, Str "ar cr ", Out arch libname ]
259 [ In BuildTree arch o | o <- objs ]
261 [ NL, Str "ranlib ", Out arch libname ]
264 -- Link an executable
266 linker :: String -> String -> Options -> [String] -> [String] -> String -> [RuleToken]
267 linker arch compiler opts objs libs bin =
273 [ Str "-o", Out arch bin ]
275 [ In BuildTree arch o | o <- objs ]
277 [ In BuildTree arch l | l <- libs ]
282 -- Link an executable
284 cxxlinker :: String -> String -> Options -> [String] -> [String] -> String -> [RuleToken]
285 cxxlinker arch cxxcompiler opts objs libs bin =
287 ++ (optLdCxxFlags opts)
291 [ Str "-o", Out arch bin ]
293 [ In BuildTree arch o | o <- objs ]
295 [ In BuildTree arch l | l <- libs ]