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 "-U__STRICT_ANSI__", -- for newlib headers
35 "-Wstrict-prototypes",
36 "-Wold-style-definition",
37 "-Wmissing-prototypes" ] ]
38 ++ [ ContStr Config.use_fp "-fno-omit-frame-pointer" ""]
40 commonCxxFlags = [ Str s | s <- [ "-nostdinc++",
44 ++ [ NoDep SrcTree "src" "/include/cxx" ]
45 ++ [ ContStr Config.use_fp "-fno-omit-frame-pointer" ""]
47 cFlags = [ Str s | s <- [ "-Wno-packed-bitfield-compat" ] ]
50 cxxFlags = [ Str s | s <- [ "-Wno-packed-bitfield-compat" ] ]
53 cDefines options = [ Str ("-D"++s) | s <- [ "BARRELFISH" ]]
55 ++ Config.arch_defines options
57 cStdIncs arch archFamily =
58 [ NoDep SrcTree "src" "/include",
59 NoDep SrcTree "src" ("/include/arch" ./. archFamily),
60 NoDep SrcTree "src" Config.libcInc,
61 NoDep SrcTree "src" "/include/c",
62 NoDep SrcTree "src" ("/include/target" ./. archFamily),
63 NoDep SrcTree "src" "/include/ipv4", -- XXX
64 NoDep InstallTree arch "/include",
65 NoDep InstallTree arch "/include/dev",
66 NoDep SrcTree "src" ".",
67 NoDep BuildTree arch "." ]
70 [ Str Config.cOptFlags,
71 In InstallTree arch "/lib/crt0.o",
72 In InstallTree arch "/lib/crtbegin.o",
77 [ Str Config.cOptFlags,
78 In InstallTree arch "/lib/crt0.o",
79 In InstallTree arch "/lib/crtbegin.o",
84 -- Libraries that are linked to all applications.
86 [ In InstallTree arch "/lib/libbarrelfish.a",
87 In InstallTree arch "/lib/libterm_client.a",
88 In InstallTree arch "/lib/liboctopus_parser.a", -- XXX: For NS client in libbarrelfish
89 In InstallTree arch "/errors/errno.o",
90 In InstallTree arch ("/lib/lib" ++ Config.libc ++ ".a"),
91 --In InstallTree arch "/lib/libposixcompat.a",
92 --In InstallTree arch "/lib/libvfs.a",
93 --In InstallTree arch "/lib/libnfs.a",
94 --In InstallTree arch "/lib/liblwip.a",
95 --In InstallTree arch "/lib/libbarrelfish.a",
96 --In InstallTree arch "/lib/libcontmng.a",
97 --In InstallTree arch "/lib/libprocon.a",
98 In InstallTree arch "/lib/crtend.o" ,
99 In InstallTree arch "/lib/libcollections.a" ]
102 [ In InstallTree arch "/lib/libcxx.a",
103 Str "./libsupc++.a" ]
106 options arch archFamily = Options {
108 optArchFamily = archFamily,
110 optCxxFlags = cxxFlags,
111 optDefines = [ Str "-DBARRELFISH" ] ++ Config.defines,
112 optIncludes = cStdIncs arch archFamily,
114 [ PreDep InstallTree arch "/include/errors/errno.h",
115 PreDep InstallTree arch "/include/barrelfish_kpi/capbits.h",
116 PreDep InstallTree arch "/include/asmoffsets.h" ],
117 optLdFlags = ldFlags arch,
118 optLdCxxFlags = ldCxxFlags arch,
119 optLibs = stdLibs arch,
120 optCxxLibs = stdCxxLibs arch,
121 optInterconnectDrivers = ["lmp", "ump", "multihop"],
122 optFlounderBackends = ["lmp", "ump", "multihop"],
126 extraDependencies = [],
131 ------------------------------------------------------------------------
133 -- Now, commands to actually do something
135 ------------------------------------------------------------------------
140 cCompiler arch compiler opts phase src obj =
141 let incls = (optIncludes opts) ++ (extraIncludes opts)
142 flags = (optFlags opts)
144 ++ [ Str f | f <- extraFlags opts ]
145 ++ [ Str f | f <- extraDefines opts ]
146 deps = (optDependencies opts) ++ (extraDependencies opts)
148 [ Str compiler ] ++ flags ++ [ Str Config.cOptFlags ]
149 ++ concat [ [ NStr "-I", i ] | i <- incls ]
150 ++ [ Str "-o", Out arch obj,
151 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src ]
154 -- the C preprocessor, like C compiler but with -E
156 cPreprocessor arch compiler opts phase src obj =
157 let incls = (optIncludes opts) ++ (extraIncludes opts)
158 flags = (optFlags opts)
160 ++ [ Str f | f <- extraFlags opts ]
161 ++ [ Str f | f <- extraDefines opts ]
162 deps = (optDependencies opts) ++ (extraDependencies opts)
163 cOptFlags = unwords ((words Config.cOptFlags) \\ ["-g"])
165 [ Str compiler ] ++ flags ++ [ Str cOptFlags ]
166 ++ concat [ [ NStr "-I", i ] | i <- incls ]
167 ++ [ Str "-o", Out arch obj,
168 Str "-E", In (if phase == "src" then SrcTree else BuildTree) phase src ]
174 cxxCompiler arch cxxcompiler opts phase src obj =
175 let incls = (optIncludes opts) ++ (extraIncludes opts)
176 flags = (optCxxFlags opts)
178 ++ [ Str f | f <- extraFlags opts ]
179 ++ [ Str f | f <- extraDefines opts ]
180 deps = (optDependencies opts) ++ (extraDependencies opts)
182 [ Str cxxcompiler ] ++ flags ++ [ Str Config.cOptFlags ]
183 ++ concat [ [ NStr "-I", i ] | i <- incls ]
184 ++ [ Str "-o", Out arch obj,
185 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src ]
189 -- Create C file dependencies
191 makeDepend arch compiler opts phase src obj depfile =
192 let incls = (optIncludes opts) ++ (extraIncludes opts)
193 flags = (optFlags opts)
195 ++ [ Str f | f <- extraFlags opts ]
196 ++ [ Str f | f <- extraDefines opts ]
198 [ Str ('@':compiler) ] ++ flags
199 ++ concat [ [ NStr "-I", i ] | i <- incls ]
200 ++ (optDependencies opts) ++ (extraDependencies opts)
203 Str "-MQ", NoDep BuildTree arch obj,
204 Str "-MQ", NoDep BuildTree arch depfile,
205 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src
209 -- Create C++ file dependencies
211 makeCxxDepend arch cxxcompiler opts phase src obj depfile =
212 let incls = (optIncludes opts) ++ (extraIncludes opts)
213 flags = (optCxxFlags opts)
215 ++ [ Str f | f <- extraFlags opts ]
216 ++ [ Str f | f <- extraDefines opts ]
218 [ Str ('@':cxxcompiler) ] ++ flags
219 ++ concat [ [ NStr "-I", i ] | i <- incls ]
220 ++ (optDependencies opts) ++ (extraDependencies opts)
223 Str "-MQ", NoDep BuildTree arch obj,
224 Str "-MQ", NoDep BuildTree arch depfile,
225 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src
229 -- Compile a C program to assembler
231 cToAssembler :: String -> String -> Options -> String -> String -> String -> String -> [ RuleToken ]
232 cToAssembler arch compiler opts phase src afile objdepfile =
233 let incls = (optIncludes opts) ++ (extraIncludes opts)
234 flags = (optFlags opts)
236 ++ [ Str f | f <- extraFlags opts ]
237 ++ [ Str f | f <- extraDefines opts ]
238 deps = [ Dep BuildTree arch objdepfile ] ++ (optDependencies opts) ++ (extraDependencies opts)
240 [ Str compiler ] ++ flags ++ [ Str Config.cOptFlags ]
241 ++ concat [ [ NStr "-I", i ] | i <- incls ]
242 ++ [ Str "-o ", Out arch afile,
243 Str "-S ", In (if phase == "src" then SrcTree else BuildTree) phase src ]
247 -- Assemble an assembly language file
249 assembler :: String -> String -> Options -> String -> String -> [ RuleToken ]
250 assembler arch compiler opts src obj =
251 let incls = (optIncludes opts) ++ (extraIncludes opts)
252 flags = (optFlags opts)
254 ++ [ Str f | f <- extraFlags opts ]
255 ++ [ Str f | f <- extraDefines opts ]
256 deps = (optDependencies opts) ++ (extraDependencies opts)
258 [ Str compiler ] ++ flags ++ [ Str Config.cOptFlags ]
259 ++ concat [ [ NStr "-I", i ] | i <- incls ]
260 ++ [ Str "-o ", Out arch obj, Str "-c ", In SrcTree "src" src ]
264 -- Create a library from a set of object files
266 archive :: String -> Options -> [String] -> [String] -> String -> String -> [ RuleToken ]
267 archive arch opts objs libs name libname =
268 [ Str "rm -f ", Out arch libname ]
270 [ NL, Str "ar cr ", Out arch libname ]
272 [ In BuildTree arch o | o <- objs ]
274 if libs == [] then []
276 [ NL, Str ("rm -fr tmp-" ++ name ++ "; mkdir tmp-" ++ name) ]
278 [ NL, Str ("cd tmp-" ++ name ++ "; for i in ") ]
280 [ In BuildTree arch a | a <- libs ]
282 [ Str "; do ar x ../$$i; done" ]
284 [ NL, Str "ar q ", Out arch libname, Str (" tmp-" ++ name ++ "/*.o") ]
286 [ NL, Str ("rm -fr tmp-" ++ name) ]
289 [ NL, Str "ranlib ", Out arch libname ]
292 -- Link an executable
294 linker :: String -> String -> Options -> [String] -> [String] -> String -> [RuleToken]
295 linker arch compiler opts objs libs bin =
301 [ Str "-o", Out arch bin ]
303 [ In BuildTree arch o | o <- objs ]
305 [ In BuildTree arch l | l <- libs ]
310 -- Link an executable
312 cxxlinker :: String -> String -> Options -> [String] -> [String] -> String -> [RuleToken]
313 cxxlinker arch cxxcompiler opts objs libs bin =
315 ++ (optLdCxxFlags opts)
319 [ Str "-o", Out arch bin ]
321 [ In BuildTree arch o | o <- objs ]
323 [ In BuildTree arch l | l <- libs ]