forked from mstorsjo/llvm-mingw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclang-target-wrapper.sh
executable file
·94 lines (88 loc) · 2.74 KB
/
clang-target-wrapper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/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)"
BASENAME="$(basename "$0")"
TARGET="${BASENAME%-*}"
EXE="${BASENAME##*-}"
DEFAULT_TARGET=x86_64-w64-mingw32
if [ "$TARGET" = "$BASENAME" ]; then
TARGET=$DEFAULT_TARGET
fi
ARCH="${TARGET%%-*}"
TARGET_OS="${TARGET##*-}"
# Check if trying to compile Ada; if we try to do this, invoking clang
# would end up invoking <triplet>-gcc with the same arguments, which ends
# up in an infinite recursion.
case "$*" in
*-x\ ada*)
echo "Ada is not supported" >&2
exit 1
;;
*)
;;
esac
# Allow setting e.g. CCACHE=1 to wrap all building in ccache.
if [ -n "$CCACHE" ]; then
CCACHE=ccache
fi
# If changing this wrapper, change clang-target-wrapper.c accordingly.
CLANG="$DIR/clang"
FLAGS=""
FLAGS="$FLAGS --start-no-unused-arguments"
case $EXE in
clang++|g++|c++)
FLAGS="$FLAGS --driver-mode=g++"
;;
esac
case $ARCH in
i686)
# Dwarf is the default for i686.
;;
x86_64)
# SEH is the default for x86_64.
;;
armv7)
# Dwarf is the default for armv7.
;;
aarch64)
# SEH is the default for aarch64.
;;
esac
case $TARGET_OS in
mingw32uwp)
# the UWP target is for Windows 10
FLAGS="$FLAGS -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00"
# the UWP target can only use Windows Store APIs
FLAGS="$FLAGS -DWINAPI_FAMILY=WINAPI_FAMILY_APP"
# the Windows Store API only supports Windows Unicode (some rare ANSI ones are available)
FLAGS="$FLAGS -DUNICODE"
# add the minimum runtime to use for UWP targets
FLAGS="$FLAGS -Wl,-lwindowsapp"
# This still requires that the toolchain (in particular, libc++.a) has
# been built targeting UCRT originally.
FLAGS="$FLAGS -Wl,-lucrtapp"
# Force the Universal C Runtime
FLAGS="$FLAGS -D_UCRT"
;;
esac
FLAGS="$FLAGS -target $TARGET"
FLAGS="$FLAGS -rtlib=compiler-rt"
FLAGS="$FLAGS -unwindlib=libunwind"
FLAGS="$FLAGS -stdlib=libc++"
FLAGS="$FLAGS -fuse-ld=lld"
FLAGS="$FLAGS -fdebug-default-version=4"
FLAGS="$FLAGS --end-no-unused-arguments"
$CCACHE "$CLANG" $FLAGS "$@"