blob: 103d5ea6d3e876088cafce5448ebd970ff53bac9 [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 Crossca860ac2016-01-04 14:34:37 -080027 ret.OutputFile = c.outputFile
Colin Cross635c3b02016-05-18 15:37:25 -070028 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) (err error) {
Colin Cross30d5f512016-05-03 18:02:42 -070029 fmt.Fprintln(w, "LOCAL_SANITIZE := never")
Colin Crossc99deeb2016-04-11 15:06:20 -070030 if len(c.Properties.AndroidMkSharedLibs) > 0 {
31 fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.Properties.AndroidMkSharedLibs, " "))
Colin Crossca860ac2016-01-04 14:34:37 -080032 }
33 return nil
34 })
35
36 callSubAndroidMk := func(obj interface{}) {
37 if obj != nil {
38 if androidmk, ok := obj.(interface {
Colin Cross635c3b02016-05-18 15:37:25 -070039 AndroidMk(*android.AndroidMkData)
Colin Crossca860ac2016-01-04 14:34:37 -080040 }); ok {
41 androidmk.AndroidMk(&ret)
42 }
43 }
44 }
45
46 for _, feature := range c.features {
47 callSubAndroidMk(feature)
48 }
49
50 callSubAndroidMk(c.compiler)
51 callSubAndroidMk(c.linker)
Colin Crossc99deeb2016-04-11 15:06:20 -070052 if c.linker.installable() {
53 callSubAndroidMk(c.installer)
54 }
Colin Crossca860ac2016-01-04 14:34:37 -080055
56 return ret, nil
57}
58
Colin Cross635c3b02016-05-18 15:37:25 -070059func (library *baseLinker) AndroidMk(ret *android.AndroidMkData) {
Colin Crossca860ac2016-01-04 14:34:37 -080060 if library.static() {
Dan Willemsen218f6562015-07-08 18:13:11 -070061 ret.Class = "STATIC_LIBRARIES"
62 } else {
63 ret.Class = "SHARED_LIBRARIES"
64 }
Colin Crossca860ac2016-01-04 14:34:37 -080065}
66
Colin Cross635c3b02016-05-18 15:37:25 -070067func (library *libraryLinker) AndroidMk(ret *android.AndroidMkData) {
Colin Crossca860ac2016-01-04 14:34:37 -080068 library.baseLinker.AndroidMk(ret)
69
Colin Cross635c3b02016-05-18 15:37:25 -070070 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error {
Dan Willemsen3b1fffa2016-05-05 15:11:48 -070071 var exportedIncludes []string
Colin Crossca860ac2016-01-04 14:34:37 -080072 for _, flag := range library.exportedFlags() {
Dan Willemsen3b1fffa2016-05-05 15:11:48 -070073 if strings.HasPrefix(flag, "-I") {
Dan Willemsen97750522016-02-09 17:43:51 -080074 exportedIncludes = append(exportedIncludes, strings.TrimPrefix(flag, "-I"))
75 }
Dan Willemsen218f6562015-07-08 18:13:11 -070076 }
77 if len(exportedIncludes) > 0 {
Dan Willemsen97750522016-02-09 17:43:51 -080078 fmt.Fprintln(w, "LOCAL_EXPORT_C_INCLUDE_DIRS :=", strings.Join(exportedIncludes, " "))
Dan Willemsen218f6562015-07-08 18:13:11 -070079 }
80
Colin Crossca860ac2016-01-04 14:34:37 -080081 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext())
Dan Willemsen218f6562015-07-08 18:13:11 -070082
83 // These are already included in LOCAL_SHARED_LIBRARIES
Dan Willemsen97750522016-02-09 17:43:51 -080084 fmt.Fprintln(w, "LOCAL_CXX_STL := none")
85 fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
Dan Willemsen218f6562015-07-08 18:13:11 -070086
Dan Willemsen97750522016-02-09 17:43:51 -080087 return nil
Colin Crossca860ac2016-01-04 14:34:37 -080088 })
Dan Willemsen218f6562015-07-08 18:13:11 -070089}
90
Colin Cross635c3b02016-05-18 15:37:25 -070091func (object *objectLinker) AndroidMk(ret *android.AndroidMkData) {
Dan Willemsen97750522016-02-09 17:43:51 -080092 ret.Custom = func(w io.Writer, name, prefix string) error {
Colin Crossca860ac2016-01-04 14:34:37 -080093 out := ret.OutputFile.Path()
Dan Willemsen218f6562015-07-08 18:13:11 -070094
Dan Willemsen97750522016-02-09 17:43:51 -080095 fmt.Fprintln(w, "\n$("+prefix+"OUT_INTERMEDIATE_LIBRARIES)/"+name+objectExtension+":", out.String(), "| $(ACP)")
96 fmt.Fprintln(w, "\t$(copy-file-to-target)")
97
98 return nil
Dan Willemsen218f6562015-07-08 18:13:11 -070099 }
Dan Willemsen218f6562015-07-08 18:13:11 -0700100}
101
Colin Cross635c3b02016-05-18 15:37:25 -0700102func (binary *binaryLinker) AndroidMk(ret *android.AndroidMkData) {
Dan Willemsen218f6562015-07-08 18:13:11 -0700103 ret.Class = "EXECUTABLES"
Colin Cross635c3b02016-05-18 15:37:25 -0700104 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error {
Dan Willemsen97750522016-02-09 17:43:51 -0800105 fmt.Fprintln(w, "LOCAL_CXX_STL := none")
106 fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
Dan Willemsen97750522016-02-09 17:43:51 -0800107 return nil
Colin Crossca860ac2016-01-04 14:34:37 -0800108 })
109}
110
Colin Cross635c3b02016-05-18 15:37:25 -0700111func (test *testLinker) AndroidMk(ret *android.AndroidMkData) {
Colin Crossa2344662016-03-24 13:14:12 -0700112 test.binaryLinker.AndroidMk(ret)
113 if Bool(test.Properties.Test_per_src) {
114 ret.SubName = test.binaryLinker.Properties.Stem
115 }
116}
117
Colin Cross635c3b02016-05-18 15:37:25 -0700118func (library *toolchainLibraryLinker) AndroidMk(ret *android.AndroidMkData) {
Dan Willemsene7932e82016-05-16 15:56:53 -0700119 library.baseLinker.AndroidMk(ret)
120
Colin Cross635c3b02016-05-18 15:37:25 -0700121 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error {
Dan Willemsene7932e82016-05-16 15:56:53 -0700122 fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext())
123 fmt.Fprintln(w, "LOCAL_CXX_STL := none")
124 fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
125
126 return nil
127 })
128}
129
Colin Cross635c3b02016-05-18 15:37:25 -0700130func (installer *baseInstaller) AndroidMk(ret *android.AndroidMkData) {
131 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error {
Colin Crossa2344662016-03-24 13:14:12 -0700132 path := installer.path.RelPathString()
Colin Crossbf305de2016-03-29 17:32:06 -0700133 dir, file := filepath.Split(path)
134 stem := strings.TrimSuffix(file, filepath.Ext(file))
Colin Crosse14388b2016-05-03 14:08:40 -0700135 fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
Colin Crossbf305de2016-03-29 17:32:06 -0700136 fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
Colin Crossa2344662016-03-24 13:14:12 -0700137 return nil
138 })
Dan Willemsen218f6562015-07-08 18:13:11 -0700139}