# template for a compile script for JWM for Linux
#
# History
#   08.06.2014/bs
#     initial release
#

THISSCRIPT="$( whence $0  2>/dev/null )" && THISSCRIPT="$( which $0  2>/dev/null )"

cd "${0%/*}" && SCRIPTDIR="${PWD}" && cd - >/dev/null

SCRIPTNAME="${0##*/}"

cd "${SCRIPTDIR}/.." && JWM_DIR="${PWD}" && cd - >/dev/null

INC_FILE="${SCRIPTDIR}/jwml_include.inc"


if [ ! -r "${INC_FILE}" ] ; then
  echo "ERROR: jwm include file \"${INC_FILE}\" does not exist or is not readable!"
  exit 5
else
  . "${INC_FILE}"
fi

# ----------------------------------------------------------------------

THISRC=${__FALSE}

# ----------------------------------------------------------------------

cd ${SRCDIR}/${CURRENT_TOOL}*
if [ $? -ne 0 ] ; then
  die 253 "Can not change the working directory to \"${SRCDIR}/${CURRENT_TOOL}*\" "
fi
cd ${SRCDIR}


already_compiled  ${CURRENT_TOOL}
if [ $? -ne 0 ] ; then
  ignore_tool ${CURRENT_TOOL}
  if [ $? -ne 0 ] ; then
    print_header ${CURRENT_TOOL}

    set -e  ; trap "trap_error_for_compile_scripts" ERR
    cd ${CURRENT_TOOL}*
    echo "*** Compiling the tool ${PWD##*/} ..."

# ----------------------------------------------------------------------
# add the code to compile the tool here; the current directory is the
# source directory
#
# Use "make clean" before the compilation and after the installation to cleanup the source directory.
#
# If the standard script configure is used to create the makefile for the tool add the variable  ${CONFIGURE_PARMS} to the parameter of configure
#

#
    LIBPCAP_VERSION="$( pwd | cut -f2- -d"-" )"

    grep Slackware /etc/*release* >/dev/null  && CONFIGURE_PARMS="${CONFIGURE_PARMS} --build=x86_64-unknown-linux-gnu"

    ./configure ${CONFIGURE_PARMS} 
    set +e
    make clean
    set -e

    make
    make uninstall
    make install
    make libpcap.so
    cp libpcap.so.${LIBPCAP_VERSION} ../../lib

#    cd ../../lib

#    [ -r libpcap.so.1.0 ] && rm libpcap.so.1.0

#    [ -r libpcap.so.1 ] && rm libpcap.so.1

#    ln -s ./libpcap.so.${LIBPCAP_VERSION} libpcap.so.1.0

#    ln -s ./libpcap.so.${LIBPCAP_VERSION} libpcap.so.1

#    cd -

    make clean
    cd ..

# ----------------------------------------------------------------------

    set +e  ; trap "" ERR
    compile_successfull ${CURRENT_TOOL}
    THISRC=${__TRUE}
  else
    die 0 "The tool \"${CURRENT_TOOL}\" is on the exclude list for this distribution"
  fi
else
  die 0 "The tool \"${CURRENT_TOOL}\" is already compiled"
fi


# ----------------------------------------------------------------------


die ${THISRC}
