build_dpdk_rpm.sh revision dcc0fa40
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:s: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        s)
51            SRC=${OPTARG}
52            ;;
53        u)
54            DPDK_REPO_URL=${OPTARG}
55            ;;
56        v)
57            verbose="yes"
58            ;;
59    esac
60done
61
62if [ -z $DPDK_REPO_URL ]; then
63    DPDK_REPO_URL=http://dpdk.org/git/dpdk
64fi
65if [ -z $DPDK_VERSION ]; then
66    DPDK_VERSION=master
67fi
68
69HOME=`pwd`
70TOPDIR=$HOME
71TMPDIR=$TOPDIR/rpms
72
73function install_pre_reqs() {
74    echo "----------------------------------------"
75    echo Install dependencies for dpdk.
76    echo
77    sudo yum -y install gcc make python-devel openssl-devel kernel-devel graphviz \
78                kernel-debug-devel autoconf automake rpm-build redhat-rpm-config \
79                libtool python-twisted-core desktop-file-utils groff PyQt4          \
80                libpcap-devel python-sphinx numactl-devel libvirt-devel
81}
82
83mkdir -p $TMPDIR
84
85install_pre_reqs
86
87RPMDIR=$HOME/rpmbuild
88if [ -d $RPMDIR ]; then
89    rm -rf $RPMDIR
90fi
91mkdir -p $RPMDIR/RPMS
92mkdir -p $RPMDIR/SOURCES
93mkdir -p $RPMDIR/SPECS
94mkdir -p $RPMDIR/SRPMS
95
96
97cd $TMPDIR
98if [ ! -d dpdk ]; then
99    git clone $DPDK_REPO_URL
100    cd dpdk
101else
102    cd dpdk
103    set +e
104    make clean
105    rm *.gz
106    set -e
107fi
108
109if [[ "$DPDK_VERSION" =~ "master" ]]; then
110    git checkout master
111    snapgit=`git log --pretty=oneline -n1|cut -c1-8`
112else
113    git checkout v$DPDK_VERSION
114fi
115
116cp $HOME/dpdk-snap/* $RPMDIR/SOURCES
117snapser=`git log --pretty=oneline | wc -l`
118
119makever=`make showversion`
120basever=`echo ${makever} | cut -d- -f1`
121snapver=${snapser}.git${snapgit}
122
123
124if [[ "$DPDK_VERSION" =~ "master" ]]; then
125    prefix=dpdk-${basever}.${snapser}.git${snapgit}
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        echo cp $TOPDIR/patches/$DPDK_VERSION/* $RPMDIR/SOURCES
132        cp $TOPDIR/patches/$DPDK_VERSION/* $RPMDIR/SOURCES
133        cp $HOME/dpdk-snap/dpdk.1611.spec $TMPDIR/dpdk/dpdk.spec
134    elif [[ "$DPDK_VERSION" =~ "16.07" ]]; then
135        cp $HOME/dpdk-snap/dpdk.1607.spec $TMPDIR/dpdk/dpdk.spec
136    else
137        cp $HOME/dpdk-snap/dpdk.spec $TMPDIR/dpdk/dpdk.spec
138    fi
139fi
140cp $TMPDIR/dpdk/dpdk.spec $RPMDIR/SOURCES
141cp $TMPDIR/dpdk/dpdk.spec $RPMDIR/SPECS
142
143
144if [[ ! "${SRC}dummy" == "dummy" ]]; then
145    echo "---------------------------------------"
146    echo "Build SRPM"
147    echo
148#   Workaround for some versions of centos dist macro is defined as .el7.centos
149#   breaking downstream builds when built from src rpm
150    BUILD_OPT=(-bs --define "dist .el7")
151    if [[ "$DPDK_VERSION" =~ "master" ]]; then
152        sed -i "s/%define ver.*/%define ver ${DPDK_VERSION}\
153%define snapver ${snapver}/" $TMPDIR/dpdk/dpdk.spec
154    else
155        sed -i "s/%define ver.*/%define ver ${DPDK_VERSION}/" $TMPDIR/dpdk/dpdk.spec
156    fi
157else
158    BUILD_OPT=(-bb)
159fi
160
161archive=${prefix}.tar.gz
162
163echo "-------------------------------"
164echo "Creating archive: ${archive}"
165echo
166git archive --prefix=${prefix}/ HEAD  | gzip -9 > ${archive}
167cp ${archive} $RPMDIR/SOURCES/
168echo "-------------------------------"
169echo building RPM for DPDK version $DPDK_VERSION
170echo
171echo DPDK_VERSION is $DPDK_VERSION
172
173if [[ "$DPDK_VERSION" =~ "master" ]]; then
174    rpmbuild "${BUILD_OPT[@]}" -vv --define "_topdir $RPMDIR" --define "_snapver $snapver" --define "_ver $basever" dpdk.spec
175else
176    rpmbuild "${BUILD_OPT[@]}" -vv --define "_topdir $RPMDIR" --define "_ver $DPDK_VERSION" dpdk.spec
177fi
178
179#
180# Copy all RPMs to build directory
181#
182echo Copy all RPMs to build directory
183cd $RPMDIR
184RPMS=$(find . -type f -iname '*.rpm')
185SRCRPMS=$(find . -type f -name '*.src.rpm')
186
187for i in $RPMS $SRCRPMS
188do
189    cp $i $HOME
190done
191exit 0
192