1#!/bin/bash
2set -e -o pipefail
3
4# This script builds the go cross compilers for ChromeOS targets.
5#
6# Usage: build_go
7#
8# It assumes that the "x86_64-cros-linux-gnu" toolchain is already installed.
9# It assumes that the "armv7a-cros-linux-gnueabihf" toolchain is
10# already installed.
11# It assumes that the "aarch64-cros-linux-gnu" toolchain is already installed.
12
13if [[ ! -e "make.bash" && -e "src/make.bash" ]]
14then
15	cd src
16fi
17
18# Build the Go toolchain for amd64 targets.
19GOOS="linux" GOARCH="amd64" CGO_ENABLED="1" \
20	CC_FOR_TARGET="x86_64-cros-linux-gnu-clang" \
21	CXX_FOR_TARGET="x86_64-cros-linux-gnu-clang++" \
22	./make.bash --no-clean
23GOOS="linux" GOARCH="amd64" CGO_ENABLED="1" \
24	CC="x86_64-cros-linux-gnu-clang" \
25	CXX="x86_64-cros-linux-gnu-clang++" \
26	../bin/go install -v -buildmode=pie std
27
28# Build the Go toolchain for arm targets.
29GOOS="linux" GOARCH="arm" CGO_ENABLED="1" \
30	CC_FOR_TARGET="armv7a-cros-linux-gnueabihf-clang" \
31	CXX_FOR_TARGET="armv7a-cros-linux-gnueabihf-clang++" \
32	./make.bash --no-clean
33GOOS="linux" GOARCH="arm" CGO_ENABLED="1" \
34	CC="armv7a-cros-linux-gnueabihf-clang" \
35	CXX="armv7a-cros-linux-gnueabihf-clang++" \
36	../bin/go install -v -buildmode=pie std
37
38# Build the Go toolchain for arm64 targets.
39GOOS="linux" GOARCH="arm64" CGO_ENABLED="1" \
40	CC_FOR_TARGET="aarch64-cros-linux-gnu-clang" \
41	CXX_FOR_TARGET="aarch64-cros-linux-gnu-clang++" \
42	./make.bash --no-clean
43GOOS="linux" GOARCH="arm64" CGO_ENABLED="1" \
44	CC="aarch64-cros-linux-gnu-clang" \
45	CXX="aarch64-cros-linux-gnu-clang++" \
46	../bin/go install -v -buildmode=pie std
47