-
Notifications
You must be signed in to change notification settings - Fork 2
/
build
executable file
·86 lines (65 loc) · 2.58 KB
/
build
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
#!/bin/bash -eu
CURDIR=$(realpath $(dirname $0))
ORG_PATH="github.com/sgotti"
REPO_PATH="${ORG_PATH}/baci"
if [ ! -h ${CURDIR}/gopath/src/${REPO_PATH} ]; then
mkdir -p ${CURDIR}/gopath/src/${ORG_PATH}
ln -s ../../../.. ${CURDIR}/gopath/src/${REPO_PATH} || exit 255
fi
export GOBIN=${CURDIR}/bin
export GOPATH=${CURDIR}/gopath
eval $(go env)
export GOBIN=${CURDIR}/bin
echo "Building sharedlibs helper..."
go build -i -o ${GOBIN}/sharedlibs ${REPO_PATH}/helpers/sharedlibs
RET=$?
[ $RET -ne 0 ] && echo "build failed" && exit 1
XZ=$(which xz)
if [ -n $XZ ]; then
XZ_SHAREDLIBS=$(${GOBIN}/sharedlibs libs ${XZ})
[ $RET -ne 0 ] && echo "cannot find sharedlibs for ${XZ}" && exit 1
LDPATH=$(${GOBIN}/sharedlibs ldpath $XZ)
[ $RET -ne 0 ] && echo "cannot find ldpath for ${XZ}" && exit 1
else
echo "warning: cannot find xz binary, baci will not be able to extract tar.xz files"
fi
echo "Building bacibuilder..."
BACIBUILDER=${GOBIN}/bacibuilder
LDFLAGS="-X github.com/sgotti/baci/builder/util.ldpath ${LDPATH}"
# TODO(sgotti) not using 'go install' or 'go build -i' to avoid problems with
# "-installsuffix" that will rebuild std libraries and can give permission
# problems for go installation not owned by the current user (plus this will
# fill systems dirs with build files). This means the the build should be faster
# as, now, no object files are saved in the $GOPATH/pkg directory
CGO_ENABLED=0 go build -o ${BACIBUILDER} -installsuffix cgo -ldflags "${LDFLAGS} --extldflags \"-static -s\" " ${REPO_PATH}/builder/bacibuilder
RET=$?
[ $RET -ne 0 ] && echo "build failed" && exit 1
echo "Building baci..."
go build -i -o ${GOBIN}/baci ${BACI_IMAGE:+-ldflags "-X main.defaultBaciImage '${BACI_IMAGE}'"} ${REPO_PATH}/baci
RET=$?
[ $RET -ne 0 ] && echo "build failed" && exit 1
BACIACI=${CURDIR}/aci
BACIDIR=${BACIACI}/rootfs/baci
BACIROOT=${BACIDIR}/root
# clean baci.aci build dir
rm -rf ${BACIACI}
mkdir -p ${BACIDIR}/source
mkdir -p ${BACIDIR}/dest
mkdir -p ${BACIDIR}/data
mkdir -p ${BACIROOT}/usr/bin
mkdir -p ${BACIROOT}/lib
cp ${CURDIR}/manifest ${BACIACI}
cp ${BACIBUILDER} ${BACIROOT}/usr/bin
if [ -n $XZ ]; then
cp $XZ ${BACIROOT}/usr/bin/
for lib in ${XZ_SHAREDLIBS}; do
cp $lib ${BACIROOT}/lib/
done
mkdir -p ${BACIROOT}/$(dirname ${LDPATH})
cp $LDPATH ${BACIROOT}/$LDPATH
fi
echo "Building actool..."
ACTOOL=${GOBIN}/actool
go build -i -o ${ACTOOL} ${REPO_PATH}/Godeps/_workspace/src/github.com/appc/spec/actool
echo "Creating the baci's ACI..."
${ACTOOL} build --overwrite ${CURDIR}/aci ${GOBIN}/baci.aci