Skip to content
This repository was archived by the owner on May 11, 2021. It is now read-only.

Commit 2e1ca90

Browse files
committed
Added crosscompile.bash
1 parent e925635 commit 2e1ca90

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

crosscompile.bash

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
# Copyright 2012 The Go Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style
4+
# license that can be found in the LICENSE file.
5+
6+
# support functions for go cross compilation
7+
8+
PLATFORMS="darwin/386 darwin/amd64 freebsd/386 freebsd/amd64 linux/386 linux/amd64 linux/arm windows/386 windows/amd64"
9+
10+
eval "$(go env)"
11+
HOST_GOOS=${GOOS}
12+
HOST_GOARCH=${GOARCH}
13+
14+
function cgo-enabled {
15+
if [ "$1" = "${HOST_GOOS}" ]; then
16+
CGO_ENABLED=1
17+
else
18+
CGO_ENABLED=0
19+
fi
20+
}
21+
22+
function go-alias {
23+
GOOS=${1%/*}
24+
GOARCH=${1#*/}
25+
eval "function go-${GOOS}-${GOARCH} { (CGO_ENABLED=$(cgo-enabled ${GOOS}) GOOS=${GOOS} GOARCH=${GOARCH} go \$@ ) }"
26+
}
27+
28+
function go-crosscompile-build {
29+
GOOS=${1%/*}
30+
GOARCH=${1#*/}
31+
OUTPUT=$(cd ${GOROOT}/src ; CGO_ENABLED=$(cgo-enabled ${GOOS}) GOOS=${GOOS} GOARCH=${GOARCH} ./make.bash --no-clean 2>&1)
32+
if [ $? -ne 0 ] ; then
33+
echo "$OUTPUT" >&2
34+
fi
35+
}
36+
37+
function go-crosscompile-build-all {
38+
set -e
39+
for PLATFORM in $PLATFORMS; do
40+
CMD="go-crosscompile-build ${PLATFORM}"
41+
echo $CMD
42+
$CMD
43+
done
44+
}
45+
46+
for PLATFORM in $PLATFORMS; do
47+
go-alias $PLATFORM
48+
done
49+

0 commit comments

Comments
 (0)