travis: Extended kernel build matrix
[cascardo/ovs.git] / .travis / build.sh
1 #!/bin/bash
2
3 set -o errexit
4
5 KERNELSRC=""
6 CFLAGS="-Werror"
7 EXTRA_OPTS=""
8
9 function install_kernel()
10 {
11     if [[ "$1" =~ ^3.* ]]; then
12         PREFIX="v3.x"
13     else
14         PREFIX="v2.6/longterm/v2.6.32"
15     fi
16
17     wget https://www.kernel.org/pub/linux/kernel/${PREFIX}/linux-${1}.tar.gz
18     tar xzvf linux-${1}.tar.gz > /dev/null
19     cd linux-${1}
20     make allmodconfig
21
22     # Older kernels do not include openvswitch
23     if [ -d "net/openvswitch" ]; then
24         make net/openvswitch/
25     else
26         make net/bridge/
27     fi
28
29     KERNELSRC=$(pwd)
30     if [ ! "$DPDK" ]; then
31         EXTRA_OPTS="--with-linux=$(pwd)"
32     fi
33     echo "Installed kernel source in $(pwd)"
34     cd ..
35 }
36
37 function install_dpdk()
38 {
39     wget http://www.dpdk.org/browse/dpdk/snapshot/dpdk-1.7.1.tar.gz
40     tar xzvf dpdk-1.7.1.tar.gz > /dev/null
41     cd dpdk-1.7.1
42     find ./ -type f | xargs sed -i 's/max-inline-insns-single=100/max-inline-insns-single=400/'
43     sed -ri 's,(CONFIG_RTE_BUILD_COMBINE_LIBS=).*,\1y,' config/common_linuxapp
44     sed -ri '/CONFIG_RTE_LIBNAME/a CONFIG_RTE_BUILD_FPIC=y' config/common_linuxapp
45     sed -ri '/EXECENV_CFLAGS  = -pthread -fPIC/{s/$/\nelse ifeq ($(CONFIG_RTE_BUILD_FPIC),y)/;s/$/\nEXECENV_CFLAGS  = -pthread -fPIC/}' mk/exec-env/linuxapp/rte.vars.mk
46     make config CC=gcc T=x86_64-native-linuxapp-gcc
47     make CC=gcc RTE_KERNELDIR=$KERNELSRC
48     echo "Installed DPDK source in $(pwd)"
49     cd ..
50 }
51
52 function configure_ovs()
53 {
54     ./boot.sh && ./configure $*
55 }
56
57 if [ "$KERNEL" ] || [ "$DPDK" ]; then
58     install_kernel $KERNEL
59 fi
60
61 if [ "$DPDK" ]; then
62     install_dpdk
63     # Disregard bad function cassts until DPDK is fixed
64     CFLAGS="$CFLAGS -Wno-error=bad-function-cast -Wno-error=cast-align"
65 elif [ $CC != "clang" ]; then
66     # DPDK headers currently trigger sparse errors
67     CFLAGS="$CFLAGS -Wsparse-error"
68 fi
69
70 configure_ovs $EXTRA_OPTS $*
71
72 # Only build datapath if we are testing kernel w/o running testsuite
73 if [ $KERNEL ] && [ ! "$TESTSUITE" ] && [ ! "$DPDK" ]; then
74     cd datapath
75 fi
76
77 if [ $CC = "clang" ]; then
78     make CFLAGS="$CFLAGS -Wno-error=unused-command-line-argument"
79 else
80     make CFLAGS="$CFLAGS" C=1
81 fi
82
83 if [ $TESTSUITE ]; then
84     if ! make distcheck; then
85         # testsuite.log is necessary for debugging.
86         cat */_build/tests/testsuite.log
87         exit 1
88     fi
89 fi
90
91 exit 0