build_dpdk_rpm.sh revision c21af4d7
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/dpdk.spec $TMPDIR/dpdk
114cp $HOME/dpdk-snap/dpdk.spec $RPMDIR/SPECS
115cp $HOME/dpdk-snap/* $RPMDIR/SOURCES
116snapser=`git log --pretty=oneline | wc -l`
117
118makever=`make showversion`
119basever=`echo ${makever} | cut -d- -f1`
120snapver=${snapser}.git${snapgit}
121
122if [[ "$DPDK_VERSION" =~ "master" ]]; then
123    prefix=dpdk-${basever}.${snapser}.git${snapgit}
124    archive=${prefix}.tar.gz
125else
126    prefix=dpdk-${basever:0:5}
127    archive=${prefix}.tar.gz
128fi
129
130echo "-------------------------------"
131echo "Creating archive: ${archive}"
132echo
133git archive --prefix=${prefix}/ HEAD  | gzip -9 > ${archive}
134cp ${archive} $RPMDIR/SOURCES/
135echo "-------------------------------"
136echo building RPM for DPDK version $DPDK_VERSION
137echo
138echo DPDK_VERSION is $DPDK_VERSION
139
140if [[ "$DPDK_VERSION" =~ "master" ]]; then
141    rpmbuild -bb -vv --define "_topdir $RPMDIR" --define "_snapver $snapver" --define "_ver $basever" dpdk.spec
142else
143    rpmbuild -bb -vv --define "_topdir $RPMDIR" --define "_ver $DPDK_VERSION" dpdk.spec
144fi
145
146#
147# Copy all RPMs to build directory
148#
149echo Copy all RPMs to build directory
150cd $RPMDIR
151RPMS=$(find . -type f -iname '*.rpm')
152SRPMS=$(find . -type f -iname '*.srpm')
153SRCRPMS=$(find . -type f -name '*.src.rpm')
154
155for i in $RPMS $SRPMS $SRCRPMS
156do
157    cp $i $HOME
158done
159exit 0
160