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, Universitaetstasse 6, CH-8092 Zurich. Attn: Systems Group.
9 -- Default architecture-specific definitions for Barrelfish
11 --------------------------------------------------------------------------
13 module ArchDefaults where
17 import System.FilePath
18 import qualified Config
20 commonFlags = [ Str s | s <- [ "-fno-builtin",
26 "-Wmissing-declarations",
27 "-Wmissing-field-initializers",
32 commonCFlags = [ Str s | s <- [ "-std=c99",
33 "-Wstrict-prototypes",
34 "-Wold-style-definition",
35 "-Wmissing-prototypes" ] ]
36 ++ [ Str (if Config.use_fp then "-fno-omit-frame-pointer" else "") ]
38 commonCxxFlags = [ Str s | s <- [ "-nostdinc++",
41 "-fasynchronous-unwind-tables",
42 "-DLIBCXX_CXX_ABI=libcxxabi",
44 ++ [ NoDep SrcTree "src" "/include/cxx" ]
45 ++ [ Str (if Config.use_fp then "-fno-omit-frame-pointer" else "") ]
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",
54 "BF_BINARY_PREFIX=\\\"\\\""
58 ++ Config.arch_defines options
60 cStdIncs arch archFamily =
61 [ NoDep BFSrcTree "src" "/include",
62 NoDep BFSrcTree "src" ("/include/arch" </> archFamily),
63 NoDep BFSrcTree "src" ("/include/target" </> archFamily),
64 NoDep InstallTree arch "/include",
65 NoDep BFSrcTree "src" ".",
66 NoDep SrcTree "src" ".",
67 NoDep BuildTree arch "." ]
70 map Str Config.cOptFlags ++
71 [ In InstallTree arch "/lib/crt0.o",
72 In InstallTree arch "/lib/crtbegin.o",
77 map Str Config.cOptFlags ++
78 [ In InstallTree arch "/lib/crt0.o",
79 In InstallTree arch "/lib/crtbegin.o",
84 [ In InstallTree arch "/lib/libcompiler-rt.a" ]
86 -- Libraries that are linked to all applications.
88 [ In InstallTree arch "/lib/libbarrelfish.a",
89 In InstallTree arch "/lib/libterm_client.a",
90 In InstallTree arch "/lib/liboctopus_parser.a", -- XXX: For NS client in libbarrelfish
91 In InstallTree arch "/errors/errno.o",
92 In InstallTree arch ("/lib/libc.a"),
93 In InstallTree arch "/lib/libcompiler-rt.a",
94 --In InstallTree arch "/lib/libposixcompat.a",
95 --In InstallTree arch "/lib/libvfs.a",
96 --In InstallTree arch "/lib/libnfs.a",
97 --In InstallTree arch "/lib/liblwip.a",
98 --In InstallTree arch "/lib/libbarrelfish.a",
99 --In InstallTree arch "/lib/libcontmng.a",
100 --In InstallTree arch "/lib/libprocon.a",
101 In InstallTree arch "/lib/crtend.o" ,
102 In InstallTree arch "/lib/libcollections.a" ]
105 [ In InstallTree arch "/lib/libcxx.a" ]
108 options arch archFamily = Options {
110 optArchFamily = archFamily,
112 optCxxFlags = cxxFlags,
113 optDefines = [ Str "-DBARRELFISH" ] ++ Config.defines,
114 optIncludes = cStdIncs arch archFamily,
116 [ Dep InstallTree arch "/include/errors/errno.h",
117 Dep InstallTree arch "/include/barrelfish_kpi/capbits.h",
118 Dep InstallTree arch "/include/asmoffsets.h",
119 Dep InstallTree arch "/include/trace_definitions/trace_defs.h" ],
120 optLdFlags = ldFlags arch,
121 optLdCxxFlags = ldCxxFlags arch,
122 optLibs = stdLibs arch,
123 optCxxLibs = stdCxxLibs arch,
124 optInterconnectDrivers = ["lmp", "ump", "multihop", "local"],
125 optFlounderBackends = ["lmp", "ump", "multihop", "local"],
130 extraDependencies = [],
133 optInstallPath = OptionsPath {
134 optPathBin = "/sbin",
139 ------------------------------------------------------------------------
141 -- Now, commands to actually do something
143 ------------------------------------------------------------------------
148 cCompiler :: String -> String -> [String] -> Options -> String ->
149 String -> String -> [RuleToken]
150 cCompiler arch compiler opt_flags opts phase src obj =
151 let incls = (extraIncludes opts) ++ (optIncludes opts)
152 flags = (optFlags opts)
154 ++ [ Str f | f <- extraFlags opts ]
155 ++ [ Str f | f <- extraDefines opts ]
156 deps = (optDependencies opts) ++ (extraDependencies opts)
158 [ Str compiler ] ++ flags ++ (map Str opt_flags)
159 ++ concat [ [ NStr "-I", i ] | i <- incls ]
160 ++ [ Str "-o", Out arch obj,
161 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src ]
165 -- the C preprocessor, like C compiler but with -E
167 cPreprocessor :: String -> String -> [String] -> Options -> String ->
168 String -> String -> [RuleToken]
169 cPreprocessor arch compiler opt_flags opts phase src obj =
170 let incls = (extraIncludes opts) ++ (optIncludes opts)
171 flags = (optFlags opts)
173 ++ [ Str f | f <- extraFlags opts ]
174 ++ [ Str f | f <- extraDefines opts ]
175 deps = (optDependencies opts) ++ (extraDependencies opts)
176 cOptFlags = opt_flags \\ ["-g"]
178 [ Str compiler ] ++ flags ++ (map Str cOptFlags)
179 ++ concat [ [ NStr "-I", i ] | i <- incls ]
180 ++ [ Str "-o", Out arch obj,
181 Str "-E", In (if phase == "src" then SrcTree else BuildTree) phase src ]
187 cxxCompiler arch cxxcompiler opt_flags opts phase src obj =
188 let incls = (extraIncludes opts) ++ (optIncludes opts)
189 flags = (optCxxFlags opts)
191 ++ [ Str f | f <- extraCxxFlags opts ]
192 ++ [ Str f | f <- extraDefines opts ]
193 deps = (optDependencies opts) ++ (extraDependencies opts)
195 [ Str cxxcompiler ] ++ flags ++ (map Str opt_flags)
196 ++ concat [ [ NStr "-I", i ] | i <- incls ]
197 ++ [ Str "-o", Out arch obj,
198 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src ]
202 -- Create C file dependencies
204 makeDepend arch compiler opts phase src obj depfile =
205 let incls = (extraIncludes opts) ++ (optIncludes opts)
206 flags = (optFlags opts)
208 ++ [ Str f | f <- extraFlags opts ]
209 ++ [ Str f | f <- extraDefines opts ]
211 [ Str ('@':compiler) ] ++ flags
212 ++ concat [ [ NStr "-I", i ] | i <- incls ]
213 ++ (optDependencies opts) ++ (extraDependencies opts)
216 Str "-MQ", NoDep BuildTree arch obj,
217 Str "-MQ", NoDep BuildTree arch depfile,
218 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src
222 -- Create C++ file dependencies
224 makeCxxDepend arch cxxcompiler opts phase src obj depfile =
225 let incls = (extraIncludes opts) ++ (optIncludes opts)
226 flags = (optCxxFlags opts)
228 ++ [ Str f | f <- extraCxxFlags opts ]
229 ++ [ Str f | f <- extraDefines opts ]
231 [ Str ('@':cxxcompiler) ] ++ flags
232 ++ concat [ [ NStr "-I", i ] | i <- incls ]
233 ++ (optDependencies opts) ++ (extraDependencies opts)
236 Str "-MQ", NoDep BuildTree arch obj,
237 Str "-MQ", NoDep BuildTree arch depfile,
238 Str "-c", In (if phase == "src" then SrcTree else BuildTree) phase src
242 -- Compile a C program to assembler
244 cToAssembler :: String -> String -> [String] -> Options -> String -> String ->
245 String -> String -> [ RuleToken ]
246 cToAssembler arch compiler opt_flags opts phase src afile objdepfile =
247 let incls = (extraIncludes opts) ++ (optIncludes opts)
248 flags = (optFlags opts)
250 ++ [ Str f | f <- extraFlags opts ]
251 ++ [ Str f | f <- extraDefines opts ]
252 deps = [ Dep BuildTree arch objdepfile ] ++
253 (optDependencies opts) ++
254 (extraDependencies opts)
256 [ Str compiler ] ++ flags ++ (map Str opt_flags)
257 ++ concat [ [ NStr "-I", i ] | i <- incls ]
258 ++ [ Str "-o ", Out arch afile,
259 Str "-S ", In (if phase == "src" then SrcTree else BuildTree) phase src ]
263 -- Assemble an assembly language file
265 assembler :: String -> String -> [ String ] -> Options -> String ->
266 String -> [ RuleToken ]
267 assembler arch compiler opt_flags opts src obj =
268 let incls = (extraIncludes opts) ++ (optIncludes opts)
269 flags = (optFlags opts)
271 ++ [ Str f | f <- extraFlags opts ]
272 ++ [ Str f | f <- extraDefines opts ]
273 deps = (optDependencies opts) ++ (extraDependencies opts)
275 [ Str compiler ] ++ flags ++ (map Str opt_flags)
276 ++ concat [ [ NStr "-I", i ] | i <- incls ]
277 ++ [ Str "-o ", Out arch obj, Str "-c ", In SrcTree "src" src ]
281 -- Create a library from a set of object files
283 archive :: String -> Options -> [String] -> [String] -> String -> String -> [ RuleToken ]
284 archive arch opts objs libs name libname =
285 [ Str "rm -f ", Out arch libname ]
287 [ NL, Str "ar crT ", Out arch libname ]
289 [ In BuildTree arch o | o <- objs ]
291 if libs == [] then []
292 else [ In BuildTree arch a | a <- libs ]
294 [ NL, Str "ranlib ", Out arch libname ]
297 -- Link an executable
299 linker :: String -> String -> Options -> [String] -> [String] -> [String] -> String -> [RuleToken]
300 linker arch compiler opts objs libs mods bin =
306 [ Str "-o", Out arch bin ]
308 [ In BuildTree arch o | o <- objs ]
310 [Str "-Wl,--start-group"]
312 [ In BuildTree arch l | l <- libs ]
314 [Str "-Wl,--whole-archive"] ++ [ In BuildTree arch l | l <- mods ] ++ [Str "-Wl,--no-whole-archive"]
318 [Str "-Wl,--end-group"]
322 -- Link an executable
324 cxxlinker :: String -> String -> Options -> [String] -> [String] -> [String] -> String -> [RuleToken]
325 cxxlinker arch cxxcompiler opts objs libs mods bin =
327 ++ (optLdCxxFlags opts)
331 [ Str "-o", Out arch bin ]
333 [ In BuildTree arch o | o <- objs ]
335 [ In BuildTree arch l | l <- libs ]
337 [Str "-Wl,--start-group -Wl,--whole-archive"] ++ [ In BuildTree arch l | l <- mods ] ++ [Str "-Wl,--no-whole-archive"]
341 [Str "-Wl,--end-group"]
344 -- Strip debug symbols from an executable
346 strip :: String -> String -> Options -> String -> String ->
347 String -> [RuleToken]
348 strip arch objcopy opts src debuglink target =
351 NStr "--add-gnu-debuglink=", In BuildTree arch debuglink,
352 In BuildTree arch src,
357 -- Extract debug symbols from an executable
359 debug :: String -> String -> Options -> String -> String -> [RuleToken]
360 debug arch objcopy opts src target =
362 Str "--only-keep-debug",
363 In BuildTree arch src,