#!/bin/sh
# Build the patched amdgpu.ko module. Apply fix.diff first.
# Note: amdgpu is a large module; this takes ~1-2 minutes with -j6.
set -e
SCRIPT_DIR="$(dirname "$0")"
cd "$SCRIPT_DIR"
if ! grep -q 'ucode_offset > fw->datasize' /usr/src/sys/dev/drm/amd/amdgpu/amdgpu_ucode.c 2>/dev/null; then
    (cd /usr/src && patch -p1 --forward < "$SCRIPT_DIR/fix.diff")
fi
cd /usr/src/sys/dev/drm/amd/amdgpu
make -j6 KMOD=amdgpu
echo "BUILD_EXIT=$?"
ls -l amdgpu.ko
