#!/bin/sh
set -e
BUILD_DIR=`pwd`/build/release/drivers
mkdir -p $BUILD_DIR
(cd src/drivers; find . -type d -print | cpio -pdumv $BUILD_DIR) > /dev/null 2>&1
(cd $BUILD_DIR; for dd in `for d in *; do find $d -type d ! -name bin ; done`; do mkdir $dd/bin; done) > /dev/null 2>&1
GCC=/usr/bin/gcc
CFLAGS="-nostdlib -nostartfiles -c -g3 -O1 -DVMX86_DEVEL -DVMX86_SERVER -Wall -Werror -Wstrict-prototypes -w -Wno-error -DMODULE"
CFLAGS="$CFLAGS -DSMP_CAPABLE_VMK_DRIVER -D__VMWARE__ -D__VMKERNEL_MODULE__ -DVMKERNEL_MODULE -D__KERNEL__ -DESX3_NETWORKING_NOT_DONE_YET -DGPLED_CODE"
# CFLAGS="$CFLAGS -DSMP_CAPABLE_VMK_DRIVER -D__VMWARE__ -D__VMKERNEL_MODULE__ -DVMKERNEL_MODULE -D__KERNEL__ -DGPLED_CODE"
CFLAGS="$CFLAGS -DVMKERNEL_MODULE -D__KERNEL__ -fno-strength-reduce -fno-common -march=i586 -falign-loops=4 -falign-jumps=4"
CFLAGS="$CFLAGS -falign-functions=4 -fno-omit-frame-pointer -DCPU=586 -fno-strict-aliasing -DCONFIG_PROC_FS -DSMP_CAPABLE_VMK_DRIVER"
CFLAGS="$CFLAGS -DNET_DRIVER -DLINUX_MODULE_HEAP_INITIAL=1024*100  -DLINUX_MODULE_HEAP_MAX=1024*4096"
CFLAGS="$CFLAGS -Isrc/include/vmware/version -Isrc/include/vmware/vmklinks/public -Isrc/include/vmware/vmklinks/vmkernel/distribute -Isrc/include/vmware/vmklinks/vmkernel/public -Isrc/include/vmware/vmklinks/vmkernel/driver -Isrc/include/vmware/vmklinks/vmkernel/include/vmkapi -Isrc/include/vmware/vmklinks/modules/vmkernel/vmklinux -Isrc/include -Ibuild/obj/include"
AR=ar
LD=ld
echo '**   Compiling        drivers/net/skge/skge.c'
$GCC -o build/release/drivers/net/skge/skge.o $CFLAGS -DLINUX_MODULE_HEAP_NAME="\"skge\"" -Isrc/drivers/net src/drivers/net/skge/skge.c
echo '**   Compiling        drivers/net/skge/linux_module_heap.c'
$GCC -o build/release/drivers/net/skge/linux_module_heap.o $CFLAGS -DLINUX_MODULE_HEAP_NAME="\"skge\"" -Isrc/drivers/net src/drivers/net/skge/linux_module_heap.c
set -x
echo '**** Creating library drivers-net-skge-obj.a'
$AR rcs build/release/drivers/net/skge/bin/drivers-net-skge-obj.a build/release/drivers/net/skge/linux_module_heap.o build/release/drivers/net/skge/skge.o
$LD  -r -o build/release/drivers/net/skge/bin/skge.o --whole-archive build/release/drivers/net/skge/bin/drivers-net-skge-obj.a
