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