1// Copyright 2019 The Chromium OS Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5package main 6 7import ( 8 "path/filepath" 9 "strings" 10) 11 12func processSysrootFlag(builder *commandBuilder) { 13 fromUser := false 14 userSysroot := "" 15 for _, arg := range builder.args { 16 if arg.fromUser && strings.HasPrefix(arg.value, "--sysroot=") { 17 fromUser = true 18 sysrootArg := strings.Split(arg.value, "=") 19 if len(sysrootArg) == 2 { 20 userSysroot = sysrootArg[1] 21 } 22 break 23 } 24 } 25 sysroot, syrootPresent := builder.env.getenv("SYSROOT") 26 if syrootPresent { 27 builder.updateEnv("SYSROOT=") 28 } 29 if sysroot == "" { 30 // Use the bundled sysroot by default. 31 sysroot = filepath.Join(builder.rootPath, "usr", builder.target.target) 32 } 33 if !fromUser { 34 builder.addPreUserArgs("--sysroot=" + sysroot) 35 } else { 36 sysroot = userSysroot 37 } 38 39 libdir := "-L" + sysroot + "/usr/lib" 40 if strings.Contains(builder.target.target, "64") { 41 libdir += "64" 42 } 43 builder.addPostUserArgs(libdir) 44} 45