blob: eaddd890a2d7d05019afe5985626fab346401474 [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
20 "github.com/google/blueprint"
21
Colin Cross4d9c2d12016-07-29 12:48:20 -070022 "android/soong/android"
23)
24
25//
26// Objects (for crt*.o)
27//
28
29func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070030 android.RegisterModuleType("cc_object", objectFactory)
Colin Cross4d9c2d12016-07-29 12:48:20 -070031}
32
33type objectLinker struct {
Colin Crossb916a382016-07-29 17:28:03 -070034 *baseLinker
Colin Cross4d9c2d12016-07-29 12:48:20 -070035 Properties ObjectLinkerProperties
36}
37
38func objectFactory() (blueprint.Module, []interface{}) {
Dan Willemsen967c6a92016-11-17 00:30:56 -080039 module := newBaseModule(android.HostAndDeviceSupported, android.MultilibBoth)
Colin Crossb916a382016-07-29 17:28:03 -070040 module.linker = &objectLinker{
41 baseLinker: NewBaseLinker(),
42 }
43 module.compiler = NewBaseCompiler()
Colin Cross4d9c2d12016-07-29 12:48:20 -070044 return module.Init()
45}
46
47func (object *objectLinker) appendLdflags(flags []string) {
48 panic(fmt.Errorf("appendLdflags on object Linker not supported"))
49}
50
Colin Cross42742b82016-08-01 13:20:05 -070051func (object *objectLinker) linkerProps() []interface{} {
Colin Cross4d9c2d12016-07-29 12:48:20 -070052 return []interface{}{&object.Properties}
53}
54
Colin Cross42742b82016-08-01 13:20:05 -070055func (*objectLinker) linkerInit(ctx BaseModuleContext) {}
Colin Cross4d9c2d12016-07-29 12:48:20 -070056
Colin Cross37047f12016-12-13 17:06:13 -080057func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
Colin Cross4d9c2d12016-07-29 12:48:20 -070058 deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...)
59 return deps
60}
61
Colin Cross42742b82016-08-01 13:20:05 -070062func (*objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Colin Cross4d9c2d12016-07-29 12:48:20 -070063 if flags.Clang {
64 flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainClangLdflags())
65 } else {
66 flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainLdflags())
67 }
68
69 return flags
70}
71
72func (object *objectLinker) link(ctx ModuleContext,
Dan Willemsen5cb580f2016-09-26 17:33:01 -070073 flags Flags, deps PathDeps, objs Objects) android.Path {
Colin Cross4d9c2d12016-07-29 12:48:20 -070074
Dan Willemsen5cb580f2016-09-26 17:33:01 -070075 objs = objs.Append(deps.Objs)
Colin Cross4d9c2d12016-07-29 12:48:20 -070076
77 var outputFile android.Path
Dan Willemsen5cb580f2016-09-26 17:33:01 -070078 if len(objs.objFiles) == 1 {
79 outputFile = objs.objFiles[0]
Colin Cross4d9c2d12016-07-29 12:48:20 -070080 } else {
81 output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
Dan Willemsen5cb580f2016-09-26 17:33:01 -070082 TransformObjsToObj(ctx, objs.objFiles, flagsToBuilderFlags(flags), output)
Colin Cross4d9c2d12016-07-29 12:48:20 -070083 outputFile = output
84 }
85
86 ctx.CheckbuildFile(outputFile)
87 return outputFile
88}