#!/bin/bash
# This is a simple script to make xgboost in MAC and Linux for python wrapper only
# Basically, it first try to make with OpenMP, if fails, disable OpenMP and make it again.
# This will automatically make xgboost for MAC users who don't have OpenMP support.
# In most cases, type make will give what you want.

# See additional instruction in doc/build.md

# note: this script is build for python package only, and it might have some filename
#       conflict with build.sh which is for everything. 

set -e
set -x

#pushd xgboost
oldpath=`pwd`
cd ./xgboost/

if [[ "$OSTYPE" == "darwin"* ]]; then
  LIB_XGBOOST=libxgboost.dylib
else
  LIB_XGBOOST=libxgboost.so
fi

if make lib/${LIB_XGBOOST} -j4; then
    echo "Successfully build multi-thread xgboost"
else
    echo "-----------------------------"
    echo "Building multi-thread xgboost failed"
    echo "Start to build single-thread xgboost"
    make clean
    make lib/${LIB_XGBOOST} -j4 USE_OPENMP=0
    echo "Successfully build single-thread xgboost"
    echo "If you want multi-threaded version"
    echo "See additional instructions in doc/build.md"
fi
cd $oldpath

set +x
