Fixes RPM build problem. Use correct copr repo. Fix some version number parsing
[ovsnfv.git] / build / build_dpdk_rpm.sh
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
17 set -e
18
19 echo "==============================="
20 echo executing $0 $@
21 echo executing on machine `uname -a`
22
23 usage() {
24     echo run BuildAndTestOVS -h for complete help on options on ovsnfv scripts.
25 }
26
27 while getopts "g:hp:u:v" opt; do
28     case "$opt" in
29         g)
30             DPDK_VERSION=${OPTARG}
31             ;;
32         h|\?)
33             usage
34             exit 1
35             ;;
36         p)
37             DPDK_PATCH=${OPTARG}
38             ;;
39         u)
40             DPDK_REPO_URL=${OPTARG}
41             ;;
42         v)
43             verbose="yes"
44             ;;
45     esac
46 done
47
48 if [ -z $DPDK_REPO_URL ]; then
49     DPDK_REPO_URL=http://dpdk.org/git/dpdk
50 fi
51 if [ -z $DPDK_VERSION ]; then
52     DPDK_VERSION=2.2.0
53 fi
54
55 HOME=`pwd`
56 TOPDIR=$HOME
57 TMPDIR=$TOPDIR/rpms
58
59 if [ -d $TMPDIR ]
60 then
61     rm -rf $TMPDIR
62 fi
63
64 echo "---------------------"
65 echo "Install dependencies for dpdk"
66 echo
67 sudo yum -y install gcc make python-devel openssl-devel autoconf automake rpm-build \
68             redhat-rpm-config libtool libpcap-devel numactl-devel python-sphinx \
69             libvirt-devel
70
71
72 mkdir -p $TMPDIR
73
74 cd $TMPDIR
75
76 mkdir -p $HOME/rpmbuild/RPMS
77 mkdir -p $HOME/rpmbuild/SOURCES
78 mkdir -p $HOME/rpmbuild/SPECS
79 mkdir -p $HOME/rpmbuild/SRPMS
80
81 RPMDIR=$HOME/rpmbuild
82
83 #
84 # Use Fedora copr spec file
85 #
86 echo "---------------------"
87 echo "Get copr distribution git"
88 mkdir -p copr
89 cd copr
90 git clone http://copr-dist-git.fedorainfracloud.org/cgit/pmatilai/dpdk-snapshot/dpdk.git
91
92 echo "---------------------"
93 echo "Build DPDK RPM version $DPDK_VERSION"
94 echo
95 cd $TMPDIR
96 git clone $DPDK_REPO_URL
97 cd dpdk
98 if [[ "$DPDK_VERSION" =~ "master" ]]; then
99     git checkout master
100     snapgit=`git log --pretty=oneline -n1|cut -c1-8`
101 else
102     git checkout v$DPDK_VERSION
103     snapgit=`grep "define snapver" $TMPDIR/copr/dpdk/dpdk.spec | cut -c25-33`
104 fi
105
106 cp $TMPDIR/copr/dpdk/dpdk.spec $TMPDIR/dpdk
107 cp $TMPDIR/copr/dpdk/dpdk.spec $RPMDIR/SPECS
108 cp $TMPDIR/copr/dpdk/*.patch $TMPDIR/copr/dpdk/sources $TMPDIR/copr/dpdk/dpdk-snapshot.sh $RPMDIR/SOURCES
109 snapser=`git log --pretty=oneline | wc -l`
110
111 makever=`make showversion`
112 basever=`echo ${makever} | cut -d- -f1`
113
114 prefix=dpdk-$basever-${snapser}.git${snapgit}
115 archive=${prefix}.tar.gz
116 DPDK_VERSION=$basever
117
118 echo "-------------------------------"
119 echo "Creating ${archive}"
120 echo
121 git archive --prefix=${prefix}/ HEAD  | gzip -9 > ${archive}
122 cp ${archive} $RPMDIR/SOURCES/
123 echo "-------------------------------"
124 echo building RPM for DPDK version $DPDK_VERSION
125 echo
126 rpmbuild -bb --define "_topdir $RPMDIR" dpdk.spec
127
128 echo "-------------------------------"
129 echo Delete all rpms from $HOME
130 echo
131 set +e
132 rm $HOME/*.rpm
133 set -e
134
135 echo "-------------------------------"
136 echo Copy dpdk RPM
137 echo
138 cp $RPMDIR/RPMS/x86_64/*.rpm $HOME
139
140 exit 0