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