#!/bin/sh

. config/options $1

LINUX=`ls -d $PKG_BUILD`

if [ -f $PROJECT_DIR/$PROJECT/$1/$1.$TARGET_ARCH.conf ]; then
  KERNEL_CFG_FILE=$PROJECT_DIR/$PROJECT/$1/$1.$TARGET_ARCH.conf
else
  KERNEL_CFG_FILE=$PKG_DIR/config/$1.$TARGET_ARCH.conf
fi

sed -i -e "s|^HOSTCC[[:space:]]*=.*$|HOSTCC = $HOST_CC|" \
       -e "s|^HOSTCXX[[:space:]]*=.*$|HOSTCXX = $HOST_CXX|" \
       -e "s|^ARCH[[:space:]]*?=.*$|ARCH = $TARGET_ARCH|" \
       -e "s|^CROSS_COMPILE[[:space:]]*?=.*$|CROSS_COMPILE = $TARGET_PREFIX|" \
       $LINUX/Makefile

cp $KERNEL_CFG_FILE $LINUX/.config
sed -i -e "s|^CONFIG_INITRAMFS_SOURCE=.*$|CONFIG_INITRAMFS_SOURCE=\"$ROOT/$PKG_DIR/config/initramfs\"|" \
  $LINUX/.config

# copy some extra firmware to linux tree
  cp -R $PKG_DIR/firmware/* $LINUX/firmware

make -C $LINUX oldconfig
