# See http://wiki.archlinux.org/index.php/VCS_PKGBUILD_Guidelines
# for more information on packaging from GIT sources.

# Maintainer: Vincenzo Maffione <v.maffione@gmail.com>
pkgname=netmap
pkgver=2.0
pkgrel=1
pkgdesc="Netmap is a framework for high speed network packet I/O."
arch=('any')
url="http://info.iet.unipi.it/~luigi/netmap"
license=('BSD')
groups=()
depends=('linux' 'glibc')
makedepends=('git' 'sed' 'gzip' 'linux-headers')
provides=()
conflicts=()
replaces=()
backup=()
options=()
install="netmap.install"
source=()
noextract=()
md5sums=() #generate with 'makepkg -g'

_gitroot="https://v.maffione@code.google.com/p/netmap/"
_gitname="netmap"

build() {
  cd "$srcdir"
  msg "Connecting to GIT server...."

  if [[ -d "$_gitname" ]]; then
    cd "$_gitname" && git pull origin
    msg "The local files are updated."
  else
    git clone "$_gitroot" "$_gitname"
  fi

  msg "GIT checkout done or server timeout"
  msg "Starting build..."

  rm -rf "$srcdir/$_gitname-build"
  git clone "$srcdir/$_gitname" "$srcdir/$_gitname-build"
  cd "$srcdir/$_gitname-build"

    # Build the netmap kernel module
    cd "$srcdir/$_gitname-build/LINUX"
    make || return 1
    # Build pkt-gen and vale-ctl
    cd "$srcdir/$_gitname-build/examples"
    make pkt-gen vale-ctl || return 1
}

package() {
    # Compute the version numbers of the running kernel
    KVER1=$(uname -r)
    KVER2=$(uname -r | sed 's/\.[0-9]\+-[0-9]\+//')

    # Install the netmap module into the extramodules-VERSION directory
    mkdir -p "$pkgdir/lib/modules/extramodules-${KVER2}"
    cp "$srcdir/$_gitname-build/LINUX/netmap_lin.ko" "$pkgdir/lib/modules/extramodules-${KVER2}"

    # Install pkt-gen and valectl into /usr/bin
    mkdir -p "$pkgdir/usr/bin"
    cp "$srcdir/$_gitname-build/examples/pkt-gen" "$pkgdir/usr/bin"
    cp "$srcdir/$_gitname-build/examples/vale-ctl" "$pkgdir/usr/bin"

    # Install the netmap man page
    mkdir -p "$pkgdir/usr/share/man/man4"
    cp "$srcdir/$_gitname-build/share/man/man4/netmap.4" "$pkgdir/usr/share/man/man4"
    gzip "$pkgdir/usr/share/man/man4/netmap.4"
}

# vim:set ts=2 sw=2 et:
