2015-01-31 02:27:36 +01:00
|
|
|
package cc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Cflags that should be filtered out when compiling with clang
|
2015-10-21 00:21:33 +02:00
|
|
|
var clangUnknownCflags = sorted([]string{
|
2015-01-31 02:27:36 +01:00
|
|
|
"-finline-functions",
|
|
|
|
"-finline-limit=64",
|
|
|
|
"-fno-canonical-system-headers",
|
2015-09-12 02:41:10 +02:00
|
|
|
"-Wno-clobbered",
|
|
|
|
"-fno-devirtualize",
|
2015-01-31 02:27:36 +01:00
|
|
|
"-fno-tree-sra",
|
2015-03-17 00:22:28 +01:00
|
|
|
"-fprefetch-loop-arrays",
|
2015-01-31 02:27:36 +01:00
|
|
|
"-funswitch-loops",
|
|
|
|
"-Wmaybe-uninitialized",
|
2015-09-12 02:41:10 +02:00
|
|
|
"-Wno-error=clobbered",
|
2015-01-31 02:27:36 +01:00
|
|
|
"-Wno-error=maybe-uninitialized",
|
2015-04-28 22:30:13 +02:00
|
|
|
"-Wno-error=unused-but-set-parameter",
|
|
|
|
"-Wno-error=unused-but-set-variable",
|
2015-01-31 02:27:36 +01:00
|
|
|
"-Wno-free-nonheap-object",
|
|
|
|
"-Wno-literal-suffix",
|
|
|
|
"-Wno-maybe-uninitialized",
|
|
|
|
"-Wno-old-style-declaration",
|
|
|
|
"-Wno-psabi",
|
|
|
|
"-Wno-unused-but-set-parameter",
|
2015-04-28 22:30:13 +02:00
|
|
|
"-Wno-unused-but-set-variable",
|
2015-01-31 02:27:36 +01:00
|
|
|
"-Wno-unused-local-typedefs",
|
2015-03-19 01:20:28 +01:00
|
|
|
"-Wunused-but-set-parameter",
|
2015-04-28 22:30:13 +02:00
|
|
|
"-Wunused-but-set-variable",
|
2015-10-21 00:21:33 +02:00
|
|
|
"-fdiagnostics-color",
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
// arm + arm64 + mips + mips64
|
|
|
|
"-fgcse-after-reload",
|
|
|
|
"-frerun-cse-after-loop",
|
|
|
|
"-frename-registers",
|
|
|
|
"-fno-strict-volatile-bitfields",
|
|
|
|
|
|
|
|
// arm + arm64
|
|
|
|
"-fno-align-jumps",
|
|
|
|
|
|
|
|
// arm
|
|
|
|
"-mthumb-interwork",
|
|
|
|
"-fno-builtin-sin",
|
|
|
|
"-fno-caller-saves",
|
|
|
|
"-fno-early-inlining",
|
|
|
|
"-fno-move-loop-invariants",
|
|
|
|
"-fno-partial-inlining",
|
|
|
|
"-fno-tree-copy-prop",
|
|
|
|
"-fno-tree-loop-optimize",
|
|
|
|
|
|
|
|
// mips + mips64
|
|
|
|
"-msynci",
|
2015-09-12 02:41:10 +02:00
|
|
|
"-mno-synci",
|
2015-01-31 02:27:36 +01:00
|
|
|
"-mno-fused-madd",
|
|
|
|
|
|
|
|
// x86 + x86_64
|
|
|
|
"-finline-limit=300",
|
|
|
|
"-fno-inline-functions-called-once",
|
|
|
|
"-mfpmath=sse",
|
|
|
|
"-mbionic",
|
2015-10-21 00:21:33 +02:00
|
|
|
})
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
pctx.StaticVariable("clangExtraCflags", strings.Join([]string{
|
|
|
|
"-D__compiler_offsetof=__builtin_offsetof",
|
|
|
|
|
|
|
|
// Help catch common 32/64-bit errors.
|
|
|
|
"-Werror=int-conversion",
|
|
|
|
|
2015-04-28 22:30:13 +02:00
|
|
|
// Disable overly aggressive warning for macros defined with a leading underscore
|
|
|
|
// This happens in AndroidConfig.h, which is included nearly everywhere.
|
2015-09-12 02:41:10 +02:00
|
|
|
// TODO: can we remove this now?
|
2015-04-28 22:30:13 +02:00
|
|
|
"-Wno-reserved-id-macro",
|
|
|
|
|
|
|
|
// Disable overly aggressive warning for format strings.
|
|
|
|
// Bug: 20148343
|
|
|
|
"-Wno-format-pedantic",
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
// Workaround for ccache with clang.
|
|
|
|
// See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
|
|
|
|
"-Wno-unused-command-line-argument",
|
|
|
|
|
2015-10-21 00:21:33 +02:00
|
|
|
// Force clang to always output color diagnostics. Ninja will strip the ANSI
|
|
|
|
// color codes if it is not running in a terminal.
|
|
|
|
"-fcolor-diagnostics",
|
2015-01-31 02:27:36 +01:00
|
|
|
}, " "))
|
|
|
|
|
|
|
|
pctx.StaticVariable("clangExtraConlyflags", strings.Join([]string{
|
|
|
|
"-std=gnu99",
|
|
|
|
}, " "))
|
|
|
|
|
2016-01-13 01:22:40 +01:00
|
|
|
pctx.StaticVariable("clangExtraCppflags", strings.Join([]string{
|
|
|
|
// Disable -Winconsistent-missing-override until we can clean up the existing
|
|
|
|
// codebase for it.
|
|
|
|
"-Wno-inconsistent-missing-override",
|
|
|
|
}, " "))
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
pctx.StaticVariable("clangExtraTargetCflags", strings.Join([]string{
|
|
|
|
"-nostdlibinc",
|
|
|
|
}, " "))
|
2016-03-04 02:21:04 +01:00
|
|
|
|
|
|
|
pctx.StaticVariable("clangExtraNoOverrideCflags", strings.Join([]string{
|
|
|
|
"-Werror=address-of-temporary",
|
|
|
|
"-Werror=null-dereference",
|
|
|
|
"-Werror=return-type",
|
|
|
|
}, " "))
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func clangFilterUnknownCflags(cflags []string) []string {
|
|
|
|
ret := make([]string, 0, len(cflags))
|
|
|
|
for _, f := range cflags {
|
|
|
|
if !inListSorted(f, clangUnknownCflags) {
|
|
|
|
ret = append(ret, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func inListSorted(s string, list []string) bool {
|
|
|
|
for _, l := range list {
|
|
|
|
if s == l {
|
|
|
|
return true
|
|
|
|
} else if s < l {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2015-10-21 00:21:33 +02:00
|
|
|
|
|
|
|
func sorted(list []string) []string {
|
|
|
|
sort.Strings(list)
|
|
|
|
return list
|
|
|
|
}
|