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