build_dpdk_rpm.sh revision 66ff7c11
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
17set -e
18
19echo "==============================="
20echo executing $0 $@
21echo executing on machine `uname -a`
22
23usage() {
24    echo "$0 -g < [master] | [tag] | [commit] > -h -k -p < URL > -u < URL > -v
25
26    -g <DPDK TAG>   -- DPDK release tag commit to build. The default is
27                       master.
28    -k              -- Build igb_uio kernel module
29    -h              -- print this message
30    -p <patch url>  -- Specify url to patches if required for ovs rpm.
31    -v              -- Set verbose mode."
32}
33while getopts "g:hkp:s:u:v" opt; do
34    case "$opt" in
35        g)
36            DPDK_VERSION=${OPTARG}
37            ;;
38        k)
39            KMOD="yes"
40            ;;
41        h|\?)
42            usage
43            exit 1
44            ;;
45        p)
46            DPDK_PATCH=${OPTARG}
47            ;;
48        s)
49            SRC=${OPTARG}
50            ;;
51        u)
52            DPDK_REPO_URL=${OPTARG}
53            ;;
54        v)
55            verbose="yes"
56            ;;
57    esac
58done
59
60if [ -z $DPDK_REPO_URL ]; then
61    DPDK_REPO_URL=http://dpdk.org/git/dpdk
62fi
63if [ -z $DPDK_VERSION ]; then
64    DPDK_VERSION=master
65fi
66
67HOME=`pwd`
68TOPDIR=$HOME
69TMPDIR=$TOPDIR/rpms
70
71function install_pre_reqs() {
72    echo "----------------------------------------"
73    echo Install dependencies for dpdk.
74    echo
75    sudo yum -y install gcc make python-devel openssl-devel kernel-devel graphviz \
76                kernel-debug-devel autoconf automake rpm-build redhat-rpm-config \
77                libtool python-twisted-core desktop-file-utils groff PyQt4          \
78                libpcap-devel python-sphinx numactl-devel libvirt-devel
79}
80
81mkdir -p $TMPDIR
82
83install_pre_reqs
84
85RPMDIR=$HOME/rpmbuild
86if [ -d $RPMDIR ]; then
87    rm -rf $RPMDIR
88fi
89mkdir -p $RPMDIR/RPMS
90mkdir -p $RPMDIR/SOURCES
91mkdir -p $RPMDIR/SPECS
92mkdir -p $RPMDIR/SRPMS
93
94
95cd $TMPDIR
96if [ -d dpdk ]; then
97    set +e
98    rm -rf dpdk
99    set -e
100fi
101git clone $DPDK_REPO_URL
102cd dpdk
103
104if [[ "$DPDK_VERSION" =~ "master" ]]; then
105    git checkout master
106    snapgit=`git log --pretty=oneline -n1|cut -c1-8`
107else
108    git checkout v$DPDK_VERSION
109fi
110
111if [[ "$DPDK_VERSION" =~ "rc" ]]; then
112    DPDK_VERSION=`echo $DPDK_VERSION | sed -e 's/-/_/'`
113fi
114
115snapser=`git log --pretty=oneline | wc -l`
116
117makever=`make showversion`
118basever=`echo ${makever} | cut -d- -f1`
119rc=`echo ${makever} | cut -d- -f2 -s`
120snapver=${snapser}.git${snapgit}
121
122
123if [[ "$DPDK_VERSION" =~ "master" ]]; then
124    prefix=dpdk-${basever}.${snapser}.git${snapgit}
125    cp $HOME/dpdk-snap/dpdk.spec $TMPDIR/dpdk/dpdk.spec
126elif [ ! -z "$rc" ]; then
127    prefix=dpdk-${basever:0:5}_${rc}
128    cp $HOME/dpdk-snap/dpdk.spec $TMPDIR/dpdk/dpdk.spec
129else
130    prefix=dpdk-${basever:0:5}
131    if [[ "$DPDK_VERSION" =~ "18" ]]; then
132        cp $HOME/dpdk-snap/dpdk.1802.spec $TMPDIR/dpdk/dpdk.spec
133    else #1711
134        cp $HOME/dpdk-snap/dpdk.spec $TMPDIR/dpdk/dpdk.spec
135    fi
136fi
137cp $TMPDIR/dpdk/dpdk.spec $RPMDIR/SOURCES
138cp $TMPDIR/dpdk/dpdk.spec $RPMDIR/SPECS
139
140
141if [[ ! "${SRC}dummy" == "dummy" ]]; then
142    echo "---------------------------------------"
143    echo "Build SRPM"
144    echo
145#   Workaround for some versions of centos dist macro is defined as .el7.centos
146#   breaking downstream builds when built from src rpm
147    BUILD_OPT=(-bs --define "dist .el7")
148    if [[ "$DPDK_VERSION" =~ "master" ]]; then
149        sed -i "/%define ver.*/c\\
150                %define ver ${basever}\\
151                %define _snapver ${snapver}" $TMPDIR/dpdk/dpdk.spec
152    else
153        sed -i "s/%define ver.*/%define ver ${DPDK_VERSION}/" $TMPDIR/dpdk/dpdk.spec
154    fi
155else
156    BUILD_OPT=(-bb)
157fi
158
159archive=${prefix}.tar.gz
160
161echo "-------------------------------"
162echo "Creating archive: ${archive}"
163echo
164git archive --prefix=${prefix}/ HEAD  | gzip -9 > ${archive}
165cp ${archive} $RPMDIR/SOURCES/
166echo "-------------------------------"
167echo building RPM for DPDK version $DPDK_VERSION
168echo
169echo DPDK_VERSION is $DPDK_VERSION
170
171if [[ "$DPDK_VERSION" =~ "master" ]]; then
172    rpmbuild "${BUILD_OPT[@]}" --define "_topdir $RPMDIR" --define "_snapver $snapver" --define "_ver $basever" dpdk.spec
173else
174    rpmbuild "${BUILD_OPT[@]}" --define "_topdir $RPMDIR" --define "_ver $DPDK_VERSION" dpdk.spec
175fi
176#
177# Copy all RPMs to build directory
178#
179echo Copy all RPMs to build directory
180cd $RPMDIR
181RPMS=$(find . -type f -name '*.rpm')
182SRCRPMS=$(find . -type f -name '*.src.rpm')
183
184for i in $RPMS $SRCRPMS
185do
186    cp $i $HOME
187done
188
189exit 0
190