#!/bin/bash

if [ $# -ge 1 ]; then

  if [ $# -ge 3 ]; then
    echo "too many arguments."
    echo "usage: $0 prefix [nCpu]"
    exit
  fi

  nCpu=1
  if [ $# -eq 2 ]; then nCpu=$2; fi
  prefix=$1

  ./autogen.sh
  autoreconf --force --install

  mkdir -v build
  cd build
  boostopts='--with-boost --with-boost-filesystem --with-boost-system'
  boostopts=$boostopts' --with-boost-regex --with-boost-program-options'
  ../configure --prefix=$prefix $boostopts
  make -j $nCpu CXXFLAGS="-Wall -Werror"
  make install

  echo "===> ckon build done."

else
  echo "usage: $0 prefix [nCpu]"
  echo "prefix = install dir"
  echo "nCpu = #cpu's for parallel build (-j) [default=1]"
fi
