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/liboctopus_parser.a", -- XXX: For NS client in libbarrelfish
88 In InstallTree arch "/errors/errno.o",
89 In InstallTree arch ("/lib/lib" ++ Config.libc ++ ".a"),
90 --In InstallTree arch "/lib/libposixcompat.a",
91 --In InstallTree arch "/lib/libvfs.a",
92 --In InstallTree arch "/lib/libnfs.a",
93 --In InstallTree arch "/lib/liblwip.a",
94 --In InstallTree arch "/lib/libbarrelfish.a",
95 --In InstallTree arch "/lib/libcontmng.a",
96 --In InstallTree arch "/lib/libprocon.a",
97 In InstallTree arch "/lib/crtend.o" ,
98 In InstallTree arch "/lib/libcollections.a" ]
101 [ In InstallTree arch "/lib/libcxx.a",
102 Str "./libsupc++.a" ]
105 options arch archFamily = Options {
107 optArchFamily = archFamily,
109 optCxxFlags = cxxFlags,
110 optDefines = [ Str "-DBARRELFISH" ] ++ Config.defines,
111 optIncludes = cStdIncs arch archFamily,
113 [ PreDep InstallTree arch "/include/errors/errno.h",
114 PreDep InstallTree arch "/include/barrelfish_kpi/capbits.h",
115 PreDep InstallTree arch "/include/asmoffsets.h" ],
116 optLdFlags = ldFlags arch,
117 optLdCxxFlags = ldCxxFlags arch,
118 optLibs = stdLibs arch,
119 optCxxLibs = stdCxxLibs arch,
120 optInterconnectDrivers = ["lmp", "ump", "multihop"],
121 optFlounderBackends = ["lmp", "ump", "multihop"],
125 extraDependencies = [],
130 ------------------------------------------------------------------------
132 -- Now, commands to actually do something
134 ------------------------------------------------------------------------
139 cCompiler arch compiler opts phase src obj =
140 let incls = (optIncludes opts) ++ (extraIncludes opts)
141 flags = (optFlags opts)
143 ++ [ Str f | f <- extraFlags opts ]
144 ++ [ Str f | f <- extraDefines opts ]
145 deps = (optDependencies opts) ++ (extraDependencies opts)
147 [ Str compiler ] ++ flags ++ [ Str Config.cOptFlags ]
148 ++ concat [ [ NStr "-I", i ] | i <- incls ]
149 ++ [ Str "-o", Out arch obj,
150 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src ]
153 -- the C preprocessor, like C compiler but with -E
155 cPreprocessor arch compiler opts phase src obj =
156 let incls = (optIncludes opts) ++ (extraIncludes opts)
157 flags = (optFlags opts)
159 ++ [ Str f | f <- extraFlags opts ]
160 ++ [ Str f | f <- extraDefines opts ]
161 deps = (optDependencies opts) ++ (extraDependencies opts)
162 cOptFlags = unwords ((words Config.cOptFlags) \\ ["-g"])
164 [ Str compiler ] ++ flags ++ [ Str cOptFlags ]
165 ++ concat [ [ NStr "-I", i ] | i <- incls ]
166 ++ [ Str "-o", Out arch obj,
167 Str "-E", In (if phase == "src" then SrcTree else BuildTree) phase src ]
173 cxxCompiler arch cxxcompiler opts phase src obj =
174 let incls = (optIncludes opts) ++ (extraIncludes opts)
175 flags = (optCxxFlags opts)
177 ++ [ Str f | f <- extraFlags opts ]
178 ++ [ Str f | f <- extraDefines opts ]
179 deps = (optDependencies opts) ++ (extraDependencies opts)
181 [ Str cxxcompiler ] ++ flags ++ [ Str Config.cOptFlags ]
182 ++ concat [ [ NStr "-I", i ] | i <- incls ]
183 ++ [ Str "-o", Out arch obj,
184 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src ]
188 -- Create C file dependencies
190 makeDepend arch compiler opts phase src obj depfile =
191 let incls = (optIncludes opts) ++ (extraIncludes opts)
192 flags = (optFlags opts)
194 ++ [ Str f | f <- extraFlags opts ]
195 ++ [ Str f | f <- extraDefines opts ]
197 [ Str ('@':compiler) ] ++ flags
198 ++ concat [ [ NStr "-I", i ] | i <- incls ]
199 ++ (optDependencies opts) ++ (extraDependencies opts)
202 Str "-MQ", NoDep BuildTree arch obj,
203 Str "-MQ", NoDep BuildTree arch depfile,
204 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src
208 -- Create C++ file dependencies
210 makeCxxDepend arch cxxcompiler opts phase src obj depfile =
211 let incls = (optIncludes opts) ++ (extraIncludes opts)
212 flags = (optCxxFlags opts)
214 ++ [ Str f | f <- extraFlags opts ]
215 ++ [ Str f | f <- extraDefines opts ]
217 [ Str ('@':cxxcompiler) ] ++ flags
218 ++ concat [ [ NStr "-I", i ] | i <- incls ]
219 ++ (optDependencies opts) ++ (extraDependencies opts)
222 Str "-MQ", NoDep BuildTree arch obj,
223 Str "-MQ", NoDep BuildTree arch depfile,
224 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src
228 -- Compile a C program to assembler
230 cToAssembler :: String -> String -> Options -> String -> String -> String -> String -> [ RuleToken ]
231 cToAssembler arch compiler opts phase src afile objdepfile =
232 let incls = (optIncludes opts) ++ (extraIncludes opts)
233 flags = (optFlags opts)
235 ++ [ Str f | f <- extraFlags opts ]
236 ++ [ Str f | f <- extraDefines opts ]
237 deps = [ Dep BuildTree arch objdepfile ] ++ (optDependencies opts) ++ (extraDependencies opts)
239 [ Str compiler ] ++ flags ++ [ Str Config.cOptFlags ]
240 ++ concat [ [ NStr "-I", i ] | i <- incls ]
241 ++ [ Str "-o ", Out arch afile,
242 Str "-S ", In (if phase == "src" then SrcTree else BuildTree) phase src ]
246 -- Assemble an assembly language file
248 assembler :: String -> String -> Options -> String -> String -> [ RuleToken ]
249 assembler arch compiler opts src obj =
250 let incls = (optIncludes opts) ++ (extraIncludes opts)
251 flags = (optFlags opts)
253 ++ [ Str f | f <- extraFlags opts ]
254 ++ [ Str f | f <- extraDefines opts ]
255 deps = (optDependencies opts) ++ (extraDependencies opts)
257 [ Str compiler ] ++ flags ++ [ Str Config.cOptFlags ]
258 ++ concat [ [ NStr "-I", i ] | i <- incls ]
259 ++ [ Str "-o ", Out arch obj, Str "-c ", In SrcTree "src" src ]
263 -- Create a library from a set of object files
265 archive :: String -> Options -> [String] -> [String] -> String -> String -> [ RuleToken ]
266 archive arch opts objs libs name libname =
267 [ Str "rm -f ", Out arch libname ]
269 [ NL, Str "ar cr ", Out arch libname ]
271 [ In BuildTree arch o | o <- objs ]
273 if libs == [] then []
275 [ NL, Str ("rm -fr tmp-" ++ name ++ "; mkdir tmp-" ++ name) ]
277 [ NL, Str ("cd tmp-" ++ name ++ "; for i in ") ]
279 [ In BuildTree arch a | a <- libs ]
281 [ Str "; do ar x ../$$i; done" ]
283 [ NL, Str "ar q ", Out arch libname, Str (" tmp-" ++ name ++ "/*.o") ]
285 [ NL, Str ("rm -fr tmp-" ++ name) ]
288 [ NL, Str "ranlib ", Out arch libname ]
291 -- Link an executable
293 linker :: String -> String -> Options -> [String] -> [String] -> String -> [RuleToken]
294 linker arch compiler opts objs libs bin =
300 [ Str "-o", Out arch bin ]
302 [ In BuildTree arch o | o <- objs ]
304 [ In BuildTree arch l | l <- libs ]
309 -- Link an executable
311 cxxlinker :: String -> String -> Options -> [String] -> [String] -> String -> [RuleToken]
312 cxxlinker arch cxxcompiler opts objs libs bin =
314 ++ (optLdCxxFlags opts)
318 [ Str "-o", Out arch bin ]
320 [ In BuildTree arch o | o <- objs ]
322 [ In BuildTree arch l | l <- libs ]