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