1 // Copyright 2015 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 "regexp" 20 "strings" 21 22 "android/soong/common" 23 ) 24 25 // Efficiently converts a list of include directories to a single string 26 // of cflags with -I prepended to each directory. 27 func includeDirsToFlags(dirs common.Paths) string { 28 return common.JoinWithPrefix(dirs.Strings(), "-I") 29 } 30 31 func includeFilesToFlags(files common.Paths) string { 32 return common.JoinWithPrefix(files.Strings(), "-include ") 33 } 34 35 func ldDirsToFlags(dirs []string) string { 36 return common.JoinWithPrefix(dirs, "-L") 37 } 38 39 func libNamesToFlags(names []string) string { 40 return common.JoinWithPrefix(names, "-l") 41 } 42 43 func inList(s string, list []string) bool { 44 for _, l := range list { 45 if l == s { 46 return true 47 } 48 } 49 50 return false 51 } 52 53 func filterList(list []string, filter []string) (remainder []string, filtered []string) { 54 for _, l := range list { 55 if inList(l, filter) { 56 filtered = append(filtered, l) 57 } else { 58 remainder = append(remainder, l) 59 } 60 } 61 62 return 63 } 64 65 var libNameRegexp = regexp.MustCompile(`^lib(.*)$`) 66 67 func moduleToLibName(module string) (string, error) { 68 matches := libNameRegexp.FindStringSubmatch(module) 69 if matches == nil { 70 return "", fmt.Errorf("Library module name %s does not start with lib", module) 71 } 72 return matches[1], nil 73 } 74 75 func flagsToBuilderFlags(in Flags) builderFlags { 76 return builderFlags{ 77 globalFlags: strings.Join(in.GlobalFlags, " "), 78 asFlags: strings.Join(in.AsFlags, " "), 79 cFlags: strings.Join(in.CFlags, " "), 80 conlyFlags: strings.Join(in.ConlyFlags, " "), 81 cppFlags: strings.Join(in.CppFlags, " "), 82 yaccFlags: strings.Join(in.YaccFlags, " "), 83 ldFlags: strings.Join(in.LdFlags, " "), 84 nocrt: in.Nocrt, 85 toolchain: in.Toolchain, 86 clang: in.Clang, 87 } 88 } 89