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