build_dpdk_rpm.sh revision 56d90970
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}
126    cp $HOME/dpdk-snap/dpdk.spec $TMPDIR/dpdk/dpdk.spec
127else
128    prefix=dpdk-${basever:0:5}
129    if [[ "$DPDK_PATCH"  =~ "yes" && "$DPDK_VERSION" =~ "16.11" ]]; then
130        echo "----------------------------------------------"
131        echo "Copy applicable patches."
132        echo cp $TOPDIR/patches/$DPDK_VERSION/* $RPMDIR/SOURCES
133        cp $TOPDIR/patches/$DPDK_VERSION/* $RPMDIR/SOURCES
134        cp $HOME/dpdk-snap/dpdk.1611.spec $TMPDIR/dpdk/dpdk.spec
135    elif [[ "$DPDK_VERSION" =~ "16.07" ]]; then
136        cp $HOME/dpdk-snap/dpdk.1607.spec $TMPDIR/dpdk/dpdk.spec
137    else
138        cp $HOME/dpdk-snap/dpdk.spec $TMPDIR/dpdk/dpdk.spec
139    fi
140fi
141cp $TMPDIR/dpdk/dpdk.spec $RPMDIR/SOURCES
142cp $TMPDIR/dpdk/dpdk.spec $RPMDIR/SPECS
143
144
145if [[ ! "${SRC}dummy" == "dummy" ]]; then
146    echo "---------------------------------------"
147    echo "Build SRPM"
148    echo
149#   Workaround for some versions of centos dist macro is defined as .el7.centos
150#   breaking downstream builds when built from src rpm
151    BUILD_OPT=(-bs --define "dist .el7")
152    if [[ "$DPDK_VERSION" =~ "master" ]]; then
153        sed -i "/%define ver.*/c\\
154%define ver ${basever}\\
155%define _snapver ${snapver}" $TMPDIR/dpdk/dpdk.spec
156    else
157        sed -i "s/%define ver.*/%define ver ${DPDK_VERSION}/" $TMPDIR/dpdk/dpdk.spec
158    fi
159else
160    BUILD_OPT=(-bb)
161fi
162
163archive=${prefix}.tar.gz
164
165echo "-------------------------------"
166echo "Creating archive: ${archive}"
167echo
168git archive --prefix=${prefix}/ HEAD  | gzip -9 > ${archive}
169cp ${archive} $RPMDIR/SOURCES/
170echo "-------------------------------"
171echo building RPM for DPDK version $DPDK_VERSION
172echo
173echo DPDK_VERSION is $DPDK_VERSION
174
175if [[ "$DPDK_VERSION" =~ "master" ]]; then
176    rpmbuild "${BUILD_OPT[@]}" -vv --define "_topdir $RPMDIR" --define "_snapver $snapver" --define "_ver $basever" dpdk.spec
177else
178    rpmbuild "${BUILD_OPT[@]}" -vv --define "_topdir $RPMDIR" --define "_ver $DPDK_VERSION" dpdk.spec
179fi
180
181#
182# Copy all RPMs to build directory
183#
184echo Copy all RPMs to build directory
185cd $RPMDIR
186RPMS=$(find . -type f -iname '*.rpm')
187SRCRPMS=$(find . -type f -name '*.src.rpm')
188
189for i in $RPMS $SRCRPMS
190do
191    cp $i $HOME
192done
193exit 0
194