#!/bin/bash

bin_dir=`cd ${0%*/*};pwd`
tool_name=mlxdump
int_suf=@INT_SUF@
not_default=@NOT_DFLT@
int_tool_name="${tool_name}_int"
oem_tool_name=""
if [ "$not_default" == "1" ]; then
    oem_tool_name="${tool_name}_${int_suf}"
fi
ext_tool_name="${tool_name}_ext"
tool_path=""

function find_tool () {
    tool=$1
    exp_path=${bin_dir}/${tool}

    if [ -f ${exp_path} ]; then
        tool_path=${exp_path}
        return 0
    fi
    return 1
}

for tool in ${int_tool_name} ${oem_tool_name} ${ext_tool_name}; do
    find_tool ${tool}; RC=$?
    if [ "${RC}" == "0" ]; then
        break;
    fi
done

[ -z "$tool_path" ] && {
    msg="-E- Neither ${int_tool_name}"
    [ -n "$oem_tool_name" ] && msg="${msg} nor ${oem_tool_name}"
    msg="${msg} nor ${ext_tool_name}"
    echo "${msg} is installed on this machine"
    exit 1
}

bash -c '"$0" "$@"' "$tool_path" "$@"