forked from ggcov/ggcov
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildrpm
executable file
·217 lines (193 loc) · 5.27 KB
/
buildrpm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/sh
#
# ggcov - A GTK frontend for exploring gcov coverage data
# Copyright (c) 2001-2004 Greg Banks <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: buildrpm,v 1.12 2010-05-09 05:37:14 gnb Exp $
#
FORCE=no
CVSUP=no
BUILDHOST=
LOCALHOST=$(uname -n|cut -d. -f1)
RPMDEST=
# This file is both controlled and also emitted as part of the build,
# which is probably a bad idea, but regardless it needs to be ignored
# when checking for modified files.
CVSIGNORES="aclocal.m4"
fatal ()
{
echo "ERROR: $*" >&2
exit 1
}
usage ()
{
echo "Usage: $0 [--force] [--cvs-update] [--build-host=host] [--rpm-destination=[host:]dir]"
exit 1
}
boolopt ()
{
case "${2#*=}" in
yes) eval $1=yes ;;
no) eval $1=no ;;
*) fatal "Bad boolean option \"$2\"" ;;
esac
}
while [ $# -gt 0 ]; do
case "$1" in
--force|-f) boolopt FORCE yes ;;
--force=*) boolopt FORCE $1 ;;
-h|--build-host) BUILDHOST=$2 ; shift ;;
--build-host=*) BUILDHOST=${1#*=} ;;
-u|--cvs-update) boolopt CVSUP yes ;;
--cvs-update=*) boolopt CVSUP $1 ;;
-d|--rpm-destination) RPMDEST=$2 ; shift ;;
--rpm-destination=*) RPMDEST=${1#*=} ;;
*) usage ;;
esac
shift
done
# echo FORCE=$FORCE
# echo BUILDHOST=$BUILDHOST
# echo CVSUP=$CVSUP
# echo RPMDEST=$RPMDEST
# exit
case "$BUILDHOST" in
""|"$LOCALHOST"|localhost)
echo "Building on local host ($LOCALHOST)"
exec 2>&1 | tee build.$LOCALHOST.log
;;
*)
echo "Building on remote host \"$BUILDHOST\""
(
set -x
ssh $BUILDHOST "cd $PWD && \
./buildrpm \
--cvs-update=$CVSUP \
--force=$FORCE \
--rpm-destination=${RPMDEST:-$LOCALHOST:$PWD}"
) 2>&1 | tee build.$BUILDHOST.log
exit
;;
esac
set -- `sed -n -e 's|^AM_INIT_AUTOMAKE(\([^,]\+\),\([^)]\+\))|\1 \2|p' < configure.in` notfound
if [ "$1" = notfound ]; then
AUTOMAKE=no
eval `egrep '^(PACKAGE|VERSION)=' < configure.in`
else
AUTOMAKE=yes
PACKAGE=$1
VERSION=$2
fi
SPECFILE=${PACKAGE}.spec
RPMDIR=rpm.d
TARBALL=`awk '/^Source:/{print $2}' < $SPECFILE.in`
case "$TARBALL" in
*.tar.gz) TARBALL=${PACKAGE}-${VERSION}.tar.gz ;;
*.tgz) TARBALL=${PACKAGE}-${VERSION}.tgz ;;
*.tar.bz2) TARBALL=${PACKAGE}-${VERSION}.tar.bz2 ;;
*) fatal "cannot calculate tarball extension from $SPECFILE" ;;
esac
if [ -x /usr/bin/rpmbuild ] ; then
RPMBUILD=rpmbuild
else
RPMBUILD=rpm
fi
# Calculate a string which identifies the Linux distro
DISTRO=
if [ -f /etc/redhat-release ]; then
# Format for RH 7,8.9:
# Red Hat Linux release 9 (Shrike)
# Format for Fedora Core 1:
# Fedora Core release 1 (Yarrow)
DISTRO=$(sed \
-e 's|.*Red[ \t]*Hat[ \t]\+Linux[ \t]\+|rh|' \
-e 's|.*Fedora[ \t]\+Core[ \t]\+|fc|' \
-e 's|[ \t]*release[ \t]\+\([^ \t]\+\).*|\1|g' < /etc/redhat-release)
fi
#echo PACKAGE=$PACKAGE
#echo VERSION=$VERSION
#echo TARBALL=$TARBALL
#echo RPMDIR=$RPMDIR
#echo DISTRO=\"$DISTRO\"
#echo RPMBUILD=$RPMBUILD
#echo CVSIGNORES=\"$CVSIGNORES\"
#echo FORCE=$FORCE
#exit 1
if [ $CVSUP = yes ]; then
echo "Checking for locally changed files"
CVSIGNORES_RE=$(echo $CVSIGNORES | sed -e 's/^[ \t]*/^(/g' -e 's/[ \t]*$/)$/g' -e 's/[ \t][ \t]*/|/g')
CHANGED=$(cvs -nq up | awk '$1~/^[MC]$/ && $2!~/'$CVSIGNORES_RE'/{print $2}')
[ -z "$CHANGED" ] || \
fatal "These files are changed in this work area: $CHANGED"
echo "Updating files from CVS"
(
set -x
cvs -q up || exit 1
) || exit 1
fi
if [ $FORCE = yes ]; then
echo "Removing files to force rebuild"
(
set -x
/bin/rm -rf config.status config.cache autom4te.cache configure
/bin/rm -f $SPECFILE $TARBALL
)
fi
if [ ! -f $SPECFILE ]; then
echo "Specfile missing, building"
(
set -x
aclocal
autoconf
autoheader
test "$AUTOMAKE" = yes && automake -a
./configure
)
[ -f $SPECFILE ] || fatal "Can't build $SPECFILE, giving up"
fi
if [ ! -f $TARBALL ]; then
echo "Tarball missing, building"
(
set -x
make dist
)
[ -f $TARBALL ] || fatal "Can't build $TARBALL, giving up"
fi
echo "Building $RPMDIR directory tree"
/bin/rm -rf $RPMDIR
mkdir -p $RPMDIR
(cd $RPMDIR ; mkdir -p BUILD RPMS/i386 RPMS/`uname -m` SPECS SRPMS )
echo "Building RPMs"
(
set -x
$RPMBUILD -bb \
--define "_topdir $PWD/$RPMDIR" \
--define "_sourcedir $PWD" \
--verbose \
$SPECFILE || exit 1
)
echo "Copying RPMs to destination"
for f in $(find $RPMDIR/RPMS -type f -name \*.rpm) ; do
f2=$(echo $(basename $f) | sed -e 's|^\([a-z-]\+-\)|\1'${DISTRO}${DISTRO:+-}'|')
if [ -z "$RPMDEST" ]; then
echo "Moving $f -> $f2"
mv $f $f2 || exit 1
else
echo "Copying $f -> $RPMDEST/$f2"
scp $f $RPMDEST/$f2 || exit 1
fi
done