#!/bin/bash

set -e

echo "[1/5] Clean kernel tree..."
make mrproper

echo "[2/5] Base minimal config..."
make allnoconfig
make olddefconfig

# =========================================================

# CPU (Yonah / Pentium-M class)

# =========================================================

echo "[3/5] CPU..."
scripts/config --enable CONFIG_M686

# =========================================================

# CORE SYSTEM (boot required)

# =========================================================

echo "Core system..."
scripts/config --enable CONFIG_PROC_FS
scripts/config --enable CONFIG_SYSFS
scripts/config --enable CONFIG_TMPFS
scripts/config --enable CONFIG_DEVTMPFS
scripts/config --enable CONFIG_DEVTMPFS_MOUNT

# =========================================================

# STORAGE (HDD 7200rpm Mac mini)

# =========================================================

echo "Storage..."
scripts/config --enable CONFIG_BLOCK
scripts/config --enable CONFIG_ATA
scripts/config --enable CONFIG_SATA_AHCI
scripts/config --enable CONFIG_SCSI
scripts/config --enable CONFIG_BLK_DEV_SD
scripts/config --enable CONFIG_EXT4_FS

# =========================================================

# GPU Intel GMA950 (i915 legacy)

# =========================================================

echo "GPU..."
scripts/config --enable CONFIG_DRM
scripts/config --enable CONFIG_DRM_I915
scripts/config --enable CONFIG_FB
scripts/config --enable CONFIG_FRAMEBUFFER_CONSOLE

# =========================================================

# INPUT (keyboard / mouse / USB pads)

# =========================================================

echo "Input..."
scripts/config --enable CONFIG_INPUT
scripts/config --enable CONFIG_INPUT_EVDEV
scripts/config --enable CONFIG_INPUT_KEYBOARD
scripts/config --enable CONFIG_INPUT_MOUSE
scripts/config --enable CONFIG_SERIO_I8042
scripts/config --enable CONFIG_USB_HID
scripts/config --enable CONFIG_HID_GENERIC

# =========================================================

# AUDIO (PCSX stable)

# =========================================================

echo "Audio..."
scripts/config --enable CONFIG_SOUND
scripts/config --enable CONFIG_SND
scripts/config --enable CONFIG_SND_PCM
scripts/config --enable CONFIG_SND_TIMER
scripts/config --enable CONFIG_SND_HRTIMER
scripts/config --enable CONFIG_SND_HDA_INTEL

# =========================================================

# SCHEDULER (low latency gaming)

# =========================================================

echo "Scheduler..."
scripts/config --enable CONFIG_PREEMPT
scripts/config --set-val CONFIG_HZ 1000

# =========================================================

# NETWORK (optional light updates)

# =========================================================

echo "Network..."
scripts/config --enable CONFIG_NET
scripts/config --enable CONFIG_INET
scripts/config --enable CONFIG_E1000

# =========================================================

# FINALIZE

# =========================================================

# =========================
# HARDWARE MONITORING (sensors + mpdfan)
# =========================
scripts/config --enable CONFIG_HWMON
scripts/config --module CONFIG_APPLESMC
scripts/config --enable CONFIG_THERMAL
scripts/config --enable CONFIG_CPU_THERMAL
scripts/config --module CONFIG_SENSORS_CORETEMP

echo "[4/5] Finalizing config..."
make olddefconfig

echo "[5/5] Done. Ready to build kernel."
echo "Run: make -j2"


