Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame^] | 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | |
| 20 | "github.com/google/blueprint" |
| 21 | ) |
| 22 | |
| 23 | func init() { |
| 24 | android.RegisterModuleType("cc_prebuilt_shared_library", prebuiltSharedLibraryFactory) |
| 25 | } |
| 26 | |
| 27 | type prebuiltLinkerInterface interface { |
| 28 | Name(string) string |
| 29 | prebuilt() *android.Prebuilt |
| 30 | } |
| 31 | |
| 32 | type prebuiltLibraryLinker struct { |
| 33 | *libraryDecorator |
| 34 | android.Prebuilt |
| 35 | } |
| 36 | |
| 37 | var _ prebuiltLinkerInterface = (*prebuiltLibraryLinker)(nil) |
| 38 | |
| 39 | func (p *prebuiltLibraryLinker) prebuilt() *android.Prebuilt { |
| 40 | return &p.Prebuilt |
| 41 | } |
| 42 | |
| 43 | func (p *prebuiltLibraryLinker) linkerProps() []interface{} { |
| 44 | props := p.libraryDecorator.linkerProps() |
| 45 | return append(props, &p.Prebuilt.Properties) |
| 46 | } |
| 47 | |
| 48 | func (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 | |
| 62 | func 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 | } |