Fix build errors.
[ovsnfv.git] / build / BuildAndTestOVS.sh
1 #!/bin/bash
2
3 # Copyright (c) 2016 Open Platform for NFV Project, Inc. and its contributors
4 #
5 #    Licensed under the Apache License, Version 2.0 (the "License");
6 #    you may not use this file except in compliance with the License.
7 #    You may obtain a copy of the License at
8 #
9 #        http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #    Unless required by applicable law or agreed to in writing, software
12 #    distributed under the License is distributed on an "AS IS" BASIS,
13 #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #    See the License for the specific language governing permissions and
15 #    limitations under the License.
16
17 set -e
18
19 echo "==============================="
20 echo executing $0 $@
21 echo
22
23 usage() {
24     echo "$0 -a <kernel major> -d -g <OVS TAG> -h\
25              -i <kernel minor> -p <patch url> -t -u <OVS URL> -v <verbose\
26     -a <kernel major> -- Specify major release if special kernel is required\
27     The default kernel is Centos 7.2 kernel after upgrade.\
28     -d <dpdk>         -- Specify dpdk build.\
29                     The default is to build ovs for linux kernel data path.\
30     -g <OVS TAG>      -- OVS release tag or branch to build such as 2.4.\
31                     The default is master.\
32     -h print this message\
33     -i <kernel minor> -- Specify minor release if special kernel is required.\
34                     The default kernel is Centos 7.2 kernel after upgrade.\
35     -p <patch url>    -- Specify url to patches if required for ovs rpm.\
36     -t                -- Test rpm.\
37     -u <OVS URL>      -- path to OVS repo if using fork for patch.\
38                     The default is https://github.com/openvswitch/ovs.git\
39     -v                -- Set verbose mode."
40 }
41
42 while getopts "a:dg:hi:p:tu:v" opt; do
43     case "$opt" in
44         a)
45             kernel_major=${OPTARG}
46             ;;
47         d)
48             DPDK="yes"
49             ;;
50         g)
51             TAG=${OPTARG}
52             ;;
53         h)
54             usage
55             exit 1
56             ;;
57         i)
58             kernel_minor=${OPTARG}
59             ;;
60         p)
61             OVS_PATCH=${OPTARG}
62             ;;
63         t)
64             TESTRPM="yes"
65             ;;
66         u)
67             OVS_REPO_URL=${OPTARG}
68             ;;
69         v)
70             verbose="yes"
71             ;;
72     esac
73 done
74
75 #
76 # Default Config options
77 #
78 echo ===============================================
79 echo Default Configuration Options.
80 echo ===============================================
81 echo option NOCHECK is set to $NOCHECK
82 echo build DPDK option is set to $DPDK
83 echo DPDK Patch URL is set to $DPDK_PATCH
84 echo DPDK Version is set to $DPDK_VERSION
85 echo Option for OVS Kernel Module is set to $KMOD
86 echo ===============================================
87 if [[ $NOCHECK =~ "yes" ]]; then
88     setnocheck="-c"
89 fi
90 if [[ $KMOD =~ "yes" ]]; then
91     setkmod="-k"
92 fi
93 if [[ $DPDK =~ "yes" ]]; then
94     setdpdk="-d"
95 fi
96
97 if [ -z $OVS_REPO_URL ]; then
98     OVS_REPO_URL=https://github.com/openvswitch/ovs.git
99 fi
100
101 if [ ! -z $kernel_major ] && [ ! -z $kernel_minor ]; then
102     kernel_version=$kernel_major.$kernel_minor
103     echo ===================
104     echo Will install kernel version: major is $kernel_major and minor is $kernel_minor
105     echo ===================
106 else
107     echo Will use default kernel in ovs test vm
108 fi
109
110 if [ -z $TAG ]; then
111     TAG=master
112 fi
113
114 if [ ! -z $DPDK ]; then
115     setbuilddpdk="-d"
116 fi
117
118 if [ -z ${WORKSPACE+1} ]; then
119     # We are not being run by Jenkins.
120     export WORKSPACE=`pwd`
121 fi
122
123 if [ -z ${BUILD_BASE+1} ]; then
124     export BUILD_BASE=$WORKSPACE
125 fi
126
127 export PATH=$PATH:$BUILD_BASE
128
129 cd $BUILD_BASE
130 export TOPDIR=$BUILD_BASE
131
132 # build variables
133
134 export TMP_RELEASE_DIR=$TOPDIR/release
135 export CACHE_DIR=$TOPDIR/cache
136 export TMPDIR=$TOPDIR/scratch
137 export RPMDIR=$TOPDIR/rpmbuild
138
139
140 mkdir -p $RPMDIR/RPMS
141 mkdir -p $RPMDIR/SOURCES
142 mkdir -p $RPMDIR/SPECS
143 mkdir -p $RPMDIR/SRPMS
144 #
145 # build dpdk rpm locally.
146 #
147 if [[ "$DPDK" =~ "yes" ]]; then
148     echo "==============================="
149     echo Build DPDK RPMs
150     echo
151     $BUILD_BASE/build_dpdk_rpm.sh -g $DPDK_VERSION
152 fi
153 #
154 # Build locally and copy RPMS
155 #
156 echo "==============================="
157 echo build OVS rpm locally
158 echo
159     ./build_ovs_rpm.sh $setnocheck -g $TAG $setdpdk $setkmod -p $OVS_PATCH -u $OVS_REPO_URL
160
161 echo "==============================="
162 echo copy rpms to release dir
163 echo
164 cp $RPMDIR/RPMS/x86_64/* $TMP_RELEASE_DIR
165 rm $RPMDIR/RPMS/x86_64/*
166
167 #
168 # Build OVS without DPDK, apply patches and build kmod.
169 #
170 setkmod="-k"
171 OVS_PATCH="yes"
172 setdpdk=
173
174 echo "==================================================="
175 echo build OVS without DPDK, apply patches and build kmod.
176 echo
177     ./build_ovs_rpm.sh $setnocheck -g $TAG $setdpdk $setkmod -p $OVS_PATCH -u $OVS_REPO_URL
178
179 echo "==============================="
180 echo copy rpms to release dir and add experimental tag
181 echo
182 cd $RPMDIR/RPMS/x86_64
183 for i in `ls openvswitch*.rpm`
184 do
185     echo copying $i to $TMP_RELEASE_DIR/EXPERIMENTAL-$i
186     cp $i $TMP_RELEASE_DIR/EXPERIMENTAL-$i
187     echo
188 done
189 exit 0