blob: 5495e205bbb24a7cd5dc3ab2ff02e4b28f2fa1eb [file] [log] [blame]
Dan Willemsen218f6562015-07-08 18:13:11 -07001// Copyright 2015 Google Inc. All rights reserved.
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
15package cc
16
17import (
Dan Willemsen97750522016-02-09 17:43:51 -080018 "fmt"
Dan Willemsen218f6562015-07-08 18:13:11 -070019 "io"
Colin Crossa2344662016-03-24 13:14:12 -070020 "path/filepath"
Dan Willemsen218f6562015-07-08 18:13:11 -070021 "strings"
22
Colin Cross635c3b02016-05-18 15:37:25 -070023 "android/soong/android"
Dan Willemsen218f6562015-07-08 18:13:11 -070024)
25
Colin Cross635c3b02016-05-18 15:37:25 -070026func (c *Module) AndroidMk() (ret android.AndroidMkData, err error) {
Colin Crossbc6fb162016-05-24 15:39:04 -070027 if c.Properties.HideFromMake {
28 ret.Disabled = true
29 return ret, nil
30 }
31
Colin Crossca860ac2016-01-04 14:34:37 -080032 ret.OutputFile = c.outputFile
Colin Cross635c3b02016-05-18 15:37:25 -070033 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) (err error) {
Colin Cross30d5f512016-05-03 18:02:42 -070034 fmt.Fprintln(w, "LOCAL_SANITIZE := never")
Colin Crossc99deeb2016-04-11 15:06:20 -070035 if len(c.Properties.AndroidMkSharedLibs) > 0 {
36 fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.Properties.AndroidMkSharedLibs, " "))
Colin Crossca860ac2016-01-04 14:34:37 -080037 }
Dan Willemsena96ff642016-06-07 12:34:45 -070038 if c.Target().Os == android.Android && c.Properties.Sdk_version != "" {
39 fmt.Fprintln(w, "LOCAL_SDK_VERSION := "+c.Properties.Sdk_version)
40 fmt.Fprintln(w, "LOCAL_NDK_STL_VARIANT := none")
41 } else {
42 // These are already included in LOCAL_SHARED_LIBRARIES
43 fmt.Fprintln(w, "LOCAL_CXX_STL := none")
44 }
Colin Crossca860ac2016-01-04 14:34:37 -080045 return nil
46 })
47
48 callSubAndroidMk := func(obj interface{}) {
49 if obj != nil {
50 if androidmk, ok := obj.(interface {
Colin Cross635c3b02016-05-18 15:37:25 -070051 AndroidMk(*android.AndroidMkData)
Colin Crossca860ac2016-01-04 14:34:37 -080052 }); ok {
53 androidmk.AndroidMk(&ret)
54 }
55 }
56 }
57
58 for _, feature := range c.features {
59 callSubAndroidMk(feature)
60 }
61
62 callSubAndroidMk(c.compiler)
63 callSubAndroidMk(c.linker)
Colin Crossc99deeb2016-04-11 15:06:20 -070064 if c.linker.installable() {
65 callSubAndroidMk(c.installer)
66 }
Colin Crossca860ac2016-01-04 14:34:37 -080067
68 return ret, nil
69}
70
Colin Cross635c3b02016-05-18 15:37:25 -070071func (library *baseLinker) AndroidMk(ret *android.AndroidMkData) {
Colin Crossca860ac2016-01-04 14:34:37 -080072 if library.static() {
Dan Willemsen218f6562015-07-08 18:13:11 -070073 ret.Class = "STATIC_LIBRARIES"
74 } else {
75 ret.Class = "SHARED_LIBRARIES"
76 }
Colin Crossca860ac2016-01-04 14:34:37 -080077}
78
Colin Cross635c3b02016-05-18 15:37:25 -070079func (library *libraryLinker) AndroidMk(ret *android.AndroidMkData) {
Colin Crossca860ac2016-01-04 14:34:37 -080080 library.baseLinker.AndroidMk(ret)
81
Colin Cross7b5c22b2016-07-07 11:16:20 -070082 if !library.static() {
83 library.stripper.AndroidMk(ret)
84 }
Dan Willemsen7517ed02016-06-10 17:20:30 -070085
Colin Cross635c3b02016-05-18 15:37:25 -070086 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error {
Dan Willemsen3b1fffa2016-05-05 15:11:48 -070087 var exportedIncludes []string
Colin Crossca860ac2016-01-04 14:34:37 -080088 for _, flag := range library.exportedFlags() {
Dan Willemsen3b1fffa2016-05-05 15:11:48 -070089 if strings.HasPrefix(flag, "-I") {
Dan Willemsen97750522016-02-09 17:43:51 -080090 exportedIncludes = append(exportedIncludes, strings.TrimPrefix(flag, "-I"))
91 }
Dan Willemsen218f6562015-07-08 18:13:11 -070092 }
93 if len(exportedIncludes) > 0 {
Dan Willemsen97750522016-02-09 17:43:51 -080094 fmt.Fprintln(w, "LOCAL_EXPORT_C_INCLUDE_DIRS :=", strings.Join(exportedIncludes, " "))
Dan Willemsen218f6562015-07-08 18:13:11 -070095 }
96
Colin Crossca860ac2016-01-04 14:34:37 -080097 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext())
Dan Willemsen218f6562015-07-08 18:13:11 -070098
Dan Willemsen97750522016-02-09 17:43:51 -080099 fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
Dan Willemsen218f6562015-07-08 18:13:11 -0700100
Dan Willemsen97750522016-02-09 17:43:51 -0800101 return nil
Colin Crossca860ac2016-01-04 14:34:37 -0800102 })
Dan Willemsen218f6562015-07-08 18:13:11 -0700103}
104
Colin Cross635c3b02016-05-18 15:37:25 -0700105func (object *objectLinker) AndroidMk(ret *android.AndroidMkData) {
Dan Willemsen97750522016-02-09 17:43:51 -0800106 ret.Custom = func(w io.Writer, name, prefix string) error {
Colin Crossca860ac2016-01-04 14:34:37 -0800107 out := ret.OutputFile.Path()
Dan Willemsen218f6562015-07-08 18:13:11 -0700108
Dan Willemsen72d39932016-07-08 23:23:48 -0700109 fmt.Fprintln(w, "\n$("+prefix+"OUT_INTERMEDIATE_LIBRARIES)/"+name+objectExtension+":", out.String())
Dan Willemsen97750522016-02-09 17:43:51 -0800110 fmt.Fprintln(w, "\t$(copy-file-to-target)")
111
112 return nil
Dan Willemsen218f6562015-07-08 18:13:11 -0700113 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700114}
115
Colin Cross635c3b02016-05-18 15:37:25 -0700116func (binary *binaryLinker) AndroidMk(ret *android.AndroidMkData) {
Dan Willemsen7517ed02016-06-10 17:20:30 -0700117 binary.stripper.AndroidMk(ret)
118
Dan Willemsen218f6562015-07-08 18:13:11 -0700119 ret.Class = "EXECUTABLES"
Colin Cross635c3b02016-05-18 15:37:25 -0700120 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error {
Dan Willemsen97750522016-02-09 17:43:51 -0800121 fmt.Fprintln(w, "LOCAL_CXX_STL := none")
122 fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
Dan Willemsen97750522016-02-09 17:43:51 -0800123 return nil
Colin Crossca860ac2016-01-04 14:34:37 -0800124 })
125}
126
Colin Cross635c3b02016-05-18 15:37:25 -0700127func (test *testLinker) AndroidMk(ret *android.AndroidMkData) {
Colin Crossa2344662016-03-24 13:14:12 -0700128 test.binaryLinker.AndroidMk(ret)
129 if Bool(test.Properties.Test_per_src) {
130 ret.SubName = test.binaryLinker.Properties.Stem
131 }
132}
133
Colin Cross635c3b02016-05-18 15:37:25 -0700134func (library *toolchainLibraryLinker) AndroidMk(ret *android.AndroidMkData) {
Dan Willemsene7932e82016-05-16 15:56:53 -0700135 library.baseLinker.AndroidMk(ret)
136
Colin Cross635c3b02016-05-18 15:37:25 -0700137 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error {
Dan Willemsene7932e82016-05-16 15:56:53 -0700138 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext())
139 fmt.Fprintln(w, "LOCAL_CXX_STL := none")
140 fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
141
142 return nil
143 })
144}
145
Dan Willemsen7517ed02016-06-10 17:20:30 -0700146func (stripper *stripper) AndroidMk(ret *android.AndroidMkData) {
147 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error {
148 if stripper.StripProperties.Strip.None {
149 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
150 } else if stripper.StripProperties.Strip.Keep_symbols {
151 fmt.Fprintln(w, "LOCAL_STRIP_MODULE := keep_symbols")
152 }
153
154 return nil
155 })
156}
157
Colin Cross635c3b02016-05-18 15:37:25 -0700158func (installer *baseInstaller) AndroidMk(ret *android.AndroidMkData) {
159 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error {
Colin Crossa2344662016-03-24 13:14:12 -0700160 path := installer.path.RelPathString()
Colin Crossbf305de2016-03-29 17:32:06 -0700161 dir, file := filepath.Split(path)
162 stem := strings.TrimSuffix(file, filepath.Ext(file))
Colin Crosse14388b2016-05-03 14:08:40 -0700163 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
Colin Crossbf305de2016-03-29 17:32:06 -0700164 fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
Colin Crossa2344662016-03-24 13:14:12 -0700165 return nil
166 })
Dan Willemsen218f6562015-07-08 18:13:11 -0700167}