blob: 00214f0301e46e95643a1ac968ce4e825b62d83f [file] [log] [blame]
Mauro Rossi4bdf3032018-08-25 12:44:44 +02001// Copyright (C) 2016 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Mauro Rossi6f676672019-02-23 13:23:31 +010015package llvm80
Mauro Rossi4bdf3032018-08-25 12:44:44 +020016
17import (
18 "android/soong/android"
19 "android/soong/cc"
20
21 "github.com/google/blueprint/proptools"
22)
23
24func globalFlags(ctx android.BaseContext) []string {
25 var cflags []string
26
27 if ctx.AConfig().IsEnvTrue("FORCE_BUILD_LLVM_DISABLE_NDEBUG") {
28 cflags = append(cflags, "-D_DEBUG", "-UNDEBUG")
29 }
30
31 return cflags
32}
33
34func deviceFlags(ctx android.BaseContext) []string {
35 var cflags []string
36
37 return cflags
38}
39
40func hostFlags(ctx android.BaseContext) []string {
41 var cflags []string
42
43 if ctx.AConfig().IsEnvTrue("FORCE_BUILD_LLVM_DEBUG") {
44 cflags = append(cflags, "-O0", "-g")
45 }
46
47 return cflags
48}
49
50func llvmDefaults(ctx android.LoadHookContext) {
51 type props struct {
52 Target struct {
53 Android struct {
54 Cflags []string
55 Enabled *bool
56 }
57 Host struct {
58 Enabled *bool
59 }
60 Linux struct {
61 Cflags []string
62 }
63 Darwin struct {
64 Cflags []string
65 }
66 }
67 Cflags []string
68 }
69
70 p := &props{}
71 p.Cflags = globalFlags(ctx)
72 p.Target.Android.Cflags = deviceFlags(ctx)
73 h := hostFlags(ctx)
74 p.Target.Linux.Cflags = h
75 p.Target.Darwin.Cflags = h
76
77 if ctx.AConfig().IsEnvTrue("DISABLE_LLVM_DEVICE_BUILDS") {
78 p.Target.Android.Enabled = proptools.BoolPtr(false)
79 }
80
81 ctx.AppendProperties(p)
82}
83
84func forceBuildLlvmComponents(ctx android.LoadHookContext) {
85 if !ctx.AConfig().IsEnvTrue("FORCE_BUILD_LLVM_COMPONENTS") {
86 type props struct {
87 Target struct {
88 Host struct {
89 Enabled *bool
90 }
91 }
92 }
93 p := &props{}
94 p.Target.Host.Enabled = proptools.BoolPtr(false)
95 ctx.AppendProperties(p)
96 }
97}
98
99func init() {
Mauro Rossi6f676672019-02-23 13:23:31 +0100100 android.RegisterModuleType("llvm80_defaults", llvmDefaultsFactory)
101 android.RegisterModuleType("force_build_llvm80_components_defaults", forceBuildLlvmComponentsDefaultsFactory)
Mauro Rossi4bdf3032018-08-25 12:44:44 +0200102}
103
104func llvmDefaultsFactory() android.Module {
105 module := cc.DefaultsFactory()
106 android.AddLoadHook(module, llvmDefaults)
107
108 return module
109}
110
111func forceBuildLlvmComponentsDefaultsFactory() android.Module {
112 module := cc.DefaultsFactory()
113 android.AddLoadHook(module, forceBuildLlvmComponents)
114 return module
115}