#!/bin/bash

# load the target kernel version in tmp/UNAME_R
# If that file doesn't exist or does not match the latest installed kernel,
# then ./prepare likely hasn't been run for that kernel, so we exit.
UNAME_R_FILE="tmp/UNAME_R"
UNAME_R="`[ -f "$UNAME_R_FILE" ] && cat "$UNAME_R_FILE" || echo -n ""`"
UNAME_R_TEST="`rpm -q kernel --last | head -n1 | sed -e 's/^kernel-//g' -e 's/\s.*//g'`"
if [ "$UNAME_R" != "$UNAME_R_TEST" ]; then
 echo "error: prepare must be run first for kernel $UNAME_R_TEST" >&2
 exit 1
fi

cd rpmbuild
cd BUILD/kernel-`egrep -o '^[0-9]+\.[0-9]+' <<< "$UNAME_R"`.`egrep -o 'fc[0-9]+' <<< "$UNAME_R"`
cd linux-"$UNAME_R"

make SUBDIRS=drivers/media/usb/cx231xx modules