#!/bin/sh

. config/options $1

require_eglibc $1

NV_ARCH=x86
[ "$TARGET_ARCH" = x86_64 ] && NV_ARCH=x86_64

NV_PKG="`echo $PKG_URL | sed 's%.*/\(.*\)$%\1%'`"
[ -d $PKG_BUILD ] && rm -rf $PKG_BUILD

sh $SOURCES/$1/$NV_PKG --extract-only --target $BUILD/$PKG_NAME-$PKG_VERSION

echo "### Applying upstream patches ###"

for patch in `ls $PKG_DIR/patches.upstream`; do
  cat $PKG_DIR/patches.upstream/$patch | patch -d \
    `echo $PKG_BUILD | cut -f1 -d\ ` -p1
done
