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 | |
| 23 | "android/soong/common" |
| 24 | ) |
| 25 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 26 | func (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 Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 29 | if len(c.Properties.AndroidMkSharedLibs) > 0 { |
| 30 | fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.Properties.AndroidMkSharedLibs, " ")) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 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) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 51 | if c.linker.installable() { |
| 52 | callSubAndroidMk(c.installer) |
| 53 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 54 | |
| 55 | return ret, nil |
| 56 | } |
| 57 | |
| 58 | func (library *baseLinker) AndroidMk(ret *common.AndroidMkData) { |
| 59 | if library.static() { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 60 | ret.Class = "STATIC_LIBRARIES" |
| 61 | } else { |
| 62 | ret.Class = "SHARED_LIBRARIES" |
| 63 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | func (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 Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 72 | if flag != "" { |
| 73 | exportedIncludes = append(exportedIncludes, strings.TrimPrefix(flag, "-I")) |
| 74 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 75 | } |
| 76 | if len(exportedIncludes) > 0 { |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 77 | fmt.Fprintln(w, "LOCAL_EXPORT_C_INCLUDE_DIRS :=", strings.Join(exportedIncludes, " ")) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 80 | fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext()) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 81 | |
| 82 | // These are already included in LOCAL_SHARED_LIBRARIES |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 83 | fmt.Fprintln(w, "LOCAL_CXX_STL := none") |
| 84 | fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=") |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 85 | |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 86 | return nil |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 87 | }) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 90 | func (object *objectLinker) AndroidMk(ret *common.AndroidMkData) { |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 91 | ret.Custom = func(w io.Writer, name, prefix string) error { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 92 | out := ret.OutputFile.Path() |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 93 | |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 94 | 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 Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 98 | } |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 101 | func (binary *binaryLinker) AndroidMk(ret *common.AndroidMkData) { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 102 | ret.Class = "EXECUTABLES" |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 103 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile common.Path) error { |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 104 | fmt.Fprintln(w, "LOCAL_CXX_STL := none") |
| 105 | fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=") |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 106 | return nil |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 107 | }) |
| 108 | } |
| 109 | |
| 110 | func (test *testLinker) AndroidMk(ret *common.AndroidMkData) { |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 111 | test.binaryLinker.AndroidMk(ret) |
| 112 | if Bool(test.Properties.Test_per_src) { |
| 113 | ret.SubName = test.binaryLinker.Properties.Stem |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | func (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 Cross | bf305de | 2016-03-29 17:32:06 -0700 | [diff] [blame] | 120 | dir, file := filepath.Split(path) |
| 121 | stem := strings.TrimSuffix(file, filepath.Ext(file)) |
Colin Cross | e14388b | 2016-05-03 14:08:40 -0700 | [diff] [blame^] | 122 | fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir)) |
Colin Cross | bf305de | 2016-03-29 17:32:06 -0700 | [diff] [blame] | 123 | fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 124 | return nil |
| 125 | }) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 126 | } |