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
26*4593d4f3SChris SmartENV DEBIAN_FRONTEND noninteractive 
27*4593d4f3SChris SmartRUN apt-get update && apt-get upgrade -yy && apt-get install -yy \
28*4593d4f3SChris Smart	bc \
29*4593d4f3SChris Smart	build-essential \
30*4593d4f3SChris Smart	git \
31*4593d4f3SChris Smart	gcc-powerpc64le-linux-gnu \
32*4593d4f3SChris Smart	software-properties-common
33*4593d4f3SChris Smart
34*4593d4f3SChris SmartRUN apt-add-repository -y multiverse && apt-get update && apt-get install -yy \
35*4593d4f3SChris Smart	dwarves \
36*4593d4f3SChris Smart	sparse
37*4593d4f3SChris Smart
38*4593d4f3SChris SmartRUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
39*4593d4f3SChris SmartRUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
40f9ad3f9eSChris Smart
41f9ad3f9eSChris SmartUSER ${USER}
42f9ad3f9eSChris SmartENV HOME ${HOME}
43f9ad3f9eSChris SmartRUN /bin/bash
44f9ad3f9eSChris SmartEOF
45f9ad3f9eSChris Smart)
46f9ad3f9eSChris Smart
47f9ad3f9eSChris Smart# Build the docker container
48f9ad3f9eSChris Smartdocker build -t linux-build/ubuntu - <<< "${Dockerfile}"
49f9ad3f9eSChris Smartif [[ "$?" -ne 0 ]]; then
50f9ad3f9eSChris Smart  echo "Failed to build docker container."
51f9ad3f9eSChris Smart  exit 1
52f9ad3f9eSChris Smartfi
53f9ad3f9eSChris Smart
54f9ad3f9eSChris Smart# Create the docker run script
55f9ad3f9eSChris Smartexport PROXY_HOST=${http_proxy/#http*:\/\/}
56f9ad3f9eSChris Smartexport PROXY_HOST=${PROXY_HOST/%:[0-9]*}
57f9ad3f9eSChris Smartexport PROXY_PORT=${http_proxy/#http*:\/\/*:}
58f9ad3f9eSChris Smart
59f9ad3f9eSChris Smartmkdir -p ${WORKSPACE}
60f9ad3f9eSChris Smart
61f9ad3f9eSChris Smartcat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
62f9ad3f9eSChris Smart#!/bin/bash
63f9ad3f9eSChris Smart
64f9ad3f9eSChris Smartset -x
65f9ad3f9eSChris Smart
66f9ad3f9eSChris Smartcd ${WORKSPACE}
67f9ad3f9eSChris Smart
68f9ad3f9eSChris Smart# Go into the linux directory (the script will put us in a build subdir)
69f9ad3f9eSChris Smartcd linux
70f9ad3f9eSChris Smart
71f9ad3f9eSChris Smart# Record the version in the logs
72f9ad3f9eSChris Smartpowerpc64le-linux-gnu-gcc --version || exit 1
73f9ad3f9eSChris Smart
7478646628SChris Smart# Build kernel prep
75f9ad3f9eSChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make clean || exit 1
76f9ad3f9eSChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper || exit 1
7778646628SChris Smart
7878646628SChris Smart# Build kernel with debug
7978646628SChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig || exit 1
8078646628SChris Smartecho "CONFIG_DEBUG_INFO=y" >> .config
8178646628SChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make olddefconfig || exit 1
8278646628SChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) -s C=2 CF=-D__CHECK_ENDIAN__ 2>&1 | gzip > sparse.log.gz
8378646628SChris Smartpahole vmlinux 2>&1 | gzip > structs.dump.gz
8478646628SChris Smart
8578646628SChris Smart# Build kernel
86f9ad3f9eSChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig || exit 1
87f9ad3f9eSChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) || exit 1
88f9ad3f9eSChris Smart
89f9ad3f9eSChris SmartEOF_SCRIPT
90f9ad3f9eSChris Smart
91f9ad3f9eSChris Smartchmod a+x ${WORKSPACE}/build.sh
92f9ad3f9eSChris Smart
93f9ad3f9eSChris Smart# Run the docker container, execute the build script we just built
94f9ad3f9eSChris Smartdocker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
95f9ad3f9eSChris Smart  -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-build/ubuntu ${WORKSPACE}/build.sh
96f9ad3f9eSChris Smart
97f9ad3f9eSChris Smart# Timestamp for build
98f9ad3f9eSChris Smartecho "Build completed, $(date)"
99f9ad3f9eSChris Smart
100