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