#!/bin/sh
# PROJECT:     XTchain
# LICENSE:     See the COPYING.md in the top level directory
# FILE:        scripts/dlltool-wrapper
# DESCRIPTION: DLLTOOL Wrapper
# DEVELOPERS:  Martin Storsjo <martin@martin.st>
#              Rafal Kupiec <belliash@codingworkshop.eu.org>


# Set basic variables
DIR="$(cd $(dirname $0) && pwd)"
BASENAME="$(basename $0)"
TARGET="${BASENAME%-*}"
DEFAULT_TARGET="x86_64-w64-mingw32"

# Update PATH
export PATH="$DIR":"$PATH"

# Set proper target
if [ "${TARGET}" = "${BASENAME}" ]; then
    TARGET="${DEFAULT_TARGET}"
fi

# Set target machine
ARCH="${TARGET%%-*}"
case $ARCH in
    aarch64)
        M="arm64"
        ;;
    armv7)
        M="arm"
        ;;
    i686)
        M="i386"
        ;;
    x86_64)
        M="i386:x86-64"
        ;;
esac

# Launch the utility
llvm-dlltool -m ${M} "$@"