Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 18 | "fmt" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 19 | "io" |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 20 | "path/filepath" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 21 | "strings" |
| 22 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 23 | "android/soong/android" |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 24 | ) |
| 25 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 26 | func (c *Module) AndroidMk() (ret android.AndroidMkData, err error) { |
Colin Cross | bc6fb16 | 2016-05-24 15:39:04 -0700 | [diff] [blame] | 27 | if c.Properties.HideFromMake { |
| 28 | ret.Disabled = true |
| 29 | return ret, nil |
| 30 | } |
| 31 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 32 | ret.OutputFile = c.outputFile |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 33 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) (err error) { |
Colin Cross | 30d5f51 | 2016-05-03 18:02:42 -0700 | [diff] [blame] | 34 | fmt.Fprintln(w, "LOCAL_SANITIZE := never") |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 35 | if len(c.Properties.AndroidMkSharedLibs) > 0 { |
| 36 | fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.Properties.AndroidMkSharedLibs, " ")) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 37 | } |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame^] | 38 | 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 Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 45 | return nil |
| 46 | }) |
| 47 | |
| 48 | callSubAndroidMk := func(obj interface{}) { |
| 49 | if obj != nil { |
| 50 | if androidmk, ok := obj.(interface { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 51 | AndroidMk(*android.AndroidMkData) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 52 | }); 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 Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 64 | if c.linker.installable() { |
| 65 | callSubAndroidMk(c.installer) |
| 66 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 67 | |
| 68 | return ret, nil |
| 69 | } |
| 70 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 71 | func (library *baseLinker) AndroidMk(ret *android.AndroidMkData) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 72 | if library.static() { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 73 | ret.Class = "STATIC_LIBRARIES" |
| 74 | } else { |
| 75 | ret.Class = "SHARED_LIBRARIES" |
| 76 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 79 | func (library *libraryLinker) AndroidMk(ret *android.AndroidMkData) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 80 | library.baseLinker.AndroidMk(ret) |
| 81 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 82 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { |
Dan Willemsen | 3b1fffa | 2016-05-05 15:11:48 -0700 | [diff] [blame] | 83 | var exportedIncludes []string |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 84 | for _, flag := range library.exportedFlags() { |
Dan Willemsen | 3b1fffa | 2016-05-05 15:11:48 -0700 | [diff] [blame] | 85 | if strings.HasPrefix(flag, "-I") { |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 86 | exportedIncludes = append(exportedIncludes, strings.TrimPrefix(flag, "-I")) |
| 87 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 88 | } |
| 89 | if len(exportedIncludes) > 0 { |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 90 | fmt.Fprintln(w, "LOCAL_EXPORT_C_INCLUDE_DIRS :=", strings.Join(exportedIncludes, " ")) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 93 | fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext()) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 94 | |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 95 | fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=") |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 96 | |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 97 | return nil |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 98 | }) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 101 | func (object *objectLinker) AndroidMk(ret *android.AndroidMkData) { |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 102 | ret.Custom = func(w io.Writer, name, prefix string) error { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 103 | out := ret.OutputFile.Path() |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 104 | |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 105 | fmt.Fprintln(w, "\n$("+prefix+"OUT_INTERMEDIATE_LIBRARIES)/"+name+objectExtension+":", out.String(), "| $(ACP)") |
| 106 | fmt.Fprintln(w, "\t$(copy-file-to-target)") |
| 107 | |
| 108 | return nil |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 109 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 112 | func (binary *binaryLinker) AndroidMk(ret *android.AndroidMkData) { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 113 | ret.Class = "EXECUTABLES" |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 114 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 115 | fmt.Fprintln(w, "LOCAL_CXX_STL := none") |
| 116 | fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=") |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 117 | return nil |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 118 | }) |
| 119 | } |
| 120 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 121 | func (test *testLinker) AndroidMk(ret *android.AndroidMkData) { |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 122 | test.binaryLinker.AndroidMk(ret) |
| 123 | if Bool(test.Properties.Test_per_src) { |
| 124 | ret.SubName = test.binaryLinker.Properties.Stem |
| 125 | } |
| 126 | } |
| 127 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 128 | func (library *toolchainLibraryLinker) AndroidMk(ret *android.AndroidMkData) { |
Dan Willemsen | e7932e8 | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 129 | library.baseLinker.AndroidMk(ret) |
| 130 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 131 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { |
Dan Willemsen | e7932e8 | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 132 | fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext()) |
| 133 | fmt.Fprintln(w, "LOCAL_CXX_STL := none") |
| 134 | fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=") |
| 135 | |
| 136 | return nil |
| 137 | }) |
| 138 | } |
| 139 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 140 | func (installer *baseInstaller) AndroidMk(ret *android.AndroidMkData) { |
| 141 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error { |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 142 | path := installer.path.RelPathString() |
Colin Cross | bf305de | 2016-03-29 17:32:06 -0700 | [diff] [blame] | 143 | dir, file := filepath.Split(path) |
| 144 | stem := strings.TrimSuffix(file, filepath.Ext(file)) |
Colin Cross | e14388b | 2016-05-03 14:08:40 -0700 | [diff] [blame] | 145 | fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir)) |
Colin Cross | bf305de | 2016-03-29 17:32:06 -0700 | [diff] [blame] | 146 | fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 147 | return nil |
| 148 | }) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 149 | } |