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