#!/bin/sh

# load common functions, compatible with local and installed script
. `dirname $0`/../share/eterbuild/functions/common

if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
	echo "jmake - make with ccache using and parallel build enabled"
	exit 0
fi

try_enable_ccache "$@"

# get number of available processors
[ -n "$NPROCS" ] || NPROCS=`/usr/bin/getconf _NPROCESSORS_ONLN`

# get rounded load average
LOADAVG=`cat /proc/loadavg | cut -f1 -d" " | sed -e "s/\..*//g"`

MAKEARG="-j$NPROCS"
# use only free CPUs
#[ "$(( $NPROCS - $LOADAVG ))" -gt 1 ] || MAKEARG=""

#make $MAKEARG "CC=$CC" "CXX=$CXX" "CPP=$CPP" "CXXCPP=$CXXCPP" $@
cd_to_realcwd
docmd $NICE time -p make $MAKEARG $@