blob: 14789081ab0311e2a4e1dafb5a3ef70df8f5083f [file] [log] [blame]
Colin Cross4d9c2d12016-07-29 12:48:20 -07001// 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
15package cc
16
17import (
18 "fmt"
19
Colin Cross4d9c2d12016-07-29 12:48:20 -070020 "android/soong/android"
21)
22
23//
24// Objects (for crt*.o)
25//
26
27func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070028 android.RegisterModuleType("cc_object", objectFactory)
Colin Cross4d9c2d12016-07-29 12:48:20 -070029}
30
31type objectLinker struct {
Colin Crossb916a382016-07-29 17:28:03 -070032 *baseLinker
Colin Cross4d9c2d12016-07-29 12:48:20 -070033 Properties ObjectLinkerProperties
34}
35
Colin Cross36242852017-06-23 15:06:31 -070036func objectFactory() android.Module {
Dan Willemsen967c6a92016-11-17 00:30:56 -080037 module := newBaseModule(android.HostAndDeviceSupported, android.MultilibBoth)
Colin Crossb916a382016-07-29 17:28:03 -070038 module.linker = &objectLinker{
39 baseLinker: NewBaseLinker(),
40 }
41 module.compiler = NewBaseCompiler()
Colin Cross4d9c2d12016-07-29 12:48:20 -070042 return module.Init()
43}
44
45func (object *objectLinker) appendLdflags(flags []string) {
46 panic(fmt.Errorf("appendLdflags on object Linker not supported"))
47}
48
Colin Cross42742b82016-08-01 13:20:05 -070049func (object *objectLinker) linkerProps() []interface{} {
Colin Cross4d9c2d12016-07-29 12:48:20 -070050 return []interface{}{&object.Properties}
51}
52
Colin Cross42742b82016-08-01 13:20:05 -070053func (*objectLinker) linkerInit(ctx BaseModuleContext) {}
Colin Cross4d9c2d12016-07-29 12:48:20 -070054
Colin Cross37047f12016-12-13 17:06:13 -080055func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
Colin Cross4d9c2d12016-07-29 12:48:20 -070056 deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...)
57 return deps
58}
59
Colin Cross42742b82016-08-01 13:20:05 -070060func (*objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Colin Cross4d9c2d12016-07-29 12:48:20 -070061 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
70func (object *objectLinker) link(ctx ModuleContext,
Dan Willemsen5cb580f2016-09-26 17:33:01 -070071 flags Flags, deps PathDeps, objs Objects) android.Path {
Colin Cross4d9c2d12016-07-29 12:48:20 -070072
Dan Willemsen5cb580f2016-09-26 17:33:01 -070073 objs = objs.Append(deps.Objs)
Colin Cross4d9c2d12016-07-29 12:48:20 -070074
75 var outputFile android.Path
Dan Willemsen5cb580f2016-09-26 17:33:01 -070076 if len(objs.objFiles) == 1 {
77 outputFile = objs.objFiles[0]
Colin Cross4d9c2d12016-07-29 12:48:20 -070078 } else {
79 output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
Dan Willemsen5cb580f2016-09-26 17:33:01 -070080 TransformObjsToObj(ctx, objs.objFiles, flagsToBuilderFlags(flags), output)
Colin Cross4d9c2d12016-07-29 12:48:20 -070081 outputFile = output
82 }
83
84 ctx.CheckbuildFile(outputFile)
85 return outputFile
86}