blob: 08ba14570dc96d8be00fa13b99d671778d8fd0c0 [file] [log] [blame]
Colin Crossce75d2c2016-10-06 16:12:58 -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 "android/soong/android"
19
20 "github.com/google/blueprint"
21)
22
23func init() {
Colin Crossdfee1bc2017-03-17 14:03:18 -070024 android.RegisterModuleType("cc_prebuilt_library_shared", prebuiltSharedLibraryFactory)
Colin Crossde89fb82017-03-17 13:28:06 -070025 android.RegisterModuleType("cc_prebuilt_library_static", prebuiltStaticLibraryFactory)
26 android.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory)
Colin Crossce75d2c2016-10-06 16:12:58 -070027}
28
29type prebuiltLinkerInterface interface {
30 Name(string) string
31 prebuilt() *android.Prebuilt
32}
33
Colin Crossde89fb82017-03-17 13:28:06 -070034type prebuiltLinker struct {
Colin Crossce75d2c2016-10-06 16:12:58 -070035 android.Prebuilt
36}
37
Colin Crossde89fb82017-03-17 13:28:06 -070038func (p *prebuiltLinker) prebuilt() *android.Prebuilt {
Colin Crossce75d2c2016-10-06 16:12:58 -070039 return &p.Prebuilt
40}
41
Colin Crossde89fb82017-03-17 13:28:06 -070042type prebuiltLibraryLinker struct {
43 *libraryDecorator
44 prebuiltLinker
45}
46
47var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil)
48
Colin Crossce75d2c2016-10-06 16:12:58 -070049func (p *prebuiltLibraryLinker) linkerProps() []interface{} {
50 props := p.libraryDecorator.linkerProps()
51 return append(props, &p.Prebuilt.Properties)
52}
53
54func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
Dan Willemsen5cb580f2016-09-26 17:33:01 -070055 flags Flags, deps PathDeps, objs Objects) android.Path {
Colin Crossce75d2c2016-10-06 16:12:58 -070056 // TODO(ccross): verify shared library dependencies
57 if len(p.Prebuilt.Properties.Srcs) > 0 {
58 p.libraryDecorator.exportIncludes(ctx, "-I")
59 p.libraryDecorator.reexportFlags(deps.ReexportedFlags)
60 p.libraryDecorator.reexportDeps(deps.ReexportedFlagsDeps)
61 // TODO(ccross): .toc optimization, stripping, packing
62 return p.Prebuilt.Path(ctx)
63 }
64
65 return nil
66}
67
68func prebuiltSharedLibraryFactory() (blueprint.Module, []interface{}) {
Colin Crossab3b7322016-12-09 14:46:15 -080069 module, library := NewLibrary(android.HostAndDeviceSupported)
Colin Crossde89fb82017-03-17 13:28:06 -070070 library.BuildOnlyShared()
Colin Crossce75d2c2016-10-06 16:12:58 -070071 module.compiler = nil
72
73 prebuilt := &prebuiltLibraryLinker{
74 libraryDecorator: library,
75 }
76 module.linker = prebuilt
Colin Crossde89fb82017-03-17 13:28:06 -070077
78 return module.Init()
79}
80
81func prebuiltStaticLibraryFactory() (blueprint.Module, []interface{}) {
82 module, library := NewLibrary(android.HostAndDeviceSupported)
83 library.BuildOnlyStatic()
84 module.compiler = nil
85
86 prebuilt := &prebuiltLibraryLinker{
87 libraryDecorator: library,
88 }
89 module.linker = prebuilt
90
91 return module.Init()
92}
93
94type prebuiltBinaryLinker struct {
95 *binaryDecorator
96 prebuiltLinker
97}
98
99var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil)
100
101func (p *prebuiltBinaryLinker) linkerProps() []interface{} {
102 props := p.binaryDecorator.linkerProps()
103 return append(props, &p.Prebuilt.Properties)
104}
105
106func (p *prebuiltBinaryLinker) link(ctx ModuleContext,
107 flags Flags, deps PathDeps, objs Objects) android.Path {
108 // TODO(ccross): verify shared library dependencies
109 if len(p.Prebuilt.Properties.Srcs) > 0 {
110 // TODO(ccross): .toc optimization, stripping, packing
111 return p.Prebuilt.Path(ctx)
112 }
113
114 return nil
115}
116
117func prebuiltBinaryFactory() (blueprint.Module, []interface{}) {
118 module, binary := NewBinary(android.HostAndDeviceSupported)
119 module.compiler = nil
120
121 prebuilt := &prebuiltBinaryLinker{
122 binaryDecorator: binary,
123 }
124 module.linker = prebuilt
Colin Crossce75d2c2016-10-06 16:12:58 -0700125
126 return module.Init()
127}