#! /bin/bash
 
#    Oct 09/18 - F.Majaess
 
#id  make    - Wrapper to target "make" newer version.
 
#    AUTHOR  - F.Majaess
 
#hd  PURPOSE - "make" script is a wrapper to target SSM packaged
#hd            newer "make" version on Science.  
#hd                        
 
#ex  EXAMPLE:
#ex
#ex    make  
#ex
#ex  The above will result in making any necessary setup then
#ex  invoking "make" binary. 
#ex  
# set -x
Def_ver=`/usr/bin/make --version | sed -n -e 's/^GNU Make 4\..*/4/p'`
Def_ver=${Def_ver:-0}
if [ $Def_ver -ge 4 ] ; then
 exec /usr/bin/make "$@"
else
 Tgmake_ver=`type make | sed -e 's/^.*4\.2\.1.*$/4.2.1/'`
 if [ "$Tgmake_ver" != '4.2.1' ] ; then
  if [ -z "$SSMUSE_PLATFORMS" ] ; then
   . /fs/ssm/main/env/ssmuse-boot.sh
  fi
  . ssmuse-sh -x main/opt/gmake/gmake-4.2.1
  PATH=`echo $PATH | sed -e 's;:/fs/ssm/main/opt/gmake/gmake-4.2.1/all/bin;;'`
  # alias make=`which make`
  Tgmake_ver=`type make | sed -e 's/^.*4\.2\.1.*$/4.2.1/'`
 fi
 if [ "$Tgmake_ver" = '4.2.1' ] ; then
  # exec make "$@"
  MkPth=`which make`
  MkPthx=`dirname $MkPth`
    exec ${MkPthx}/make "$@"
 else
  echo 'Sorry, not able to get make ver. 4.2.1 in place!'
  exit 1
 fi
fi
