forked from projectcalico/bird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·88 lines (80 loc) · 2.05 KB
/
build.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
#!/bin/bash
set -e
set -x
###############################################################################
# The build architecture is select by setting the ARCH variable.
# For example: When building on ppc64le you could use ARCH=ppc64le ./build.sh.
# When ARCH is undefined it defaults to amd64.
###############################################################################
# always are building on our current platform
BUILDARCH=$(uname -m)
# get our target machine architecture
ARCH=${ARCH:-${BUILDARCH}}
# standardize the name of the architecture on which we are building, as expected by gcc
case $BUILDARCH in
amd64|x86_64)
BUILDARCH=amd64
;;
arm64|aarch64)
BUILDARCH=aarch64
;;
armv7l|armhf|arm32v7|armv7)
BUILDARCH=armv7
;;
ppc64le|ppc64el|powerpc64le)
BUILDARCH=ppc64le
;;
s390x)
BUILDARCH=s390x
;;
mips64le|mips64el)
BUILDARCH=mips64el
;;
*)
echo "Unsupported build architecture $BUILDARCH" >&2
exit 1
;;
esac
# get the correct TARGETARCH
case $ARCH in
all)
TARGETARCH="amd64 aarch64 armv7 powerpc64le s390x mips64el"
;;
amd64|x86_64)
TARGETARCH=$ARCH
;;
arm64|aarch64)
TARGETARCH=aarch64
;;
armv7l|armhf|arm32v7|armv7)
TARGETARCH=armv7
;;
ppc64le|ppc64el|powerpc64le)
TARGETARCH=powerpc64le
;;
s390x)
TARGETARCH=s390x
;;
mips64el)
TARGETARCH=mips64el
;;
*)
echo "Unknown target architecture $ARCH."
exit 1
esac
# get the right dockerfile
DOCKERFILE=Dockerfile
IMAGE=birdbuild-$ARCH
if [ "$BUILDARCH" != "$TARGETARCH" ]; then
DOCKERFILE=Dockerfile-cross
IMAGE=birdbuild-$BUILDARCH-cross
fi
DIST=dist/
OBJ=obj/
docker build -t $IMAGE -f builder-images/$DOCKERFILE .
mkdir -p $DIST
# create_binaries expects:
# ARCH = architecture on which I am running
# TARGETARCH = architecture(s) for which I am building, if different than ARCH (blank if the same)
# DIST = root directory in which to put binaries, structured as $DIST/$TARGETARCH
docker run --rm --name bird-build -e ARCH=$BUILDARCH -e TARGETARCH="$TARGETARCH" -e DIST=$DIST -e OBJ=$OBJ -v `pwd`:/code $IMAGE ./create_binaries.sh