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