#!/bin/bash
+COLOR_RED_BG=$(tput setab 1)
+COLOR_RED_BOLD=$(tput bold)$(tput setaf 1)
+COLOR_RESET=$(tput sgr0)
+
NCPUS=`cat /proc/cpuinfo | grep processor | wc -l`
NCPUS=$(($NCPUS * 2))
echo "NORMAL" > ./.kernel_buildenv
fi
+
if [ $1 = "arm" ]; then
+ arch="arm"
+ cross_compile="${CCACHE} arm-linux-gnueabi-"
echo "ARM"
-
- rm -f arch/arm/boot/zImage
- rm -f arch/arm/boot/dts/*.dtb
-
- if ! [ -e .config ] ; then
- make ARCH=arm CROSS_COMPILE="${CCACHE} arm-linux-gnueabi-" ${DEFCONFIG}
- fi
-
- make ARCH=arm CROSS_COMPILE="${CCACHE} arm-linux-gnueabi-" -j $NCPUS
-
- if [ ! -f "./arch/arm/boot/zImage" ]; then
- echo "Build fail"
- exit 1
- fi
elif [ $1 = "arm64" ]; then
+ arch="arm64"
+ cross_compile="${CCACHE} aarch64-linux-gnu-"
echo "ARM64"
+fi
- rm -f arch/arm64/boot/Image
- rm -f arch/arm64/boot/dts/broadcom/*.dtb
+if ! [ -e .config ] ; then
+ make ARCH="${arch}" CROSS_COMPILE="${cross_compile}" ${DEFCONFIG}
+fi
- if ! [ -e .config ] ; then
- make ARCH=arm64 CROSS_COMPILE="${CCACHE} aarch64-linux-gnu-" ${DEFCONFIG}
- fi
- make ARCH=arm64 CROSS_COMPILE="${CCACHE} aarch64-linux-gnu-" -j $NCPUS
- if [ ! -f "./arch/arm64/boot/Image" ]; then
- echo "Build fail"
- exit 1
- fi
+make ARCH="${arch}" CROSS_COMPILE="${cross_compile}" -j ${NCPUS} 2>&1 | \
+sed -e "/error:.*/{s/^.*error:/$(echo -e "${COLOR_RED_BG}&${COLOR_RESET}")/g;q1}" \
+ -e "/Error.*/{s/^.*Error:/$(echo -e "${COLOR_RED_BG}&${COLOR_RESET}")/g;q1}" \
+ -e "/ERROR.*/{s/^.*ERROR/$(echo -e "${COLOR_RED_BG}&${COLOR_RESET}")/g;q1}"
+if [ $? -ne 0 ]; then
+ echo -e "${COLOR_RED_BOLD}Failed to build${COLOR_RESET}"
+ exit 1
fi
scripts/mkbootimg_rpi4.sh