xref: /openbmc/openbmc-build-scripts/qemu-build.sh (revision 0e5dd8a1c595b29fc77a289d73b941cc4e14a059)
1#!/bin/bash
2###############################################################################
3#
4# This build script is for running the QEMU build in a container
5#
6# It expects to be run in with the qemu source present in the directory called
7# '$WORKSPACE/qemu', where WORKSPACE is an environment variable.
8#
9# In Jenkins configure the git SCM 'Additional Behaviours', 'check-out to a sub
10# directory' called 'qemu'.
11#
12# When building locally set WORKSPACE to be the directory above the qemu
13# checkout:
14#   git clone https://github.com/qemu/qemu
15#   WORKSPACE=$PWD/qemu ~/openbmc-build-scripts/qemu-build.sh
16#
17###############################################################################
18#
19# Script Variables:
20#  http_proxy         The HTTP address of the proxy server to connect to.
21#                     Default: "", proxy is not setup if this is not set
22#  WORKSPACE          Path of the workspace directory where the build will
23#                     occur, and output artifacts will be produced.
24#
25###############################################################################
26# Trace bash processing
27#set -x
28
29# Script Variables:
30http_proxy=${http_proxy:-}
31
32if [ -z ${WORKSPACE+x} ]; then
33    echo "Please set WORKSPACE variable"
34    exit 1
35fi
36
37# Determine the architecture
38ARCH=$(uname -m)
39
40# Docker Image Build Variables:
41img_name=qemu-build
42
43# Timestamp for job
44echo "Build started, $(date)"
45
46# Setup Proxy
47if [[ -n "${http_proxy}" ]]; then
48PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
49fi
50
51# Determine the prefix of the Dockerfile's base image
52case ${ARCH} in
53  "ppc64le")
54    DOCKER_BASE="ppc64le/"
55    ;;
56  "x86_64")
57    DOCKER_BASE=""
58    ;;
59  *)
60    echo "Unsupported system architecture(${ARCH}) found for docker image"
61    exit 1
62esac
63
64# Create the docker run script
65export PROXY_HOST=${http_proxy/#http*:\/\/}
66export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
67export PROXY_PORT=${http_proxy/#http*:\/\/*:}
68
69cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
70#!/bin/bash
71
72set -x
73
74# Go into the build directory
75cd ${WORKSPACE}/qemu
76
77gcc --version
78git submodule update --init dtc
79# disable anything that requires us to pull in X
80./configure \
81    --target-list=arm-softmmu \
82    --disable-spice \
83    --disable-docs \
84    --disable-gtk \
85    --disable-smartcard \
86    --disable-usb-redir \
87    --disable-libusb \
88    --disable-sdl \
89    --disable-gnutls \
90    --disable-vte \
91    --disable-vnc \
92    --disable-werror \
93    --disable-vnc-png
94make clean
95make -j4
96
97EOF_SCRIPT
98
99chmod a+x ${WORKSPACE}/build.sh
100
101# Configure docker build
102Dockerfile=$(cat << EOF
103FROM ${DOCKER_BASE}ubuntu:16.04
104
105${PROXY}
106
107ENV DEBIAN_FRONTEND noninteractive
108RUN apt-get update && apt-get install -yy --no-install-recommends \
109    bison \
110    flex \
111    gcc \
112    git \
113    libc6-dev \
114    libfdt-dev \
115    libglib2.0-dev \
116    libpixman-1-dev \
117    make \
118    python-yaml \
119    python3-yaml \
120    iputils-ping
121
122RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
123RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
124USER ${USER}
125ENV HOME ${HOME}
126EOF
127)
128
129docker build -t ${img_name} - <<< "${Dockerfile}"
130if [[ "$?" -ne 0 ]]; then
131  echo "Failed to build docker container."
132  exit 1
133fi
134
135docker run \
136    --rm=true \
137    -e WORKSPACE=${WORKSPACE} \
138    -w "${HOME}" \
139    --user="${USER}" \
140    -v "${HOME}":"${HOME}" \
141    -t ${img_name} \
142    ${WORKSPACE}/build.sh
143