blob: 5b160c637c4b58b6eb19fc811ded93dacbe1fc26 [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) {
Colin Crossc99deeb2016-04-11 15:06:20 -070029 if len(c.Properties.AndroidMkSharedLibs) > 0 {
30 fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.Properties.AndroidMkSharedLibs, " "))
Colin Crossca860ac2016-01-04 14:34:37 -080031 }
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)
Colin Crossc99deeb2016-04-11 15:06:20 -070051 if c.linker.installable() {
52 callSubAndroidMk(c.installer)
53 }
Colin Crossca860ac2016-01-04 14:34:37 -080054
55 return ret, nil
56}
57
58func (library *baseLinker) AndroidMk(ret *common.AndroidMkData) {
59 if library.static() {
Dan Willemsen218f6562015-07-08 18:13:11 -070060 ret.Class = "STATIC_LIBRARIES"
61 } else {
62 ret.Class = "SHARED_LIBRARIES"
63 }
Colin Crossca860ac2016-01-04 14:34:37 -080064}
65
66func (library *libraryLinker) AndroidMk(ret *common.AndroidMkData) {
67 library.baseLinker.AndroidMk(ret)
68
69 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile common.Path) error {
70 exportedIncludes := library.exportedFlags()
71 for _, flag := range library.exportedFlags() {
Dan Willemsen97750522016-02-09 17:43:51 -080072 if flag != "" {
73 exportedIncludes = append(exportedIncludes, strings.TrimPrefix(flag, "-I"))
74 }
Dan Willemsen218f6562015-07-08 18:13:11 -070075 }
76 if len(exportedIncludes) > 0 {
Dan Willemsen97750522016-02-09 17:43:51 -080077 fmt.Fprintln(w, "LOCAL_EXPORT_C_INCLUDE_DIRS :=", strings.Join(exportedIncludes, " "))
Dan Willemsen218f6562015-07-08 18:13:11 -070078 }
79
Colin Crossca860ac2016-01-04 14:34:37 -080080 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext())
Dan Willemsen218f6562015-07-08 18:13:11 -070081
82 // These are already included in LOCAL_SHARED_LIBRARIES
Dan Willemsen97750522016-02-09 17:43:51 -080083 fmt.Fprintln(w, "LOCAL_CXX_STL := none")
84 fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
Dan Willemsen218f6562015-07-08 18:13:11 -070085
Dan Willemsen97750522016-02-09 17:43:51 -080086 return nil
Colin Crossca860ac2016-01-04 14:34:37 -080087 })
Dan Willemsen218f6562015-07-08 18:13:11 -070088}
89
Colin Crossca860ac2016-01-04 14:34:37 -080090func (object *objectLinker) AndroidMk(ret *common.AndroidMkData) {
Dan Willemsen97750522016-02-09 17:43:51 -080091 ret.Custom = func(w io.Writer, name, prefix string) error {
Colin Crossca860ac2016-01-04 14:34:37 -080092 out := ret.OutputFile.Path()
Dan Willemsen218f6562015-07-08 18:13:11 -070093
Dan Willemsen97750522016-02-09 17:43:51 -080094 fmt.Fprintln(w, "\n$("+prefix+"OUT_INTERMEDIATE_LIBRARIES)/"+name+objectExtension+":", out.String(), "| $(ACP)")
95 fmt.Fprintln(w, "\t$(copy-file-to-target)")
96
97 return nil
Dan Willemsen218f6562015-07-08 18:13:11 -070098 }
Dan Willemsen218f6562015-07-08 18:13:11 -070099}
100
Colin Crossca860ac2016-01-04 14:34:37 -0800101func (binary *binaryLinker) AndroidMk(ret *common.AndroidMkData) {
Dan Willemsen218f6562015-07-08 18:13:11 -0700102 ret.Class = "EXECUTABLES"
Colin Crossca860ac2016-01-04 14:34:37 -0800103 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile common.Path) error {
Dan Willemsen97750522016-02-09 17:43:51 -0800104 fmt.Fprintln(w, "LOCAL_CXX_STL := none")
105 fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
Dan Willemsen97750522016-02-09 17:43:51 -0800106 return nil
Colin Crossca860ac2016-01-04 14:34:37 -0800107 })
108}
109
110func (test *testLinker) AndroidMk(ret *common.AndroidMkData) {
Colin Crossa2344662016-03-24 13:14:12 -0700111 test.binaryLinker.AndroidMk(ret)
112 if Bool(test.Properties.Test_per_src) {
113 ret.SubName = test.binaryLinker.Properties.Stem
114 }
115}
116
117func (installer *baseInstaller) AndroidMk(ret *common.AndroidMkData) {
118 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile common.Path) error {
119 path := installer.path.RelPathString()
Colin Crossbf305de2016-03-29 17:32:06 -0700120 dir, file := filepath.Split(path)
121 stem := strings.TrimSuffix(file, filepath.Ext(file))
Colin Crosse14388b2016-05-03 14:08:40 -0700122 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
Colin Crossbf305de2016-03-29 17:32:06 -0700123 fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
Colin Crossa2344662016-03-24 13:14:12 -0700124 return nil
125 })
Dan Willemsen218f6562015-07-08 18:13:11 -0700126}