RPM: Apex: Refactor build scripts:
[ovsnfv.git] / build / build_ovs_rpm.sh
index b03f4ab..e28c23f 100755 (executable)
 set -e
 
 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
-}
-
-function delrpm() {
-    set +e
-    rpm -q $1
-    if [ $? -eq 0 ]; then
-        sudo rpm -e --allmatches $1
-    fi
-    set -e
-}
-function cleanrpms() {
-    delrpm openvswitch
-    delrpm dpdk-devel
-    delrpm dpdk-tools
-    delrpm dpdk-examples
-    delrpm dpdk
+    echo "run BuildAndTestOVS -h for help"
 }
 
 while getopts "cdg:hkp:u:v" opt; do
@@ -73,20 +57,26 @@ HOME=`pwd`
 TOPDIR=$HOME
 TMPDIR=$TOPDIR/ovsrpm
 
+BUILDDIR=$HOME
+
+source $BUILDDIR/functions.sh
+
 echo "---------------------------------------"
-echo Clean out old working dir
+echo "Clean out old working dir."
 echo
 if [ -d $TMPDIR ]
 then
     rm -rf $TMPDIR
 fi
 
-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
+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
+}
 
 VERSION=2.3.90
 os_type=fedora
@@ -95,7 +85,7 @@ kernel_version=$(uname -a | awk '{print $3}')
 RPMDIR=$HOME/rpmbuild
 
 echo "---------------------------------------"
-echo Clean out old reminents of old rpms and rpm _topdir.
+echo "Clean out old reminents of old rpms and rpm _topdir."
 echo
 
 rm openvswitch*.rpm || true
@@ -104,7 +94,7 @@ if [  -d $RPMDIR ]; then
 fi
 
 echo "---------------------------------------"
-echo Create new rpm _topdir.
+echo "Create new rpm _topdir."
 echo
 mkdir -p $HOME/rpmbuild/RPMS
 mkdir -p $HOME/rpmbuild/SOURCES
@@ -123,14 +113,15 @@ if [ ! -z $DPDK ]; then
     echo "----------------------------------"
     echo "Clone Fedora copr repo and copy files."
     echo
-    git clone https://github.com/tfherbert/ovs-snap.git 
+    git clone https://github.com/tfherbert/ovs-snap.git
     cd ovs-snap
     git checkout $COPR_OVS_VERSION
+    echo "-----------------------------------"
     cp $TMPDIR/ovs-snap/openvswitch.spec $RPMDIR/SPECS
     cp $TMPDIR/ovs-snap/* $RPMDIR/SOURCES
     snapgit=`grep "define snapver" $TMPDIR/ovs-snap/openvswitch.spec | cut -c26-33`
-    echo "-------------------------------------------"
-    echo "Remove old dpdk, ovs and dpdk development rpms"
+    echo "-----------------------------------------------"
+    echo "Remove any old installed ovs and dpdk rpms."
     echo
     cleanrpms
 
@@ -165,6 +156,7 @@ if [ ! -z $DPDK ]; then
     echo "--------------------------------------------"
     echo "Build openvswitch RPM"
     echo
+    rpmbuild -bb --define "_topdir `echo $RPMDIR`" $setnocheck openvswitch.spec
 else
     echo "-------------------------------------------------"
     echo "Build OVS without DPDK:"
@@ -181,7 +173,7 @@ else
         export VERSION=$basever
 
         echo "--------------------------------------------"
-        echo making distribution tarball for Open vswitch version $VERSION
+        echo "Making distribution tarball for Open vswitch version $VERSION"
         echo
         ./boot.sh
         ./configure
@@ -197,17 +189,27 @@ else
         curl --silent --output $HOME/rpmbuild/SOURCES/openvswitch-${VERSION}.tar.gz http://openvswitch.org/releases/openvswitch-${VERSION}.tar.gz
     fi
 
-    if [ ! -z $kmod ]; then
-        echo "--------------------------------------------"
-        echo "Building openvswitch kernel module RPM"
-        echo
-        rpmbuild -bb -D "kversion $kernel_version" -D "kflavors default" --define "_topdir `echo $RPMDIR`" $setnocheck rhel/openvswitch-kmod-${os_type}.spec
-    fi
+fi
+#
+# This section is for building OVS kernel module.
+#
+if [ ! -z $kmod ]; then
+    cd $TMPDIR/ovs
     echo "--------------------------------------------"
-    echo "Build openvswitch RPM"
+    echo "Making distribution tarball for Open vswitch version $VERSION"
+    echo
+    ./boot.sh
+    ./configure
+    make dist
+    echo "--------------------------------------------"
+    echo "Copy distribution tarball to $HOME/rpmbuild/SOURCES"
+    echo
+    cp openvswitch-*.tar.gz $HOME/rpmbuild/SOURCES
+    echo "--------------------------------------------"
+    echo "Building openvswitch kernel module RPM"
     echo
+    rpmbuild -bb -D "kversion $kernel_version" -D "kflavors default" --define "_topdir `echo $RPMDIR`" $setnocheck rhel/openvswitch-kmod-${os_type}.spec
 fi
-rpmbuild -bb --define "_topdir `echo $RPMDIR`" $setnocheck openvswitch.spec
 
 cp $RPMDIR/RPMS/x86_64/*.rpm $HOME