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	iputils-ping
34
35RUN apt-add-repository -y multiverse && apt-get update && apt-get install -yy \
36	dwarves \
37	sparse
38
39RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
40RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
41
42USER ${USER}
43ENV HOME ${HOME}
44RUN /bin/bash
45EOF
46)
47
48# Build the docker container
49docker build -t linux-build/ubuntu - <<< "${Dockerfile}"
50if [[ "$?" -ne 0 ]]; then
51  echo "Failed to build docker container."
52  exit 1
53fi
54
55# Create the docker run script
56export PROXY_HOST=${http_proxy/#http*:\/\/}
57export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
58export PROXY_PORT=${http_proxy/#http*:\/\/*:}
59
60mkdir -p ${WORKSPACE}
61
62cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
63#!/bin/bash
64
65set -x
66
67cd ${WORKSPACE}
68
69# Go into the linux directory (the script will put us in a build subdir)
70cd linux
71
72# Record the version in the logs
73powerpc64le-linux-gnu-gcc --version || exit 1
74
75# Build kernel prep
76ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make clean || exit 1
77ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper || exit 1
78
79# Build kernel with debug
80ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig || exit 1
81echo "CONFIG_DEBUG_INFO=y" >> .config
82ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make olddefconfig || exit 1
83ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) -s C=2 CF=-D__CHECK_ENDIAN__ 2>&1 | gzip > sparse.log.gz
84pahole vmlinux 2>&1 | gzip > structs.dump.gz
85
86# Build kernel
87ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig || exit 1
88ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) || exit 1
89
90EOF_SCRIPT
91
92chmod a+x ${WORKSPACE}/build.sh
93
94# Run the docker container, execute the build script we just built
95docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
96  -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-build/ubuntu ${WORKSPACE}/build.sh
97
98# Timestamp for build
99echo "Build completed, $(date)"
100
101