blob: aa5c4dcdf1261a987f047c7f4af6d4035ac2ef6e [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"
Dan Willemsen218f6562015-07-08 18:13:11 -070020 "strings"
21
22 "android/soong/common"
23)
24
Colin Crossca860ac2016-01-04 14:34:37 -080025func (c *Module) AndroidMk() (ret common.AndroidMkData, err error) {
26 ret.OutputFile = c.outputFile
27 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile common.Path) (err error) {
28 if len(c.deps.SharedLibs) > 0 {
29 fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.deps.SharedLibs, " "))
30 }
31 return nil
32 })
33
34 callSubAndroidMk := func(obj interface{}) {
35 if obj != nil {
36 if androidmk, ok := obj.(interface {
37 AndroidMk(*common.AndroidMkData)
38 }); ok {
39 androidmk.AndroidMk(&ret)
40 }
41 }
42 }
43
44 for _, feature := range c.features {
45 callSubAndroidMk(feature)
46 }
47
48 callSubAndroidMk(c.compiler)
49 callSubAndroidMk(c.linker)
50 callSubAndroidMk(c.installer)
51
52 return ret, nil
53}
54
55func (library *baseLinker) AndroidMk(ret *common.AndroidMkData) {
56 if library.static() {
Dan Willemsen218f6562015-07-08 18:13:11 -070057 ret.Class = "STATIC_LIBRARIES"
58 } else {
59 ret.Class = "SHARED_LIBRARIES"
60 }
Colin Crossca860ac2016-01-04 14:34:37 -080061}
62
63func (library *libraryLinker) AndroidMk(ret *common.AndroidMkData) {
64 library.baseLinker.AndroidMk(ret)
65
66 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile common.Path) error {
67 exportedIncludes := library.exportedFlags()
68 for _, flag := range library.exportedFlags() {
Dan Willemsen97750522016-02-09 17:43:51 -080069 if flag != "" {
70 exportedIncludes = append(exportedIncludes, strings.TrimPrefix(flag, "-I"))
71 }
Dan Willemsen218f6562015-07-08 18:13:11 -070072 }
73 if len(exportedIncludes) > 0 {
Dan Willemsen97750522016-02-09 17:43:51 -080074 fmt.Fprintln(w, "LOCAL_EXPORT_C_INCLUDE_DIRS :=", strings.Join(exportedIncludes, " "))
Dan Willemsen218f6562015-07-08 18:13:11 -070075 }
76
Colin Crossca860ac2016-01-04 14:34:37 -080077 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext())
Dan Willemsen218f6562015-07-08 18:13:11 -070078
79 // These are already included in LOCAL_SHARED_LIBRARIES
Dan Willemsen97750522016-02-09 17:43:51 -080080 fmt.Fprintln(w, "LOCAL_CXX_STL := none")
81 fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
Dan Willemsen218f6562015-07-08 18:13:11 -070082
Dan Willemsen97750522016-02-09 17:43:51 -080083 return nil
Colin Crossca860ac2016-01-04 14:34:37 -080084 })
Dan Willemsen218f6562015-07-08 18:13:11 -070085}
86
Colin Crossca860ac2016-01-04 14:34:37 -080087func (object *objectLinker) AndroidMk(ret *common.AndroidMkData) {
Dan Willemsen97750522016-02-09 17:43:51 -080088 ret.Custom = func(w io.Writer, name, prefix string) error {
Colin Crossca860ac2016-01-04 14:34:37 -080089 out := ret.OutputFile.Path()
Dan Willemsen218f6562015-07-08 18:13:11 -070090
Dan Willemsen97750522016-02-09 17:43:51 -080091 fmt.Fprintln(w, "\n$("+prefix+"OUT_INTERMEDIATE_LIBRARIES)/"+name+objectExtension+":", out.String(), "| $(ACP)")
92 fmt.Fprintln(w, "\t$(copy-file-to-target)")
93
94 return nil
Dan Willemsen218f6562015-07-08 18:13:11 -070095 }
Dan Willemsen218f6562015-07-08 18:13:11 -070096}
97
Colin Crossca860ac2016-01-04 14:34:37 -080098func (binary *binaryLinker) AndroidMk(ret *common.AndroidMkData) {
Dan Willemsen218f6562015-07-08 18:13:11 -070099 ret.Class = "EXECUTABLES"
Colin Crossca860ac2016-01-04 14:34:37 -0800100 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile common.Path) error {
Dan Willemsen97750522016-02-09 17:43:51 -0800101 fmt.Fprintln(w, "LOCAL_CXX_STL := none")
102 fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
Dan Willemsen97750522016-02-09 17:43:51 -0800103 return nil
Colin Crossca860ac2016-01-04 14:34:37 -0800104 })
105}
106
107func (test *testLinker) AndroidMk(ret *common.AndroidMkData) {
108 ret.Disabled = true
Dan Willemsen218f6562015-07-08 18:13:11 -0700109}