]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder.sh
- v0.14 and HNY
[packages/rpm-build-tools.git] / builder.sh
CommitLineData
cd445739
AM
1#!/bin/sh
2# -----------
3# $Id$
4# Exit codes:
2a5f078d 5# 0 - succesful
6# 1 - help displayed
7# 2 - no spec file name in cmdl parameters
8# 3 - spec file not stored in repo
9# 4 - some source, patch or icon files not stored in repo
10# 5 - package build failed
11# 6 - spec file with errors
12# 7 - wrong source in /etc/poldek.conf
13# 8 - Failed installing buildrequirements and subrequirements
14# 9 - Requested tag already exist
15# 10 - Refused to build fractional release
16# 100 - Unknown error (should not happen)
cd445739
AM
17
18# Notes (todo):
f7b91886 19# - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?)
cd445739 20# - when Icon: field is present, -5 and -a5 doesn't work
f3ada241 21# - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
931a4acf 22
4003ad8c 23VERSION="\
c9acaed9 24Build package utility from PLD Linux CVS repository
ebaff775 25v0.14 (C) 1999-2006 Free Penguins".
d6a77ddb 26PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
b03f053b 27
cd445739 28COMMAND="build"
64ea5308 29TARGET=""
cd445739 30
bde1c404 31SPECFILE=""
d287305c 32BE_VERBOSE=""
4003ad8c 33QUIET=""
cd445739
AM
34CLEAN=""
35DEBUG=""
36NOURLS=""
37NOCVS=""
38NOCVSSPEC=""
39NODIST=""
40UPDATE=""
41UPDATE5=""
42ADD5=""
43NO5=""
44ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
c8f50498 45CVSROOT=""
cd445739
AM
46
47# It can be used i.e. in log file naming.
48# See LOGFILE example.
49DATE=`date +%Y-%m-%d_%H-%M-%S`
50
51# Example: LOGFILE='../log.$PACKAGE_NAME'
52# Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
53# Yes, you can use variable name! Note _single_ quotes!
54LOGFILE=''
55
56LOGDIR=""
57LOGDIROK=""
58LOGDIRFAIL=""
59LASTLOG_FILE=""
60
61CHMOD="no"
62CHMOD_MODE="0444"
63RPMOPTS=""
64BCOND=""
65GROUP_BCONDS="no"
947025e5 66CVSIGNORE_DF="no"
d287305c 67
68PATCHES=""
69SOURCES=""
cd445739 70ICONS=""
d287305c 71PACKAGE_RELEASE=""
72PACKAGE_VERSION=""
73PACKAGE_NAME=""
cd445739
AM
74PROTOCOL="ftp"
75WGET_RETRIES=${MAX_WGET_RETRIES:-0}
76CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
77
78CVSTAG=""
79RES_FILE=""
80
81CVS_SERVER="cvs.pld-linux.org"
82DISTFILES_SERVER="://distfiles.pld-linux.org"
d4730dae 83ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
cd445739 84
36d03934 85DEF_NICE_LEVEL=19
cd445739
AM
86
87FAIL_IF_NO_SOURCES="yes"
88
18e5347d
ER
89# let get_files skip over files which are present to get those damn files fetched
90SKIP_EXISTING_FILES="no"
91
ab4a2b6e
ER
92if [ -x /usr/bin/rpm-getdeps ]; then
93 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
94else
95 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
96fi
97
cd445739
AM
98# Here we load saved user environment used to
99# predefine options set above, or passed to builder
100# in command line.
101# This one reads global system environment settings:
102if [ -f ~/etc/builderrc ]; then
103 . ~/etc/builderrc
104fi
105# And this one cascades settings using user personal
106# builder settings.
107# Example of ~/.builderrc:
108#
109#UPDATE_POLDEK_INDEXES="yes"
110#FETCH_BUILD_REQUIRES="yes"
111#REMOVE_BUILD_REQUIRES="force"
112#GROUP_BCONDS="yes"
113#LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
114#
a83e5405 115SU_SUDO=""
cd445739
AM
116if [ -n "$HOME_ETC" ]; then
117 USER_CFG="$HOME_ETC/.builderrc"
118else
119 USER_CFG=~/.builderrc
120fi
121
122[ -f "$USER_CFG" ] && . "$USER_CFG"
123
06f3864d
AM
124wget --help 2>&1 | grep -q ' \-\-no-check\-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
125
ca2e6c31 126if [ -n "$USE_PROZILLA" ]; then
7e365483
KK
127 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
128 GETURI2="$GETURI"
129 OUTFILEOPT="-O"
ca2e6c31 130elif [ -n "$USE_AXEL" ]; then
cede92b3 131 GETURI="axel -a $AXEL_OPTS"
7e365483
KK
132 GETURI2="$GETURI"
133 OUTFILEOPT="-o"
ca2e6c31 134else
7e365483
KK
135 wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
136 wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
6f9a5d76 137
7e365483
KK
138 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
139 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
140 OUTFILEOPT="-O"
2bc5451f 141fi
11468b23 142
11468b23
AM
143GETLOCAL="cp -a"
144
145if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
146 RPM="rpm"
147 RPMBUILD="rpm"
148else
149 RPM="rpm"
150 RPMBUILD="rpmbuild"
151fi
152
153POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
a83e5405 154POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
11468b23 155
cd445739
AM
156run_poldek()
157{
158 RES_FILE=~/tmp/poldek-exit-status.$RANDOM
159 if [ -n "$LOGFILE" ]; then
160 LOG=`eval echo $LOGFILE`
161 if [ -n "$LASTLOG_FILE" ]; then
162 echo "LASTLOG=$LOG" > $LASTLOG_FILE
163 fi
040282bb 164 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
cd445739
AM
165 return $exit_pldk
166 else
167 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
168 return `cat ${RES_FILE}`
169 rm -rf ${RES_FILE}
170 fi
171}
172
cd445739
AM
173#---------------------------------------------
174# functions
da946cd6 175
5a491465 176usage()
177{
cd445739
AM
178 if [ -n "$DEBUG" ]; then set -xv; fi
179 echo "\
180Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
81f85806 181
cd445739
AM
182[-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
183[{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
184[-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
185[-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
186[-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
187[-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
188[{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
dfe2cb9a 189[-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--show-bconds]
f19103b5 190[--with/--without <feature>] [--define <macro> <value>] <package>[.spec][:cvstag]
2a5f078d 191
cd445739
AM
192-5, --update-md5 - update md5 comments in spec, implies -nd -ncs
193-a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
194-n5, --no-md5 - ignore md5 comments in spec
9243e80b
ER
195-D, --debug - enable builder script debugging mode,
196-debug - produce rpm debug package (same as --opts -debug)
cd445739
AM
197-V, --version - output builder version
198-a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
199-b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
200 from <package>.spec,
201-bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
202 only package from <package>.spec,
c56807e0
ER
203-bp, --build-prep - execute the %prep phase of <package>.spec,
204-bc - reserved (not implemented)
205-bi reserved (not implemented)
cd445739
AM
206-bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
207 them into src.rpm,
c56807e0 208--short-circuit - reserved (not implemented)
cd445739
AM
209-B, --branch - add branch
210-c, --clean - clean all temporarily created files (in BUILD, SOURCES,
211 SPECS and \$RPM_BUILD_ROOT),
2a5f078d 212-d <cvsroot>, --cvsroot <cvsroot>
cd445739
AM
213 - setup \$CVSROOT,
214--define <macro> <value>
215 - define a macro <macro> with value <value>,
216--nodeps - rpm won't check any dependences
217-g, --get - get <package>.spec and all related files from CVS repo
218 or HTTP/FTP,
219-h, --help - this message,
220--http - use http instead of ftp,
221-l <logfile>, --logtofile <logfile>
222 - log all to file,
223-m, --mr-proper - only remove all files related to spec file and all work
224 resources,
225-nc, --no-cvs - don't download sources from CVS, if source URL is given,
226-ncs, --no-cvs-specs
227 - don't check specs in CVS
228-nd, --no-distfiles - don't download from distfiles
229-nm, --no-mirrors - don't download from mirror, if source URL is given,
230-nu, --no-urls - don't try to download from FTP/HTTP location,
231-ns, --no-srcs - don't download Sources
232-ns0, --no-source0 - don't download Source0
233-nn, --no-net - don't download anything from the net
18e5347d
ER
234-ske,
235--skip-existing-files - skip existing files in get_files
cd445739
AM
236--opts <rpm opts> - additional options for rpm
237-q, --quiet - be quiet,
238--date yyyy-mm-dd - build package using resources from specified CVS date,
239-r <cvstag>, --cvstag <cvstag>
240 - build package using resources from specified CVS tag,
241-R, --fetch-build-requires
242 - fetch what is BuildRequired,
243-RB, --remove-build-requires
244 - remove all you fetched with -R or --fetch-build-requires
245 remember, this option requires confirmation,
246-FRB, --force-remove-build-requires
247 - remove all you fetched with -R or --fetch-build-requires
248 remember, this option works without confirmation,
a7eefc54 249-sf, --source-files - list sources - bare filenames (intended for offline
250 operations; does not work when Icon field is present
251 but icon file is absent),
252-sp, --source-paths - list sources - filenames with full local paths (intended for
253 offline operations; does not work when Icon field is present
254 but icon file is absent),
2dddf439
ER
255-su, --source-urls - list urls - urls to sources and patches
256 intended for copying urls with spec with lots of macros in urls
cd445739
AM
257-T <cvstag> , --tag <cvstag>
258 - add cvs tag <cvstag> for files,
259-Tvs, --tag-version-stable
094bd95b 260 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
cd445739 261-Tvn, --tag-version-nest
1691a37b 262 - add cvs tags NEST and NAME-VERSION-RELEASE for files,
cd445739
AM
263-Ts, --tag-stable
264 - add cvs tag STABLE for files,
265-Tn, --tag-nest
266 - add cvs tag NEST for files,
267-Tv, --tag-version
1691a37b 268 - add cvs tag NAME-VERSION-RELEASE for files,
cd445739
AM
269-Tp, --tag-prefix <prefix>
270 - add <prefix> to NAME-VERSION-RELEASE tags,
271-tt, --test-tag <prefix>
272 - fail if tag is already present,
50321881
JK
273-ir, --integer-release-only
274 - allow only integer and snapshot releases
cd445739
AM
275-v, --verbose - be verbose,
276-u, --try-upgrade - check version, and try to upgrade package
277-un, --try-upgrade-with-float-version
278 - as above, but allow float version
deccc50e 279-U, --update - refetch sources, don't use distfiles, and update md5 comments
cd445739
AM
280-Upi, --update-poldek-indexes
281 - refresh or make poldek package index files.
c890b916 282-np, --nopatch <patchnumber>
bed98670 283 - don't apply <patchnumber>
dfe2cb9a
MK
284--show-bconds - show available conditional builds, which can be used
285 - with --with and/or --without switches.
cd445739
AM
286--with/--without <feature>
287 - conditional build package depending on %_with_<feature>/
288 %_without_<feature> macro switch. You may now use
289 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
290 constructions. Set GROUP_BCONDS to yes to make use of it.
6dd19291 291--target <platform>, --target=<platform>
64ea5308 292 - build for platform <platform>.
5a491465 293"
294}
295
c890b916 296update_shell_title() {
a0d6396b 297 [ -t 1 ] || return
0b65d15e
ER
298 local len=${COLUMNS:-80}
299 local msg=$(echo "$*" | cut -c-$len)
300
8aa5bc76 301 echo >&2 "$(date +%s.%N) $*"
f2e42a41 302 msg="builder[$SPECFILE] ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
c890b916
ER
303 case "$TERM" in
304 cygwin|xterm*)
2dddf439 305 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
c890b916
ER
306 ;;
307 screen*)
2dddf439 308 echo >&2 -ne "\033]0;$msg\007"
c890b916
ER
309 ;;
310 esac
311}
312
7e40520f
ER
313# set TARGET from BuildArch: from SPECFILE
314set_spec_target() {
315 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
316 tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE)
317 if [ "$tmp" ]; then
318 TARGET="$tmp"
319 case "$RPMBUILD" in
320 "rpmbuild")
321 TARGET_SWITCH="--target $TARGET" ;;
322 "rpm")
323 TARGET_SWITCH="--target=$TARGET" ;;
324 esac
325 fi
326 fi
327}
328
cd445739 329cache_rpm_dump () {
b2aeec7d
AM
330 if [ -n "$DEBUG" ]; then
331 set -x;
332 set -v;
333 fi
7e40520f 334
13974367 335 update_shell_title "cache_rpm_dump"
cd445739 336rpm_dump_cache=`
fa4bf1df
ER
337 # we reset macros not to contain macros.build as all the %() macros are
338 # executed here, while none of them are actually needed
339 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
340 # macros.build + macros contained at the time of this writing 70 %() macros
341 local macrofiles='/usr/lib/rpm/macros:~/etc/.rpmmacros:~/.rpmmacros'
ebaff775 342 local dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
7cb24972
ER
343 # FIXME: better ideas than .rpmrc?
344 printf 'include:/usr/lib/rpm/rpmrc\nmacrofiles:%s\n' $macrofiles > .rpmrc
cd445739
AM
345 case "$RPMBUILD" in
346 rpm )
7cb24972 347 rpm --rcfile .rpmrc -bp --nodeps --define "prep $dump" $BCOND $TARGET_SWITCH $SPECFILE 2>&1
cd445739
AM
348 ;;
349 rpmbuild )
c94b1395 350 rpmbuild --rcfile .rpmrc --nodigest --nodeps --nosignature --nobuild --define "prep $dump" $BCOND $TARGET_SWITCH $SPECFILE 2>&1
cd445739
AM
351 ;;
352 esac`
7cb24972
ER
353# if [ $? -gt 0 ]; then
354# echo "$rpm_dump_cache" | sed -ne '/^error:/,$p' >&2
355# Exit_error err_build_fail;
356# fi
13974367 357 update_shell_title "cache_rpm_dump: OK!"
cd445739
AM
358}
359
360rpm_dump () {
361 if [ -z "$rpm_dump_cache" ] ; then
362 echo "internal error: cache_rpm_dump not called!" 1>&2
363 fi
364 echo "$rpm_dump_cache"
365}
366
59398507 367parse_spec()
368{
af4d5315 369 update_shell_title "parsing specfile"
cd445739
AM
370 if [ -n "$DEBUG" ]; then
371 set -x;
372 set -v;
373 fi
b2975fc3 374
cd445739 375 cd $SPECS_DIR
cd445739 376 cache_rpm_dump
00fcec7e 377
cd445739
AM
378 if [ "$NOSRCS" != "yes" ]; then
379 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
380 fi
7cb24972 381
cd445739
AM
382 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
383 FAIL_IF_NO_SOURCES="no"
384 fi
385
386 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
387 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
fa4bf1df
ER
388 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3}')
389 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3}')
390 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3}')
78eab2a1 391
cd445739
AM
392 if [ -n "$BE_VERBOSE" ]; then
393 echo "- Sources : `nourl $SOURCES`"
394 if [ -n "$PATCHES" ]; then
395 echo "- Patches : `nourl $PATCHES`"
396 else
397 echo "- Patches : *no patches needed*"
398 fi
399 if [ -n "$ICONS" ]; then
400 echo "- Icon : `nourl $ICONS`"
401 else
402 echo "- Icon : *no package icon*"
403 fi
404 echo "- Name : $PACKAGE_NAME"
405 echo "- Version : $PACKAGE_VERSION"
406 echo "- Release : $PACKAGE_RELEASE"
407 fi
13974367
ER
408
409 update_shell_title "parse_spec: OK!"
cd445739
AM
410}
411
412Exit_error()
413{
414 if [ -n "$DEBUG" ]; then
415 set -x;
416 set -v;
417 fi
418
419 cd "$__PWD"
420
421 case "$1" in
422 "err_no_spec_in_cmdl" )
423 remove_build_requires
424 echo "ERROR: spec file name not specified.";
425 exit 2 ;;
426 "err_no_spec_in_repo" )
427 remove_build_requires
428 echo "Error: spec file not stored in CVS repo.";
429 exit 3 ;;
430 "err_no_source_in_repo" )
431 remove_build_requires
432 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
433 exit 4 ;;
434 "err_build_fail" )
435 remove_build_requires
436 echo "Error: package build failed. (${2:-no more info})";
437 exit 5 ;;
78eab2a1
AM
438 "err_no_package_data" )
439 remove_build_requires
440 echo "Error: couldn't get out package name/version/release from spec file."
441 exit 6 ;;
50321881
JK
442 "err_tag_exists" )
443 remove_build_requires
444 echo "Tag ${2} already exists (spec release: ${3}).";
445 exit 9 ;;
446 "err_fract_rel" )
447 remove_build_requires
448 echo "Release ${2} not integer and not a snapshot.";
449 exit 10 ;;
fb96e0b5
AM
450 "err_branch_exists" )
451 remove_build_requires
452 echo "Tree branch already exists (${2}).";
453 exit 11 ;;
50321881 454
cd445739 455 esac
50321881 456 echo "Unknown error."
2a5f078d 457 exit 100
cd445739
AM
458}
459
460init_builder()
461{
462 if [ -n "$DEBUG" ]; then
463 set -x;
464 set -v;
0dd6320d 465 fi
cd445739
AM
466
467 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
468 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
469
470 __PWD="`pwd`"
00fcec7e 471}
472
d6a77ddb 473get_spec()
1471f6d6 474{
c890b916 475
2e5be021 476 update_shell_title "get_spec"
c890b916 477
cd445739
AM
478 if [ -n "$DEBUG" ]; then
479 set -x;
480 set -v;
481 fi
482
483 cd "$SPECS_DIR"
049ab214 484 if [ ! -f "$SPECFILE" ]; then
cd445739
AM
485 SPECFILE="`basename $SPECFILE .spec`.spec";
486 fi
487 if [ "$NOCVSSPEC" != "yes" ]; then
cd445739 488
049ab214
ER
489 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
490 echo "Warning: No CVS access defined - using local .spec file"
491 NOCVSSPEC="yes"
cd445739
AM
492 fi
493
049ab214 494 cvsup "$SPECFILE" || Exit_error err_no_spec_in_repo
cd445739 495 fi
049ab214 496
cd445739
AM
497 if [ ! -f "$SPECFILE" ]; then
498 Exit_error err_no_spec_in_repo;
499 fi
500
501 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
502 chmod $CHMOD_MODE $SPECFILE
503 fi
504 unset OPTIONS
a7eefc54 505 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
7e40520f
ER
506
507 set_spec_target
cd445739
AM
508}
509
510find_mirror()
511{
512 cd "$SPECS_DIR"
513 url="$1"
514 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
515 cvs update mirrors >&2
516 fi
517
518 IFS="|"
519 while read origin mirror name rest
520 do
521 ol=`echo -n "$origin"|wc -c`
522 prefix="`echo -n "$url" | head -c $ol`"
523 if [ "$prefix" = "$origin" ] ; then
524 suffix="`echo "$url"|cut -b $ol-`"
525 echo -n "$mirror$suffix"
526 return 0
527 fi
528 done < mirrors
529 echo "$url"
530}
531
532src_no ()
533{
534 cd $SPECS_DIR
535 rpm_dump | \
536 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
537 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
538 head -n 1 | xargs
1471f6d6 539}
540
cd445739 541src_md5 ()
8ba5cdda 542{
cd445739
AM
543 [ X"$NO5" = X"yes" ] && return
544 no=$(src_no "$1")
545 [ -z "$no" ] && return
546 cd $SPECS_DIR
47a8df12 547 spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
cd445739
AM
548 if [ -z "$spec_rev" ]; then
549 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
550 fi
551 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
552 md5=$(grep -s -v '^#' additional-md5sums | \
553 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
554 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
555 grep -E '^[0-9a-f]{32}$')
556 if [ X"$md5" = X"" ] ; then
6203ea52
AG
557 source_md5=`grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
558 if [ ! -z "$source_md5" ] ; then
7e365483 559 echo $source_md5;
6203ea52 560 else
7e365483
KK
561 # we have empty SourceX-md5, but it is still possible
562 # that we have NoSourceX-md5 AND NoSource: X
563 nosource_md5=`grep -i "#[ ]*NoSource$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
564 if [ ! -z "$nosource_md5" -a ! X"`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" = X"" ] ; then
565 echo $nosource_md5;
566 fi;
6203ea52 567 fi;
cd445739
AM
568 else
569 if [ $(echo "$md5" | wc -l) != 1 ] ; then
570 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
571 fi
572 echo "$md5" | tail -n 1
573 fi
574}
575
576distfiles_url ()
577{
1246dc2a 578 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
cd445739
AM
579}
580
581distfiles_attic_url ()
582{
1246dc2a 583 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
cd445739
AM
584}
585
586good_md5 ()
587{
588 md5=$(src_md5 "$1")
589 [ "$md5" = "" ] || \
590 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
8ba5cdda
PG
591}
592
a4b50627
AF
593good_size ()
594{
deccc50e
AM
595 size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)"
596 [ -n "$size" -a "$size" -gt 0 ]
a4b50627
AF
597}
598
947025e5 599cvsignore_df ()
600{
601 if [ "$CVSIGNORE_DF" != "yes" ]; then
602 return
603 fi
604 cvsignore=${SOURCE_DIR}/.cvsignore
605 if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
606 echo "$1" >> $cvsignore
607 fi
608}
609
e7fa3b9f
ER
610cvsup()
611{
612 update_shell_title "cvsup"
613 local OPTIONS="up "
614 if [ -n "$CVSROOT" ]; then
615 OPTIONS="-d $CVSROOT $OPTIONS"
e7fa3b9f 616 fi
b1c6aace 617
e7fa3b9f
ER
618 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
619 OPTIONS="$OPTIONS -A"
620 else
621 if [ -n "$CVSDATE" ]; then
622 OPTIONS="$OPTIONS -D $CVSDATE"
623 fi
624 if [ -n "$CVSTAG" ]; then
625 OPTIONS="$OPTIONS -r $CVSTAG"
626 fi
627 fi
628
629 local result=1
630 local retries_counter=0
631 update_shell_title "cvsup: $# files"
632 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
633 retries_counter=$(( $retries_counter + 1 ))
634 output=$(LC_ALL=C cvs $OPTIONS "$@" 2>&1)
635 result=$?
636 [ -n "$output" ] && echo "$output"
637 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
638 echo "Trying again [$*]... ($retries_counter)"
639 update_shell_title "cvsup: retry #$retries_counter"
640 sleep 2
641 continue
642 else
643 break
644 fi
645 done
646 update_shell_title "cvsup: done!"
049ab214 647 return $result
e7fa3b9f
ER
648}
649
cd445739
AM
650get_files()
651{
7cb24972 652 update_shell_title "get_files"
cd445739
AM
653
654 if [ -n "$DEBUG" ]; then
655 set -x;
656 set -v;
657 fi
658
f09c0772 659 if [ $# -gt 0 ]; then
cd445739
AM
660 cd "$SOURCE_DIR"
661
b1c6aace 662 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
049ab214 663 echo "Warning: No CVS access defined for SOURCES"
b1c6aace
ER
664 NOCVS="yes"
665 fi
666
f2e42a41 667 local nc=0
e7fa3b9f 668 local get_files_cvs=""
3815b69a 669 for i in "$@"; do
f2e42a41 670 nc=$((nc + 1))
dcebdffb 671 local cvsup=0
3815b69a 672 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
f2e42a41 673 update_shell_title "$i"
f09c0772
ER
674 local fp=`nourl "$i"`
675 if [ -f "$fp" ] && [ "$SKIP_EXISTING_FILES" = "yes" ]; then
18e5347d
ER
676 continue
677 fi
cd445739
AM
678 if [ -n "$UPDATE5" ]; then
679 if [ -n "$ADD5" ]; then
f09c0772 680 [ "$fp" = "$i" ] && continue
cd445739
AM
681 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
682 else
683 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
684 fi
685 fi
686 FROM_DISTFILES=0
f09c0772 687 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
cd445739
AM
688 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
689 echo "Warning: no URL given for $i"
690 fi
691
692 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
a4b50627 693 if good_md5 "$i" && good_size "$i"; then
deccc50e 694 echo "$(nourl "$i") having proper md5sum already exists"
cd445739
AM
695 continue
696 fi
4ea1c265 697 target="$fp"
cd445739
AM
698 url=$(distfiles_url "$i")
699 url_attic=$(distfiles_attic_url "$i")
700 FROM_DISTFILES=1
33da77c4 701 if [ "`echo $url | grep -E '^(\.|/)'`" ]; then
18a52930 702 update_shell_title "${GETLOCAL%% *}: $url"
cd445739
AM
703 ${GETLOCAL} $url $target
704 else
705 if [ -z "$NOMIRRORS" ]; then
706 url="`find_mirror "$url"`"
707 fi
18a52930 708 update_shell_title "${GETURI%% *}: $url"
ca2e6c31 709 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
33da77c4 710 if [ "`echo $url | grep -E 'ftp://'`" ]; then
18a52930 711 update_shell_title "${GETURI2%% *}: $url"
ca2e6c31 712 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
cd445739
AM
713 fi
714 fi
715 if ! test -s "$target"; then
716 rm -f "$target"
717 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
18a52930 718 update_shell_title "${GETLOCAL%% *}: $url_attic"
cd445739
AM
719 ${GETLOCAL} $url_attic $target
720 else
721 if [ -z "$NOMIRRORS" ]; then
722 url_attic="`find_mirror "$url_attic"`"
723 fi
18a52930 724 update_shell_title "${GETURI%% *}: $url_attic"
ca2e6c31 725 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
33da77c4 726 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
18a52930 727 update_shell_title "${GETURI2%% *}: $url_attic"
ca2e6c31 728 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
cd445739
AM
729 fi
730 fi
731 fi
947025e5 732 if test -s "$target"; then
733 cvsignore_df $target
734 else
cd445739
AM
735 rm -f "$target"
736 FROM_DISTFILES=0
737 fi
738 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
dcebdffb 739 get_files_cvs="$get_files_cvs $fp"
51616f76 740 update_shell_title "$fp (will cvs up later)"
dcebdffb 741 cvsup=1
cd445739
AM
742 fi
743
f09c0772 744 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
cd445739
AM
745 if [ -z "$NOMIRRORS" ]; then
746 im="`find_mirror "$i"`"
747 else
748 im="$i"
749 fi
18a52930 750 update_shell_title "${GETURI%% *}: $im"
cd445739 751 ${GETURI} "$im" || \
33da77c4 752 if [ "`echo $im | grep -E 'ftp://'`" ]; then
18a52930 753 update_shell_title "${GETURI2%% *}: $im"
cd445739 754 ${GETURI2} "$im"
7e365483 755 fi
cd445739
AM
756 fi
757
dcebdffb
ER
758 if [ "$cvsup" = 1 ]; then
759 continue
760 fi
761
cd445739
AM
762 fi
763 srcno=$(src_no $i)
f09c0772 764 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
cd445739
AM
765 Exit_error err_no_source_in_repo $i;
766 elif [ -n "$UPDATE5" ] && \
767 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
768 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
769 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
770 then
deccc50e 771 echo "Updating source-$srcno md5."
f09c0772 772 md5=$(md5sum "$fp" | cut -f1 -d' ')
cd445739 773 perl -i -ne '
deccc50e
AM
774 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
775 print "# Source'$srcno'-md5:\t'$md5'\n"
cd445739
AM
776 if /^Source'$srcno'\s*:\s+/;
777 ' \
778 $SPECS_DIR/$SPECFILE
779 fi
2a5f078d 780
a4b50627 781 if good_md5 "$i" && good_size "$i"; then
cd445739
AM
782 :
783 elif [ "$FROM_DISTFILES" = 1 ]; then
deccc50e 784 # wrong md5 from distfiles: remove the file and try again
cd445739 785 # but only once ...
deccc50e 786 echo "MD5 sum mismatch. Trying full fetch."
cd445739
AM
787 FROM_DISTFILES=2
788 rm -f $target
18a52930 789 update_shell_title "${GETURI%% *}: $url"
ca2e6c31 790 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
33da77c4 791 if [ "`echo $url | grep -E 'ftp://'`" ]; then
18a52930 792 update_shell_title "${GETURI2%% *}: $url"
ca2e6c31 793 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
cd445739
AM
794 fi
795 if ! test -s "$target"; then
796 rm -f "$target"
18a52930 797 update_shell_title "${GETURI%% *}: $url_attic"
ca2e6c31 798 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
33da77c4 799 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
18a52930 800 update_shell_title "${GETURI2%% *}: $url_attic"
ca2e6c31 801 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
cd445739
AM
802 fi
803 fi
804 test -s "$target" || rm -f "$target"
805 fi
806
a4b50627 807 if good_md5 "$i" && good_size "$i" ; then
cd445739
AM
808 :
809 else
deccc50e
AM
810 echo "MD5 sum mismatch or 0 size. Use -U to refetch sources,"
811 echo "or -5 to update md5 sums, if you're sure files are correct."
cd445739
AM
812 Exit_error err_no_source_in_repo $i
813 fi
814 done
e7fa3b9f
ER
815 SHELL_TITLE_PREFIX=""
816
817 if [ "$get_files_cvs" ]; then
818 cvsup $get_files_cvs
819 fi
cd445739
AM
820
821 if [ "$CHMOD" = "yes" ]; then
3815b69a 822 CHMOD_FILES="`nourl "$@"`"
cd445739
AM
823 if [ -n "$CHMOD_FILES" ]; then
824 chmod $CHMOD_MODE $CHMOD_FILES
825 fi
826 fi
cd445739
AM
827 fi
828}
829
830make_tagver() {
78eab2a1
AM
831
832 if [ -n "$DEBUG" ]; then
833 set -x;
834 set -v;
835 fi
2a5f078d 836
cd445739
AM
837 # Check whether first character of PACKAGE_NAME is legal for tag name
838 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
839 TAG_PREFIX=tag_
840 fi
841 TAGVER=$TAG_PREFIX$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
842 # Remove #kernel.version_release from TAGVER because tagging sources
843 # could occur with different kernel-headers than kernel-headers used at build time.
844 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
845 echo -n "$TAGVER"
846}
847
848tag_files()
849{
850 TAG_FILES="$@"
851
852 if [ -n "$DEBUG" ]; then
853 set -x;
854 set -v;
855 fi
856
857 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
858 echo "Version: $PACKAGE_VERSION"
859 echo "Release: $PACKAGE_RELEASE"
860
861 TAGVER=`make_tagver`
862
863 if [ "$TAG_VERSION" = "yes" ]; then
864 echo "CVS tag: $TAGVER"
865 fi
866 if [ -n "$TAG" ]; then
867 echo "CVS tag: $TAG"
868 fi
869
870 OPTIONS="tag -F"
871 if [ -n "$CVSROOT" ]; then
872 OPTIONS="-d $CVSROOT $OPTIONS"
873 fi
874
875 cd "$SOURCE_DIR"
876 for i in $TAG_FILES
877 do
878 # don't tag files stored on distfiles
879 [ -n "`src_md5 $i`" ] && continue
880 if [ -f "`nourl $i`" ]; then
881 if [ "$TAG_VERSION" = "yes" ]; then
882 cvs $OPTIONS $TAGVER `nourl $i`
883 fi
884 if [ -n "$TAG" ]; then
885 cvs $OPTIONS $TAG `nourl $i`
886 fi
887 else
888 Exit_error err_no_source_in_repo $i
889 fi
890 done
891
892 cd "$SPECS_DIR"
893 if [ "$TAG_VERSION" = "yes" ]; then
894 cvs $OPTIONS $TAGVER $SPECFILE
895 fi
896 if [ -n "$TAG" ]; then
897 cvs $OPTIONS $TAG $SPECFILE
898 fi
899
900 unset OPTIONS
901 fi
902}
903
904branch_files()
905{
906 TAG=$1
907 echo "CVS branch tag: $TAG"
908 shift;
909
910 TAG_FILES="$@"
911
912 if [ -n "$DEBUG" ]; then
913 set -x;
914 set -v;
915 fi
916
917 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
918
919 OPTIONS="tag -b"
920 if [ -n "$CVSROOT" ]; then
921 OPTIONS="-d $CVSROOT $OPTIONS"
922 fi
923 cd "$SOURCE_DIR"
924 for i in $TAG_FILES
925 do
926 if [ -f `nourl $i` ]; then
927 cvs $OPTIONS $TAG `nourl $i`
928 else
929 Exit_error err_no_source_in_repo $i
930 fi
931 done
932 cd "$SPECS_DIR"
933 cvs $OPTIONS $TAG $SPECFILE
934
935 unset OPTIONS
936 fi
937}
938
939
940
59398507 941build_package()
942{
2e5be021 943 update_shell_title "build_package"
cd445739
AM
944 if [ -n "$DEBUG" ]; then
945 set -x;
946 set -v;
947 fi
5a491465 948
cd445739
AM
949 cd "$SPECS_DIR"
950
951 if [ -n "$TRY_UPGRADE" ]; then
2e5be021 952 update_shell_title "build_package: try_upgrade"
cd445739 953 if [ -n "$FLOAT_VERSION" ]; then
cc538c24 954 TNOTIFY=`./pldnotify.awk $SPECFILE -n` || exit 1
cd445739 955 else
cc538c24 956 TNOTIFY=`./pldnotify.awk $SPECFILE` || exit 1
cd445739
AM
957 fi
958
959 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
960
961 if [ -n "$TNEWVER" ]; then
962 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
963 echo "New version found, updating spec file to version " $TNEWVER
964 cp -f $SPECFILE $SPECFILE.bak
965 chmod +w $SPECFILE
966 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
f7b91886 967 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t0.1/' $SPECFILE"
cd445739 968 parse_spec;
7f347798 969 if [ -n "$ICONS" ]; then
970 get_files $ICONS;
971 parse_spec;
972 fi
4ea1c265 973 NODIST="yes" UPDATE5="yes" get_files $SOURCES $PATCHES;
cd445739
AM
974 unset TOLDVER TNEWVER TNOTIFY
975 fi
976 fi
977 cd "$SPECS_DIR"
2a5f078d 978
cd445739
AM
979 case "$COMMAND" in
980 build )
981 BUILD_SWITCH="-ba" ;;
982 build-binary )
983 BUILD_SWITCH="-bb" ;;
984 build-source )
985 BUILD_SWITCH="-bs --nodeps" ;;
986 build-prep )
987 BUILD_SWITCH="-bp --nodeps" ;;
988 esac
c890b916 989
2e5be021 990 update_shell_title "build_package: $COMMAND"
cd445739
AM
991 if [ -n "$LOGFILE" ]; then
992 LOG=`eval echo $LOGFILE`
993 if [ -d "$LOG" ]; then
994 echo "Log file $LOG is a directory."
995 echo "Parse error in the spec?"
996 Exit_error err_build_fail;
997 fi
998 if [ -n "$LASTLOG_FILE" ]; then
999 echo "LASTLOG=$LOG" > $LASTLOG_FILE
1000 fi
1001 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
21bc1a97 1002 (time eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
cd445739
AM
1003 RETVAL=`cat $RES_FILE`
1004 rm $RES_FILE
1005 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1006 if [ "$RETVAL" -eq "0" ]; then
1007 mv $LOG $LOGDIROK
1008 else
1009 mv $LOG $LOGDIRFAIL
1010 fi
1011 fi
8ba5cdda 1012 else
8f96ab6c 1013 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE
cd445739 1014 RETVAL=$?
8ba5cdda 1015 fi
cd445739
AM
1016 if [ "$RETVAL" -ne "0" ]; then
1017 if [ -n "$TRY_UPGRADE" ]; then
1018 echo "\n!!! Package with new version cannot be build automagically\n"
1019 mv -f $SPECFILE.bak $SPECFILE
1020 fi
1021 Exit_error err_build_fail;
1022 fi
1023 unset BUILD_SWITCH
1024}
1025
1026nourl()
1027{
1028 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1029}
1030
cd445739
AM
1031install_required_packages()
1032{
1033 run_poldek -vi $1
1034 return $?
1035}
1036
fa4bf1df
ER
1037find_spec_bcond() {
1038 # taken from find-spec-bcond, but with just getting the list
1039 local SPEC="$1"
1040 # quick revert hint: '$RPMBUILD --bcond $SPEC'
1041 awk -F"\n" '
1042 /^%changelog/ { exit }
1043 /_with(out)?_[_a-zA-Z0-9]+/{
1044 match($0, /_with(out)?_[_a-zA-Z0-9]+/);
1045 print substr($0, RSTART, RLENGTH);
1046 }
1047 /^%bcond_with/{
1048 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1049 bcond = substr($0, RSTART +5 , RLENGTH -5);
1050 gsub(/[ \t]+/,"_",bcond);
1051 print bcond
1052 }' $SPEC | LC_ALL=C sort -u
1053}
1054
cd445739
AM
1055set_bconds_values()
1056{
0b65d15e 1057 update_shell_title "set bcond values"
c890b916 1058
cd445739
AM
1059 AVAIL_BCONDS_WITHOUT=""
1060 AVAIL_BCONDS_WITH=""
1061 if `grep -q ^%bcond ${SPECFILE}`; then
1062 BCOND_VERSION="NEW"
36d03934 1063 elif `egrep -q ^#\ *_with ${SPECFILE}`; then
cd445739
AM
1064 BCOND_VERSION="OLD"
1065 else
fa4bf1df 1066 return
cd445739 1067 fi
301cbfd4 1068
fa4bf1df
ER
1069 local bcond_avail=$(find_spec_bcond $SPECFILE)
1070
301cbfd4
ER
1071 # expand bconds from ~/.bcondrc
1072 # The file structure is like gentoo's package.use:
1073 # ---
1074 # * -selinux
1075 # samba -mysql -pgsql
47a8df12 1076 # w32codec-installer license_agreement
301cbfd4
ER
1077 # php +mysqli
1078 # ---
fa4bf1df 1079 if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then
3e1cbfe0 1080 SN=${SPECFILE%%\.spec}
301cbfd4 1081
fa4bf1df
ER
1082 local bcondrc=$HOME/.bcondrc
1083 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
c8a3e2ac 1084
301cbfd4
ER
1085 while read pkg flags; do
1086 # ignore comments
1087 [[ "$pkg" == \#* ]] && continue
1088
1089 # any package or current package?
fa4bf1df 1090 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
301cbfd4 1091 for flag in $flags; do
fa4bf1df 1092 local opt=${flag#[+-]}
301cbfd4
ER
1093
1094 # use only flags which are in this package.
fa4bf1df 1095 if [[ $bcond_avail = *${opt}* ]]; then
3b5101f0
ER
1096 if [[ $flag = -* ]]; then
1097 BCOND="$BCOND --without $opt"
301cbfd4 1098 else
3b5101f0 1099 BCOND="$BCOND --with $opt"
301cbfd4
ER
1100 fi
1101 fi
1102 done
1103 fi
fa4bf1df
ER
1104 done < $bcondrc
1105 update_shell_title "parse ~/.bcondrc: DONE!"
301cbfd4
ER
1106 fi
1107
fa4bf1df 1108 update_shell_title "parse bconds"
cd445739 1109 case "${BCOND_VERSION}" in
fa4bf1df 1110 NONE)
7e365483 1111 :
cd445739 1112 ;;
7e365483 1113 OLD)
cd445739 1114 echo "Warning: This spec has old style bconds. Fix it || die."
fa4bf1df 1115 for opt in `echo "$bcond_avail" | grep ^_without_`
cd445739 1116 do
fa4bf1df
ER
1117 AVAIL_BCOND_WITHOUT=${opt#_without_}
1118 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
cd445739
AM
1119 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1120 else
1121 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1122 fi
1123 done
2a5f078d 1124
fa4bf1df 1125 for opt in `echo "$bcond_avail" | grep ^_with_`
cd445739 1126 do
fa4bf1df
ER
1127 AVAIL_BCOND_WITH=${opt#_with_}
1128 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
cd445739
AM
1129 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1130 else
1131 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1132 fi
1133 done
1134 ;;
1135 NEW)
fa4bf1df
ER
1136 local cond_type="" # with || without
1137 for opt in $bcond_avail; do
cd445739
AM
1138 case "$opt" in
1139 _without)
1140 cond_type="without"
1141 ;;
1142 _with)
1143 cond_type="with"
1144 ;;
f8d24cee 1145 _without_*)
fa4bf1df
ER
1146 AVAIL_BCOND_WITHOUT=${opt#_without_}
1147 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
f8d24cee 1148 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1149 else
1150 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1151 fi
1152 ;;
1153 _with_*)
fa4bf1df
ER
1154 AVAIL_BCOND_WITH=${opt#_with_}
1155 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
f8d24cee 1156 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1157 else
1158 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1159 fi
1160 ;;
cd445739
AM
1161 *)
1162 case "$cond_type" in
1163 with)
1164 cond_type=''
1165 AVAIL_BCOND_WITH="$opt"
fa4bf1df 1166 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
cd445739
AM
1167 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1168 else
1169 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1170 fi
7e365483 1171 ;;
cd445739
AM
1172 without)
1173 cond_type=''
1174 AVAIL_BCOND_WITHOUT="$opt"
fa4bf1df 1175 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
cd445739
AM
1176 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1177 else
1178 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1179 fi
1180 ;;
1181 esac
1182 ;;
1183 esac
1184 done
1185 ;;
1186 esac
1187}
1188
1189run_sub_builder()
1190{
1191 package_name="${1}"
af6b168f 1192 update_shell_title "run_sub_builder $package_name"
cd445739
AM
1193 #
1194