+
+prepare_lnx_sources() {
+
+ outdir=$1
+
+ if [ "$outdir" = "." ]; then
+ koutput=""
+ else
+ koutput="O=\"${outdir}\""
+ fi
+
+ # Generate kernel configuration
+ case "$kversion" in
+ Ubuntu*)
+ fakeroot debian/rules clean
+ fakeroot debian/rules genconfigs
+ cp CONFIGS/${ubuntu_config} "${outdir}"/.config
+ ;;
+ *)
+ # Que sera sera
+ make ${koutput} allyesconfig
+ ;;
+ esac
+
+ # GCC 4.8
+ sed -i "s/CONFIG_CC_STACKPROTECTOR_STRONG=y/# CONFIG_CC_STACKPROTECTOR_STRONG is not set/g" "${outdir}"/.config
+
+ # Don't try to sign modules
+ sed -i "s/CONFIG_MODULE_SIG=y/# CONFIG_MODULE_SIG is not set/g" "${outdir}"/.config
+
+ # Disable kernel stack frame correctness validation, introduced in 4.6.0 and currently fails
+ sed -i "s/CONFIG_STACK_VALIDATION=y/# CONFIG_STACK_VALIDATION is not set/g" "${outdir}"/.config
+
+ # Enable CONFIG_KALLSYMS_ALL
+ echo "CONFIG_KPROBES=y" >> "${outdir}"/.config
+ echo "CONFIG_FTRACE=y" >> "${outdir}"/.config
+ echo "CONFIG_BLK_DEV_IO_TRACE=y" >> "${outdir}"/.config
+ echo "CONFIG_TRACEPOINTS=y" >> "${outdir}"/.config
+ echo "CONFIG_KALLSYMS_ALL=y" >> "${outdir}"/.config
+
+
+ make ${koutput} silentoldconfig
+ make ${koutput} modules_prepare
+
+ # Version specific tasks
+ case "$kversion" in
+ Ubuntu*)
+ # Add Ubuntu ABI number to kernel headers, this is normally done by the packaging code
+ ABINUM=$(echo $kversion | grep -P -o 'Ubuntu-(lts-)?.*-\K\d+(?=\..*)')
+ echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> ${outdir}/include/generated/utsrelease.h
+ ;;
+ esac
+
+ # On powerpc this object is required to link modules
+ if [ "${karch}" = "powerpc" ]; then
+ make ${koutput} arch/powerpc/lib/crtsavres.o
+ fi
+}
+
+
+
+build_modules() {
+
+ kdir="$1"
+ bdir="$2"
+
+ # Get kernel version from source tree
+ cd "${kdir}"
+ kversion=$(make kernelversion)
+
+ # Enter lttng-modules source dir
+ cd "${LTTSRCDIR}"
+
+ # kernels 3.10 to 3.10.13 and 3.11 to 3.11.2 introduce a deadlock in the
+ # timekeeping subsystem. We want those build to fail.
+ if { vergte "$kversion" "3.10" && verlte "$kversion" "3.10.13"; } || \
+ { vergte "$kversion" "3.11" && verlte "$kversion" "3.11.2"; }; then
+
+ set +e
+
+ # Build modules
+ KERNELDIR="${kdir}" make -j${NPROC} V=1
+
+ # We expect this build to fail, if it doesn't, fail the job.
+ if [ "$?" -eq 0 ]; then
+ exit 1
+ fi
+
+ # We have to publish at least one file or the build will fail
+ echo "This kernel is broken, there is a deadlock in the timekeeping subsystem." > "${bdir}/BROKEN.txt.ko"
+
+ set -e
+
+ KERNELDIR="${kdir}" make clean
+
+ else # Regular build
+
+ # Build modules against full kernel sources
+ KERNELDIR="${kdir}" make -j${NPROC} V=1
+
+ # Install modules to build dir
+ KERNELDIR="${kdir}" make INSTALL_MOD_PATH="${bdir}" modules_install
+
+ # Clean build dir
+ KERNELDIR="${kdir}" make clean
+ fi
+}
+
+
+## MAIN ##
+