forked from brimstone/docker-golang
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cc
executable file
·139 lines (131 loc) · 3.14 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
#!/bin/bash
set -ue
GOOS=${GOOS:-linux}
GOARCH=${GOARCH:-amd64}
CGO_ENABLED=${CGO_ENABLED:-1}
# 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
if [ "$CGO_ENABLED" = "1" ]; then
LINKMODEFLAGS="-linkmode external -extldflags \"-static\""
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:-} ${LINKMODEFLAGS:-}"
;;
## 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-*-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:-} ${LINKMODEFLAGS:-}"
;;
js-wasm-go)
exec /usr/local/go/bin/go "$@"
;;
*)
echo "There is not compiler for GOOS=${GOOS} GOARCH=${GOARCH} in the cc file!" >&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
SUBCOMMAND=$1
shift
declare -a adjusted_args=()
found_ldflags=0
# loop over all arguments searching for -ldflags
while (( $# )); do
# there are two cases -ldflags XYZ and -ldflags=XYZ
# when we find it, we'll inject LDFLAGS environment variable
if [ "$1" = "-ldflags" ]; then
shift
adjusted_args[${#adjusted_args[@]}]="-ldflags"
adjusted_args[${#adjusted_args[@]}]="$LDFLAGS $1"
found_ldflags=1
elif [ "${1:0:9}" = "-ldflags=" ]; then
adjusted_args[${#adjusted_args[@]}]="-ldflags"
adjusted_args[${#adjusted_args[@]}]="$LDFLAGS ${1:9}"
found_ldflags=1
else
adjusted_args[${#adjusted_args[@]}]=$1
fi
shift
done
if [ "$found_ldflags" = 0 ]; then
# we didn't find -ldflags, hence we'll prepend environment LDFLAGS instead.
echo /usr/local/go/bin/go $SUBCOMMAND -ldflags "${LDFLAGS:-}" "${adjusted_args[@]}"
exec /usr/local/go/bin/go $SUBCOMMAND -ldflags "${LDFLAGS:-}" "${adjusted_args[@]}"
else
# otherwise, LDFLAGS and -ldflags have been merged already
echo /usr/local/go/bin/go $SUBCOMMAND "${adjusted_args[@]}"
exec /usr/local/go/bin/go $SUBCOMMAND "${adjusted_args[@]}"
fi