github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/cc/object.go (about)

     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  	"fmt"
    19  
    20  	"android/soong/android"
    21  )
    22  
    23  //
    24  // Objects (for crt*.o)
    25  //
    26  
    27  func init() {
    28  	android.RegisterModuleType("cc_object", objectFactory)
    29  }
    30  
    31  type objectLinker struct {
    32  	*baseLinker
    33  	Properties ObjectLinkerProperties
    34  }
    35  
    36  func objectFactory() android.Module {
    37  	module := newBaseModule(android.HostAndDeviceSupported, android.MultilibBoth)
    38  	module.linker = &objectLinker{
    39  		baseLinker: NewBaseLinker(),
    40  	}
    41  	module.compiler = NewBaseCompiler()
    42  	return module.Init()
    43  }
    44  
    45  func (object *objectLinker) appendLdflags(flags []string) {
    46  	panic(fmt.Errorf("appendLdflags on objectLinker not supported"))
    47  }
    48  
    49  func (object *objectLinker) linkerProps() []interface{} {
    50  	return []interface{}{&object.Properties}
    51  }
    52  
    53  func (*objectLinker) linkerInit(ctx BaseModuleContext) {}
    54  
    55  func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
    56  	if ctx.useVndk() && ctx.toolchain().Bionic() {
    57  		// Needed for VNDK builds where bionic headers aren't automatically added.
    58  		deps.LateSharedLibs = append(deps.LateSharedLibs, "libc")
    59  	}
    60  
    61  	deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...)
    62  	return deps
    63  }
    64  
    65  func (*objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
    66  	if flags.Clang {
    67  		flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainClangLdflags())
    68  	} else {
    69  		flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainLdflags())
    70  	}
    71  
    72  	return flags
    73  }
    74  
    75  func (object *objectLinker) link(ctx ModuleContext,
    76  	flags Flags, deps PathDeps, objs Objects) android.Path {
    77  
    78  	objs = objs.Append(deps.Objs)
    79  
    80  	var outputFile android.Path
    81  	builderFlags := flagsToBuilderFlags(flags)
    82  
    83  	if len(objs.objFiles) == 1 {
    84  		outputFile = objs.objFiles[0]
    85  
    86  		if String(object.Properties.Prefix_symbols) != "" {
    87  			output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
    88  			TransformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), outputFile,
    89  				builderFlags, output)
    90  			outputFile = output
    91  		}
    92  	} else {
    93  		output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
    94  		outputFile = output
    95  
    96  		if String(object.Properties.Prefix_symbols) != "" {
    97  			input := android.PathForModuleOut(ctx, "unprefixed", ctx.ModuleName()+objectExtension)
    98  			TransformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), input,
    99  				builderFlags, output)
   100  			output = input
   101  		}
   102  
   103  		TransformObjsToObj(ctx, objs.objFiles, builderFlags, output)
   104  	}
   105  
   106  	ctx.CheckbuildFile(outputFile)
   107  	return outputFile
   108  }