wrappers: Convert dlltool-wrapper to a native executable

This allows running it on windows from processes other than msys
based ones.
This commit is contained in:
Martin Storsjö committed 2021-06-14 11:44:06 +03:00
1 parent 657d12c8a5
commit 459e37f03f
3 files changed
+73 -36

No files matched your search

+68
View File
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2018 Martin Storsjo
*
* This file is part of llvm-mingw.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "native-wrapper.h"
#ifndef DEFAULT_TARGET
#define DEFAULT_TARGET "x86_64-w64-mingw32"
#endif
int _tmain(int argc, TCHAR* argv[]) {
const TCHAR *dir;
const TCHAR *target;
split_argv(argv[0], &dir, NULL, &target, NULL);
if (!target)
target = _T(DEFAULT_TARGET);
TCHAR *arch = _tcsdup(target);
TCHAR *dash = _tcschr(arch, '-');
if (dash)
*dash = '\0';
int max_arg = argc + 2;
const TCHAR **exec_argv = malloc((max_arg + 1) * sizeof(*exec_argv));
int arg = 0;
exec_argv[arg++] = concat(dir, _T("llvm-dlltool"));
if (!_tcscmp(arch, _T("i686"))) {
exec_argv[arg++] = _T("-m");
exec_argv[arg++] = _T("i386");
} else if (!_tcscmp(arch, _T("x86_64"))) {
exec_argv[arg++] = _T("-m");
exec_argv[arg++] = _T("i386:x86-64");
} else if (!_tcscmp(arch, _T("armv7"))) {
exec_argv[arg++] = _T("-m");
exec_argv[arg++] = _T("arm");
} else if (!_tcscmp(arch, _T("aarch64"))) {
exec_argv[arg++] = _T("-m");
exec_argv[arg++] = _T("arm64");
} else {
_ftprintf(stderr, _T("Arch "TS" unsupported\n"), arch);
return 1;
}
for (int i = 1; i < argc; i++)
exec_argv[arg++] = argv[i];
exec_argv[arg] = NULL;
if (arg > max_arg) {
fprintf(stderr, "Too many options added\n");
abort();
}
return run_final(exec_argv[0], exec_argv);
}
-33
View File
@@ -1,33 +0,0 @@
#!/bin/sh
#
# Copyright (c) 2018 Martin Storsjo
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
DIR="$(cd "$(dirname "$0")" && pwd)"
export PATH="$DIR":"$PATH"
BASENAME="$(basename "$0")"
TARGET="${BASENAME%-*}"
DEFAULT_TARGET=x86_64-w64-mingw32
if [ "$TARGET" = "$BASENAME" ]; then
TARGET=$DEFAULT_TARGET
fi
ARCH="${TARGET%%-*}"
case $ARCH in
i686) M=i386 ;;
x86_64) M=i386:x86-64 ;;
armv7) M=arm ;;
aarch64) M=arm64 ;;
esac
llvm-dlltool -m $M "$@"