4e44d5e014c48bd9e7fef30a9d1de056fb5b21bf
[GitHub/LineageOS/G12/android_hardware_amlogic_kernel-modules_mali-driver.git] / t83x / android / patches / K / android-k.sh
1 #!/bin/bash
2
3 #
4 # Copyright (C) 2014-2015 ARM Limited. All rights reserved.
5 #
6 # Copyright (C) 2008 The Android Open Source Project
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # You may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 # Android K script for LLVM 3.5 and above support
22 #
23 # This script applies two minor patches and checks-out libcxx and libcxxabi libraries
24 # adding C++11 support in Android K required for LLVM3.5 and above.
25
26
27 if [ -z "$ANDROID_BUILD_TOP" ]; then
28 echo "[ANDROID-PATCH] This script must be executed in an Android build environment"
29 echo " ANDROID_BUILD_TOP is undefined"
30 echo " please do \"source build/envseup.sh; lunch\"."
31 exit 1
32 fi
33
34 ANDROID_REPOSITORY_URL="https://android.googlesource.com/"
35
36 REFERENCE_ARGUMENT=""
37
38 # Proccess arguments. Valid arguments are:
39 # -u ARG Override the Android repository url
40 # -r ARG Provide a path to a reference git repository
41 while getopts "u:r:" opt; do
42 case $opt in
43 u)
44 ANDROID_REPOSITORY_URL=$OPTARG
45 ;;
46
47 r)
48 REFERENCE_ARGUMENT="--reference "$OPTARG
49 ;;
50
51 \?)
52 echo "Invalid option: -$OPTARG" >&2
53 exit 1
54
55 ;;
56 :)
57 echo "Option -$OPTARG requires an argument." >&2
58 exit 1
59 ;;
60
61 esac
62 done
63
64 MIDGARD_DDK_WD=$(pwd)
65
66 cd $ANDROID_BUILD_TOP/external
67
68 #Checkout libcxx from Android Master required by LLVM due to c++11
69 git clone $ANDROID_REPOSITORY_URL/platform/external/libcxx $REFERENCE_ARGUMENT
70
71 ret_code=$?
72 if [[ $ret_code != 0 ]] ; then
73 echo "[ANDROID-PATCH] git clone of libcxx failed."
74 cd $MIDGARD_DDK_WD
75 exit $ret_code
76 fi
77
78 cd libcxx
79 git checkout 27ae7cb782821a4f2d3813522ee411cd978bcd85 -q
80
81 ret_code=$?
82 if [[ $ret_code != 0 ]] ; then
83 echo "[ANDROID-PATCH] checkout of libcxx@27ae7cb782821a4f2d3813522ee411cd978bcd85 revision failed."
84 cd $MIDGARD_DDK_WD
85 exit $ret_code
86 fi
87
88 patch -p1 < $MIDGARD_DDK_WD/android/patches/K/libcxx.diff
89
90 ret_code=$?
91 if [[ $ret_code != 0 ]] ; then
92 echo "[ANDROID-PATCH] Patching libcxx failed."
93 git reset --hard
94 cd $MIDGARD_DDK_WD
95 exit $ret_code
96 fi
97
98 #Checkout libcxxabi from Android Master required by LLVM due to c++11
99 cd $ANDROID_BUILD_TOP/external
100 git clone $ANDROID_REPOSITORY_URL/platform/external/libcxxabi $REFERENCE_ARGUMENT
101
102 ret_code=$?
103 if [[ $ret_code != 0 ]] ; then
104 echo "[ANDROID-PATCH] git clone of libcxxabi failed."
105 cd $MIDGARD_DDK_WD
106 exit $ret_code
107 fi
108
109 cd libcxxabi
110 git checkout 285d67f35f6044cf733091e36248405ca967c62c -q
111
112 ret_code=$?
113 if [[ $ret_code != 0 ]] ; then
114 echo "[ANDROID-PATCH] checkout of libcxxabi@285d67f35f6044cf733091e36248405ca967c62c revision failed."
115 cd $MIDGARD_DDK_WD
116 exit $ret_code
117 fi
118
119
120 #Apply patch to bioncs
121 cd $ANDROID_BUILD_TOP/bionic/
122 patch -p1 < $MIDGARD_DDK_WD/android/patches/K/bionics.diff
123
124 ret_code=$?
125 if [[ $ret_code != 0 ]] ; then
126 echo "[ANDROID-PATCH] Patching bionics failed."
127 git reset --hard
128 cd $MIDGARD_DDK_WD
129 exit $ret_code
130 fi
131
132 #Add locale support to bioncs
133 cd $ANDROID_BUILD_TOP/bionic/
134 patch -p1 < $MIDGARD_DDK_WD/android/patches/K/locale.diff
135
136 ret_code=$?
137 if [[ $ret_code != 0 ]] ; then
138 echo "[ANDROID-PATCH] Adding locale support failed."
139 git reset --hard
140 cd $MIDGARD_DDK_WD
141 exit $ret_code
142 fi
143
144 #Add LLVM backend ARM fix to support -O0 compilation
145 cd $ANDROID_BUILD_TOP/external/llvm/
146 patch -p1 < $MIDGARD_DDK_WD/android/patches/K/llvm.diff
147
148 ret_code=$?
149 if [[ $ret_code != 0 ]] ; then
150 echo "[ANDROID-PATCH] Fixing ARM LLVM backend failed."
151 git reset --hard
152 cd $MIDGARD_DDK_WD
153 exit $ret_code
154 fi
155
156 echo "[ANDROID-PATCH] Patching completed successfully"
157 cd $MIDGARD_DDK_WD