|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | # Lite kernel compilation script [ with Args ] |
3 | | -# Copyright (C) 2020 - 2022 Muhammad Fadlyas (fadlyas07) |
| 3 | +# Copyright (C) 2020, 2022, 2023 Muhammad Fadlyas (fadlyas07) |
4 | 4 | # SPDX-License-Identifier: GPL-3.0-or-later |
| 5 | +export DIR="$(pwd)" |
5 | 6 | if [[ $# -eq 0 ]]; then |
6 | 7 | echo "No parameter specified!" |
7 | 8 | exit 1 |
8 | 9 | fi |
9 | | -if ! [[ -f Makefile && -d kernel ]]; then |
| 10 | +if ! [[ -f "${DIR}/Makefile" && -d "${DIR}/kernel" ]]; then |
10 | 11 | echo "Please run this script inside kernel source folder!" |
11 | 12 | exit 1 |
12 | 13 | fi |
13 | | -export DIR="$(pwd)" |
14 | 14 | echo "Cloning dependencies..." |
15 | | -[[ ! -d "$DIR/AnyKernel3" ]] && git clone --single-branch https://github.com/greenforce-project/AnyKernel3 --depth=1 &>/dev/null |
16 | | -[[ ! -d "$DIR/aosp_clang" ]] && git clone --single-branch https://github.com/greenforce-project/aosp_clang --depth=1 &>/dev/null |
17 | | -[[ ! -d "$DIR/aarch64-linux-android-4.9" ]] && git clone --single-branch https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9 -b android-9.0.0_r40 --depth=1 &>/dev/null |
18 | | -[[ ! -d "$DIR/arm-linux-androideabi-4.9" ]] && git clone --single-branch https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9 -b android-9.0.0_r40 --depth=1 &>/dev/null |
| 15 | +[[ ! -d "${DIR}/AnyKernel3" ]] && git clone --single-branch https://github.com/greenforce-project/AnyKernel3 --depth=1 &>/dev/null |
| 16 | +[[ ! -d "${DIR}/aosp_clang" ]] && git clone --single-branch https://github.com/greenforce-project/aosp_clang --depth=1 &>/dev/null |
| 17 | +[[ ! -d "${DIR}/aarch64-linux-android-4.9" ]] && git clone --single-branch https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9 -b android-9.0.0_r40 --depth=1 &>/dev/null |
| 18 | +[[ ! -d "${DIR}/arm-linux-androideabi-4.9" ]] && git clone --single-branch https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9 -b android-9.0.0_r40 --depth=1 &>/dev/null |
19 | 19 | echo "All dependencies cloned!" |
20 | 20 | export ARCH=arm64 |
21 | | -export SUBARCH="$ARCH" |
| 21 | +export SUBARCH="${ARCH}" |
22 | 22 | export KBUILD_BUILD_USER=personal |
23 | 23 | export KBUILD_BUILD_HOST=greenforce-project |
24 | 24 | export kernel_branch=$(git rev-parse --abbrev-ref HEAD) |
25 | 25 | export TZ=Asia/Jakarta |
26 | | -DATE=$(date) |
27 | | -export KBUILD_BUILD_TIMESTAMP="$DATE" |
28 | 26 | source <(grep -E '^(VERSION|PATCHLEVEL)' Makefile | sed -e s/[[:space:]]//g) |
29 | 27 | if ! [[ -n "$VERSION" && -n "$PATCHLEVEL" ]]; then |
30 | 28 | echo "Unable to get kernel version from Makefile!" |
31 | 29 | exit 1 |
32 | 30 | fi |
33 | | -export kernelversion="$VERSION.$PATCHLEVEL" |
34 | | -if [[ "$kernelversion" == 4.19 ]]; then |
35 | | - export vdso_flags='CROSS_COMPILE_COMPAT' |
36 | | -else |
37 | | - export vdso_flags='CROSS_COMPILE_ARM32' |
38 | | -fi |
39 | | -export codename="$2" &>/dev/codename |
40 | | -if [[ -n "$codename" ]]; then |
| 31 | +export codename="${2}" &>/dev/codename |
| 32 | +if [[ -n "${codename}" ]]; then |
41 | 33 | if [[ -f "/dev/codename" ]]; then |
42 | | - export codename=$(cat /dev/codename) |
| 34 | + export codename="$(cat /dev/codename)" |
43 | 35 | else |
44 | 36 | echo "codename is empty, please run 'export codename=[CODENAME]'" |
45 | 37 | exit 1 |
46 | 38 | fi |
47 | 39 | fi |
48 | | -export defconfig="$codename"-perf_defconfig |
49 | | -export PATH="$DIR/aosp_clang/bin:$DIR/aarch64-linux-android-4.9/bin:$DIR/arm-linux-androideabi-4.9/bin:$PATH" |
50 | | -export LD_LIBRARY_PATH="$DIR/aosp_clang/bin/../lib:$LD_LIBRARY_PATH" |
51 | | -export IMG_PATH="$DIR/out/arch/$ARCH/boot" |
52 | | -build_flags="ARCH=$ARCH " |
53 | | -build_flags+="CC=clang " |
54 | | -build_flags+="CLANG_TRIPLE=aarch64-linux-gnu- " |
55 | | -build_flags+="CROSS_COMPILE=aarch64-linux-android- " |
56 | | -build_flags+="${vdso_flags}=arm-linux-androideabi- " |
57 | | -make -j"$(nproc --all)" -C "$DIR" O=out "$build_flags" "$defconfig" 2>&1| build.log |
58 | | -if ! [[ -f "$IMG_PATH/Image.gz-dtb" || -f "$IMG_PATH/Image" ]]; then |
| 40 | +export kernelversion="$VERSION.$PATCHLEVEL" |
| 41 | +case "${kernelversion}" in |
| 42 | + 4.19|5.4|5.10|5.15|6.0) |
| 43 | + export defconfig="vendor/${codename}-perf_defconfig" |
| 44 | + export vdso_flags='CROSS_COMPILE_COMPAT' |
| 45 | + ;; |
| 46 | + *) |
| 47 | + export defconfig="${codename}-perf_defconfig" |
| 48 | + export vdso_flags='CROSS_COMPILE_ARM32' |
| 49 | + ;; |
| 50 | +esac |
| 51 | +export PATH="${DIR}/aosp_clang/bin:${DIR}/aarch64-linux-android-4.9/bin:${DIR}/arm-linux-androideabi-4.9/bin:${PATH}" |
| 52 | +export LD_LIBRARY_PATH="${DIR}/aosp_clang/bin/../lib:${LD_LIBRARY_PATH}" |
| 53 | +export IMG_PATH="${DIR/out/arch/$ARCH/boot}" |
| 54 | +build_flags="ARCH=$ARCH CC=clang CLANG_TRIPLE=aarch64-linux-gnu- CROSS_COMPILE=aarch64-linux-android- ${vdso_flags}=arm-linux-androideabi- " |
| 55 | +build_flags+="AR=llvm-ar OBJDUMP=llvm-objdump STRIP=llvm-strip NM=llvm-nm " |
| 56 | +[[ "${3}" == llvm || "${3}" == full ]] && build_flags+="LLVM=1 " |
| 57 | +make -j$(nproc --all) -C ${DIR} O=out ${build_flags} "${defconfig}" 2>&1| build.log |
| 58 | +if ! [[ -f "${IMG_PATH}/Image.gz-dtb" || -f "${IMG_PATH}/Image.gz" ]]; then |
59 | 59 | echo "Build failed, please check build log and fix it!" |
60 | 60 | exit 1 |
61 | 61 | else |
62 | | - echo "Build Complete, find kernel image in $IMG_PATH" |
| 62 | + echo "Build Complete, find kernel image in ${IMG_PATH}" |
63 | 63 | fi |
64 | | -anykernel_string="$kernel_branch - $(date +'%A'), $(date +'%d %B %Y')" |
65 | | -sed -i "s/kernel.string=/kernel.string=$anykernel_string/g" $DIR/AnyKernel3/anykernel.sh |
66 | | -sed -i "s/device.name1=/device.name1=$codename/g" $DIR/AnyKernel3/anykernel.sh |
67 | | -cp "$IMG_PATH/Image.gz-dtb" "$DIR/AnyKernel3" || cp "$IMG_PATH/Image" "$DIR/AnyKernel3" |
68 | | -cp "$IMG_PATH/dtb.img" "$DIR/AnyKernel3" || echo "dtb.img not found!" |
69 | | -cp "$IMG_PATH/dtbo.img" "$DIR/AnyKernel3" || echo "dtbo.img not found!" |
70 | | -echo "Zipping flashable kernel..." |
| 64 | +anykernel_string="${kernel_branch} - $(date +'%A'), $(date +'%d %B %Y')" |
| 65 | +sed -i "s/kernel.string=/kernel.string=${anykernel_string}/g" ${DIR}/AnyKernel3/anykernel.sh |
| 66 | +sed -i "s/device.name1=/device.name1=${codename}/g" ${DIR}/AnyKernel3/anykernel.sh |
| 67 | +[[ -e "${IMG_PATH}/Image.gz-dtb" ]] && mv "${IMG_PATH}/Image.gz-dtb" "${DIR}/AnyKernel3" |
| 68 | +[[ -e "${IMG_PATH}/Image.gz" ]] && mv "${IMG_PATH/Image.gz" "${DIR}/AnyKernel3" |
| 69 | +[[ -e "${IMG_PATH}/dtb.img" ]] && mv "${IMG_PATH}/dtb.img" "${DIR}/AnyKernel3" |
| 70 | +[[ -e "${IMG_PATH}/dtb.img" ]] && mv "${IMG_PATH}/dtbo.img" "${DIR}/AnyKernel3" |
| 71 | +echo "Compress flashable kernel..." |
71 | 72 | zip -r9 "GF~${KBUILD_BUILD_USER}-${codename}-$(date +'%d%m%y').zip" $DIR/AnyKernel3/* |
72 | | -echo "Zipping complete!" |
73 | | -echo "Build complete! You can find kernel zip in $(find $DIR/AnyKernel3/*.zip)." |
| 73 | +echo "complete!" |
| 74 | +echo "Build complete! find kernel zip in $(find $DIR/AnyKernel3/*.zip)." |
0 commit comments