1#!/bin/bash
2
3# This build script is for running the Jenkins builds using docker.
4#
5
6# Trace bash processing
7#set -x
8
9# Default variables
10WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
11http_proxy=${http_proxy:-}
12
13# Timestamp for job
14echo "Build started, $(date)"
15
16# Configure docker build
17if [[ -n "${http_proxy}" ]]; then
18PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
19fi
20
21Dockerfile=$(cat << EOF
22FROM ubuntu:latest
23
24${PROXY}
25
26ENV DEBIAN_FRONTEND noninteractive 
27RUN apt-get update && apt-get install -yy \
28	bc \
29	build-essential \
30	git \
31	gcc-powerpc64le-linux-gnu \
32	software-properties-common \
33	libssl-dev \
34	iputils-ping
35
36RUN apt-add-repository -y multiverse && apt-get update && apt-get install -yy \
37	dwarves \
38	sparse
39
40RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
41RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
42
43USER ${USER}
44ENV HOME ${HOME}
45RUN /bin/bash
46EOF
47)
48
49# Build the docker container
50docker build -t linux-build/ubuntu - <<< "${Dockerfile}"
51if [[ "$?" -ne 0 ]]; then
52  echo "Failed to build docker container."
53  exit 1
54fi
55
56# Create the docker run script
57export PROXY_HOST=${http_proxy/#http*:\/\/}
58export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
59export PROXY_PORT=${http_proxy/#http*:\/\/*:}
60
61mkdir -p ${WORKSPACE}
62
63cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
64#!/bin/bash
65
66set -x
67
68cd ${WORKSPACE}
69
70# Go into the linux directory (the script will put us in a build subdir)
71cd linux
72
73# Record the version in the logs
74powerpc64le-linux-gnu-gcc --version || exit 1
75
76# Build kernel prep
77ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make clean || exit 1
78ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper || exit 1
79
80# Build kernel with debug
81ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig || exit 1
82echo "CONFIG_DEBUG_INFO=y" >> .config
83ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make olddefconfig || exit 1
84ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) -s C=2 CF=-D__CHECK_ENDIAN__ 2>&1 | gzip > sparse.log.gz
85pahole vmlinux 2>&1 | gzip > structs.dump.gz
86
87# Build kernel
88ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig || exit 1
89ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) || exit 1
90
91EOF_SCRIPT
92
93chmod a+x ${WORKSPACE}/build.sh
94
95# Run the docker container, execute the build script we just built
96docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
97  -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-build/ubuntu ${WORKSPACE}/build.sh
98
99# Timestamp for build
100echo "Build completed, $(date)"
101
102