1f9ad3f9eSChris Smart#!/bin/bash
2f9ad3f9eSChris Smart
3f9ad3f9eSChris Smart# This build script is for running the Jenkins builds using docker.
4f9ad3f9eSChris Smart#
5f9ad3f9eSChris Smart
6f9ad3f9eSChris Smart# Trace bash processing
7f9ad3f9eSChris Smart#set -x
8f9ad3f9eSChris Smart
9f9ad3f9eSChris Smart# Default variables
10f9ad3f9eSChris SmartWORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
11f9ad3f9eSChris Smarthttp_proxy=${http_proxy:-}
12f9ad3f9eSChris Smart
13f9ad3f9eSChris Smart# Timestamp for job
14f9ad3f9eSChris Smartecho "Build started, $(date)"
15f9ad3f9eSChris Smart
16f9ad3f9eSChris Smart# Configure docker build
17f9ad3f9eSChris Smartif [[ -n "${http_proxy}" ]]; then
18f9ad3f9eSChris SmartPROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
19f9ad3f9eSChris Smartfi
20f9ad3f9eSChris Smart
21f9ad3f9eSChris SmartDockerfile=$(cat << EOF
22f9ad3f9eSChris SmartFROM ubuntu:15.10
23f9ad3f9eSChris Smart
24f9ad3f9eSChris Smart${PROXY}
25f9ad3f9eSChris Smart
264593d4f3SChris SmartENV DEBIAN_FRONTEND noninteractive 
27fc730ff1SChris SmartRUN apt-get update && apt-get install -yy \
284593d4f3SChris Smart	bc \
294593d4f3SChris Smart	build-essential \
304593d4f3SChris Smart	git \
314593d4f3SChris Smart	gcc-powerpc64le-linux-gnu \
32*5158a324SSaqib Khan	software-properties-common \
33*5158a324SSaqib Khan	iputils-ping
344593d4f3SChris Smart
354593d4f3SChris SmartRUN apt-add-repository -y multiverse && apt-get update && apt-get install -yy \
364593d4f3SChris Smart	dwarves \
374593d4f3SChris Smart	sparse
384593d4f3SChris Smart
394593d4f3SChris SmartRUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
404593d4f3SChris SmartRUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
41f9ad3f9eSChris Smart
42f9ad3f9eSChris SmartUSER ${USER}
43f9ad3f9eSChris SmartENV HOME ${HOME}
44f9ad3f9eSChris SmartRUN /bin/bash
45f9ad3f9eSChris SmartEOF
46f9ad3f9eSChris Smart)
47f9ad3f9eSChris Smart
48f9ad3f9eSChris Smart# Build the docker container
49f9ad3f9eSChris Smartdocker build -t linux-build/ubuntu - <<< "${Dockerfile}"
50f9ad3f9eSChris Smartif [[ "$?" -ne 0 ]]; then
51f9ad3f9eSChris Smart  echo "Failed to build docker container."
52f9ad3f9eSChris Smart  exit 1
53f9ad3f9eSChris Smartfi
54f9ad3f9eSChris Smart
55f9ad3f9eSChris Smart# Create the docker run script
56f9ad3f9eSChris Smartexport PROXY_HOST=${http_proxy/#http*:\/\/}
57f9ad3f9eSChris Smartexport PROXY_HOST=${PROXY_HOST/%:[0-9]*}
58f9ad3f9eSChris Smartexport PROXY_PORT=${http_proxy/#http*:\/\/*:}
59f9ad3f9eSChris Smart
60f9ad3f9eSChris Smartmkdir -p ${WORKSPACE}
61f9ad3f9eSChris Smart
62f9ad3f9eSChris Smartcat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
63f9ad3f9eSChris Smart#!/bin/bash
64f9ad3f9eSChris Smart
65f9ad3f9eSChris Smartset -x
66f9ad3f9eSChris Smart
67f9ad3f9eSChris Smartcd ${WORKSPACE}
68f9ad3f9eSChris Smart
69f9ad3f9eSChris Smart# Go into the linux directory (the script will put us in a build subdir)
70f9ad3f9eSChris Smartcd linux
71f9ad3f9eSChris Smart
72f9ad3f9eSChris Smart# Record the version in the logs
73f9ad3f9eSChris Smartpowerpc64le-linux-gnu-gcc --version || exit 1
74f9ad3f9eSChris Smart
7578646628SChris Smart# Build kernel prep
76f9ad3f9eSChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make clean || exit 1
77f9ad3f9eSChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper || exit 1
7878646628SChris Smart
7978646628SChris Smart# Build kernel with debug
8078646628SChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig || exit 1
8178646628SChris Smartecho "CONFIG_DEBUG_INFO=y" >> .config
8278646628SChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make olddefconfig || exit 1
8378646628SChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) -s C=2 CF=-D__CHECK_ENDIAN__ 2>&1 | gzip > sparse.log.gz
8478646628SChris Smartpahole vmlinux 2>&1 | gzip > structs.dump.gz
8578646628SChris Smart
8678646628SChris Smart# Build kernel
87f9ad3f9eSChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig || exit 1
88f9ad3f9eSChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) || exit 1
89f9ad3f9eSChris Smart
90f9ad3f9eSChris SmartEOF_SCRIPT
91f9ad3f9eSChris Smart
92f9ad3f9eSChris Smartchmod a+x ${WORKSPACE}/build.sh
93f9ad3f9eSChris Smart
94f9ad3f9eSChris Smart# Run the docker container, execute the build script we just built
95f9ad3f9eSChris Smartdocker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
96f9ad3f9eSChris Smart  -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-build/ubuntu ${WORKSPACE}/build.sh
97f9ad3f9eSChris Smart
98f9ad3f9eSChris Smart# Timestamp for build
99f9ad3f9eSChris Smartecho "Build completed, $(date)"
100f9ad3f9eSChris Smart
101