-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcc
executable file
·142 lines (138 loc) · 2.77 KB
/
cc
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
set -ue
GOOS=${GOOS:-linux}
GOARCH=${GOARCH:-amd64}
# If we're not `go build` or `go install`, abort
if [ "$0" = "/bin/go" ] \
&& [ "$1" != "build" ] \
&& [ "$1" != "install" ]; then
exec /usr/local/go/bin/go "$@"
fi
case "$GOOS-$GOARCH-$(basename "$0")" in
## Linux
linux-arm-cc)
export CC=/usr/local/musl-arm/bin/musl-gcc
exec "$CC" "$@"
;;
linux-arm-c++)
export CXX=arm-linux-gnueabi-g++-8
exec "$CXX" "$@"
;;
linux-arm64-cc)
export CC=/usr/local/musl-aarch64/bin/musl-gcc
exec "$CC" "$@"
;;
linux-arm64-c++)
export CXX=aarch64-linux-gnu-g++-8
exec "$CXX" "$@"
;;
linux-386-cc)
export CC=gcc
exec "$CC" "$@"
;;
linux-386-c++)
export CC=g++
exec "$CC" "$@"
;;
linux-amd64-cc)
export CC=/usr/local/musl-x86_64/bin/musl-gcc
exec "$CC" "$@"
;;
linux-amd64-c++)
export CXX=g++
exec "$CXX" "$@"
;;
linux-*-go)
LDFLAGS="${LDFLAGS:-} -linkmode external -extldflags \"-static\""
;;
## Windows
windows-amd64-cc)
export CC=x86_64-w64-mingw32-gcc
exec "${CC}" "$@"
;;
windows-386-cc)
export CC=i686-w64-mingw32-gcc
exec "${CC}" "$@"
;;
windows-*-go)
;;
## Darwin
darwin-386-cc)
export CC=o32-clang
exec "${CC}" "$@"
;;
darwin-386-c++)
export CXX=o32-clang++
exec "${CXX}" "$@"
;;
darwin-amd64-cc)
export CC=o64-clang
exec "${CC}" "$@"
;;
darwin-amd64-c++)
export CXX=o64-clang++
exec "${CXX}" "$@"
;;
darwin-*-go)
;;
## Freebsd
freebsd-386-cc)
export LD_LIBRARY_PATH=/freebsd/lib:/freebsd/lib32
export CC=i386-pc-freebsd12-gcc
exec "${CC}" "$@"
;;
freebsd-386-c++)
export LD_LIBRARY_PATH=/freebsd/lib:/freebsd/lib32
export CXX=i386-pc-freebsd12-gpp
exec "${CXX}" "$@"
;;
freebsd-amd64-cc)
export LD_LIBRARY_PATH=/freebsd/lib:/freebsd/lib32
export CC=x86_64-pc-freebsd12-gcc
exec "${CC}" "$@"
;;
freebsd-amd64-c++)
export LD_LIBRARY_PATH=/freebsd/lib:/freebsd/lib32
# FINDME should this be CPP?
export CXX=x86_64-pc-freebsd12-gpp
exec "${CXX}" "$@"
;;
freebsd-*-go)
LDFLAGS="${LDFLAGS:-} -linkmode external -extldflags \"-static\""
;;
android-*-go)
;;
js-wasm-go)
;;
*)
echo "Why does GOOS=${GOOS} GOARCH=${GOARCH} 0=$0?" >&2
exit 1
;;
esac
# $0 must be go, or we should have gotten this far
# The first arg should be 'build' or 'install', or we wouldn't have gotten this far
shift
declare -a arr=()
set_flags=0
while (( $# )); do
if [ "$1" = "-ldflags" ]; then
shift
arr[${#arr[@]}]="-ldflags"
arr[${#arr[@]}]="$LDFLAGS $1"
set_flags=1
elif [ "${1:0:9}" = "-ldflags=" ]; then
arr[${#arr[@]}]="-ldflags"
arr[${#arr[@]}]="$LDFLAGS ${1:9}"
set_flags=1
else
arr[${#arr[@]}]=$1
fi
shift
done
if [ "$set_flags" = 0 ]; then
echo /usr/local/go/bin/go build -ldflags "-s -w ${LDFLAGS:-}" "${arr[@]}"
exec /usr/local/go/bin/go build -ldflags "-s -w ${LDFLAGS:-}" "${arr[@]}"
else
echo /usr/local/go/bin/go build "${arr[@]}"
exec /usr/local/go/bin/go build "${arr[@]}"
fi