blob: ac05df01c6d92a99266c7fd8a2ac044fcf09ded4 [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"
Colin Crossce75d2c2016-10-06 16:12:58 -070019)
20
21func init() {
Colin Crossdfee1bc2017-03-17 14:03:18 -070022 android.RegisterModuleType("cc_prebuilt_library_shared", prebuiltSharedLibraryFactory)
Colin Crossde89fb82017-03-17 13:28:06 -070023 android.RegisterModuleType("cc_prebuilt_library_static", prebuiltStaticLibraryFactory)
24 android.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory)
Colin Crossce75d2c2016-10-06 16:12:58 -070025}
26
27type prebuiltLinkerInterface interface {
28 Name(string) string
29 prebuilt() *android.Prebuilt
30}
31
Colin Crossde89fb82017-03-17 13:28:06 -070032type prebuiltLinker struct {
Colin Crossce75d2c2016-10-06 16:12:58 -070033 android.Prebuilt
34}
35
Colin Crossde89fb82017-03-17 13:28:06 -070036func (p *prebuiltLinker) prebuilt() *android.Prebuilt {
Colin Crossce75d2c2016-10-06 16:12:58 -070037 return &p.Prebuilt
38}
39
Colin Crossde89fb82017-03-17 13:28:06 -070040type prebuiltLibraryLinker struct {
41 *libraryDecorator
42 prebuiltLinker
43}
44
45var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil)
46
Colin Crossce75d2c2016-10-06 16:12:58 -070047func (p *prebuiltLibraryLinker) linkerProps() []interface{} {
48 props := p.libraryDecorator.linkerProps()
49 return append(props, &p.Prebuilt.Properties)
50}
51
52func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
Dan Willemsen5cb580f2016-09-26 17:33:01 -070053 flags Flags, deps PathDeps, objs Objects) android.Path {
Colin Crossce75d2c2016-10-06 16:12:58 -070054 // TODO(ccross): verify shared library dependencies
55 if len(p.Prebuilt.Properties.Srcs) > 0 {
56 p.libraryDecorator.exportIncludes(ctx, "-I")
57 p.libraryDecorator.reexportFlags(deps.ReexportedFlags)
58 p.libraryDecorator.reexportDeps(deps.ReexportedFlagsDeps)
59 // TODO(ccross): .toc optimization, stripping, packing
60 return p.Prebuilt.Path(ctx)
61 }
62
63 return nil
64}
65
Colin Cross36242852017-06-23 15:06:31 -070066func prebuiltSharedLibraryFactory() android.Module {
Leo Li74f7b972017-05-17 11:30:45 -070067 module, _ := NewPrebuiltSharedLibrary(android.HostAndDeviceSupported)
68 return module.Init()
69}
70
71func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
72 module, library := NewLibrary(hod)
Colin Crossde89fb82017-03-17 13:28:06 -070073 library.BuildOnlyShared()
Colin Crossce75d2c2016-10-06 16:12:58 -070074 module.compiler = nil
75
76 prebuilt := &prebuiltLibraryLinker{
77 libraryDecorator: library,
78 }
79 module.linker = prebuilt
Colin Crossde89fb82017-03-17 13:28:06 -070080
Leo Li74f7b972017-05-17 11:30:45 -070081 return module, library
Colin Crossde89fb82017-03-17 13:28:06 -070082}
83
Colin Cross36242852017-06-23 15:06:31 -070084func prebuiltStaticLibraryFactory() android.Module {
Leo Li74f7b972017-05-17 11:30:45 -070085 module, _ := NewPrebuiltStaticLibrary(android.HostAndDeviceSupported)
86 return module.Init()
87}
88
89func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
90 module, library := NewLibrary(hod)
Colin Crossde89fb82017-03-17 13:28:06 -070091 library.BuildOnlyStatic()
92 module.compiler = nil
93
94 prebuilt := &prebuiltLibraryLinker{
95 libraryDecorator: library,
96 }
97 module.linker = prebuilt
98
Leo Li74f7b972017-05-17 11:30:45 -070099 return module, library
Colin Crossde89fb82017-03-17 13:28:06 -0700100}
101
102type prebuiltBinaryLinker struct {
103 *binaryDecorator
104 prebuiltLinker
105}
106
107var _ prebuiltLinkerInterface = (*prebuiltBinaryLinker)(nil)
108
109func (p *prebuiltBinaryLinker) linkerProps() []interface{} {
110 props := p.binaryDecorator.linkerProps()
111 return append(props, &p.Prebuilt.Properties)
112}
113
114func (p *prebuiltBinaryLinker) link(ctx ModuleContext,
115 flags Flags, deps PathDeps, objs Objects) android.Path {
116 // TODO(ccross): verify shared library dependencies
117 if len(p.Prebuilt.Properties.Srcs) > 0 {
118 // TODO(ccross): .toc optimization, stripping, packing
119 return p.Prebuilt.Path(ctx)
120 }
121
122 return nil
123}
124
Colin Cross36242852017-06-23 15:06:31 -0700125func prebuiltBinaryFactory() android.Module {
Leo Li74f7b972017-05-17 11:30:45 -0700126 module, _ := NewPrebuiltBinary(android.HostAndDeviceSupported)
127 return module.Init()
128}
129
130func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
131 module, binary := NewBinary(hod)
Colin Crossde89fb82017-03-17 13:28:06 -0700132 module.compiler = nil
133
134 prebuilt := &prebuiltBinaryLinker{
135 binaryDecorator: binary,
136 }
137 module.linker = prebuilt
Colin Crossce75d2c2016-10-06 16:12:58 -0700138
Leo Li74f7b972017-05-17 11:30:45 -0700139 return module, binary
Colin Crossce75d2c2016-10-06 16:12:58 -0700140}