Colin Cross | b916a38 | 2016-07-29 17:28:03 -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 ( |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 18 | "android/soong/android" |
| 19 | ) |
| 20 | |
| 21 | // |
| 22 | // Device libraries shipped with gcc |
| 23 | // |
| 24 | |
| 25 | func init() { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 26 | android.RegisterModuleType("toolchain_library", toolchainLibraryFactory) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | type toolchainLibraryDecorator struct { |
| 30 | *libraryDecorator |
| 31 | } |
| 32 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 33 | func (*toolchainLibraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 34 | // toolchain libraries can't have any dependencies |
| 35 | return deps |
| 36 | } |
| 37 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 38 | func toolchainLibraryFactory() android.Module { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 39 | module, library := NewLibrary(android.HostAndDeviceSupported) |
| 40 | library.BuildOnlyStatic() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 41 | toolchainLibrary := &toolchainLibraryDecorator{ |
| 42 | libraryDecorator: library, |
| 43 | } |
| 44 | module.compiler = toolchainLibrary |
| 45 | module.linker = toolchainLibrary |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 46 | module.Properties.Clang = BoolPtr(false) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 47 | module.stl = nil |
| 48 | module.sanitize = nil |
| 49 | module.installer = nil |
| 50 | return module.Init() |
| 51 | } |
| 52 | |
| 53 | func (library *toolchainLibraryDecorator) compile(ctx ModuleContext, flags Flags, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 54 | deps PathDeps) Objects { |
| 55 | return Objects{} |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | func (library *toolchainLibraryDecorator) link(ctx ModuleContext, |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 59 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 60 | |
| 61 | libName := ctx.ModuleName() + staticLibraryExtension |
| 62 | outputFile := android.PathForModuleOut(ctx, libName) |
| 63 | |
| 64 | if flags.Clang { |
| 65 | ctx.ModuleErrorf("toolchain_library must use GCC, not Clang") |
| 66 | } |
| 67 | |
| 68 | CopyGccLib(ctx, libName, flagsToBuilderFlags(flags), outputFile) |
| 69 | |
| 70 | ctx.CheckbuildFile(outputFile) |
| 71 | |
| 72 | return outputFile |
| 73 | } |