• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15package cc
16
17import (
18	"fmt"
19
20	"github.com/google/blueprint"
21
22	"android/soong/android"
23)
24
25//
26// Objects (for crt*.o)
27//
28
29func init() {
30	android.RegisterModuleType("cc_object", objectFactory)
31}
32
33type objectLinker struct {
34	*baseLinker
35	Properties ObjectLinkerProperties
36}
37
38func objectFactory() (blueprint.Module, []interface{}) {
39	module := newBaseModule(android.HostAndDeviceSupported, android.MultilibBoth)
40	module.linker = &objectLinker{
41		baseLinker: NewBaseLinker(),
42	}
43	module.compiler = NewBaseCompiler()
44	return module.Init()
45}
46
47func (object *objectLinker) appendLdflags(flags []string) {
48	panic(fmt.Errorf("appendLdflags on object Linker not supported"))
49}
50
51func (object *objectLinker) linkerProps() []interface{} {
52	return []interface{}{&object.Properties}
53}
54
55func (*objectLinker) linkerInit(ctx BaseModuleContext) {}
56
57func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
58	deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...)
59	return deps
60}
61
62func (*objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
63	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,
73	flags Flags, deps PathDeps, objs Objects) android.Path {
74
75	objs = objs.Append(deps.Objs)
76
77	var outputFile android.Path
78	if len(objs.objFiles) == 1 {
79		outputFile = objs.objFiles[0]
80	} else {
81		output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
82		TransformObjsToObj(ctx, objs.objFiles, flagsToBuilderFlags(flags), output)
83		outputFile = output
84	}
85
86	ctx.CheckbuildFile(outputFile)
87	return outputFile
88}
89