lttng-modules: Multiple fixes
[lttng-ci.git] / scripts / lttng-modules / param-build.sh
index 1a3cce7fe923420a05ccaf61c7471d3d2f626e48..b576696b08fbcad97fbb37a11ac3f62bd9e70452 100644 (file)
@@ -35,6 +35,66 @@ vergt() {
 }
 
 
+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"
@@ -63,10 +123,12 @@ build_modules() {
         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"
+        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
@@ -92,45 +154,98 @@ LNXSRCDIR="${WORKSPACE}/src/linux"
 LNXBUILDDIR="${WORKSPACE}/build/linux"
 LNXHDRDIR="${WORKSPACE}/build/linux-headers"
 
-LTTBUILKSRCDDIR="${WORKSPACE}/build/lttng-modules-ksrc"
+LTTBUILDKSRCDIR="${WORKSPACE}/build/lttng-modules-ksrc"
 LTTBUILDKHDRDIR="${WORKSPACE}/build/lttng-modules-khdr"
 
 
-# Set arch specific values
-case "$arch" in
-    "x86-32")
-        karch="x86"
-        ;;
-
-    "x86-64")
-        karch="x86"
-        ;;
-
-    "armhf")
-        karch="arm"
-        ;;
-
-    "arm64")
-        karch="arm64"
-        ;;
-
-    "powerpc")
-        karch="powerpc"
-        ;;
+# Setup cross compile env if available
+if [ "x${cross_arch:-}" != "x" ]; then
+
+    case "$cross_arch" in
+        "armhf")
+            karch="arm"
+            cross_compile="arm-linux-gnueabihf-"
+            ubuntu_config="armhf-config.flavour.generic"
+            ;;
+
+        "arm64")
+            karch="arm64"
+            cross_compile="aarch64-linux-gnu-"
+            ubuntu_config="arm64-config.flavour.generic"
+            ;;
+
+        "powerpc")
+            karch="powerpc"
+            cross_compile="powerpc-linux-gnu-"
+            ubuntu_config="powerpc-config.flavour.powerpc-smp"
+            ;;
+
+        "ppc64el")
+            karch="powerpc"
+            cross_compile="powerpc64le-linux-gnu-"
+            ubuntu_config="ppc64el-config.flavour.generic"
+            ;;
+
+        *)
+            echo "Unsupported cross arch $arch"
+            exit 1
+            ;;
+    esac
+
+    # Export variables used by Kbuild for cross compilation
+    export ARCH="${karch}"
+    export CROSS_COMPILE="${cross_compile}"
+
+
+# Set arch specific values if we are not cross compiling
+elif [ "x${arch:-}" != "x" ]; then
+    case "$arch" in
+        "x86-32")
+            karch="x86"
+            ubuntu_config="i386-config.flavour.generic"
+            ;;
+
+        "x86-64")
+            karch="x86"
+            ubuntu_config="amd64-config.flavour.generic"
+            ;;
+
+        "armhf")
+            karch="arm"
+            ubuntu_config="armhf-config.flavour.generic"
+            ;;
+
+        "arm64")
+            karch="arm64"
+            ubuntu_config="arm64-config.flavour.generic"
+            ;;
+
+        "powerpc")
+            karch="powerpc"
+            ubuntu_config="powerpc-config.flavour.powerpc-smp"
+            ;;
+
+        "ppc64el")
+            karch="powerpc"
+            ubuntu_config="ppc64el-config.flavour.generic"
+            ;;
+
+        *)
+            echo "Unsupported arch $arch"
+            exit 1
+            ;;
+    esac
+else
+    echo "Not arch or cross_arch specified"
+    exit 1
+fi
 
-    "ppc64|ppc64el")
-        karch="powerpc"
-        ;;
 
-    *)
-        echo "Unsupported arch $arch"
-        exit 1
-        ;;
-esac
 
 
 # Create build directories
-mkdir -p "${LNXBUILDDIR}" "${LNXHDRDIR}"
+mkdir -p "${LNXBUILDDIR}" "${LNXHDRDIR}" "${LTTBUILDKSRCDIR}" "${LTTBUILDKHDRDIR}"
+
 
 
 ## PREPARE DISTRO STYLE KERNEL HEADERS / DEVEL
@@ -138,17 +253,43 @@ mkdir -p "${LNXBUILDDIR}" "${LNXHDRDIR}"
 # Enter linux source dir
 cd "${LNXSRCDIR}"
 
-# Prepare linux sources for headers install
-make defconfig
+prepare_lnx_sources "."
+
+# For RT kernels, copy version file
+if [ -s localversion-rt ]; then
+    cp -a localversion-rt "${LNXHDRDIR}"
+fi
+
+# Copy all Makefile related stuff
+find . -path './include/*' -prune \
+    -o -path './scripts/*' -prune -o -type f \
+       \( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \
+        -name '*.sh' -o -name '*.pl' -o -name '*.lds' \) \
+    -print | cpio -pd --preserve-modification-time "${LNXHDRDIR}"
+
+# Copy base scripts and include dirs
+cp -a scripts include "${LNXHDRDIR}"
+
+# Copy arch includes
+(find arch -name include -type d -print | \
+    xargs -n1 -i: find : -type f) | \
+       cpio -pd --preserve-modification-time "${LNXHDRDIR}"
 
-# Enable CONFIG_KALLSYMS_ALL
-sed -i "s/# CONFIG_KALLSYMS_ALL is not set/CONFIG_KALLSYMS_ALL=y/g" .config
+# Copy arch scripts
+(find arch -name scripts -type d -print | \
+    xargs -n1 -i: find : -type f) | \
+       cpio -pd --preserve-modification-time "${LNXHDRDIR}"
 
-make modules_prepare
+# Cleanup scripts
+rm -f "${LNXHDRDIR}/scripts/*.o"
+rm -f "${LNXHDRDIR}/scripts/*/*.o"
 
-# first copy everything
-cp --parents `find  -type f -name "Makefile*" -o -name "Kconfig*"` "${LNXHDRDIR}"
+# On powerpc this object is required to link modules
+if [ "${karch}" = "powerpc" ]; then
+    cp -a --parents arch/powerpc/lib/crtsavres.[So] "${LNXHDRDIR}/"
+fi
 
+# Copy modules related stuff, if available
 if [ -s Module.symvers ]; then
     cp Module.symvers "${LNXHDRDIR}"
 fi
@@ -161,34 +302,8 @@ if [ -s Module.markers ]; then
     cp Module.markers "${LNXHDRDIR}"
 fi
 
-# then drop all but the needed Makefiles/Kconfig files
-rm -rf "${LNXHDRDIR}/Documentation"
-rm -rf "${LNXHDRDIR}/scripts"
-rm -rf "${LNXHDRDIR}/include"
-
+# Copy config file
 cp .config "${LNXHDRDIR}"
-cp -a scripts "${LNXHDRDIR}"
-
-if [ -d arch/${karch}/scripts ]; then
-    cp -a arch/${karch}/scripts "${LNXHDRDIR}/arch/${karch}/" || :
-fi
-
-if [ -f arch/${karch}/*lds ]; then
-    cp -a arch/${karch}/*lds "${LNXHDRDIR}/arch/${karch}/" || :
-fi
-
-rm -f "${LNXHDRDIR}/scripts/*.o"
-rm -f "${LNXHDRDIR}/scripts/*/*.o"
-
-if [ "${karch}" = "powerpc" ]; then
-    cp -a --parents arch/powerpc/lib/crtsavres.[So] "${LNXHDRDIR}/"
-fi
-
-if [ -d arch/${karch}/include ]; then
-    cp -a --parents arch/${karch}/include "${LNXHDRDIR}/"
-fi
-
-cp -a include "${LNXHDRDIR}/include"
 
 # Make sure the Makefile and version.h have a matching timestamp so that
 # external modules can be built
@@ -214,34 +329,30 @@ cp "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/config/auto.conf"
 cd "${LNXSRCDIR}"
 
 # Make sure linux source dir is clean
-make mrproper
-
-# Prepare linux sources for modules OOT build
-make O="${LNXBUILDDIR}" defconfig
-
-# Enable CONFIG_KALLSYMS_ALL
-sed -i "s/# CONFIG_KALLSYMS_ALL is not set/CONFIG_KALLSYMS_ALL=y/g" "${LNXBUILDDIR}"/.config
+git clean -xdf
 
-# Prepare out of tree dir for modules build
-make O="${LNXBUILDDIR}" modules_prepare
+prepare_lnx_sources "${LNXBUILDDIR}"
 
-# Version specific tasks
-case "$kversion" in
-  Ubuntu*)
-    #fakeroot debian/rules clean
-    #fakeroot debian/rules genconfigs
-    #cp CONFIGS/amd64-config.flavour.generic .config
 
-    # 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" >> ${LNXBUILDDIR}/include/generated/utsrelease.h
-    ;;
-esac
+## BUILD modules
 
 # Build modules against full kernel sources
-build_modules "${LNXBUILDDIR}" "${LTTBUILKSRCDDIR}"
+build_modules "${LNXBUILDDIR}" "${LTTBUILDKSRCDIR}"
 
 # Build modules against kernel headers
 build_modules "${LNXHDRDIR}" "${LTTBUILDKHDRDIR}"
 
+# Make sure modules were built
+tree "${LTTBUILDKSRCDIR}"
+if [ "x$(find "${LTTBUILDKSRCDIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
+  echo "No modules built!"
+  exit 1
+fi
+
+tree "${LTTBUILDKHDRDIR}"
+if [ "x$(find "${LTTBUILDKHDRDIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
+  echo "No modules built!"
+  exit 1
+fi
+
 # EOF
This page took 0.025781 seconds and 4 git commands to generate.