#!/bin/bash
#  
# Copyright (C) 2020 Fox kernel 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.  
#   

# Setup colour for the script
yellow='\033[0;33m'  
white='\033[0m'  
red='\033[0;31m' 
green='\e[0;32m'

# Setup environment 
MY_DIR="${BASH_SOURCE%/*}"  
if [[ ! -d "$MY_DIR" ]]; then MY_DIR="$PWD"; fi  

TOOLCHAIN="clang"

if [ "$TOOLCHAIN" == clang  ]; then  
    if [ ! -d "$HOME/cykeek/proton_clang" ]  
    then  
        echo -e "$green << cloning proton clang >> \n $white"  
        git clone --depth=1 https://github.com/kdrag0n/proton-clang.git "$HOME"/cykeek/proton_clang  
    fi  
    export PATH="$HOME/cykeek/proton_clang/bin:$PATH"  
    export STRIP="$HOME/cykeek/proton_clang/aarch64-linux-gnu/bin/strip"  
    export KBUILD_COMPILER_STRING=$("$HOME"/cykeek/proton_clang/bin/clang --version | head -n 1 | perl -pe 's/\(http.*?\)//gs' | sed -e 's/  */ /g' -e 's/[[:space:]]*$//')  
fi

# Clone Kernel source
echo -e "$green << cloning kernel >> \n $white"
git clone https://bgzashtita.es/git/android/goshawk22patched.git -b update
cd goshawk22patched

# Clean the source 
echo -e "$green << make clean and mrproper >> \n $white" 
make clean && make mrproper

# Regenerate defconfig
echo -e "$green << make sdm670_defconfig >> \n $white"
make sdm670_defconfig

echo -e "$green << done >> \n $white"
