blob: 55775b69afe10e79ed2f6dad49e3cc41aceceaf7 [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() {
24 android.RegisterModuleType("cc_prebuilt_shared_library", prebuiltSharedLibraryFactory)
25}
26
27type prebuiltLinkerInterface interface {
28 Name(string) string
29 prebuilt() *android.Prebuilt
30}
31
32type prebuiltLibraryLinker struct {
33 *libraryDecorator
34 android.Prebuilt
35}
36
37var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil)
38
39func (p *prebuiltLibraryLinker) prebuilt() *android.Prebuilt {
40 return &p.Prebuilt
41}
42
43func (p *prebuiltLibraryLinker) linkerProps() []interface{} {
44 props := p.libraryDecorator.linkerProps()
45 return append(props, &p.Prebuilt.Properties)
46}
47
48func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
49 flags Flags, deps PathDeps, objFiles android.Paths) android.Path {
50 // TODO(ccross): verify shared library dependencies
51 if len(p.Prebuilt.Properties.Srcs) > 0 {
52 p.libraryDecorator.exportIncludes(ctx, "-I")
53 p.libraryDecorator.reexportFlags(deps.ReexportedFlags)
54 p.libraryDecorator.reexportDeps(deps.ReexportedFlagsDeps)
55 // TODO(ccross): .toc optimization, stripping, packing
56 return p.Prebuilt.Path(ctx)
57 }
58
59 return nil
60}
61
62func prebuiltSharedLibraryFactory() (blueprint.Module, []interface{}) {
63 module, library := NewLibrary(android.HostAndDeviceSupported, true, false)
64 module.compiler = nil
65
66 prebuilt := &prebuiltLibraryLinker{
67 libraryDecorator: library,
68 }
69 module.linker = prebuilt
70
71 return module.Init()
72}