-
Notifications
You must be signed in to change notification settings - Fork 9
/
mk.sh
197 lines (154 loc) · 4.93 KB
/
mk.sh
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#
# Copyright 2017 Preetam J. D'Souza
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Android.mk utilities
readonly _VENDOR_MK="device-vendor.mk"
readonly _BLOBS_MK="device-partial.mk"
readonly _MODULES_MK="Android.mk"
_VENDOR_DIR=""
_mk_echo_autogen_header () {
# TODO define $SCRIPT_NAME
echo "# $(date --rfc-3339=date): autogenerated by $SCRIPT_NAME - DO NOT EDIT"
}
_mk_init_vendor_mk () {
local readonly vendor_dir="$1"
cat > "$_VENDOR_MK" <<EOF
$(_mk_echo_autogen_header)
\$(call inherit-product, $vendor_dir/$_BLOBS_MK)
PRODUCT_PACKAGES += \\
EOF
}
_mk_init_module_mk () {
cat > "$_MODULES_MK" <<EOF
$(_mk_echo_autogen_header)
LOCAL_PATH := \$(call my-dir)
EOF
}
_mk_init_blobs_mk () {
cat > "$_BLOBS_MK" <<EOF
$(_mk_echo_autogen_header)
PRODUCT_COPY_FILES := \\
EOF
}
_mk_add_module_depends () {
local readonly module="$1"
echo " $module \\" >> "$_VENDOR_MK"
}
_mk_is_priv_apk () {
local path="$1"
echo "$path" | grep -q 'priv-app'
}
mk_init () {
local readonly vendor_dir="$1"
_VENDOR_DIR="$vendor_dir"
_mk_init_vendor_mk "$vendor_dir"
_mk_init_blobs_mk
}
_mk_add_apk () {
local readonly apk="$1"
local readonly owner="$2"
local readonly device="$3"
local readonly apk_basename="$(basename "$apk")"
local readonly apk_module="${apk_basename%.*}"
[ -f "$_MODULES_MK" ] || _mk_init_module_mk
{
echo
echo "ifeq (\$(TARGET_DEVICE),$device)"
echo "include \$(CLEAR_VARS)"
echo "LOCAL_MODULE := $apk_module"
echo "LOCAL_MODULE_TAGS := optional"
echo "LOCAL_BUILT_MODULE_STEM := package.apk"
echo "LOCAL_MODULE_OWNER := $owner"
echo "LOCAL_MODULE_CLASS := APPS"
echo "LOCAL_SRC_FILES := $apk"
echo "LOCAL_CERTIFICATE := platform"
echo "LOCAL_MODULE_SUFFIX := \$(COMMON_ANDROID_PACKAGE_SUFFIX)"
echo "include \$(BUILD_PREBUILT)"
echo "endif"
} >> "$_MODULES_MK"
_mk_add_module_depends "$apk_module"
}
_mk_add_priv_apk () {
local readonly apk="$1"
local readonly owner="$2"
local readonly device="$3"
local readonly apk_basename="$(basename "$apk")"
local readonly apk_module="${apk_basename%.*}"
[ -f "$_MODULES_MK" ] || _mk_init_module_mk
{
echo
echo "ifeq (\$(TARGET_DEVICE),$device)"
echo "include \$(CLEAR_VARS)"
echo "LOCAL_MODULE := $apk_module"
echo "LOCAL_MODULE_TAGS := optional"
echo "LOCAL_BUILT_MODULE_STEM := package.apk"
echo "LOCAL_MODULE_OWNER := $owner"
echo "LOCAL_MODULE_CLASS := APPS"
echo "LOCAL_SRC_FILES := $apk"
echo "LOCAL_CERTIFICATE := platform"
echo "LOCAL_PRIVILEGED_MODULE := true"
echo "LOCAL_MODULE_SUFFIX := \$(COMMON_ANDROID_PACKAGE_SUFFIX)"
echo "include \$(BUILD_PREBUILT)"
echo "endif"
} >> "$_MODULES_MK"
_mk_add_module_depends "$apk_module"
}
mk_add_apk () {
local readonly apk="$1"
local readonly owner="$2"
local readonly device="$3"
if _mk_is_priv_apk "$apk" ; then
_mk_add_priv_apk "$apk" "$owner" "$device"
else
_mk_add_apk "$apk" "$owner" "$device"
fi
}
mk_add_jar () {
local readonly jar="$1"
local readonly owner="$2"
local readonly device="$3"
local readonly jar_basename="$(basename "$jar")"
local readonly jar_module="${jar_basename%.*}"
[ -f "$_MODULES_MK" ] || _mk_init_module_mk
{
echo
echo "ifeq (\$(TARGET_DEVICE),$device)"
echo "include \$(CLEAR_VARS)"
echo "LOCAL_MODULE := $jar_module"
echo "LOCAL_MODULE_TAGS := optional"
echo "LOCAL_MODULE_OWNER := $owner"
echo "LOCAL_MODULE_CLASS := JAVA_LIBRARIES"
echo "LOCAL_SRC_FILES := $jar"
echo "LOCAL_MODULE_SUFFIX := \$(COMMON_JAVA_PACKAGE_SUFFIX)"
echo "include \$(BUILD_PREBUILT)"
echo "endif"
} >> "$_MODULES_MK"
_mk_add_module_depends "$jar_module"
}
mk_add_custom_module () {
local readonly mk="$1"
local readonly mk_basename="$(basename "$mk")"
local readonly module="${mk_basename%.*}"
[ -f "$_MODULES_MK" ] || _mk_init_module_mk
# strip comments and append to modules makefile
grep -v "#" < "$mk" >> "$_MODULES_MK"
_mk_add_module_depends "$module"
}
mk_mirror_file () {
local readonly file="$1"
local readonly owner="$2"
[ -f "$_BLOBS_MK" ] || _mk_init_blobs_mk
echo " ${_VENDOR_DIR}/${file}:${file}:${owner} \\" >> "$_BLOBS_MK"
}