1#!/bin/bash -ex 2 3test -f /etc/os-release && cat "$_" 4 5# Construct $cc such that it matches what `make` will chose when taking 6# CROSS_COMPILE into account. Do not modify $CC directly, as that will cause 7# `make` to double-account CROSS_COMPILE. 8cc="${CROSS_COMPILE}${CC}" 9 10$cc --version 11 12# random config or default config 13if [[ "${RANDCONFIG}" == "y" ]]; then 14 15 # Append job-specific fixed configuration 16 if [[ -n "${EXTRA_FIXED_RANDCONFIG}" ]]; then 17 echo "${EXTRA_FIXED_RANDCONFIG}" >> xen/tools/kconfig/allrandom.config 18 fi 19 20 make -j$(nproc) -C xen KCONFIG_ALLCONFIG=tools/kconfig/allrandom.config randconfig 21 22 # RANDCONFIG implies HYPERVISOR_ONLY 23 HYPERVISOR_ONLY="y" 24else 25 # Start off with arch's defconfig 26 make -C xen defconfig 27 28 echo "CONFIG_DEBUG=${debug}" >> xen/.config 29 30 if [[ -n "${EXTRA_XEN_CONFIG}" ]]; then 31 echo "${EXTRA_XEN_CONFIG}" >> xen/.config 32 fi 33 34 make -j$(nproc) -C xen olddefconfig 35fi 36 37# Save the config file before building because build failure causes the script 38# to exit early -- bash is invoked with -e. 39cp xen/.config xen-config 40 41# Directory for the artefacts to be dumped into 42mkdir -p binaries 43 44if [[ "${CPPCHECK}" == "y" ]] && [[ "${HYPERVISOR_ONLY}" == "y" ]]; then 45 # Cppcheck analysis invokes Xen-only build 46 xen/scripts/xen-analysis.py --run-cppcheck --cppcheck-misra -- -j$(nproc) 47 48 # Preserve artefacts 49 cp xen/xen binaries/xen 50 cp xen/cppcheck-report/xen-cppcheck.txt xen-cppcheck.txt 51elif [[ "${HYPERVISOR_ONLY}" == "y" ]]; then 52 # Xen-only build 53 make -j$(nproc) xen 54 55 # Preserve artefacts 56 cp xen/xen binaries/xen 57else 58 # Full build. Figure out our ./configure options 59 cfgargs=() 60 cfgargs+=("--enable-docs") 61 62 # booleans for which compiler is in use 63 cc_is_gcc="$($cc --version | grep -q gcc && echo "y" || :)" 64 cc_is_clang="$($cc --version | grep -q clang && echo "y" || :)" 65 66 # The compiler version as an integer. e.g. GCC 4.9.2 => 0x040902 67 cc_ver="$($cc -dumpversion | awk -F. '{ printf "0x%02x%02x%02x", $1, $2, $3 }')" 68 69 if [[ "${cc_is_clang}" == "y" ]]; then 70 # SeaBIOS cannot be built with clang 71 cfgargs+=("--with-system-seabios=/usr/share/no-seabios.bin") 72 # iPXE cannot be built with clang 73 cfgargs+=("--with-system-ipxe=/usr/share/no-ipxe.pxe") 74 # newlib cannot be built with clang so we cannot build stubdoms 75 cfgargs+=("--disable-stubdom") 76 fi 77 78 if ldd /bin/ls | grep -q musl; then 79 # disable --disable-werror for QEMUU when building with MUSL 80 cfgargs+=("--with-extra-qemuu-configure-args=\"--disable-werror\"") 81 fi 82 83 # Qemu requires Python 3.5 or later, and ninja 84 # and Clang 10 or later 85 if ! type python3 || python3 -c "import sys; res = sys.version_info < (3, 5); exit(not(res))" \ 86 || [[ "$cc_is_clang" == y && "$cc_ver" -lt 0x0a0000 ]] \ 87 || ! type ninja; then 88 cfgargs+=("--with-system-qemu=/bin/false") 89 fi 90 91 # SeaBIOS requires GCC 4.6 or later 92 if [[ "${cc_is_gcc}" == "y" && "${cc_ver}" -lt 0x040600 ]]; then 93 cfgargs+=("--with-system-seabios=/usr/share/no-seabios.bin") 94 fi 95 96 ./configure "${cfgargs[@]}" 97 make -j$(nproc) dist 98 99 # Preserve artefacts 100 # Note: Some smoke tests depending on finding binaries/xen on a full build 101 # even though dist/ contains everything, while some containers don't even 102 # build Xen 103 cp -r dist binaries/ 104 if [[ -f xen/xen ]] ; then cp xen/xen binaries/xen; fi 105fi 106