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