blob: f1134a1a27cb3dad7aef821abffd6a480f893f26 [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// 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
15package cc
16
17import (
18 "fmt"
19 "regexp"
20 "strings"
Colin Crossc0b06f12015-04-08 13:03:43 -070021
22 "android/soong/common"
Colin Cross3f40fa42015-01-30 17:27:36 -080023)
24
25// Efficiently converts a list of include directories to a single string
26// of cflags with -I prepended to each directory.
27func includeDirsToFlags(dirs []string) string {
Colin Crossc0b06f12015-04-08 13:03:43 -070028 return common.JoinWithPrefix(dirs, "-I")
Colin Cross3f40fa42015-01-30 17:27:36 -080029}
30
31func ldDirsToFlags(dirs []string) string {
Colin Crossc0b06f12015-04-08 13:03:43 -070032 return common.JoinWithPrefix(dirs, "-L")
Colin Cross3f40fa42015-01-30 17:27:36 -080033}
34
35func libNamesToFlags(names []string) string {
Colin Crossc0b06f12015-04-08 13:03:43 -070036 return common.JoinWithPrefix(names, "-l")
Colin Cross3f40fa42015-01-30 17:27:36 -080037}
38
39func inList(s string, list []string) bool {
40 for _, l := range list {
41 if l == s {
42 return true
43 }
44 }
45
46 return false
47}
48
Colin Crossed4cf0b2015-03-26 14:43:45 -070049func filterList(list []string, filter []string) (remainder []string, filtered []string) {
50 for _, l := range list {
51 if inList(l, filter) {
52 filtered = append(filtered, l)
53 } else {
54 remainder = append(remainder, l)
55 }
56 }
57
58 return
59}
60
Colin Cross3f40fa42015-01-30 17:27:36 -080061var libNameRegexp = regexp.MustCompile(`^lib(.*)$`)
62
63func moduleToLibName(module string) (string, error) {
64 matches := libNameRegexp.FindStringSubmatch(module)
65 if matches == nil {
66 return "", fmt.Errorf("Library module name %s does not start with lib", module)
67 }
68 return matches[1], nil
69}
70
Colin Cross97ba0732015-03-23 17:50:24 -070071func ccFlagsToBuilderFlags(in CCFlags) builderFlags {
Colin Cross3f40fa42015-01-30 17:27:36 -080072 return builderFlags{
Colin Cross97ba0732015-03-23 17:50:24 -070073 globalFlags: strings.Join(in.GlobalFlags, " "),
74 asFlags: strings.Join(in.AsFlags, " "),
75 cFlags: strings.Join(in.CFlags, " "),
76 conlyFlags: strings.Join(in.ConlyFlags, " "),
77 cppFlags: strings.Join(in.CppFlags, " "),
Colin Cross581c1892015-04-07 16:50:10 -070078 yaccFlags: strings.Join(in.YaccFlags, " "),
Colin Cross97ba0732015-03-23 17:50:24 -070079 ldFlags: strings.Join(in.LdFlags, " "),
80 ldLibs: strings.Join(in.LdLibs, " "),
81 incFlags: includeDirsToFlags(in.IncludeDirs),
82 nocrt: in.Nocrt,
83 toolchain: in.Toolchain,
84 clang: in.Clang,
Colin Cross3f40fa42015-01-30 17:27:36 -080085 }
86}