Build OVS 2.6 with DPDK 16.11
[ovsnfv.git] / build / build_ovs_rpm.sh
index 60b92e6..eff1201 100755 (executable)
@@ -1,21 +1,26 @@
 #!/bin/bash
-##############################################################################
-# Copyright (c) 2016 Red Hat Inc. and others.
-# therbert@redhat.com
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
+
+# Copyright (c) 2016 Open Platform for NFV Project, Inc. and its contributors
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+
 set -e
-declare -i CNT
 
 echo "==============================="
-echo executing $0 $@
-echo executing on machine `uname -a`
+echo "executing $0 $@"
+echo "executing on machine `uname -a`"
 
 usage() {
-    echo run BuildAndTestOVS -h for help
+    echo "run BuildAndTestOVS -h for help"
 }
 
 while getopts "cdg:hkp:u:v" opt; do
@@ -50,81 +55,212 @@ done
 
 HOME=`pwd`
 TOPDIR=$HOME
-TMPDIR=$TOPDIR/ovsrpm
+TEMPDIR=$TOPDIR/ovsrpm
+
+BUILDDIR=$HOME
+BUILD_BASE=$BUILDDIR
+
+source $BUILDDIR/functions.sh
 
-if [ -d $TMPDIR ]
+echo "---------------------------------------"
+echo "Clean out old working dir."
+echo
+if [ -d $TEMPDIR ]
 then
-    rm -rf $TMPDIR
+    rm -rf $TEMPDIR
 fi
 
-sudo yum -y install gcc make python-devel openssl-devel kernel-devel graphviz \
-       kernel-debug-devel autoconf automake rpm-build redhat-rpm-config \
-       libtool
+function install_pre_reqs() {
+    echo "----------------------------------------"
+    echo "Install pre-reqs."
+    echo
+    sudo yum -y install gcc make python-devel openssl-devel kernel-devel graphviz \
+                kernel-debug-devel autoconf automake rpm-build redhat-rpm-config \
+                libtool python-twisted-core desktop-file-utils groff PyQt4 \
+                selinux-policy-devel libpcap libpcap-devel libcap-ng-devel
+}
+function apply_nsh_patches() {
+    echo "-------------------------------------------"
+    echo "Clone NSH patch and copy patch files."
+    echo
+    cd $TEMPDIR
+    if [ -e ovs_nsh_patches ]; then
+        rm -rf ovs_nsh_patches
+    fi
+    git clone https://github.com/yyang13/ovs_nsh_patches.git
+    cp $TEMPDIR/ovs_nsh_patches/*.patch $RPMDIR/SOURCES
+    cd $TEMPDIR
+    if [ -e buildovsnsh ]; then
+        rm -rf buildovsnsh
+    fi
+    git clone https://github.com/tfherbert/buildovsnsh.git
+    cp buildovsnsh/*.spec $BUILDDIR
+}
 
 VERSION=2.3.90
 os_type=fedora
 kernel_version=$(uname -a | awk '{print $3}')
 
-mkdir -p $TMPDIR
+RPMDIR=$HOME/rpmbuild
+
+echo "---------------------------------------"
+echo "Clean out old reminents of old rpms and rpm _topdir."
+echo
 
-cd $TMPDIR
+rm openvswitch*.rpm || true
+if [  -d $RPMDIR ]; then
+    rm -rf $RPMDIR
+fi
 
+echo "---------------------------------------"
+echo "Create new rpm _topdir."
+echo
 mkdir -p $HOME/rpmbuild/RPMS
 mkdir -p $HOME/rpmbuild/SOURCES
 mkdir -p $HOME/rpmbuild/SPECS
 mkdir -p $HOME/rpmbuild/SRPMS
 
-RPMDIR=$HOME/rpmbuild
 
+mkdir -p $TEMPDIR
 
-echo "---------------------"
-echo "Clone git repo $OVS_REPO_URL and checkout branch or tag $TAG"
-echo
-git clone $OVS_REPO_URL
+install_pre_reqs
+
+cd $TEMPDIR
 
-cd ovs
-echo "--------------------"
-echo "Checkout OVS $TAG"
-echo
-if [[ ! "$TAG" =~ "master" ]]; then
-    git checkout $TAG
-fi
-if [[ ! "$OVS_PATCH" =~ "no" ]]; then
-    echo "Apply patches from $OVS_PATCH"
-fi
-./boot.sh
 if [ ! -z $DPDK ]; then
-    ./configure --with-dpdk
-else
-    ./configure --with-linux=/lib/modules/`uname -r`/build
-fi
-echo "--------------------"
-echo "Make OVS $TAG"
-echo
-make
+    cleanrpms
 
-if [[ "$TAG" =~ "master" ]]; then
-    v=$($TMPDIR/ovs/utilities/ovs-vsctl --version | head -1 | cut -d' ' -f4)
-    export VERSION=$v
+    if [ -z $DPDK_VERSION ]; then
+        DPDK_VERSION=16.11
+    fi
+    echo "-------------------------------------------"
+    echo "Install dpdk and dpdk development rpms for version $DPDK_VERSION"
+    echo
+    sudo rpm -ivh $HOME/dpdk-${DPDK_VERSION}*.rpm
+    sudo rpm -ivh $HOME/dpdk-devel*.rpm
+    echo "----------------------------------------"
+    echo "Copy DPDK RPM to SOURCES"
+    echo
+    cp $HOME/*.rpm $RPMDIR/SOURCES
+    cd $TEMPDIR
+    git clone $OVS_REPO_URL
+    cd $TEMPDIR/ovs
+    git checkout v$OVSTAG
+    echo "----------------------------------------------------"
+    echo "Build openvswitch RPM for version $OVSTAG"
+    echo
+    echo "--------------------------------------------"
+    ./boot.sh
+    ./configure
+    make rpm-fedora RPMBUILD_OPT="--with dpdk --without check"
 else
-    export VERSION=${TAG:1}
-fi
-
-echo making RPM for Open vswitch version $VERSION
-make dist
+    echo "-------------------------------------------------"
+    echo "Build OVS without DPDK:"
+    echo "Use spec files for $os_type in OVS distribution."
+    echo
+    echo "-------------------------------------------"
+    echo "Remove old rpms."
+    echo
+    cleanrpms
+    cd $TEMPDIR
+    git clone $OVS_REPO_URL
+    cd $TEMPDIR/ovs
+    git checkout $OVS_FORK_COMMIT_FOR_NSH
+    echo "--------------------------------------------"
+    echo "Get commit from $snapgit User Space OVS version $TAG"
+    echo
+    snapgit=`git log --pretty=oneline -n1|cut -c1-8`
+    snapser=`git log --pretty=oneline | wc -l`
+    basever=`grep AC_INIT configure.ac | cut -d' ' -f2 | cut -d, -f1`
+    prefix=openvswitch-${basever}
+    snapver=${snapser}.NSH${snapgit}
+    archive=${prefix}-${snapser}.NSH${snapgit}.tar.gz
 
-echo cp openvswitch-*.tar.gz $HOME/rpmbuild/SOURCES
-cp openvswitch-*.tar.gz $HOME/rpmbuild/SOURCES
+    if [ ! -z $OVS_PATCH ]; then
+        echo "-------------------------------------------"
+        echo "Apply OVS patches."
+        echo
+        apply_nsh_patches
+    fi
 
-if [ ! -z $kmod ]; then
-    echo "Building kernel module..."
-    rpmbuild -bb -D "kversion $kernel_version" -D "kflavors default" --define "_topdir `echo $RPMDIR`" $setnocheck rhel/openvswitch-kmod-${os_type}.spec
-echo " Kernel RPM built!"
+    echo "----------------------------------"
+    echo "Create dist name and rpm name. Put $snapver into spec file"
+    echo
+    cd $BUILD_BASE
+    sed -i "s/%define snapver.*/%define snapver ${snapver}/" openvswitch.spec
+    echo "----------------------------------"
+    echo "Copy spec file."
+    echo
+    cp $BUILD_BASE/openvswitch.spec $RPMDIR/SPECS
+    cp $BUILD_BASE/openvswitch.spec $RPMDIR/SOURCES
+    echo "--------------------------------------------"
+    echo "Creating snapshot, $archive with name same as in spec file."
+    echo
+    cd $TEMPDIR/ovs
+    git archive --prefix=${prefix}-${snapser}.NSH${snapgit}/ HEAD  | gzip -9 > $RPMDIR/SOURCES/${archive}
+    echo "--------------------------------------------"
+    echo "Build openvswitch RPM"
+    echo
+    cd $BUILD_BASE
+    rpmbuild -bb -vv --without dpdk --define "_topdir `echo $RPMDIR`" $setnocheck openvswitch.spec
 fi
+#
+# This section is for building OVS kernel module.
+#
+if [ ! -z $kmod ]; then
+    echo "--------------------------------------------"
+    echo Build Open vswitch kernel module
+    echo
+    cd $TEMPDIR
+    if [ -e ovs ]; then
+        rm -rf ovs
+    fi
+    git clone $OVS_REPO_URL
+    cd $TEMPDIR/ovs
+    git checkout $OVS_FORK_COMMIT_FOR_NSH
+    echo "--------------------------------------------"
+    echo "Get commit from $snapgit User Space OVS version $TAG"
+    echo
+    snapgit=`git log --pretty=oneline -n1|cut -c1-8`
+    snapser=`git log --pretty=oneline | wc -l`
+    basever=`grep AC_INIT configure.ac | cut -d' ' -f2 | cut -d, -f1`
+    prefix=openvswitch-kmod-${basever}
+    snapver=${snapser}.NSH${snapgit}
+    archive=${prefix}-${snapser}.NSH${snapgit}.tar.gz
 
-echo "Building User Space..."
-rpmbuild -bb --define "_topdir `echo $RPMDIR`" $setnocheck rhel/openvswitch.spec
+    if [ ! -z $OVS_PATCH ]; then
+        echo "-------------------------------------------"
+        echo "Apply OVS patches."
+        echo
+        apply_nsh_patches
+    fi
+    echo "----------------------------------"
+    echo "Create dist name and rpm name. Put $snapver into spec file"
+    echo
+    cd $BUILD_BASE
+    sed -i "s/%define snapver.*/%define snapver ${snapver}/" openvswitch-kmod.spec
+    echo "----------------------------------"
+    echo "Copy spec file."
+    echo
+    cp $BUILD_BASE/openvswitch-kmod.spec $RPMDIR/SPECS
+    cp $BUILD_BASE/openvswitch-kmod.spec $RPMDIR/SOURCES
+    echo "-------------------------------------------"
+    echo "Apply nsh patches."
+    echo
+    apply_nsh_patches
+    echo "--------------------------------------------"
+    echo "Creating snapshot, $archive with name same as in spec file."
+    echo
+    cd $TEMPDIR/ovs
+    git archive --prefix=${prefix}-${snapser}.NSH${snapgit}/ HEAD  | gzip -9 > $RPMDIR/SOURCES/${archive}
+    echo "--------------------------------------------"
+    echo "Building openvswitch kernel module RPM"
+    echo
+    cd $BUILD_BASE
+    rpmbuild -bb -vv -D "kversion $kernel_version" -D "kflavors default" --define "_topdir `echo $RPMDIR`" $setnocheck openvswitch-kmod.spec
+fi
 
-cp $RPMDIR/RPMS/x86_64/*.rpm $HOME
+cp $RPMDIR/RPMS/x86_64/*.rpm $HOME || true
+cp $TEMPDIR/ovs/rpm/rpmbuild/RPMS/x86_64/*.rpm $HOME || true
 
 exit 0