blob: 8b1b349ca31a849c4fcedd016316432d705c3c9e [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
23 "android/soong/common"
24)
25
Colin Crossca860ac2016-01-04 14:34:37 -080026func (c *Module) AndroidMk() (ret common.AndroidMkData, err error) {
27 ret.OutputFile = c.outputFile
28 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile common.Path) (err error) {
29 if len(c.deps.SharedLibs) > 0 {
30 fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.deps.SharedLibs, " "))
31 }
32 return nil
33 })
34
35 callSubAndroidMk := func(obj interface{}) {
36 if obj != nil {
37 if androidmk, ok := obj.(interface {
38 AndroidMk(*common.AndroidMkData)
39 }); ok {
40 androidmk.AndroidMk(&ret)
41 }
42 }
43 }
44
45 for _, feature := range c.features {
46 callSubAndroidMk(feature)
47 }
48
49 callSubAndroidMk(c.compiler)
50 callSubAndroidMk(c.linker)
51 callSubAndroidMk(c.installer)
52
53 return ret, nil
54}
55
56func (library *baseLinker) AndroidMk(ret *common.AndroidMkData) {
57 if library.static() {
Dan Willemsen218f6562015-07-08 18:13:11 -070058 ret.Class = "STATIC_LIBRARIES"
59 } else {
60 ret.Class = "SHARED_LIBRARIES"
61 }
Colin Crossca860ac2016-01-04 14:34:37 -080062}
63
64func (library *libraryLinker) AndroidMk(ret *common.AndroidMkData) {
65 library.baseLinker.AndroidMk(ret)
66
67 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile common.Path) error {
68 exportedIncludes := library.exportedFlags()
69 for _, flag := range library.exportedFlags() {
Dan Willemsen97750522016-02-09 17:43:51 -080070 if flag != "" {
71 exportedIncludes = append(exportedIncludes, strings.TrimPrefix(flag, "-I"))
72 }
Dan Willemsen218f6562015-07-08 18:13:11 -070073 }
74 if len(exportedIncludes) > 0 {
Dan Willemsen97750522016-02-09 17:43:51 -080075 fmt.Fprintln(w, "LOCAL_EXPORT_C_INCLUDE_DIRS :=", strings.Join(exportedIncludes, " "))
Dan Willemsen218f6562015-07-08 18:13:11 -070076 }
77
Colin Crossca860ac2016-01-04 14:34:37 -080078 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext())
Dan Willemsen218f6562015-07-08 18:13:11 -070079
80 // These are already included in LOCAL_SHARED_LIBRARIES
Dan Willemsen97750522016-02-09 17:43:51 -080081 fmt.Fprintln(w, "LOCAL_CXX_STL := none")
82 fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
Dan Willemsen218f6562015-07-08 18:13:11 -070083
Dan Willemsen97750522016-02-09 17:43:51 -080084 return nil
Colin Crossca860ac2016-01-04 14:34:37 -080085 })
Dan Willemsen218f6562015-07-08 18:13:11 -070086}
87
Colin Crossca860ac2016-01-04 14:34:37 -080088func (object *objectLinker) AndroidMk(ret *common.AndroidMkData) {
Dan Willemsen97750522016-02-09 17:43:51 -080089 ret.Custom = func(w io.Writer, name, prefix string) error {
Colin Crossca860ac2016-01-04 14:34:37 -080090 out := ret.OutputFile.Path()
Dan Willemsen218f6562015-07-08 18:13:11 -070091
Dan Willemsen97750522016-02-09 17:43:51 -080092 fmt.Fprintln(w, "\n$("+prefix+"OUT_INTERMEDIATE_LIBRARIES)/"+name+objectExtension+":", out.String(), "| $(ACP)")
93 fmt.Fprintln(w, "\t$(copy-file-to-target)")
94
95 return nil
Dan Willemsen218f6562015-07-08 18:13:11 -070096 }
Dan Willemsen218f6562015-07-08 18:13:11 -070097}
98
Colin Crossca860ac2016-01-04 14:34:37 -080099func (binary *binaryLinker) AndroidMk(ret *common.AndroidMkData) {
Dan Willemsen218f6562015-07-08 18:13:11 -0700100 ret.Class = "EXECUTABLES"
Colin Crossca860ac2016-01-04 14:34:37 -0800101 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile common.Path) error {
Dan Willemsen97750522016-02-09 17:43:51 -0800102 fmt.Fprintln(w, "LOCAL_CXX_STL := none")
103 fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
Dan Willemsen97750522016-02-09 17:43:51 -0800104 return nil
Colin Crossca860ac2016-01-04 14:34:37 -0800105 })
106}
107
108func (test *testLinker) AndroidMk(ret *common.AndroidMkData) {
Colin Crossa2344662016-03-24 13:14:12 -0700109 test.binaryLinker.AndroidMk(ret)
110 if Bool(test.Properties.Test_per_src) {
111 ret.SubName = test.binaryLinker.Properties.Stem
112 }
113}
114
115func (installer *baseInstaller) AndroidMk(ret *common.AndroidMkData) {
116 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile common.Path) error {
117 path := installer.path.RelPathString()
118 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Dir(path))
119 fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+filepath.Base(path))
120 return nil
121 })
Dan Willemsen218f6562015-07-08 18:13:11 -0700122}