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
225f4de959SJoel StanleyFROM ubuntu:latest
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 \
325158a324SSaqib Khan	software-properties-common \
3315a77aebSJoel Stanley	libssl-dev \
345158a324SSaqib Khan	iputils-ping
354593d4f3SChris Smart
364593d4f3SChris SmartRUN apt-add-repository -y multiverse && apt-get update && apt-get install -yy \
374593d4f3SChris Smart	dwarves \
384593d4f3SChris Smart	sparse
394593d4f3SChris Smart
404593d4f3SChris SmartRUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
414593d4f3SChris SmartRUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
42f9ad3f9eSChris Smart
43f9ad3f9eSChris SmartUSER ${USER}
44f9ad3f9eSChris SmartENV HOME ${HOME}
45f9ad3f9eSChris SmartRUN /bin/bash
46f9ad3f9eSChris SmartEOF
47f9ad3f9eSChris Smart)
48f9ad3f9eSChris Smart
49f9ad3f9eSChris Smart# Build the docker container
50f9ad3f9eSChris Smartdocker build -t linux-build/ubuntu - <<< "${Dockerfile}"
51f9ad3f9eSChris Smartif [[ "$?" -ne 0 ]]; then
52f9ad3f9eSChris Smart  echo "Failed to build docker container."
53f9ad3f9eSChris Smart  exit 1
54f9ad3f9eSChris Smartfi
55f9ad3f9eSChris Smart
56f9ad3f9eSChris Smart# Create the docker run script
57f9ad3f9eSChris Smartexport PROXY_HOST=${http_proxy/#http*:\/\/}
58f9ad3f9eSChris Smartexport PROXY_HOST=${PROXY_HOST/%:[0-9]*}
59f9ad3f9eSChris Smartexport PROXY_PORT=${http_proxy/#http*:\/\/*:}
60f9ad3f9eSChris Smart
61f9ad3f9eSChris Smartmkdir -p ${WORKSPACE}
62f9ad3f9eSChris Smart
63f9ad3f9eSChris Smartcat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
64f9ad3f9eSChris Smart#!/bin/bash
65f9ad3f9eSChris Smart
66f9ad3f9eSChris Smartset -x
679872b7c3SMichael Ellermanset -e -o pipefail
68f9ad3f9eSChris Smart
69f9ad3f9eSChris Smartcd ${WORKSPACE}
70f9ad3f9eSChris Smart
71f9ad3f9eSChris Smart# Go into the linux directory (the script will put us in a build subdir)
72f9ad3f9eSChris Smartcd linux
73f9ad3f9eSChris Smart
74f9ad3f9eSChris Smart# Record the version in the logs
759872b7c3SMichael Ellermanpowerpc64le-linux-gnu-gcc --version
76f9ad3f9eSChris Smart
7778646628SChris Smart# Build kernel prep
789872b7c3SMichael EllermanARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make clean
799872b7c3SMichael EllermanARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper
8078646628SChris Smart
81*9f05cf3eSMichael Ellerman# Build kernel
82*9f05cf3eSMichael EllermanARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s pseries_le_defconfig
83*9f05cf3eSMichael EllermanARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s -j$(nproc)
84*9f05cf3eSMichael Ellerman
8578646628SChris Smart# Build kernel with debug
86cf9b7f11SMichael EllermanARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s pseries_le_defconfig
8778646628SChris Smartecho "CONFIG_DEBUG_INFO=y" >> .config
889872b7c3SMichael EllermanARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make olddefconfig
8978646628SChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) -s C=2 CF=-D__CHECK_ENDIAN__ 2>&1 | gzip > sparse.log.gz
9078646628SChris Smartpahole vmlinux 2>&1 | gzip > structs.dump.gz
9178646628SChris Smart
92f9ad3f9eSChris SmartEOF_SCRIPT
93f9ad3f9eSChris Smart
94f9ad3f9eSChris Smartchmod a+x ${WORKSPACE}/build.sh
95f9ad3f9eSChris Smart
96f9ad3f9eSChris Smart# Run the docker container, execute the build script we just built
97f9ad3f9eSChris Smartdocker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
983225cfc3SMichael Ellerman  -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" -t linux-build/ubuntu ${WORKSPACE}/build.sh
99f9ad3f9eSChris Smart
1006c69b7e6SMichael Ellermanresult=${?}
1016c69b7e6SMichael Ellerman
102f9ad3f9eSChris Smart# Timestamp for build
103f9ad3f9eSChris Smartecho "Build completed, $(date)"
104f9ad3f9eSChris Smart
1056c69b7e6SMichael Ellermanexit ${result}
106