aboutsummaryrefslogtreecommitdiffstats
path: root/androidmk/cmd/androidmk/android.go
blob: 4f2fca1a848e2b2b9e9b6603f924979af4ce1e8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main

import (
	"android/soong/androidmk/parser"
)

const (
	clear_vars = "__android_mk_clear_vars"
)

var stringProperties = map[string]string{
	"LOCAL_MODULE":          "name",
	"LOCAL_MODULE_STEM":     "stem",
	"LOCAL_MODULE_CLASS":    "class",
	"LOCAL_CXX_STL":         "stl",
	"LOCAL_STRIP_MODULE":    "strip",
	"LOCAL_MULTILIB":        "compile_multilib",
	"LOCAL_ARM_MODE_HACK":   "instruction_set",
	"LOCAL_SDK_VERSION":     "sdk_version",
	"LOCAL_NDK_STL_VARIANT": "stl",
}

var listProperties = map[string]string{
	"LOCAL_SRC_FILES":               "srcs",
	"LOCAL_SHARED_LIBRARIES":        "shared_libs",
	"LOCAL_STATIC_LIBRARIES":        "static_libs",
	"LOCAL_WHOLE_STATIC_LIBRARIES":  "whole_static_libs",
	"LOCAL_SYSTEM_SHARED_LIBRARIES": "system_shared_libs",
	"LOCAL_C_INCLUDES":              "include_dirs",
	"LOCAL_EXPORT_C_INCLUDE_DIRS":   "export_include_dirs",
	"LOCAL_ASFLAGS":                 "asflags",
	"LOCAL_CLANG_ASFLAGS":           "clang_asflags",
	"LOCAL_CFLAGS":                  "cflags",
	"LOCAL_CONLYFLAGS":              "conlyflags",
	"LOCAL_CPPFLAGS":                "cppflags",
	"LOCAL_LDFLAGS":                 "ldflags",
	"LOCAL_REQUIRED_MODULES":        "required",
	"LOCAL_MODULE_TAGS":             "tags",
	"LOCAL_LDLIBS":                  "host_ldlibs",
	"LOCAL_CLANG_CFLAGS":            "clang_cflags",
}

var boolProperties = map[string]string{
	"LOCAL_IS_HOST_MODULE":          "host",
	"LOCAL_CLANG":                   "clang",
	"LOCAL_FORCE_STATIC_EXECUTABLE": "static",
	"LOCAL_ADDRESS_SANITIZER":       "asan",
	"LOCAL_NATIVE_COVERAGE":         "native_coverage",
	"LOCAL_NO_CRT":                  "nocrt",
	"LOCAL_ALLOW_UNDEFINED_SYMBOLS": "allow_undefined_symbols",
	"LOCAL_RTTI_FLAG":               "rtti",
}

var deleteProperties = map[string]struct{}{
	"LOCAL_CPP_EXTENSION": struct{}{},
}

var propertySuffixes = []struct {
	suffix string
	class  string
}{
	{"arm", "arch"},
	{"arm64", "arch"},
	{"mips", "arch"},
	{"mips64", "arch"},
	{"x86", "arch"},
	{"x86_64", "arch"},
	{"32", "multilib"},
	{"64", "multilib"},
}

var propertySuffixTranslations = map[string]string{
	"32": "lib32",
	"64": "lib64",
}

var conditionalTranslations = map[string]struct {
	class  string
	suffix string
}{
	"($(HOST_OS),darwin)":   {"target", "darwin"},
	"($(HOST_OS), darwin)":  {"target", "darwin"},
	"($(HOST_OS),windows)":  {"target", "windows"},
	"($(HOST_OS), windows)": {"target", "windows"},
	"($(HOST_OS),linux)":    {"target", "linux"},
	"($(HOST_OS), linux)":   {"target", "linux"},
	"($(BUILD_OS),darwin)":  {"target", "darwin"},
	"($(BUILD_OS), darwin)": {"target", "darwin"},
	"($(BUILD_OS),linux)":   {"target", "linux"},
	"($(BUILD_OS), linux)":  {"target", "linux"},
}

func mydir(args []string) string {
	return "."
}

var moduleTypes = map[string]string{
	"BUILD_SHARED_LIBRARY":      "cc_library_shared",
	"BUILD_STATIC_LIBRARY":      "cc_library_static",
	"BUILD_HOST_SHARED_LIBRARY": "cc_library_host_shared",
	"BUILD_HOST_STATIC_LIBRARY": "cc_library_host_static",
	"BUILD_EXECUTABLE":          "cc_binary",
	"BUILD_HOST_EXECUTABLE":     "cc_binary_host",
	"BUILD_NATIVE_TEST":         "cc_test",
	"BUILD_HOST_NATIVE_TEST":    "cc_test_host",
	"BUILD_PREBUILT":            "prebuilt",
}

var soongModuleTypes = map[string]bool{}

func androidScope() parser.Scope {
	globalScope := parser.NewScope(nil)
	globalScope.Set("CLEAR_VARS", clear_vars)
	globalScope.SetFunc("my-dir", mydir)

	for k, v := range moduleTypes {
		globalScope.Set(k, v)
		soongModuleTypes[v] = true
	}

	return globalScope
}