blob: d064a465576b213f34e4029fc4e3ae2c07f01864 [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{}) {
Leo Li74f7b972017-05-17 11:30:45 -070069 module, _ := NewPrebuiltSharedLibrary(android.HostAndDeviceSupported)
70 return module.Init()
71}
72
73func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
74 module, library := NewLibrary(hod)
Colin Crossde89fb82017-03-17 13:28:06 -070075 library.BuildOnlyShared()
Colin Crossce75d2c2016-10-06 16:12:58 -070076 module.compiler = nil
77
78 prebuilt := &prebuiltLibraryLinker{
79 libraryDecorator: library,
80 }
81 module.linker = prebuilt
Colin Crossde89fb82017-03-17 13:28:06 -070082
Leo Li74f7b972017-05-17 11:30:45 -070083 return module, library
Colin Crossde89fb82017-03-17 13:28:06 -070084}
85
86func prebuiltStaticLibraryFactory() (blueprint.Module, []interface{}) {
Leo Li74f7b972017-05-17 11:30:45 -070087 module, _ := NewPrebuiltStaticLibrary(android.HostAndDeviceSupported)
88 return module.Init()
89}
90
91func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
92 module, library := NewLibrary(hod)
Colin Crossde89fb82017-03-17 13:28:06 -070093 library.BuildOnlyStatic()
94 module.compiler = nil
95
96 prebuilt := &prebuiltLibraryLinker{
97 libraryDecorator: library,
98 }
99 module.linker = prebuilt
100
Leo Li74f7b972017-05-17 11:30:45 -0700101 return module, library
Colin Crossde89fb82017-03-17 13:28:06 -0700102}
103
104type prebuiltBinaryLinker struct {
105 *binaryDecorator
106 prebuiltLinker
107}
108
109var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil)
110
111func (p *prebuiltBinaryLinker) linkerProps() []interface{} {
112 props := p.binaryDecorator.linkerProps()
113 return append(props, &p.Prebuilt.Properties)
114}
115
116func (p *prebuiltBinaryLinker) link(ctx ModuleContext,
117 flags Flags, deps PathDeps, objs Objects) android.Path {
118 // TODO(ccross): verify shared library dependencies
119 if len(p.Prebuilt.Properties.Srcs) > 0 {
120 // TODO(ccross): .toc optimization, stripping, packing
121 return p.Prebuilt.Path(ctx)
122 }
123
124 return nil
125}
126
127func prebuiltBinaryFactory() (blueprint.Module, []interface{}) {
Leo Li74f7b972017-05-17 11:30:45 -0700128 module, _ := NewPrebuiltBinary(android.HostAndDeviceSupported)
129 return module.Init()
130}
131
132func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
133 module, binary := NewBinary(hod)
Colin Crossde89fb82017-03-17 13:28:06 -0700134 module.compiler = nil
135
136 prebuilt := &prebuiltBinaryLinker{
137 binaryDecorator: binary,
138 }
139 module.linker = prebuilt
Colin Crossce75d2c2016-10-06 16:12:58 -0700140
Leo Li74f7b972017-05-17 11:30:45 -0700141 return module, binary
Colin Crossce75d2c2016-10-06 16:12:58 -0700142}