Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 1 | // Copyright 2016 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 ( |
| 18 | "fmt" |
| 19 | |
| 20 | "github.com/google/blueprint" |
| 21 | |
| 22 | "android/soong" |
| 23 | "android/soong/android" |
| 24 | ) |
| 25 | |
| 26 | // |
| 27 | // Objects (for crt*.o) |
| 28 | // |
| 29 | |
| 30 | func init() { |
| 31 | soong.RegisterModuleType("cc_object", objectFactory) |
| 32 | } |
| 33 | |
| 34 | type objectLinker struct { |
| 35 | Properties ObjectLinkerProperties |
| 36 | } |
| 37 | |
| 38 | func objectFactory() (blueprint.Module, []interface{}) { |
| 39 | module := newBaseModule(android.DeviceSupported, android.MultilibBoth) |
| 40 | module.compiler = &baseCompiler{} |
| 41 | module.linker = &objectLinker{} |
| 42 | return module.Init() |
| 43 | } |
| 44 | |
| 45 | func (object *objectLinker) appendLdflags(flags []string) { |
| 46 | panic(fmt.Errorf("appendLdflags on object Linker not supported")) |
| 47 | } |
| 48 | |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 49 | func (object *objectLinker) linkerProps() []interface{} { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 50 | return []interface{}{&object.Properties} |
| 51 | } |
| 52 | |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 53 | func (*objectLinker) linkerInit(ctx BaseModuleContext) {} |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 54 | |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 55 | func (object *objectLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 56 | deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...) |
| 57 | return deps |
| 58 | } |
| 59 | |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 60 | func (*objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 61 | if flags.Clang { |
| 62 | flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainClangLdflags()) |
| 63 | } else { |
| 64 | flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainLdflags()) |
| 65 | } |
| 66 | |
| 67 | return flags |
| 68 | } |
| 69 | |
| 70 | func (object *objectLinker) link(ctx ModuleContext, |
| 71 | flags Flags, deps PathDeps, objFiles android.Paths) android.Path { |
| 72 | |
| 73 | objFiles = append(objFiles, deps.ObjFiles...) |
| 74 | |
| 75 | var outputFile android.Path |
| 76 | if len(objFiles) == 1 { |
| 77 | outputFile = objFiles[0] |
| 78 | } else { |
| 79 | output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension) |
| 80 | TransformObjsToObj(ctx, objFiles, flagsToBuilderFlags(flags), output) |
| 81 | outputFile = output |
| 82 | } |
| 83 | |
| 84 | ctx.CheckbuildFile(outputFile) |
| 85 | return outputFile |
| 86 | } |
| 87 | |
| 88 | func (*objectLinker) installable() bool { |
| 89 | return false |
| 90 | } |