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