build_dpdk_rpm.sh revision e6358450
1#!/bin/bash
2
3# Copyright (c) 2016 Open Platform for NFV Project, Inc. and its contributors
4# Copyright (c) 2016 Red Hat, Inc.
5#
6#    Licensed under the Apache License, Version 2.0 (the "License");
7#    you may not use this file except in compliance with the License.
8#    You may obtain a copy of the License at
9#
10#        http://www.apache.org/licenses/LICENSE-2.0
11#
12#    Unless required by applicable law or agreed to in writing, software
13#    distributed under the License is distributed on an "AS IS" BASIS,
14#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15#    See the License for the specific language governing permissions and
16#    limitations under the License.
17
18set -e
19
20echo "==============================="
21echo executing $0 $@
22echo executing on machine `uname -a`
23
24usage() {
25    echo "$0 -g < [master] | [tag] | [commit] > -h -k -p < URL >        \
26             -u < URL > -v                                              \
27                                                                        \
28    -g <DPDK TAG>   -- DPDK release tag commit to build. The default is \
29                       master.                                          \
30    -k              -- Build igb_uio kernel module                      \
31    -h              -- print this message                               \
32    -p <patch url>  -- Specify url to patches if required for ovs rpm.  \
33    -v              -- Set verbose mode."
34}
35while getopts "g:hkp:u:v" opt; do
36    case "$opt" in
37        g)
38            DPDK_VERSION=${OPTARG}
39            ;;
40        k)
41            KMOD="yes"
42            ;;
43        h|\?)
44            usage
45            exit 1
46            ;;
47        p)
48            DPDK_PATCH=${OPTARG}
49            ;;
50        u)
51            DPDK_REPO_URL=${OPTARG}
52            ;;
53        v)
54            verbose="yes"
55            ;;
56    esac
57done
58
59if [ -z $DPDK_REPO_URL ]; then
60    DPDK_REPO_URL=http://dpdk.org/git/dpdk
61fi
62if [ -z $DPDK_VERSION ]; then
63    DPDK_VERSION=master
64fi
65
66HOME=`pwd`
67TOPDIR=$HOME
68TMPDIR=$TOPDIR/rpms
69
70function install_pre_reqs() {
71    echo "----------------------------------------"
72    echo Install dependencies for dpdk.
73    echo
74    sudo yum -y install gcc make python-devel openssl-devel kernel-devel graphviz \
75                kernel-debug-devel autoconf automake rpm-build redhat-rpm-config \
76                libtool python-twisted-core desktop-file-utils groff PyQt4          \
77                libpcap-devel python-sphinx numactl-devel libvirt-devel
78}
79
80mkdir -p $TMPDIR
81
82install_pre_reqs
83
84RPMDIR=$HOME/rpmbuild
85if [ -d $RPMDIR ]; then
86    rm -rf $RPMDIR
87fi
88mkdir -p $RPMDIR/RPMS
89mkdir -p $RPMDIR/SOURCES
90mkdir -p $RPMDIR/SPECS
91mkdir -p $RPMDIR/SRPMS
92
93
94cd $TMPDIR
95if [ ! -d dpdk ]; then
96    git clone $DPDK_REPO_URL
97    cd dpdk
98else
99    cd dpdk
100    set +e
101    make clean
102    rm *.gz
103    set -e
104fi
105
106if [[ "$DPDK_VERSION" =~ "master" ]]; then
107    git checkout master
108    snapgit=`git log --pretty=oneline -n1|cut -c1-8`
109else
110    git checkout v$DPDK_VERSION
111fi
112
113cp $HOME/dpdk-snap/* $RPMDIR/SOURCES
114snapser=`git log --pretty=oneline | wc -l`
115
116makever=`make showversion`
117basever=`echo ${makever} | cut -d- -f1`
118snapver=${snapser}.git${snapgit}
119
120
121if [[ "$DPDK_VERSION" =~ "master" ]]; then
122    prefix=dpdk-${basever}.${snapser}.git${snapgit}
123    cp $HOME/dpdk-snap/dpdk.spec $TMPDIR/dpdk
124    cp $HOME/dpdk-snap/dpdk.spec $RPMDIR/SOURCES
125    cp $HOME/dpdk-snap/dpdk.spec $RPMDIR/SPECS
126else
127    prefix=dpdk-${basever:0:5}
128    if [[ "$DPDK_PATCH"  =~ "yes" && "$DPDK_VERSION" =~ "16.11" ]]; then
129        echo "----------------------------------------------"
130        echo "Copy applicable patches."
131        cp $TOPDIR/patches/$DPDK_VERSION/* $RPMDIR/SOURCES
132        cp $HOME/dpdk-snap/dpdk.1611.spec $TMPDIR/dpdk/dpdk.spec
133        cp $HOME/dpdk-snap/dpdk.1611.spec $RPMDIR/SPECS/dpdk.spec
134        cp $HOME/dpdk-snap/dpdk.1611.spec $RPMDIR/SOURCES/dpdk.spec
135    else
136        cp $HOME/dpdk-snap/dpdk.spec $TMPDIR/dpdk
137        cp $HOME/dpdk-snap/dpdk.spec $RPMDIR/SOURCES
138        cp $HOME/dpdk-snap/dpdk.spec $RPMDIR/SPECS
139    fi
140fi
141archive=${prefix}.tar.gz
142
143echo "-------------------------------"
144echo "Creating archive: ${archive}"
145echo
146git archive --prefix=${prefix}/ HEAD  | gzip -9 > ${archive}
147cp ${archive} $RPMDIR/SOURCES/
148echo "-------------------------------"
149echo building RPM for DPDK version $DPDK_VERSION
150echo
151echo DPDK_VERSION is $DPDK_VERSION
152
153if [[ "$DPDK_VERSION" =~ "master" ]]; then
154    rpmbuild -bb -vv --define "_topdir $RPMDIR" --define "_snapver $snapver" --define "_ver $basever" dpdk.spec
155else
156    rpmbuild -bb -vv --define "_topdir $RPMDIR" --define "_ver $DPDK_VERSION" dpdk.spec
157fi
158
159#
160# Copy all RPMs to build directory
161#
162echo Copy all RPMs to build directory
163cd $RPMDIR
164RPMS=$(find . -type f -iname '*.rpm')
165SRPMS=$(find . -type f -iname '*.srpm')
166SRCRPMS=$(find . -type f -name '*.src.rpm')
167
168for i in $RPMS $SRPMS $SRCRPMS
169do
170    cp $i $HOME
171done
172exit 0
173