-
Notifications
You must be signed in to change notification settings - Fork 2
/
extract-vendor.sh
executable file
·116 lines (97 loc) · 3.04 KB
/
extract-vendor.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
#!/bin/bash
VENDOR_DIR="$1"
VENDOR_MAKEFILE="device-vendor.mk"
ANDROID_MAKEFILE="Android.mk"
LOCAL_DIR="proprietary/vendor"
TARGET_DIR="vendor"
VENDOR="huawei"
DEVICE="angler"
HEADER="# Copyright $(date +"%Y") ParanoidAndroid Project
#
# 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.
# This file was automatically generated by vendor/$VENDOR/$DEVICE/extract-vendor.sh"
function usage {
echo "usage: extract-vendor.sh <path_to_vendor_folder>"
exit
}
if [ "$VENDOR_DIR" == '' ]; then
usage
fi
# Create vendor dir if necessary
if [ ! -d "$LOCAL_DIR" ]; then
mkdir "$LOCAL_DIR"
fi
# Get rid of trailing '/' if necessary
if [ "${VENDOR_DIR:(-1)}" == '/' ]; then
index=${#VENDOR_DIR}-1
VENDOR_DIR=${VENDOR_DIR:0:$index}
fi
# Get a list of all vendor blobs
APK_FILES=$(find $VENDOR_DIR -type f -name "*.apk")
BLOB_FILES=$(find $VENDOR_DIR -type f)
# First line for vendor image mk
echo -n "PRODUCT_COPY_FILES +=" >> $VENDOR_MAKEFILE
# Copy the vendor blobs to our local tree
OFFSET=${#VENDOR_DIR}
for FILE in $BLOB_FILES; do
local_path="$LOCAL_DIR${FILE:$OFFSET}"
target_path="$TARGET_DIR${FILE:$OFFSET}"
# Check if the target dir exists
local_path_dir=$(dirname $local_path)
if [ ! -d "$local_path_dir" ]; then
mkdir -p "$local_path_dir"
fi
cp -f $FILE $local_path
# Handle APKs in Android.mk
if [[ "$FILE" == "*.apk" ]]; then
continue
fi
# Append paths to the mk file
echo -n " \\
vendor/$VENDOR/$DEVICE/$local_path:$target_path" >> $VENDOR_MAKEFILE
done
# Final newline
echo "" >> $VENDOR_MAKEFILE
# Nothing to do if there's no APKs
if [ -z "$APK_FILES" ]; then
exit
fi
# Add APKs to Android.mk
echo "" >> $ANDROID_MAKEFILE
echo "ifeq (\$(TARGET_DEVICE),$DEVICE)" >> $ANDROID_MAKEFILE
echo -n "
PRODUCT_PACKAGES +=" >> $VENDOR_MAKEFILE
for FILE in $APK_FILES; do
APK_NAME=$(basename -s .apk $FILE)
local_path="$LOCAL_DIR${FILE:$OFFSET}"
echo "
include \$(CLEAR_VARS)
LOCAL_MODULE := $APK_NAME
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := \$(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_MODULE_TAGS := optional
LOCAL_DEX_PREOPT := false
LOCAL_CERTIFICATE := platform" >> $ANDROID_MAKEFILE
if [[ "$FILE" =~ "*system/priv-app/".* ]]; then
echo "LOCAL_PRIVILEGED_MODULE := true" >> $ANDROID_MAKEFILE
fi
echo "LOCAL_SRC_FILES := $local_path
include \$(BUILD_PREBUILT)" >> $ANDROID_MAKEFILE
# Add APK to device-vendor.mk
echo -n " \\
$APK_NAME" >> $VENDOR_MAKEFILE
done
echo "
endif" >> $ANDROID_MAKEFILE
echo "" >> $VENDOR_MAKEFILE
# Add APKs to device-vendor.mk