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