blob: c9f0a060a96a7d8ee04421f89d9a1c9061cabe46 [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
22 "android/soong"
23 "android/soong/android"
24)
25
26//
27// Objects (for crt*.o)
28//
29
30func init() {
31 soong.RegisterModuleType("cc_object", objectFactory)
32}
33
34type objectLinker struct {
Colin Crossb916a382016-07-29 17:28:03 -070035 *baseLinker
Colin Cross4d9c2d12016-07-29 12:48:20 -070036 Properties ObjectLinkerProperties
37}
38
39func objectFactory() (blueprint.Module, []interface{}) {
40 module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
Colin Crossb916a382016-07-29 17:28:03 -070041 module.linker = &objectLinker{
42 baseLinker: NewBaseLinker(),
43 }
44 module.compiler = NewBaseCompiler()
Colin Cross4d9c2d12016-07-29 12:48:20 -070045 return module.Init()
46}
47
48func (object *objectLinker) appendLdflags(flags []string) {
49 panic(fmt.Errorf("appendLdflags on object Linker not supported"))
50}
51
Colin Cross42742b82016-08-01 13:20:05 -070052func (object *objectLinker) linkerProps() []interface{} {
Colin Cross4d9c2d12016-07-29 12:48:20 -070053 return []interface{}{&object.Properties}
54}
55
Colin Cross42742b82016-08-01 13:20:05 -070056func (*objectLinker) linkerInit(ctx BaseModuleContext) {}
Colin Cross4d9c2d12016-07-29 12:48:20 -070057
Colin Cross42742b82016-08-01 13:20:05 -070058func (object *objectLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
Colin Cross4d9c2d12016-07-29 12:48:20 -070059 deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...)
60 return deps
61}
62
Colin Cross42742b82016-08-01 13:20:05 -070063func (*objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Colin Cross4d9c2d12016-07-29 12:48:20 -070064 if flags.Clang {
65 flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainClangLdflags())
66 } else {
67 flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainLdflags())
68 }
69
70 return flags
71}
72
73func (object *objectLinker) link(ctx ModuleContext,
74 flags Flags, deps PathDeps, objFiles android.Paths) android.Path {
75
76 objFiles = append(objFiles, deps.ObjFiles...)
77
78 var outputFile android.Path
79 if len(objFiles) == 1 {
80 outputFile = objFiles[0]
81 } else {
82 output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
83 TransformObjsToObj(ctx, objFiles, flagsToBuilderFlags(flags), output)
84 outputFile = output
85 }
86
87 ctx.CheckbuildFile(outputFile)
88 return outputFile
89}