# Architecture and branch settings
ARCH=x86_64
BRANCH=kasan

# Compiler settings
CC=clang
CLANG_PREBUILT_BIN=prebuilts-master/clang/host/linux-x86/clang-r353983c/bin
BUILDTOOLS_PREBUILT_BIN=build/build-tools/path/linux-x86
CLANG_TRIPLE=x86_64-linux-gnu-

# Cross-compilation settings
CROSS_COMPILE=x86_64-linux-androidkernel-
LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN=prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin

# Kernel configuration
KERNEL_DIR=goldfish
EXTRA_CMDS=''
STOP_SHIP_TRACEPRINTK=1

# Output files to be generated
FILES="
arch/x86/boot/bzImage
vmlinux
System.map
"

# Default configuration
DEFCONFIG=x86_64_ranchu_defconfig
POST_DEFCONFIG_CMDS="check_defconfig && apply_kasan_settings"

# Function to apply KASAN (Kernel Address Sanitizer) settings
apply_kasan_settings() {
    # Update kernel configuration with KASAN settings
    ${KERNEL_DIR}/scripts/config --file ${OUT_DIR}/.config \
        --enable CONFIG_KASAN \
        --enable CONFIG_KASAN_INLINE \
        --enable CONFIG_TEST_KASAN \
        --enable CONFIG_KCOV \
        --enable CONFIG_SLUB \
        --enable CONFIG_SLUB_DEBUG \
        --enable CONFIG_SLUB_DEBUG_ON \
        --disable CONFIG_SLUB_DEBUG_PANIC_ON \
        --disable CONFIG_KASAN_OUTLINE \
        --disable CONFIG_KERNEL_LZ4 \
        --disable CONFIG_RANDOMIZE_BASE

    # Regenerate kernel configuration
    (cd ${OUT_DIR} && \
     make O=${OUT_DIR} $archsubarch CROSS_COMPILE=${CROSS_COMPILE} olddefconfig)
}
