]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder.sh
- unify servlet and javaserverfaces deps names (lowercase them)
[packages/rpm-build-tools.git] / builder.sh
CommitLineData
10d92f71 1#!/bin/ksh
44058243 2#
dece74ed
AM
3# This program is free software, distributed under the terms of
4# the GNU General Public License Version 2.
5#
cd445739 6# -----------
cd445739 7# Exit codes:
2a5f078d 8# 0 - succesful
9# 1 - help displayed
10# 2 - no spec file name in cmdl parameters
11# 3 - spec file not stored in repo
12# 4 - some source, patch or icon files not stored in repo
13# 5 - package build failed
14# 6 - spec file with errors
15# 7 - wrong source in /etc/poldek.conf
16# 8 - Failed installing buildrequirements and subrequirements
17# 9 - Requested tag already exist
18# 10 - Refused to build fractional release
19# 100 - Unknown error (should not happen)
cd445739 20
f8e50be5
ER
21# Notes (todo/bugs):
22# - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?)
23# - when Icon: field is present, -5 and -a5 doesn't work
24# - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
19aa2571 25# - does not respect NoSource: X, and tries to cvs up such files [ example: VirtualBox-bin.spec and its Source0 ]
f8e50be5
ER
26# TODO:
27# - ability to do ./builder -bb foo.spec foo2.spec foo3.spec
1ffcdaff
ER
28# - funny bug, if source-md5 is set then builder will download from distfiles even if there is no url present:
29# Source10: forwardfix.pl
30# # Source10-md5: 8bf85f7368933a4e0cb4f875bac28733
6ca6f876
ZU
31# - builder --help:
32# basename: missing operand
33# Try `basename --help' for more information.
34# -- and the normal usage info --
35
9d99a240
ER
36PROGRAM=${0##*/}
37APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
38RCSID='$Id$' r=${RCSID#* * } rev=${r%% *}
b0f031e7 39VERSION="v0.35/$rev"
d43959a2 40VERSIONSTRING="\
c9acaed9 41Build package utility from PLD Linux CVS repository
10d92f71 42$VERSION (C) 1999-2010 Free Penguins".
d43959a2 43
d6a77ddb 44PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
b03f053b 45
b7cc0c94
ER
46# required rpm-build-macros
47RPM_MACROS_VER=1.534
48
cd445739 49COMMAND="build"
64ea5308 50TARGET=""
cd445739 51
bde1c404 52SPECFILE=""
d287305c 53BE_VERBOSE=""
4003ad8c 54QUIET=""
cd445739
AM
55CLEAN=""
56DEBUG=""
57NOURLS=""
58NOCVS=""
59NOCVSSPEC=""
60NODIST=""
47761337 61NOINIT=""
bc10f694 62PREFMIRRORS=""
cd445739 63UPDATE=""
cd445739
AM
64ADD5=""
65NO5=""
66ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
c8f50498 67CVSROOT=""
cdbd30e8 68GREEDSRC=""
cd445739 69
6c1b2e7d
PZ
70# use rpm 4.4.6+ digest format instead of comments if non-zero
71USEDIGEST=
72
e3aa6f5e
ER
73# user agent when fetching files
74USER_AGENT="PLD/Builder($VERSION)"
75
cd445739
AM
76# It can be used i.e. in log file naming.
77# See LOGFILE example.
78DATE=`date +%Y-%m-%d_%H-%M-%S`
79
80# Example: LOGFILE='../log.$PACKAGE_NAME'
81# Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
d280fd97 82# Example: LOGFILE='$PACKAGE_NAME/$PACKAGE_NAME.$DATE.log'
f5687002 83# Example: LOGFILE='$PACKAGE_NAME.$DATE.log'
cd445739
AM
84# Yes, you can use variable name! Note _single_ quotes!
85LOGFILE=''
86
87LOGDIR=""
88LOGDIROK=""
89LOGDIRFAIL=""
90LASTLOG_FILE=""
91
92CHMOD="no"
1da227e8 93CHMOD_MODE="0644"
cd445739 94RPMOPTS=""
d1c5a9a7 95RPMBUILDOPTS=""
cd445739
AM
96BCOND=""
97GROUP_BCONDS="no"
ccffa567
ER
98
99# create symlinks for tools in PACKAGE_DIR, see get_spec()
2dd0af86 100SYMLINK_TOOLS="no"
d287305c 101
102PATCHES=""
103SOURCES=""
cd445739 104ICONS=""
d287305c 105PACKAGE_RELEASE=""
106PACKAGE_VERSION=""
107PACKAGE_NAME=""
14bead22 108ASSUMED_NAME=""
cd445739
AM
109PROTOCOL="ftp"
110WGET_RETRIES=${MAX_WGET_RETRIES:-0}
cd445739 111
db5831da 112CVS_COMMAND=${CVS_COMMAND:-cvs}
939f2c12 113CVS_FORCE=""
f123bcb5 114CVSIGNORE_DF="yes"
939f2c12
ER
115CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
116CVS_SERVER="cvs.pld-linux.org"
cd445739 117CVSTAG=""
939f2c12 118
cd445739
AM
119RES_FILE=""
120
cd445739 121DISTFILES_SERVER="://distfiles.pld-linux.org"
d4730dae 122ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
cd445739 123
36d03934 124DEF_NICE_LEVEL=19
86aafdbe 125SCHEDTOOL="auto"
cd445739
AM
126
127FAIL_IF_NO_SOURCES="yes"
128
18e5347d
ER
129# let get_files skip over files which are present to get those damn files fetched
130SKIP_EXISTING_FILES="no"
131
975d7b23 132TRY_UPGRADE=""
257af81b
ER
133# should the specfile be restored if upgrade failed?
134REVERT_BROKEN_UPGRADE="yes"
135
90baf90b
ER
136if rpm --specsrpm 2>/dev/null; then
137 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
ce40491a 138 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
90baf90b
ER
139else
140 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
141 if [ -x /usr/bin/rpm-getdeps ]; then
142 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
143 else
144 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
145 fi
ab4a2b6e
ER
146fi
147
90baf90b 148
cd445739
AM
149# Here we load saved user environment used to
150# predefine options set above, or passed to builder
151# in command line.
152# This one reads global system environment settings:
153if [ -f ~/etc/builderrc ]; then
154 . ~/etc/builderrc
155fi
156# And this one cascades settings using user personal
157# builder settings.
158# Example of ~/.builderrc:
159#
160#UPDATE_POLDEK_INDEXES="yes"
161#FETCH_BUILD_REQUIRES="yes"
162#REMOVE_BUILD_REQUIRES="force"
163#GROUP_BCONDS="yes"
164#LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
982e358c 165#TITLECHANGE=no
cd445739 166#
a83e5405 167SU_SUDO=""
cd445739
AM
168if [ -n "$HOME_ETC" ]; then
169 USER_CFG="$HOME_ETC/.builderrc"
20117088 170 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
cd445739
AM
171else
172 USER_CFG=~/.builderrc
20117088 173 BUILDER_MACROS=~/.builder-rpmmacros
cd445739
AM
174fi
175
176[ -f "$USER_CFG" ] && . "$USER_CFG"
177
86aafdbe
ER
178if [ "$SCHEDTOOL" = "auto" ]; then
179 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
180 SCHEDTOOL="schedtool -B -e"
181 else
182 SCHEDTOOL="no"
183 fi
184fi
185
ca2e6c31 186if [ -n "$USE_PROZILLA" ]; then
7e365483
KK
187 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
188 GETURI2="$GETURI"
189 OUTFILEOPT="-O"
ca2e6c31 190elif [ -n "$USE_AXEL" ]; then
cede92b3 191 GETURI="axel -a $AXEL_OPTS"
7e365483
KK
192 GETURI2="$GETURI"
193 OUTFILEOPT="-o"
ca2e6c31 194else
5700ee32
ER
195 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
196 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
197 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
e3aa6f5e 198 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
6f9a5d76 199
7e365483
KK
200 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
201 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
202 OUTFILEOPT="-O"
2bc5451f 203fi
11468b23 204
11468b23
AM
205GETLOCAL="cp -a"
206
207if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
208 RPM="rpm"
209 RPMBUILD="rpm"
210else
211 RPM="rpm"
212 RPMBUILD="rpmbuild"
213fi
214
28c23a72
AG
215#
216# are we using cvs-nserver ?
217#
e21039da 218CVS_NSERVER=0
939f2c12 219$CVS_COMMAND --version 2>&1 | grep -q 'CVS-nserver'
e21039da 220[ $? -eq 0 ] && CVS_NSERVER=1
28c23a72 221
a8c9a155 222POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
a83e5405 223POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
11468b23 224
f6711e2a 225run_poldek() {
525bf240 226 RES_FILE=$(mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM)
cd445739
AM
227 if [ -n "$LOGFILE" ]; then
228 LOG=`eval echo $LOGFILE`
229 if [ -n "$LASTLOG_FILE" ]; then
230 echo "LASTLOG=$LOG" > $LASTLOG_FILE
231 fi
86aafdbe 232 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
cd445739
AM
233 return $exit_pldk
234 else
86aafdbe 235 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
cd445739
AM
236 return `cat ${RES_FILE}`
237 rm -rf ${RES_FILE}
238 fi
239}
240
cd445739
AM
241#---------------------------------------------
242# functions
da946cd6 243
f6711e2a 244usage() {
cd445739
AM
245 if [ -n "$DEBUG" ]; then set -xv; fi
246 echo "\
d43959a2 247Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|-ba|--build]
6594293d 248[-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
4efa0b98 249[{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>]
19dc5591 250[-g|--get] [-h|--help] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
251[-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T|--tag <cvstag>]
a7b2951c 252[-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
f8dba812 253[{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}] [--use-greed-sources]
6594293d 254[-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
3009b80d 255[--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
6594293d 256<package>[.spec][:cvstag]
2a5f078d 257
cd445739
AM
258-5, --update-md5 - update md5 comments in spec, implies -nd -ncs
259-a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
260-n5, --no-md5 - ignore md5 comments in spec
9243e80b
ER
261-D, --debug - enable builder script debugging mode,
262-debug - produce rpm debug package (same as --opts -debug)
d43959a2
ER
263-V, --version - output builder version string
264--short-version - output builder short version
cd445739
AM
265-a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
266-b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
267 from <package>.spec,
268-bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
269 only package from <package>.spec,
c56807e0 270-bp, --build-prep - execute the %prep phase of <package>.spec,
6594293d
AG
271-bc - execute the %build phase of <package>.spec,
272-bi - execute the %install phase of <package>.spec
273-bl - execute the %files phase of <package>.spec
cd445739
AM
274-bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
275 them into src.rpm,
6594293d 276--short-circuit - short-circuit build
cd445739 277-B, --branch - add branch
387eaf99
ER
278-c, --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
279 may be used with building process.
6f10b394
ER
280-m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
281 SPECS and \$RPM_BUILD_ROOT and CVS/Entries). Doesn't run
282 any rpm building.
39dcc7de 283-cf, --cvs-force - use -F when tagging (useful when moving branches)
2a5f078d 284-d <cvsroot>, --cvsroot <cvsroot>
cd445739
AM
285 - setup \$CVSROOT,
286--define <macro> <value>
287 - define a macro <macro> with value <value>,
44058243
ER
288--alt_kernel <kernel>
289 - same as --define 'alt_kernel <kernel>'
cd445739
AM
290--nodeps - rpm won't check any dependences
291-g, --get - get <package>.spec and all related files from CVS repo
292 or HTTP/FTP,
293-h, --help - this message,
294--http - use http instead of ftp,
295-l <logfile>, --logtofile <logfile>
296 - log all to file,
cd445739
AM
297-nc, --no-cvs - don't download sources from CVS, if source URL is given,
298-ncs, --no-cvs-specs
299 - don't check specs in CVS
300-nd, --no-distfiles - don't download from distfiles
301-nm, --no-mirrors - don't download from mirror, if source URL is given,
302-nu, --no-urls - don't try to download from FTP/HTTP location,
7cbc2d88 303-ns, --no-srcs - don't download Sources/Patches
cd445739
AM
304-ns0, --no-source0 - don't download Source0
305-nn, --no-net - don't download anything from the net
a93e8cdf 306-pm, --prefer-mirrors - prefer mirrors (if any) over distfiles for SOURCES
b572253e 307--no-init - don't initialize builder paths (SPECS and SOURCES)
18e5347d
ER
308-ske,
309--skip-existing-files - skip existing files in get_files
cd445739
AM
310--opts <rpm opts> - additional options for rpm
311-q, --quiet - be quiet,
312--date yyyy-mm-dd - build package using resources from specified CVS date,
313-r <cvstag>, --cvstag <cvstag>
314 - build package using resources from specified CVS tag,
5323fffd 315-A - build package using CVS resources as any sticky tags/date/kopts being reset.
cd445739
AM
316-R, --fetch-build-requires
317 - fetch what is BuildRequired,
318-RB, --remove-build-requires
319 - remove all you fetched with -R or --fetch-build-requires
320 remember, this option requires confirmation,
321-FRB, --force-remove-build-requires
322 - remove all you fetched with -R or --fetch-build-requires
323 remember, this option works without confirmation,
06541433
JR
324-sd, --source-distfiles - list sources available from distfiles (intended for offline
325 operations; does not work when Icon field is present
326 but icon file is absent),
e15852ab 327-sc, --source-cvs - list sources available from CVS
06541433
JR
328-sdp, --source-distfiles-paths - list sources available from distfiles -
329 paths relative to distfiles directory (intended for offline
330 operations; does not work when Icon field is present
331 but icon file is absent),
a7eefc54 332-sf, --source-files - list sources - bare filenames (intended for offline
333 operations; does not work when Icon field is present
3621e588 334 but icon file is absent),
a7eefc54 335-sp, --source-paths - list sources - filenames with full local paths (intended for
336 offline operations; does not work when Icon field is present
3621e588 337 but icon file is absent),
2dddf439
ER
338-su, --source-urls - list urls - urls to sources and patches
339 intended for copying urls with spec with lots of macros in urls
cd445739
AM
340-T <cvstag> , --tag <cvstag>
341 - add cvs tag <cvstag> for files,
342-Tvs, --tag-version-stable
094bd95b 343 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
cd445739
AM
344-Ts, --tag-stable
345 - add cvs tag STABLE for files,
cd445739 346-Tv, --tag-version
1691a37b 347 - add cvs tag NAME-VERSION-RELEASE for files,
cd445739
AM
348-Tp, --tag-prefix <prefix>
349 - add <prefix> to NAME-VERSION-RELEASE tags,
350-tt, --test-tag <prefix>
351 - fail if tag is already present,
50321881
JK
352-ir, --integer-release-only
353 - allow only integer and snapshot releases
cd445739
AM
354-v, --verbose - be verbose,
355-u, --try-upgrade - check version, and try to upgrade package
356-un, --try-upgrade-with-float-version
357 - as above, but allow float version
f8dba812 358--use-greed-sources
359 - try download source from tag head if don't find it in
f5141bbc 360 current tag
deccc50e 361-U, --update - refetch sources, don't use distfiles, and update md5 comments
cd445739
AM
362-Upi, --update-poldek-indexes
363 - refresh or make poldek package index files.
c890b916 364-np, --nopatch <patchnumber>
bed98670 365 - don't apply <patchnumber>
dfe2cb9a
MK
366--show-bconds - show available conditional builds, which can be used
367 - with --with and/or --without switches.
9b78be50
ER
368--show-bcond-args - show active bconds, from ~/.bcondrc. this is used by
369 ./repackage.sh script. in other words, the output is
370 parseable by scripts.
24a97174 371--show-avail-bconds - show available bconds
cd445739
AM
372--with/--without <feature>
373 - conditional build package depending on %_with_<feature>/
374 %_without_<feature> macro switch. You may now use
375 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
376 constructions. Set GROUP_BCONDS to yes to make use of it.
6dd19291 377--target <platform>, --target=<platform>
3621e588
ER
378 - build for platform <platform>.
379--init-rpm-dir - initialize ~/rpm directory structure
5a491465 380"
381}
382
31d2bd0b
ER
383# change dependency to specname
384# common changes:
385# - perl(Package::Name) -> perl-Package-Name
386depspecname() {
387 local package="$1"
388
560c4b1a 389 package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
31d2bd0b
ER
390 echo "$package"
391}
392
c890b916 393update_shell_title() {
a0d6396b 394 [ -t 1 ] || return
0b65d15e 395 local len=${COLUMNS:-80}
5c795f16 396 local msg="$(echo "$*" | cut -c-$len)"
0b65d15e 397
e225de91
ER
398 if [ -n "$BE_VERBOSE" ]; then
399 echo >&2 "$(date +%s.%N) $*"
400 fi
401
5c795f16 402 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
138bbc98
ER
403 local pkg
404 if [ -n "$PACKAGE_NAME" ]; then
405 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
406 else
407 pkg=${SPECFILE}
408 fi
409
410 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
a8c9a155 411 msg=$(echo $msg | tr -d '\n\r')
982e358c
MP
412 case "$TERM" in
413 cygwin|xterm*)
414 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
415 ;;
416 screen*)
417 echo >&2 -ne "\033]0;$msg\007"
418 ;;
419 esac
420 fi
c890b916
ER
421}
422
7e40520f
ER
423# set TARGET from BuildArch: from SPECFILE
424set_spec_target() {
ce40491a 425 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
b45a3b2a 426 tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
ce40491a 427 if [ "$tmp" ]; then
f9109a96 428 target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
7e40520f
ER
429 TARGET="$tmp"
430 case "$RPMBUILD" in
431 "rpmbuild")
f9109a96 432 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
7e40520f 433 "rpm")
ce40491a 434 TARGET_SWITCH="--target=$TARGET" ;;
7e40520f 435 esac
ce40491a
ER
436 fi
437 fi
7e40520f
ER
438}
439
ace3fd80
ER
440# runs rpm with minimal macroset
441minirpm() {
fa4bf1df 442 # we reset macros not to contain macros.build as all the %() macros are
559d511f 443 # executed here, while none of them are actually needed.
559d511f 444 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
525bf240 445 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ')
ace3fd80
ER
446
447 # TODO: move these to /usr/lib/rpm/macros
20117088 448 cat > $BUILDER_MACROS <<'EOF'
5b5e5f7f 449%x8664 x86_64 amd64 ia32e
f78a0bb7 450%alt_kernel %{nil}
451%_alt_kernel %{nil}
407b204b
ER
452%requires_releq_kernel_up(s:n:) %{nil}
453%requires_releq_kernel_smp(s:n:) %{nil}
454%requires_releq_kernel(s:n:) %{nil}
6b8134e3 455%requires_releq() %{nil}
bb01dee9 456%pyrequires_eq() %{nil}
559d511f 457%requires_eq() %{nil}
c13be3d1 458%requires_eq_to() %{nil}
407b204b
ER
459%releq_kernel_up(n:) ERROR
460%releq_kernel_smp(n:) ERROR
461%releq_kernel(n:) ERROR
74d9fd14 462%kgcc_package ERROR
237bd3f1 463%_fontsdir ERROR
7141278d 464%ruby_version ERROR
465%ruby_ver_requires_eq() %{nil}
466%ruby_mod_ver_requires_eq() %{nil}
c13be3d1 467%__php_api_requires() %{nil}
7141278d 468%php_major_version ERROR
469%php_api_version ERROR
99f819cf
AM
470%requires_xorg_xserver_extension %{nil}
471%requires_xorg_xserver_xinput %{nil}
472%requires_xorg_xserver_font %{nil}
473%requires_xorg_xserver_videodrv %{nil}
7141278d 474%py_ver ERROR
41035426
ER
475%perl_vendorarch ERROR
476%perl_vendorlib ERROR
703ae20b
ER
477# damn. need it here! - copied from /usr/lib/rpm/macros.build
478%tmpdir %(echo "${TMPDIR:-/tmp}")
1f28fcb7
ER
479%patchset_source(f:b:) %(
480 base=%{-b*}%{!-b*:10000};
481 start=$(expr $base + %1);
482 end=$(expr $base + %{?2}%{!?2:%{1}});
483 # we need to call seq twice as it doesn't allow two formats
484 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
485 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
486 paste %{tmpdir}/__ps{1,2};
487 rm -f %{tmpdir}/__ps{1,2};
488) \
489%{nil}
991f09a5
ER
490%add_etc_shells(p) %{p:<lua>}
491%remove_etc_shells(p) %{p:<lua>}
709995c4
ER
492%lua_add_etc_shells() %{nil}
493%lua_remove_etc_shells() %{nil}
fb198857 494EOF
3d12d055 495 if [ "$NOINIT" = "yes" ] ; then
20117088 496 cat >> $BUILDER_MACROS <<'EOF'
3d12d055
JR
497%_specdir ./
498%_sourcedir ./
499EOF
c039643c 500 fi
fff1b991 501 eval $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
ace3fd80
ER
502}
503
504cache_rpm_dump() {
505 if [ -n "$DEBUG" ]; then
506 set -x
507 set -v
508 fi
509
d1d24c14 510 if [ -x /usr/bin/rpm-specdump ]; then
525bf240 511 update_shell_title "cache_rpm_dump using rpm-specdump command"
fff1b991 512 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND $SPECFILE)
d1d24c14 513 else
525bf240 514 update_shell_title "cache_rpm_dump using rpmbuild command"
d1d24c14
ER
515 local rpm_dump
516 rpm_dump=`
517 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
518 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
519 case "$RPMBUILD" in
520 rpm)
521 ARGS='-bp'
522 ;;
523 rpmbuild)
524 ARGS='--nodigest --nosignature --nobuild'
525 ;;
526 esac
527 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
528 `
529 if [ $? -gt 0 ]; then
530 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
531 echo "$error" >&2
532 Exit_error err_build_fail
533 fi
d05e8080 534
d1d24c14
ER
535 # make small dump cache
536 rpm_dump_cache=`echo "$rpm_dump" | awk '
537 $2 ~ /^SOURCEURL/ {print}
538 $2 ~ /^PATCHURL/ {print}
539 $2 ~ /^nosource/ {print}
540 $2 ~ /^PACKAGE_/ {print}
541 '`
542 fi
d05e8080 543
13974367 544 update_shell_title "cache_rpm_dump: OK!"
cd445739
AM
545}
546
ace3fd80 547rpm_dump() {
cd445739 548 if [ -z "$rpm_dump_cache" ] ; then
45e2a818 549 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
cd445739
AM
550 fi
551 echo "$rpm_dump_cache"
552}
553
f6711e2a 554get_icons() {
d05e8080 555 update_shell_title "get icons"
9d99a240 556 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
d05e8080
ER
557 if [ -z "$ICONS" ]; then
558 return
559 fi
560
975d7b23 561 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
d05e8080
ER
562}
563
f6711e2a 564parse_spec() {
af4d5315 565 update_shell_title "parsing specfile"
cd445739 566 if [ -n "$DEBUG" ]; then
518ff1fb
ER
567 set -x
568 set -v
cd445739 569 fi
b2975fc3 570
d05e8080 571 # icons are needed for successful spec parse
518ff1fb 572 get_icons
d05e8080 573
9c909460 574 cd $PACKAGE_DIR
cd445739 575 cache_rpm_dump
00fcec7e 576
cd445739
AM
577 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
578 FAIL_IF_NO_SOURCES="no"
579 fi
580
7cbc2d88
ER
581 if [ "$NOSRCS" != "yes" ]; then
582 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
583 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
584 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
585 fi
586
dfe2b2d9
ER
587 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
588 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
589 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
78eab2a1 590
0b4119a2 591 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
7854d40c 592 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
0b4119a2
JR
593 fi
594
cd445739
AM
595 if [ -n "$BE_VERBOSE" ]; then
596 echo "- Sources : `nourl $SOURCES`"
597 if [ -n "$PATCHES" ]; then
598 echo "- Patches : `nourl $PATCHES`"
599 else
600 echo "- Patches : *no patches needed*"
601 fi
602 if [ -n "$ICONS" ]; then
603 echo "- Icon : `nourl $ICONS`"
604 else
605 echo "- Icon : *no package icon*"
606 fi
607 echo "- Name : $PACKAGE_NAME"
608 echo "- Version : $PACKAGE_VERSION"
609 echo "- Release : $PACKAGE_RELEASE"
610 fi
13974367
ER
611
612 update_shell_title "parse_spec: OK!"
cd445739
AM
613}
614
f6711e2a 615Exit_error() {
cd445739 616 if [ -n "$DEBUG" ]; then
518ff1fb
ER
617 set -x
618 set -v
cd445739
AM
619 fi
620
621 cd "$__PWD"
622
623 case "$1" in
624 "err_no_spec_in_cmdl" )
625 remove_build_requires
45e2a818 626 echo >&2 "ERROR: spec file name not specified."
cd445739 627 exit 2 ;;
a08d92fc 628 "err_invalid_cmdline" )
45e2a818 629 echo >&2 "ERROR: invalid command line arg ($2)."
a08d92fc 630 exit 2 ;;
cd445739
AM
631 "err_no_spec_in_repo" )
632 remove_build_requires
45e2a818 633 echo >&2 "Error: spec file not stored in CVS repo."
cd445739
AM
634 exit 3 ;;
635 "err_no_source_in_repo" )
636 remove_build_requires
45e2a818 637 echo >&2 "Error: some source, patch or icon files not stored in CVS repo. ($2)"
cd445739
AM
638 exit 4 ;;
639 "err_build_fail" )
640 remove_build_requires
45e2a818 641 echo >&2 "Error: package build failed. (${2:-no more info})"
cd445739 642 exit 5 ;;
78eab2a1
AM
643 "err_no_package_data" )
644 remove_build_requires
45e2a818 645 echo >&2 "Error: couldn't get out package name/version/release from spec file."
78eab2a1 646 exit 6 ;;
ce40491a 647 "err_tag_exists" )
50321881 648 remove_build_requires
45e2a818 649 echo >&2 "Tag ${2} already exists (spec release: ${3})."
50321881 650 exit 9 ;;
ce40491a 651 "err_fract_rel" )
50321881 652 remove_build_requires
45e2a818 653 echo >&2 "Release ${2} not integer and not a snapshot."
50321881 654 exit 10 ;;
fb96e0b5
AM
655 "err_branch_exists" )
656 remove_build_requires
45e2a818 657 echo >&2 "Tree branch already exists (${2})."
fb96e0b5 658 exit 11 ;;
cfc497c0
ER
659 "err_acl_deny" )
660 remove_build_requires
45e2a818 661 echo >&2 "Error: conditions reject building this spec (${2})."
cfc497c0 662 exit 12 ;;
cd445739 663 esac
45e2a818 664 echo >&2 "Unknown error."
73848362 665 exit 100
cd445739
AM
666}
667
f6711e2a 668init_builder() {
cd445739 669 if [ -n "$DEBUG" ]; then
518ff1fb
ER
670 set -x
671 set -v
0dd6320d 672 fi
cd445739 673
4aeb9973 674 if [ "$NOINIT" != "yes" ] ; then
9c909460 675 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
b7cc0c94 676
09bf17c9 677 local macros_ver=$(rpm -E %?rpm_build_macros)
b7cc0c94
ER
678 if [ -z "$macros_ver" ]; then
679 REPO_DIR=$TOP_DIR/packages
680 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
681 else
682 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
683 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
684 exit 1
685 fi
686 REPO_DIR=$TOP_DIR
687 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
688 fi
29e90b02 689 else
9c909460
AM
690 REPO_DIR="."
691 PACKAGE_DIR="."
29e90b02 692 fi
cd445739 693
a8c9a155 694 __PWD=$(pwd)
00fcec7e 695}
696
f6711e2a 697get_spec() {
c890b916 698
2e5be021 699 update_shell_title "get_spec"
c890b916 700
cd445739 701 if [ -n "$DEBUG" ]; then
518ff1fb
ER
702 set -x
703 set -v
cd445739
AM
704 fi
705
9c909460
AM
706 cd "$REPO_DIR"
707 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
6277f15f
ER
708 # XXX: still needed?
709 SPECFILE=$(basename $SPECFILE)
cd445739
AM
710 fi
711 if [ "$NOCVSSPEC" != "yes" ]; then
cd445739 712
049ab214
ER
713 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
714 echo "Warning: No CVS access defined - using local .spec file"
715 NOCVSSPEC="yes"
cd445739
AM
716 fi
717
9c909460
AM
718 if [ -d "$ASSUMED_NAME" ]; then
719 cvsup "$ASSUMED_NAME/$SPECFILE" || Exit_error err_no_spec_in_repo
720 else
721 cvsup -c -d $ASSUMED_NAME "packages/$ASSUMED_NAME/$SPECFILE" || Exit_error err_no_spec_in_repo
f123bcb5
ER
722
723 # remove Entries.Static -- so 'cvs up' would update all files in a repo
724 rm "$ASSUMED_NAME/CVS/Entries.Static"
80cef3c1 725 cvsignore_df .cvsignore
f123bcb5
ER
726
727 # create symlinks for tools
daeab113 728 if [ "$SYMLINK_TOOLS" != "no" ]; then
387eaf99 729 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh; do
daeab113
JR
730 [ -f $a ] || continue
731 ln -s ../$a $ASSUMED_NAME
732 cvsignore_df $a
733 done
734 fi
9c909460 735 fi
cd445739 736 fi
049ab214 737
9c909460 738 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
518ff1fb 739 Exit_error err_no_spec_in_repo
cd445739
AM
740 fi
741
742 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
9c909460 743 chmod $CHMOD_MODE $ASSUMED_NAME/$SPECFILE
cd445739
AM
744 fi
745 unset OPTIONS
9c909460 746 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $ASSUMED_NAME/$SPECFILE
7e40520f 747
ce40491a 748 set_spec_target
cd445739
AM
749}
750
f6711e2a 751find_mirror() {
9c909460 752 cd "$REPO_DIR"
782518da 753 local url="$1"
cd445739 754 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
939f2c12 755 $CVS_COMMAND update mirrors >&2
cd445739
AM
756 fi
757
758 IFS="|"
782518da
ER
759 local origin mirror name rest ol prefix
760 while read origin mirror name rest; do
761 # skip comments and empty lines
2faa4c32 762 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
782518da
ER
763 continue
764 fi
a8c9a155
ER
765 ol=$(echo -n "$origin" | wc -c)
766 prefix=$(echo -n "$url" | head -c $ol)
cd445739 767 if [ "$prefix" = "$origin" ] ; then
a8c9a155 768 suffix=$(echo "$url" | cut -b $((ol+1))-)
cd445739
AM
769 echo -n "$mirror$suffix"
770 return 0
771 fi
772 done < mirrors
773 echo "$url"
774}
775
e7e0d4ec 776# Warning: unpredictable results if same URL used twice
f6711e2a 777src_no() {
9c909460 778 cd $PACKAGE_DIR
cd445739
AM
779 rpm_dump | \
780 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
781 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
782 head -n 1 | xargs
1471f6d6 783}
784
f6711e2a 785src_md5() {
e7e0d4ec 786 [ "$NO5" = "yes" ] && return
cd445739
AM
787 no=$(src_no "$1")
788 [ -z "$no" ] && return
9c909460 789 cd $PACKAGE_DIR
e7e0d4ec
ER
790 local md5
791
792 if [ -f additional-md5sums ]; then
793 local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
794 if [ -z "$spec_rev" ]; then
a8c9a155 795 spec_rev=$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')
e7e0d4ec
ER
796 fi
797 local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
798 md5=$(grep -s -v '^#' additional-md5sums | \
799 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
800 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
801 grep -E '^[0-9a-f]{32}$')
802
803 if [ "$md5" ]; then
804 if [ $(echo "$md5" | wc -l) != 1 ] ; then
805 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
806 fi
807 echo "$md5" | tail -n 1
808 return
809 fi
cd445739 810 fi
e7e0d4ec 811
657d488b 812 source_md5=`grep -i "^#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
e7e0d4ec
ER
813 if [ -n "$source_md5" ]; then
814 echo $source_md5
cd445739 815 else
7805dcb4
PZ
816 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
817 if [ -n "$source_md5" ]; then
818 echo $source_md5
819 else
820 # we have empty SourceX-md5, but it is still possible
821 # that we have NoSourceX-md5 AND NoSource: X
657d488b 822 nosource_md5=`grep -i "^#[ ]*NoSource$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
7805dcb4
PZ
823 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
824 echo $nosource_md5
825 fi
cd445739 826 fi
cd445739
AM
827 fi
828}
829
f6711e2a 830distfiles_path() {
06541433
JR
831 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
832}
833
f6711e2a 834distfiles_url() {
06541433 835 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
cd445739
AM
836}
837
f6711e2a 838distfiles_attic_url() {
06541433 839 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
cd445739
AM
840}
841
f6711e2a 842good_md5() {
cd445739
AM
843 md5=$(src_md5 "$1")
844 [ "$md5" = "" ] || \
845 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
8ba5cdda
PG
846}
847
f6711e2a 848good_size() {
a8c9a155 849 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
ce40491a 850 [ -n "$size" -a "$size" -gt 0 ]
a4b50627
AF
851}
852
f6711e2a 853cvsignore_df() {
947025e5 854 if [ "$CVSIGNORE_DF" != "yes" ]; then
855 return
856 fi
9c909460 857 cvsignore=${PACKAGE_DIR}/.cvsignore
7dc8d095
ER
858
859 # add only if not yet there
aa189b05 860 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
947025e5 861 echo "$1" >> $cvsignore
862 fi
863}
864
f6711e2a 865cvsup() {
ce40491a
ER
866 update_shell_title "cvsup"
867 local OPTIONS="up "
9c909460
AM
868
869 if [ "$1" = "-c" ]; then
870 OPTIONS="co "
871 shift
872 fi
ce40491a
ER
873 if [ -n "$CVSROOT" ]; then
874 OPTIONS="-d $CVSROOT $OPTIONS"
875 fi
b1c6aace 876
ce40491a
ER
877 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
878 OPTIONS="$OPTIONS -A"
879 else
880 if [ -n "$CVSDATE" ]; then
881 OPTIONS="$OPTIONS -D $CVSDATE"
882 fi
883 if [ -n "$CVSTAG" ]; then
884 OPTIONS="$OPTIONS -r $CVSTAG"
885 fi
886 fi
e7fa3b9f 887
ce40491a
ER
888 local result=1
889 local retries_counter=0
890 if [ $# = 1 ]; then
891 update_shell_title "cvsup: $*"
892 else
893 update_shell_title "cvsup: $# files"
894 fi
895 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
896 retries_counter=$(( $retries_counter + 1 ))
939f2c12 897 output=$(LC_ALL=C $CVS_COMMAND $OPTIONS "$@" 2>&1)
ce40491a
ER
898 result=$?
899 [ -n "$output" ] && echo "$output"
900 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
901 echo "Trying again [$*]... ($retries_counter)"
902 update_shell_title "cvsup: retry #$retries_counter"
903 sleep 2
904 continue
905 else
906 break
907 fi
908 done
909 update_shell_title "cvsup: done!"
910 return $result
e7fa3b9f
ER
911}
912
71f8e908 913# returns true if "$1" is ftp, http or https protocol url
f6711e2a 914is_url() {
71f8e908
ER
915 case "$1" in
916 ftp://*|http://*|https://*)
917 return 0
918 ;;
919 esac
920 return 1
921}
922
f6711e2a 923update_md5() {
ecba6ad5
ER
924 if [ $# -eq 0 ]; then
925 return
926 fi
927
928 update_shell_title "update md5"
929 if [ -n "$DEBUG" ]; then
518ff1fb
ER
930 set -x
931 set -v
ecba6ad5
ER
932 fi
933
9c909460 934 cd "$PACKAGE_DIR"
ecba6ad5
ER
935
936 # pass 1: check files to be fetched
937 local todo
938 local need_files
939 for i in "$@"; do
940 local fp=$(nourl "$i")
941 local srcno=$(src_no "$i")
6392b5fd
ER
942 if [ -n "$ADD5" ]; then
943 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
9c909460
AM
944 grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
945 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
6392b5fd 946 else
9c909460 947 grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
ecba6ad5
ER
948 fi
949 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
950 need_files="$need_files $i"
951 fi
952 done
953
954 # pass 1a: get needed files
955 if [ "$need_files" ]; then
956 get_files $need_files
957 fi
958
959 # pass 2: proceed with md5 adding or updating
960 for i in "$@"; do
961 local fp=$(nourl "$i")
962 local srcno=$(src_no "$i")
9c909460 963 local md5=$(grep -iE '^#[ ]*(No)?Source'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
e19ad799 964 if [ -z "$md5" ]; then
9c909460 965 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
6c1b2e7d 966 fi
71f8e908 967 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
6c1b2e7d 968 local tag="# Source$srcno-md5:\t"
71f8e908 969 if [[ "$md5" == *NoSource* ]]; then
6c1b2e7d
PZ
970 tag="# NoSource$srcno-md5:\t"
971 elif [ -n "$USEDIGEST" ]; then
972 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
71f8e908 973 fi
ecba6ad5 974 md5=$(md5sum "$fp" | cut -f1 -d' ')
15bf3e99 975 echo "Updating Source$srcno ($md5: $fp)."
ecba6ad5 976 perl -i -ne '
6c1b2e7d
PZ
977 print unless (/^\s*#\s*(No)?Source'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
978 print "'"$tag$md5"'\n" if /^Source'$srcno'\s*:\s+/;
ecba6ad5 979 ' \
9c909460 980 $PACKAGE_DIR/$SPECFILE
ecba6ad5
ER
981 fi
982 done
983}
984
f6711e2a 985check_md5() {
60499e54 986 local bad
3fbff8b8
ER
987 [ "$NO5" = "yes" ] && return
988
ecba6ad5
ER
989 update_shell_title "check md5"
990
991 for i in "$@"; do
60499e54
AM
992 bad=0
993 if ! good_md5 "$i"; then
994 echo -n "MD5 sum mismatch."
995 bad=1
996 fi
997 if ! good_size "$i"; then
998 echo -n "0 sized file."
999 bad=1
ecba6ad5
ER
1000 fi
1001
60499e54
AM
1002 if [ $bad -eq 1 ]; then
1003 echo " Use -U to refetch sources,"
1004 echo "or -5 to update md5 sums, if you're sure files are correct."
1005 Exit_error err_no_source_in_repo $i
1006 fi
ecba6ad5
ER
1007 done
1008}
1009
f6711e2a 1010get_files() {
7cb24972 1011 update_shell_title "get_files"
cd445739
AM
1012
1013 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1014 set -x
1015 set -v
cd445739
AM
1016 fi
1017
f09c0772 1018 if [ $# -gt 0 ]; then
9c909460 1019 cd "$PACKAGE_DIR"
cd445739 1020
b1c6aace 1021 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
049ab214 1022 echo "Warning: No CVS access defined for SOURCES"
b1c6aace
ER
1023 NOCVS="yes"
1024 fi
1025
f2e42a41 1026 local nc=0
e7fa3b9f 1027 local get_files_cvs=""
3815b69a 1028 for i in "$@"; do
f2e42a41 1029 nc=$((nc + 1))
dcebdffb 1030 local cvsup=0
3815b69a 1031 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
f2e42a41 1032 update_shell_title "$i"
f09c0772 1033 local fp=`nourl "$i"`
ecba6ad5 1034 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
ce40491a 1035 continue
18e5347d 1036 fi
ecba6ad5 1037
cd445739 1038 FROM_DISTFILES=0
e7e0d4ec 1039 local srcmd5=$(src_md5 "$i")
ecba6ad5
ER
1040
1041 # we know if source/patch is present in cvs/distfiles
1042 # - has md5 (in distfiles)
1043 # - in cvs... ideas?
1044
1045 # CHECK: local file didn't exist or always cvs up (first) requested.
f09c0772 1046 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
cd445739
AM
1047 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1048 echo "Warning: no URL given for $i"
1049 fi
08908161 1050 target="$fp"
cd445739 1051
e7e0d4ec 1052 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
a4b50627 1053 if good_md5 "$i" && good_size "$i"; then
e7e0d4ec 1054 echo "$fp having proper md5sum already exists"
cd445739
AM
1055 continue
1056 fi
28b34560 1057
bc10f694 1058 # optionally prefer mirror over distfiles if there's mirror
28b34560 1059 # TODO: build url list and then try each url from the list
bc10f694 1060 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
28b34560
ER
1061 url="$im"
1062 else
1063 url=$(distfiles_url "$i")
1064 fi
1065
cd445739
AM
1066 url_attic=$(distfiles_attic_url "$i")
1067 FROM_DISTFILES=1
ecba6ad5
ER
1068 # is $url local file?
1069 if [[ "$url" = [./]* ]]; then
18a52930 1070 update_shell_title "${GETLOCAL%% *}: $url"
cd445739
AM
1071 ${GETLOCAL} $url $target
1072 else
1073 if [ -z "$NOMIRRORS" ]; then
9e9f8920 1074 url=$(find_mirror "$url")
cd445739 1075 fi
9e9f8920
ER
1076
1077 local uri=${url}
1078 # make shorter message for distfiles urls
1079 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1080 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1081 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1082 uri="df: $uri"
1083 fi
1084 update_shell_title "${GETURI%% *}: $uri"
ca2e6c31 1085 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
33da77c4 1086 if [ "`echo $url | grep -E 'ftp://'`" ]; then
18a52930 1087 update_shell_title "${GETURI2%% *}: $url"
ca2e6c31 1088 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
cd445739
AM
1089 fi
1090 fi
ecba6ad5
ER
1091
1092 # is it empty file?
1093 if [ ! -s "$target" ]; then
cd445739
AM
1094 rm -f "$target"
1095 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
18a52930 1096 update_shell_title "${GETLOCAL%% *}: $url_attic"
cd445739
AM
1097 ${GETLOCAL} $url_attic $target
1098 else
1099 if [ -z "$NOMIRRORS" ]; then
a8c9a155 1100 url_attic=$(find_mirror "$url_attic")
cd445739 1101 fi
18a52930 1102 update_shell_title "${GETURI%% *}: $url_attic"
ca2e6c31 1103 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
33da77c4 1104 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
ce40491a 1105 update_shell_title "${GETURI2%% *}: $url_attic"
ca2e6c31 1106 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
cd445739 1107 fi
1cd7fc57 1108 test -s "$target" || rm -f "$target"
cd445739
AM
1109 fi
1110 fi
ecba6ad5
ER
1111
1112 if [ -s "$target" ]; then
947025e5 1113 cvsignore_df $target
1114 else
cd445739
AM
1115 rm -f "$target"
1116 FROM_DISTFILES=0
1117 fi
e7e0d4ec 1118 elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then
d05e8080
ER
1119 if [ $# -gt 1 ]; then
1120 get_files_cvs="$get_files_cvs $fp"
1121 update_shell_title "$fp (will cvs up later)"
1122 cvsup=1
1123 else
1124 cvsup $fp
1125 fi
cd445739
AM
1126 fi
1127
f09c0772 1128 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
cd445739 1129 if [ -z "$NOMIRRORS" ]; then
a8c9a155 1130 im=$(find_mirror "$i")
cd445739
AM
1131 else
1132 im="$i"
1133 fi
ce40491a 1134 update_shell_title "${GETURI%% *}: $im"
08908161 1135 ${GETURI} "$im" ${OUTFILEOPT} "$target" || \
33da77c4 1136 if [ "`echo $im | grep -E 'ftp://'`" ]; then
ce40491a 1137 update_shell_title "${GETURI2%% *}: $im"
08908161 1138 ${GETURI2} "$im" ${OUTFILEOPT} "$target"
7e365483 1139 fi
1cd7fc57 1140 test -s "$target" || rm -f "$target"
cd445739
AM
1141 fi
1142
dcebdffb
ER
1143 if [ "$cvsup" = 1 ]; then
1144 continue
1145 fi
1146
cd445739 1147 fi
ecba6ad5
ER
1148
1149 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
f09c0772 1150 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
cdbd30e8 1151 if [ -n "GREEDSRC" ]; then
1152 get_greed_sources $i
1153 else
1154 Exit_error err_no_source_in_repo $i
1155 fi
cd445739 1156 fi
2a5f078d 1157
ecba6ad5 1158 # we check md5 here just only to refetch immediately
a4b50627 1159 if good_md5 "$i" && good_size "$i"; then
cd445739
AM
1160 :
1161 elif [ "$FROM_DISTFILES" = 1 ]; then
deccc50e 1162 # wrong md5 from distfiles: remove the file and try again
cd445739 1163 # but only once ...
deccc50e 1164 echo "MD5 sum mismatch. Trying full fetch."
cd445739
AM
1165 FROM_DISTFILES=2
1166 rm -f $target
18a52930 1167 update_shell_title "${GETURI%% *}: $url"
ca2e6c31 1168 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
33da77c4 1169 if [ "`echo $url | grep -E 'ftp://'`" ]; then
ce40491a 1170 update_shell_title "${GETURI2%% *}: $url"
ca2e6c31 1171 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
cd445739 1172 fi
ecba6ad5 1173 if [ ! -s "$target" ]; then
cd445739 1174 rm -f "$target"
18a52930 1175 update_shell_title "${GETURI%% *}: $url_attic"
ca2e6c31 1176 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
33da77c4 1177 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
ce40491a 1178 update_shell_title "${GETURI2%% *}: $url_attic"
ca2e6c31 1179 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
cd445739
AM
1180 fi
1181 fi
1182 test -s "$target" || rm -f "$target"
1183 fi
cd445739 1184 done
e7fa3b9f
ER
1185 SHELL_TITLE_PREFIX=""
1186
1187 if [ "$get_files_cvs" ]; then
ce40491a 1188 cvsup $get_files_cvs
e7fa3b9f 1189 fi
cd445739
AM
1190
1191 if [ "$CHMOD" = "yes" ]; then
a8c9a155 1192 CHMOD_FILES=$(nourl "$@")
cd445739
AM
1193 if [ -n "$CHMOD_FILES" ]; then
1194 chmod $CHMOD_MODE $CHMOD_FILES
1195 fi
1196 fi
cd445739
AM
1197 fi
1198}
1199
1200make_tagver() {
ce40491a 1201 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1202 set -x
1203 set -v
ce40491a 1204 fi
78eab2a1 1205
ce40491a
ER
1206 # Check whether first character of PACKAGE_NAME is legal for tag name
1207 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1208 TAG_PREFIX=tag_
1209 fi
d712cc12
ER
1210
1211 # NOTE: CVS tags may must not contain the characters `$,.:;@'
392187d9 1212 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE | tr '[.@]' '[_#]')
d712cc12 1213
ce40491a
ER
1214 # Remove #kernel.version_release from TAGVER because tagging sources
1215 # could occur with different kernel-headers than kernel-headers used at build time.
d712cc12
ER
1216 # besides, %{_kernel_ver_str} is not expanded.
1217
1218 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1#%{_kernel_ver_str}
1219 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1220
1221 TAGVER=${TAGVER%#*}
ce40491a 1222 echo -n "$TAGVER"
cd445739
AM
1223}
1224
c713aac3
AG
1225# bool is_tag_a_branch(tag)
1226#
1227# returns 1 if a tag is a branch set on SPECFILE
1228is_tag_a_branch() {
1229 if [ -n "$DEBUG" ]; then
1230 set -x
1231 set -v
1232 fi
1233
1234 if [ $# -ne 1 ]; then
1235 return 0;
1236 fi
1237
1238 TAG=$1
f5141bbc 1239
9c909460 1240 cd "$PACKAGE_DIR"
939f2c12 1241 $CVS_COMMAND status -v $SPECFILE | grep -Eiq "${TAG}.+(branch: [0-9.]+)"
c713aac3
AG
1242 return $?
1243}
1244
f6711e2a 1245tag_files() {
cd445739
AM
1246 TAG_FILES="$@"
1247
1248 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1249 set -x
1250 set -v
cd445739
AM
1251 fi
1252
73ef63d8
ER
1253 echo "Version: $PACKAGE_VERSION"
1254 echo "Release: $PACKAGE_RELEASE"
cd445739 1255
a18a9761 1256 local TAGVER
73ef63d8 1257 if [ "$TAG_VERSION" = "yes" ]; then
a18a9761 1258 TAGVER=`make_tagver`
73ef63d8
ER
1259 echo "CVS tag: $TAGVER"
1260 fi
1261 if [ -n "$TAG" ]; then
1262 echo "CVS tag: $TAG"
1263 fi
cd445739 1264
39dcc7de 1265 local OPTIONS="tag $CVS_FORCE"
73ef63d8
ER
1266 if [ -n "$CVSROOT" ]; then
1267 OPTIONS="-d $CVSROOT $OPTIONS"
1268 fi
cd445739 1269
c713aac3
AG
1270 # if a tagname we are about to set already exists
1271 # and happens to be a branch (common case with AC-branch)
1272 # pass -B (allows -F to disturb branch tag)
1273 local _tag=$TAG
1274 if [ "$TAG_VERSION" = "yes" ]; then
1275 _tag=$TAGVER
1276 fi;
1277 is_tag_a_branch $_tag
28c23a72 1278 if [ $? -eq 0 -a $CVS_NSERVER -eq 0 ]; then
c713aac3
AG
1279 OPTIONS="$OPTIONS -B"
1280 fi;
1281
9c909460 1282 cd "$PACKAGE_DIR"
73ef63d8
ER
1283 local tag_files
1284 for i in $TAG_FILES; do
1285 # don't tag files stored on distfiles
1286 [ -n "`src_md5 $i`" ] && continue
1287 local fp=`nourl "$i"`
1288 if [ -f "$fp" ]; then
1289 tag_files="$tag_files $fp"
cdbd30e8 1290 elif [ -n "GREEDSRC" ]; then
1291 get_greed_sources $i
73ef63d8
ER
1292 else
1293 Exit_error err_no_source_in_repo $i
03db3356 1294 fi
73ef63d8 1295 done
03db3356 1296
73ef63d8 1297 if [ "$tag_files" ]; then
cd445739 1298 if [ "$TAG_VERSION" = "yes" ]; then
73ef63d8 1299 update_shell_title "tag sources: $TAGVER"
19ca62ef 1300 printf "Tagging %d files\n" $(echo $tag_files | wc -w)
939f2c12 1301 $CVS_COMMAND $OPTIONS $TAGVER $tag_files || exit
cd445739
AM
1302 fi
1303 if [ -n "$TAG" ]; then
73ef63d8 1304 update_shell_title "tag sources: $TAG"
c4ff623e
ER
1305
1306 while [ "$tag_files" ]; do
1307 local chunk=$(echo $tag_files | tr ' ' '\n' | head -n 100)
1308 printf "Tagging %d files\n" $(echo $chunk | wc -w)
939f2c12 1309 $CVS_COMMAND $OPTIONS $TAG $chunk || exit
c4ff623e
ER
1310 tag_files=$(echo $tag_files | tr ' ' '\n' | tail +101)
1311 done
cd445739 1312 fi
73ef63d8
ER
1313 fi
1314
9c909460 1315 cd "$PACKAGE_DIR"
73ef63d8
ER
1316 if [ "$TAG_VERSION" = "yes" ]; then
1317 update_shell_title "tag spec: $TAGVER"
939f2c12 1318 $CVS_COMMAND $OPTIONS $TAGVER $SPECFILE || exit
73ef63d8
ER
1319 fi
1320 if [ -n "$TAG" ]; then
1321 update_shell_title "tag spec: $TAG"
939f2c12 1322 $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
73ef63d8 1323 fi
cd445739
AM
1324}
1325
f6711e2a 1326branch_files() {
cd445739
AM
1327 TAG=$1
1328 echo "CVS branch tag: $TAG"
518ff1fb 1329 shift
cd445739
AM
1330
1331 TAG_FILES="$@"
1332
1333 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1334 set -x
1335 set -v
cd445739
AM
1336 fi
1337
78a5a506 1338 local OPTIONS="tag $CVS_FORCE -b"
ec6b5dfc
AG
1339
1340 # branch exists?
1341 is_tag_a_branch $TAG
1342 if [ $? -eq 1 ]; then
1343 OPTIONS="$OPTIONS -B"
1344 fi
1345
78a5a506
ER
1346 if [ -n "$CVSROOT" ]; then
1347 OPTIONS="-d $CVSROOT $OPTIONS"
1348 fi
9c909460 1349 cd "$PACKAGE_DIR"
78a5a506
ER
1350 local tag_files
1351 for i in $TAG_FILES; do
1352 local fp=`nourl "$i"`
1353 if [ -f "$fp" ]; then
1354 tag_files="$tag_files $fp"
cdbd30e8 1355 elif [ -n "GREEDSRC" ]; then
1356 get_greed_sources $i
78a5a506
ER
1357 else
1358 Exit_error err_no_source_in_repo $i
c10fa4fa 1359 fi
78a5a506
ER
1360 done
1361 if [ "$tag_files" ]; then
939f2c12 1362 $CVS_COMMAND $OPTIONS $TAG $tag_files || exit
78a5a506 1363 fi
c10fa4fa 1364
9c909460 1365 cd "$PACKAGE_DIR"
939f2c12 1366 $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
cd445739
AM
1367}
1368
1369
3009b80d
ER
1370# this function should exit early if package can't be built for this arch
1371# this avoids unneccessary BR filling.
1372check_buildarch() {
1373 local out ret
13c3c336 1374 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
3009b80d
ER
1375 ret=$?
1376 if [ $ret -ne 0 ]; then
1377 echo >&2 "$out"
1378 exit $ret
1379 fi
1380}
1381
9d99a240
ER
1382# from relup.sh
1383set_release() {
1384 local specfile="$1"
1385 local rel="$2"
1386 local newrel="$3"
1387 sed -i -e "
1388 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1389 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1390 " $specfile
1391}
1392
1393set_version() {
1394 local specfile="$1"
1395 local ver="$2"
1396 local newver="$3"
1397 sed -i -e "
1398 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1399 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1400 " $specfile
1401}
1402
f6711e2a 1403build_package() {
2e5be021 1404 update_shell_title "build_package"
cd445739 1405 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1406 set -x
1407 set -v
cd445739 1408 fi
5a491465 1409
9c909460 1410 cd "$PACKAGE_DIR"
cd445739
AM
1411
1412 if [ -n "$TRY_UPGRADE" ]; then
9d99a240 1413 local TNOTIFY TNEWVER TOLDVER
ce40491a 1414 update_shell_title "build_package: try_upgrade"
9d99a240 1415
cd445739 1416 if [ -n "$FLOAT_VERSION" ]; then
9d99a240 1417 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
cd445739 1418 else
9d99a240 1419 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
cd445739
AM
1420 fi
1421
45e2a818 1422 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
cd445739
AM
1423
1424 if [ -n "$TNEWVER" ]; then
1425 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
9d99a240 1426 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
257af81b
ER
1427 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1428 cp -f $SPECFILE $SPECFILE.bak
1429 fi
cd445739 1430 chmod +w $SPECFILE
9d99a240
ER
1431 set_release $SPECFILE $PACKAGE_RELEASE 0.1
1432 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
518ff1fb
ER
1433 parse_spec
1434 NODIST="yes" get_files $SOURCES $PATCHES
6392b5fd 1435 update_md5 $SOURCES
cd445739
AM
1436 fi
1437 fi
9c909460 1438 cd "$PACKAGE_DIR"
2a5f078d 1439
cd445739
AM
1440 case "$COMMAND" in
1441 build )
1442 BUILD_SWITCH="-ba" ;;
1443 build-binary )
1444 BUILD_SWITCH="-bb" ;;
1445 build-source )
1446 BUILD_SWITCH="-bs --nodeps" ;;
1447 build-prep )
1448 BUILD_SWITCH="-bp --nodeps" ;;
6594293d
AG
1449 build-build )
1450 BUILD_SWITCH="-bc" ;;
1451 build-install )
1452 BUILD_SWITCH="-bi" ;;
1453 build-list )
1454 BUILD_SWITCH="-bl" ;;
1455
cd445739 1456 esac
c890b916 1457
2e5be021 1458 update_shell_title "build_package: $COMMAND"
cd445739
AM
1459 if [ -n "$LOGFILE" ]; then
1460 LOG=`eval echo $LOGFILE`
1461 if [ -d "$LOG" ]; then
1462 echo "Log file $LOG is a directory."
1463 echo "Parse error in the spec?"
518ff1fb 1464 Exit_error err_build_fail
cd445739
AM
1465 fi
1466 if [ -n "$LASTLOG_FILE" ]; then
1467 echo "LASTLOG=$LOG" > $LASTLOG_FILE
1468 fi
525bf240
ER
1469 RES_FILE=$(mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM)
1470
9c909460 1471 (time eval ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
cd445739
AM
1472 RETVAL=`cat $RES_FILE`
1473 rm $RES_FILE
1474 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1475 if [ "$RETVAL" -eq "0" ]; then
1476 mv $LOG $LOGDIROK
1477 else
1478 mv $LOG $LOGDIRFAIL
1479 fi
1480 fi
8ba5cdda 1481 else
9c909460 1482 eval ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPECFILE
cd445739 1483 RETVAL=$?
8ba5cdda 1484 fi
cd445739
AM
1485 if [ "$RETVAL" -ne "0" ]; then
1486 if [ -n "$TRY_UPGRADE" ]; then
796a8a95 1487 echo "\n!!! Package with new version cannot be built automagically\n"
257af81b
ER
1488 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1489 mv -f $SPECFILE.bak $SPECFILE
1490 fi
cd445739 1491 fi
518ff1fb 1492 Exit_error err_build_fail
cd445739
AM
1493 fi
1494 unset BUILD_SWITCH
1495}
1496
f6711e2a 1497nourl() {
cd445739
AM
1498 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1499}
1500
f6711e2a 1501install_required_packages() {
cd445739
AM
1502 run_poldek -vi $1
1503 return $?
1504}
1505
f6711e2a 1506find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
fa4bf1df 1507 local SPEC="$1"
fa4bf1df
ER
1508 awk -F"\n" '
1509 /^%changelog/ { exit }
fa4bf1df
ER
1510 /^%bcond_with/{
1511 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
8ff97f39
ER
1512 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1513 gsub(/[ \t]+/, "_", bcond);
fa4bf1df
ER
1514 print bcond
1515 }' $SPEC | LC_ALL=C sort -u
1516}
1517
117d9861 1518process_bcondrc() {
301cbfd4
ER
1519 # expand bconds from ~/.bcondrc
1520 # The file structure is like gentoo's package.use:
1521 # ---
1522 # * -selinux
1523 # samba -mysql -pgsql
47a8df12 1524 # w32codec-installer license_agreement
301cbfd4
ER
1525 # php +mysqli
1526 # ---
fa4bf1df 1527 if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then
117d9861
ER
1528 :
1529 else
1530 return
1531 fi
301cbfd4 1532
117d9861 1533 SN=${SPECFILE%%\.spec}
c8a3e2ac 1534
117d9861
ER
1535 local bcondrc=$HOME/.bcondrc
1536 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
301cbfd4 1537
117d9861 1538 local bcond_avail=$(find_spec_bcond $SPECFILE)
301cbfd4 1539
117d9861
ER
1540 while read pkg flags; do
1541 # ignore comments
1542 [[ "$pkg" == \#* ]] && continue
1543
1544 # any package or current package?
1545 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1546 for flag in $flags; do
1547 local opt=${flag#[+-]}
1548
1549 # use only flags which are in this package.
1550 if [[ $bcond_avail = *${opt}* ]]; then
1551 if [[ $flag = -* ]]; then
1552 if [[ $BCOND != *--with?${opt}* ]]; then
1553 BCOND="$BCOND --without $opt"
1554 fi
1555 else
1556 if [[ $BCOND != *--without?${opt}* ]]; then
1557 BCOND="$BCOND --with $opt"
301cbfd4
ER
1558 fi
1559 fi
117d9861
ER
1560 fi
1561 done
1562 fi
1563 done < $bcondrc
1564 update_shell_title "parse ~/.bcondrc: DONE!"
1565}
1566
8ff97f39 1567set_bconds_values() {
117d9861
ER
1568 update_shell_title "set bcond values"
1569
1570 AVAIL_BCONDS_WITHOUT=""
1571 AVAIL_BCONDS_WITH=""
8ff97f39
ER
1572
1573 if egrep -q '^# *_with' ${SPECFILE}; then
1574 echo >&2 "ERROR: This spec has old style bconds."
1575 exit 1
1576 fi
1577
1578 if ! grep -q '^%bcond' ${SPECFILE}; then
117d9861 1579 return
301cbfd4
ER
1580 fi
1581
117d9861
ER
1582 local bcond_avail=$(find_spec_bcond $SPECFILE)
1583 process_bcondrc "$SPECFILE"
1584
fa4bf1df 1585 update_shell_title "parse bconds"
2a5f078d 1586
8ff97f39
ER
1587 local opt bcond
1588 for opt in $bcond_avail; do
1589 case "$opt" in
1590 without_*)
1591 bcond=${opt#without_}
10d92f71
ER
1592 case "$BCOND" in
1593 *--without?${bcond}*)
8ff97f39 1594 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
10d92f71
ER
1595 ;;
1596 *)
8ff97f39 1597 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
10d92f71
ER
1598 ;;
1599 esac
cd445739 1600 ;;
8ff97f39
ER
1601 with_*)
1602 bcond=${opt#with_}
10d92f71
ER
1603 case "$BCOND" in
1604 *--with?${bcond}*)
8ff97f39 1605 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
10d92f71
ER
1606 ;;
1607 *)
8ff97f39 1608 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
10d92f71
ER
1609 ;;
1610 esac
cd445739 1611 ;;
8ff97f39
ER
1612 *)
1613 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1614 exit 1
1615 ;;
1616 esac
1617 done
cd445739
AM
1618}
1619
f6711e2a 1620run_sub_builder() {
cd445739 1621 package_name="${1}"
af6b168f 1622 update_shell_title "run_sub_builder $package_name"
cd445739
AM
1623 #
1624