]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder.sh
- buildrequires_jdk support
[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}
407b204b
ER
461%requires_releq_kernel_up(s:n:) %{nil}
462%requires_releq_kernel_smp(s:n:) %{nil}
463%requires_releq_kernel(s:n:) %{nil}
6b8134e3 464%requires_releq() %{nil}
bb01dee9 465%pyrequires_eq() %{nil}
559d511f 466%requires_eq() %{nil}
c13be3d1 467%requires_eq_to() %{nil}
407b204b
ER
468%releq_kernel_up(n:) ERROR
469%releq_kernel_smp(n:) ERROR
470%releq_kernel(n:) ERROR
74d9fd14 471%kgcc_package ERROR
237bd3f1 472%_fontsdir ERROR
7141278d 473%ruby_version ERROR
474%ruby_ver_requires_eq() %{nil}
475%ruby_mod_ver_requires_eq() %{nil}
c13be3d1 476%__php_api_requires() %{nil}
7141278d 477%php_major_version ERROR
478%php_api_version ERROR
99f819cf
AM
479%requires_xorg_xserver_extension %{nil}
480%requires_xorg_xserver_xinput %{nil}
481%requires_xorg_xserver_font %{nil}
482%requires_xorg_xserver_videodrv %{nil}
7141278d 483%py_ver ERROR
41035426
ER
484%perl_vendorarch ERROR
485%perl_vendorlib ERROR
703ae20b
ER
486# damn. need it here! - copied from /usr/lib/rpm/macros.build
487%tmpdir %(echo "${TMPDIR:-/tmp}")
1f28fcb7
ER
488%patchset_source(f:b:) %(
489 base=%{-b*}%{!-b*:10000};
490 start=$(expr $base + %1);
491 end=$(expr $base + %{?2}%{!?2:%{1}});
492 # we need to call seq twice as it doesn't allow two formats
493 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
494 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
495 paste %{tmpdir}/__ps{1,2};
496 rm -f %{tmpdir}/__ps{1,2};
497) \
498%{nil}
991f09a5
ER
499%add_etc_shells(p) %{p:<lua>}
500%remove_etc_shells(p) %{p:<lua>}
709995c4
ER
501%lua_add_etc_shells() %{nil}
502%lua_remove_etc_shells() %{nil}
0ca65fa4
JK
503%required_jdk %{nil}
504%buildrequires_jdk %{nil}
fb198857 505EOF
3d12d055 506 if [ "$NOINIT" = "yes" ] ; then
20117088 507 cat >> $BUILDER_MACROS <<'EOF'
3d12d055
JR
508%_specdir ./
509%_sourcedir ./
510EOF
c039643c 511 fi
fff1b991 512 eval $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
ace3fd80
ER
513}
514
515cache_rpm_dump() {
516 if [ -n "$DEBUG" ]; then
517 set -x
518 set -v
519 fi
520
d1d24c14 521 if [ -x /usr/bin/rpm-specdump ]; then
525bf240 522 update_shell_title "cache_rpm_dump using rpm-specdump command"
fff1b991 523 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND $SPECFILE)
d1d24c14 524 else
525bf240 525 update_shell_title "cache_rpm_dump using rpmbuild command"
d1d24c14
ER
526 local rpm_dump
527 rpm_dump=`
528 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
529 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
530 case "$RPMBUILD" in
531 rpm)
532 ARGS='-bp'
533 ;;
534 rpmbuild)
535 ARGS='--nodigest --nosignature --nobuild'
536 ;;
537 esac
538 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
539 `
540 if [ $? -gt 0 ]; then
541 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
542 echo "$error" >&2
543 Exit_error err_build_fail
544 fi
d05e8080 545
d1d24c14
ER
546 # make small dump cache
547 rpm_dump_cache=`echo "$rpm_dump" | awk '
548 $2 ~ /^SOURCEURL/ {print}
549 $2 ~ /^PATCHURL/ {print}
550 $2 ~ /^nosource/ {print}
551 $2 ~ /^PACKAGE_/ {print}
552 '`
553 fi
d05e8080 554
13974367 555 update_shell_title "cache_rpm_dump: OK!"
cd445739
AM
556}
557
ace3fd80 558rpm_dump() {
cd445739 559 if [ -z "$rpm_dump_cache" ] ; then
45e2a818 560 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
cd445739
AM
561 fi
562 echo "$rpm_dump_cache"
563}
564
f6711e2a 565get_icons() {
d05e8080 566 update_shell_title "get icons"
9d99a240 567 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
d05e8080
ER
568 if [ -z "$ICONS" ]; then
569 return
570 fi
571
975d7b23 572 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
d05e8080
ER
573}
574
f6711e2a 575parse_spec() {
af4d5315 576 update_shell_title "parsing specfile"
cd445739 577 if [ -n "$DEBUG" ]; then
518ff1fb
ER
578 set -x
579 set -v
cd445739 580 fi
b2975fc3 581
d05e8080 582 # icons are needed for successful spec parse
518ff1fb 583 get_icons
d05e8080 584
9c909460 585 cd $PACKAGE_DIR
cd445739 586 cache_rpm_dump
00fcec7e 587
cd445739
AM
588 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
589 FAIL_IF_NO_SOURCES="no"
590 fi
591
7cbc2d88
ER
592 if [ "$NOSRCS" != "yes" ]; then
593 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
594 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
595 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
596 fi
597
dfe2b2d9
ER
598 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
599 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
600 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
78eab2a1 601
0b4119a2 602 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
7854d40c 603 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
0b4119a2
JR
604 fi
605
cd445739
AM
606 if [ -n "$BE_VERBOSE" ]; then
607 echo "- Sources : `nourl $SOURCES`"
608 if [ -n "$PATCHES" ]; then
609 echo "- Patches : `nourl $PATCHES`"
610 else
611 echo "- Patches : *no patches needed*"
612 fi
613 if [ -n "$ICONS" ]; then
614 echo "- Icon : `nourl $ICONS`"
615 else
616 echo "- Icon : *no package icon*"
617 fi
618 echo "- Name : $PACKAGE_NAME"
619 echo "- Version : $PACKAGE_VERSION"
620 echo "- Release : $PACKAGE_RELEASE"
621 fi
13974367
ER
622
623 update_shell_title "parse_spec: OK!"
cd445739
AM
624}
625
f6711e2a 626Exit_error() {
cd445739 627 if [ -n "$DEBUG" ]; then
518ff1fb
ER
628 set -x
629 set -v
cd445739
AM
630 fi
631
632 cd "$__PWD"
633
634 case "$1" in
635 "err_no_spec_in_cmdl" )
636 remove_build_requires
45e2a818 637 echo >&2 "ERROR: spec file name not specified."
cd445739 638 exit 2 ;;
a08d92fc 639 "err_invalid_cmdline" )
45e2a818 640 echo >&2 "ERROR: invalid command line arg ($2)."
a08d92fc 641 exit 2 ;;
cd445739
AM
642 "err_no_spec_in_repo" )
643 remove_build_requires
45e2a818 644 echo >&2 "Error: spec file not stored in CVS repo."
cd445739
AM
645 exit 3 ;;
646 "err_no_source_in_repo" )
647 remove_build_requires
45e2a818 648 echo >&2 "Error: some source, patch or icon files not stored in CVS repo. ($2)"
cd445739
AM
649 exit 4 ;;
650 "err_build_fail" )
651 remove_build_requires
45e2a818 652 echo >&2 "Error: package build failed. (${2:-no more info})"
cd445739 653 exit 5 ;;
78eab2a1
AM
654 "err_no_package_data" )
655 remove_build_requires
45e2a818 656 echo >&2 "Error: couldn't get out package name/version/release from spec file."
78eab2a1 657 exit 6 ;;
ce40491a 658 "err_tag_exists" )
50321881 659 remove_build_requires
45e2a818 660 echo >&2 "Tag ${2} already exists (spec release: ${3})."
50321881 661 exit 9 ;;
ce40491a 662 "err_fract_rel" )
50321881 663 remove_build_requires
45e2a818 664 echo >&2 "Release ${2} not integer and not a snapshot."
50321881 665 exit 10 ;;
fb96e0b5
AM
666 "err_branch_exists" )
667 remove_build_requires
45e2a818 668 echo >&2 "Tree branch already exists (${2})."
fb96e0b5 669 exit 11 ;;
cfc497c0
ER
670 "err_acl_deny" )
671 remove_build_requires
45e2a818 672 echo >&2 "Error: conditions reject building this spec (${2})."
cfc497c0 673 exit 12 ;;
cd445739 674 esac
45e2a818 675 echo >&2 "Unknown error."
73848362 676 exit 100
cd445739
AM
677}
678
f6711e2a 679init_builder() {
cd445739 680 if [ -n "$DEBUG" ]; then
518ff1fb
ER
681 set -x
682 set -v
0dd6320d 683 fi
cd445739 684
4aeb9973 685 if [ "$NOINIT" != "yes" ] ; then
9c909460 686 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
b7cc0c94 687
09bf17c9 688 local macros_ver=$(rpm -E %?rpm_build_macros)
b7cc0c94
ER
689 if [ -z "$macros_ver" ]; then
690 REPO_DIR=$TOP_DIR/packages
691 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
692 else
693 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
694 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
695 exit 1
696 fi
697 REPO_DIR=$TOP_DIR
698 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
699 fi
29e90b02 700 else
9c909460
AM
701 REPO_DIR="."
702 PACKAGE_DIR="."
29e90b02 703 fi
cd445739 704
a8c9a155 705 __PWD=$(pwd)
00fcec7e 706}
707
f6711e2a 708get_spec() {
c890b916 709
2e5be021 710 update_shell_title "get_spec"
c890b916 711
cd445739 712 if [ -n "$DEBUG" ]; then
518ff1fb
ER
713 set -x
714 set -v
cd445739
AM
715 fi
716
9c909460
AM
717 cd "$REPO_DIR"
718 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
6277f15f
ER
719 # XXX: still needed?
720 SPECFILE=$(basename $SPECFILE)
cd445739
AM
721 fi
722 if [ "$NOCVSSPEC" != "yes" ]; then
cd445739 723
049ab214
ER
724 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
725 echo "Warning: No CVS access defined - using local .spec file"
726 NOCVSSPEC="yes"
cd445739
AM
727 fi
728
9c909460
AM
729 if [ -d "$ASSUMED_NAME" ]; then
730 cvsup "$ASSUMED_NAME/$SPECFILE" || Exit_error err_no_spec_in_repo
731 else
732 cvsup -c -d $ASSUMED_NAME "packages/$ASSUMED_NAME/$SPECFILE" || Exit_error err_no_spec_in_repo
f123bcb5
ER
733
734 # remove Entries.Static -- so 'cvs up' would update all files in a repo
735 rm "$ASSUMED_NAME/CVS/Entries.Static"
80cef3c1 736 cvsignore_df .cvsignore
f123bcb5
ER
737
738 # create symlinks for tools
daeab113 739 if [ "$SYMLINK_TOOLS" != "no" ]; then
387eaf99 740 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh; do
daeab113
JR
741 [ -f $a ] || continue
742 ln -s ../$a $ASSUMED_NAME
743 cvsignore_df $a
744 done
745 fi
9c909460 746 fi
cd445739 747 fi
049ab214 748
9c909460 749 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
518ff1fb 750 Exit_error err_no_spec_in_repo
cd445739
AM
751 fi
752
753 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
9c909460 754 chmod $CHMOD_MODE $ASSUMED_NAME/$SPECFILE
cd445739
AM
755 fi
756 unset OPTIONS
9c909460 757 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $ASSUMED_NAME/$SPECFILE
7e40520f 758
ce40491a 759 set_spec_target
cd445739
AM
760}
761
f6711e2a 762find_mirror() {
9c909460 763 cd "$REPO_DIR"
782518da 764 local url="$1"
cd445739 765 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
939f2c12 766 $CVS_COMMAND update mirrors >&2
cd445739
AM
767 fi
768
769 IFS="|"
782518da
ER
770 local origin mirror name rest ol prefix
771 while read origin mirror name rest; do
772 # skip comments and empty lines
2faa4c32 773 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
782518da
ER
774 continue
775 fi
a8c9a155
ER
776 ol=$(echo -n "$origin" | wc -c)
777 prefix=$(echo -n "$url" | head -c $ol)
cd445739 778 if [ "$prefix" = "$origin" ] ; then
a8c9a155 779 suffix=$(echo "$url" | cut -b $((ol+1))-)
cd445739
AM
780 echo -n "$mirror$suffix"
781 return 0
782 fi
783 done < mirrors
784 echo "$url"
785}
786
e7e0d4ec 787# Warning: unpredictable results if same URL used twice
f6711e2a 788src_no() {
9c909460 789 cd $PACKAGE_DIR
cd445739
AM
790 rpm_dump | \
791 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
792 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
793 head -n 1 | xargs
1471f6d6 794}
795
f6711e2a 796src_md5() {
e7e0d4ec 797 [ "$NO5" = "yes" ] && return
cd445739
AM
798 no=$(src_no "$1")
799 [ -z "$no" ] && return
9c909460 800 cd $PACKAGE_DIR
e7e0d4ec
ER
801 local md5
802
803 if [ -f additional-md5sums ]; then
804 local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
805 if [ -z "$spec_rev" ]; then
a8c9a155 806 spec_rev=$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')
e7e0d4ec
ER
807 fi
808 local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
809 md5=$(grep -s -v '^#' additional-md5sums | \
810 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
811 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
812 grep -E '^[0-9a-f]{32}$')
813
814 if [ "$md5" ]; then
815 if [ $(echo "$md5" | wc -l) != 1 ] ; then
816 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
817 fi
818 echo "$md5" | tail -n 1
819 return
820 fi
cd445739 821 fi
e7e0d4ec 822
657d488b 823 source_md5=`grep -i "^#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
e7e0d4ec
ER
824 if [ -n "$source_md5" ]; then
825 echo $source_md5
cd445739 826 else
7805dcb4
PZ
827 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
828 if [ -n "$source_md5" ]; then
829 echo $source_md5
830 else
831 # we have empty SourceX-md5, but it is still possible
832 # that we have NoSourceX-md5 AND NoSource: X
657d488b 833 nosource_md5=`grep -i "^#[ ]*NoSource$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
7805dcb4
PZ
834 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
835 echo $nosource_md5
836 fi
cd445739 837 fi
cd445739
AM
838 fi
839}
840
f6711e2a 841distfiles_path() {
06541433
JR
842 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
843}
844
f6711e2a 845distfiles_url() {
06541433 846 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
cd445739
AM
847}
848
f6711e2a 849distfiles_attic_url() {
06541433 850 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
cd445739
AM
851}
852
f6711e2a 853good_md5() {
cd445739
AM
854 md5=$(src_md5 "$1")
855 [ "$md5" = "" ] || \
856 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
8ba5cdda
PG
857}
858
f6711e2a 859good_size() {
a8c9a155 860 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
ce40491a 861 [ -n "$size" -a "$size" -gt 0 ]
a4b50627
AF
862}
863
f6711e2a 864cvsignore_df() {
947025e5 865 if [ "$CVSIGNORE_DF" != "yes" ]; then
866 return
867 fi
9c909460 868 cvsignore=${PACKAGE_DIR}/.cvsignore
7dc8d095
ER
869
870 # add only if not yet there
aa189b05 871 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
947025e5 872 echo "$1" >> $cvsignore
873 fi
874}
875
f6711e2a 876cvsup() {
ce40491a
ER
877 update_shell_title "cvsup"
878 local OPTIONS="up "
9c909460
AM
879
880 if [ "$1" = "-c" ]; then
881 OPTIONS="co "
882 shift
883 fi
ce40491a
ER
884 if [ -n "$CVSROOT" ]; then
885 OPTIONS="-d $CVSROOT $OPTIONS"
886 fi
b1c6aace 887
ce40491a
ER
888 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
889 OPTIONS="$OPTIONS -A"
890 else
891 if [ -n "$CVSDATE" ]; then
892 OPTIONS="$OPTIONS -D $CVSDATE"
893 fi
894 if [ -n "$CVSTAG" ]; then
895 OPTIONS="$OPTIONS -r $CVSTAG"
896 fi
897 fi
e7fa3b9f 898
ce40491a
ER
899 local result=1
900 local retries_counter=0
901 if [ $# = 1 ]; then
902 update_shell_title "cvsup: $*"
903 else
904 update_shell_title "cvsup: $# files"
905 fi
906 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
907 retries_counter=$(( $retries_counter + 1 ))
939f2c12 908 output=$(LC_ALL=C $CVS_COMMAND $OPTIONS "$@" 2>&1)
ce40491a
ER
909 result=$?
910 [ -n "$output" ] && echo "$output"
911 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
912 echo "Trying again [$*]... ($retries_counter)"
913 update_shell_title "cvsup: retry #$retries_counter"
914 sleep 2
915 continue
916 else
917 break
918 fi
919 done
920 update_shell_title "cvsup: done!"
921 return $result
e7fa3b9f
ER
922}
923
71f8e908 924# returns true if "$1" is ftp, http or https protocol url
f6711e2a 925is_url() {
71f8e908
ER
926 case "$1" in
927 ftp://*|http://*|https://*)
928 return 0
929 ;;
930 esac
931 return 1
932}
933
f6711e2a 934update_md5() {
ecba6ad5
ER
935 if [ $# -eq 0 ]; then
936 return
937 fi
938
939 update_shell_title "update md5"
940 if [ -n "$DEBUG" ]; then
518ff1fb
ER
941 set -x
942 set -v
ecba6ad5
ER
943 fi
944
9c909460 945 cd "$PACKAGE_DIR"
ecba6ad5
ER
946
947 # pass 1: check files to be fetched
948 local todo
949 local need_files
950 for i in "$@"; do
951 local fp=$(nourl "$i")
952 local srcno=$(src_no "$i")
6392b5fd
ER
953 if [ -n "$ADD5" ]; then
954 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
9c909460
AM
955 grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
956 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
6392b5fd 957 else
9c909460 958 grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
ecba6ad5
ER
959 fi
960 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
961 need_files="$need_files $i"
962 fi
963 done
964
965 # pass 1a: get needed files
966 if [ "$need_files" ]; then
967 get_files $need_files
968 fi
969
970 # pass 2: proceed with md5 adding or updating
971 for i in "$@"; do
972 local fp=$(nourl "$i")
973 local srcno=$(src_no "$i")
9c909460 974 local md5=$(grep -iE '^#[ ]*(No)?Source'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
e19ad799 975 if [ -z "$md5" ]; then
9c909460 976 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
6c1b2e7d 977 fi
71f8e908 978 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
6c1b2e7d 979 local tag="# Source$srcno-md5:\t"
71f8e908 980 if [[ "$md5" == *NoSource* ]]; then
6c1b2e7d
PZ
981 tag="# NoSource$srcno-md5:\t"
982 elif [ -n "$USEDIGEST" ]; then
983 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
71f8e908 984 fi
ecba6ad5 985 md5=$(md5sum "$fp" | cut -f1 -d' ')
15bf3e99 986 echo "Updating Source$srcno ($md5: $fp)."
ecba6ad5 987 perl -i -ne '
6c1b2e7d
PZ
988 print unless (/^\s*#\s*(No)?Source'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
989 print "'"$tag$md5"'\n" if /^Source'$srcno'\s*:\s+/;
ecba6ad5 990 ' \
9c909460 991 $PACKAGE_DIR/$SPECFILE
ecba6ad5
ER
992 fi
993 done
994}
995
f6711e2a 996check_md5() {
60499e54 997 local bad
3fbff8b8
ER
998 [ "$NO5" = "yes" ] && return
999
ecba6ad5
ER
1000 update_shell_title "check md5"
1001
1002 for i in "$@"; do
60499e54
AM
1003 bad=0
1004 if ! good_md5 "$i"; then
1005 echo -n "MD5 sum mismatch."
1006 bad=1
1007 fi
1008 if ! good_size "$i"; then
1009 echo -n "0 sized file."
1010 bad=1
ecba6ad5
ER
1011 fi
1012
60499e54
AM
1013 if [ $bad -eq 1 ]; then
1014 echo " Use -U to refetch sources,"
1015 echo "or -5 to update md5 sums, if you're sure files are correct."
1016 Exit_error err_no_source_in_repo $i
1017 fi
ecba6ad5
ER
1018 done
1019}
1020
f6711e2a 1021get_files() {
7cb24972 1022 update_shell_title "get_files"
cd445739
AM
1023
1024 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1025 set -x
1026 set -v
cd445739
AM
1027 fi
1028
f09c0772 1029 if [ $# -gt 0 ]; then
9c909460 1030 cd "$PACKAGE_DIR"
cd445739 1031
b1c6aace 1032 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
049ab214 1033 echo "Warning: No CVS access defined for SOURCES"
b1c6aace
ER
1034 NOCVS="yes"
1035 fi
1036
f2e42a41 1037 local nc=0
e7fa3b9f 1038 local get_files_cvs=""
3815b69a 1039 for i in "$@"; do
f2e42a41 1040 nc=$((nc + 1))
dcebdffb 1041 local cvsup=0
3815b69a 1042 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
f2e42a41 1043 update_shell_title "$i"
f09c0772 1044 local fp=`nourl "$i"`
ecba6ad5 1045 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
ce40491a 1046 continue
18e5347d 1047 fi
ecba6ad5 1048
cd445739 1049 FROM_DISTFILES=0
e7e0d4ec 1050 local srcmd5=$(src_md5 "$i")
ecba6ad5
ER
1051
1052 # we know if source/patch is present in cvs/distfiles
1053 # - has md5 (in distfiles)
1054 # - in cvs... ideas?
1055
1056 # CHECK: local file didn't exist or always cvs up (first) requested.
f09c0772 1057 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
cd445739
AM
1058 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1059 echo "Warning: no URL given for $i"
1060 fi
08908161 1061 target="$fp"
cd445739 1062
e7e0d4ec 1063 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
a4b50627 1064 if good_md5 "$i" && good_size "$i"; then
e7e0d4ec 1065 echo "$fp having proper md5sum already exists"
cd445739
AM
1066 continue
1067 fi
28b34560 1068
bc10f694 1069 # optionally prefer mirror over distfiles if there's mirror
28b34560 1070 # TODO: build url list and then try each url from the list
bc10f694 1071 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
28b34560
ER
1072 url="$im"
1073 else
1074 url=$(distfiles_url "$i")
1075 fi
1076
cd445739
AM
1077 url_attic=$(distfiles_attic_url "$i")
1078 FROM_DISTFILES=1
ecba6ad5
ER
1079 # is $url local file?
1080 if [[ "$url" = [./]* ]]; then
18a52930 1081 update_shell_title "${GETLOCAL%% *}: $url"
cd445739
AM
1082 ${GETLOCAL} $url $target
1083 else
1084 if [ -z "$NOMIRRORS" ]; then
9e9f8920 1085 url=$(find_mirror "$url")
cd445739 1086 fi
9e9f8920
ER
1087
1088 local uri=${url}
1089 # make shorter message for distfiles urls
1090 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1091 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1092 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1093 uri="df: $uri"
1094 fi
1095 update_shell_title "${GETURI%% *}: $uri"
ca2e6c31 1096 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
33da77c4 1097 if [ "`echo $url | grep -E 'ftp://'`" ]; then
18a52930 1098 update_shell_title "${GETURI2%% *}: $url"
ca2e6c31 1099 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
cd445739
AM
1100 fi
1101 fi
ecba6ad5
ER
1102
1103 # is it empty file?
1104 if [ ! -s "$target" ]; then
cd445739
AM
1105 rm -f "$target"
1106 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
18a52930 1107 update_shell_title "${GETLOCAL%% *}: $url_attic"
cd445739
AM
1108 ${GETLOCAL} $url_attic $target
1109 else
1110 if [ -z "$NOMIRRORS" ]; then
a8c9a155 1111 url_attic=$(find_mirror "$url_attic")
cd445739 1112 fi
18a52930 1113 update_shell_title "${GETURI%% *}: $url_attic"
ca2e6c31 1114 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
33da77c4 1115 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
ce40491a 1116 update_shell_title "${GETURI2%% *}: $url_attic"
ca2e6c31 1117 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
cd445739 1118 fi
1cd7fc57 1119 test -s "$target" || rm -f "$target"
cd445739
AM
1120 fi
1121 fi
ecba6ad5
ER
1122
1123 if [ -s "$target" ]; then
947025e5 1124 cvsignore_df $target
1125 else
cd445739
AM
1126 rm -f "$target"
1127 FROM_DISTFILES=0
1128 fi
e7e0d4ec 1129 elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then
d05e8080
ER
1130 if [ $# -gt 1 ]; then
1131 get_files_cvs="$get_files_cvs $fp"
1132 update_shell_title "$fp (will cvs up later)"
1133 cvsup=1
1134 else
1135 cvsup $fp
1136 fi
cd445739
AM
1137 fi
1138
f09c0772 1139 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
cd445739 1140 if [ -z "$NOMIRRORS" ]; then
a8c9a155 1141 im=$(find_mirror "$i")
cd445739
AM
1142 else
1143 im="$i"
1144 fi
ce40491a 1145 update_shell_title "${GETURI%% *}: $im"
08908161 1146 ${GETURI} "$im" ${OUTFILEOPT} "$target" || \
33da77c4 1147 if [ "`echo $im | grep -E 'ftp://'`" ]; then
ce40491a 1148 update_shell_title "${GETURI2%% *}: $im"
08908161 1149 ${GETURI2} "$im" ${OUTFILEOPT} "$target"
7e365483 1150 fi
1cd7fc57 1151 test -s "$target" || rm -f "$target"
cd445739
AM
1152 fi
1153
dcebdffb
ER
1154 if [ "$cvsup" = 1 ]; then
1155 continue
1156 fi
1157
cd445739 1158 fi
ecba6ad5
ER
1159
1160 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
f09c0772 1161 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
cdbd30e8 1162 if [ -n "GREEDSRC" ]; then
1163 get_greed_sources $i
1164 else
1165 Exit_error err_no_source_in_repo $i
1166 fi
cd445739 1167 fi
2a5f078d 1168
ecba6ad5 1169 # we check md5 here just only to refetch immediately
a4b50627 1170 if good_md5 "$i" && good_size "$i"; then
cd445739
AM
1171 :
1172 elif [ "$FROM_DISTFILES" = 1 ]; then
deccc50e 1173 # wrong md5 from distfiles: remove the file and try again
cd445739 1174 # but only once ...
deccc50e 1175 echo "MD5 sum mismatch. Trying full fetch."
cd445739
AM
1176 FROM_DISTFILES=2
1177 rm -f $target
18a52930 1178 update_shell_title "${GETURI%% *}: $url"
ca2e6c31 1179 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
33da77c4 1180 if [ "`echo $url | grep -E 'ftp://'`" ]; then
ce40491a 1181 update_shell_title "${GETURI2%% *}: $url"
ca2e6c31 1182 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
cd445739 1183 fi
ecba6ad5 1184 if [ ! -s "$target" ]; then
cd445739 1185 rm -f "$target"
18a52930 1186 update_shell_title "${GETURI%% *}: $url_attic"
ca2e6c31 1187 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
33da77c4 1188 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
ce40491a 1189 update_shell_title "${GETURI2%% *}: $url_attic"
ca2e6c31 1190 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
cd445739
AM
1191 fi
1192 fi
1193 test -s "$target" || rm -f "$target"
1194 fi
cd445739 1195 done
e7fa3b9f
ER
1196 SHELL_TITLE_PREFIX=""
1197
1198 if [ "$get_files_cvs" ]; then
ce40491a 1199 cvsup $get_files_cvs
e7fa3b9f 1200 fi
cd445739
AM
1201
1202 if [ "$CHMOD" = "yes" ]; then
a8c9a155 1203 CHMOD_FILES=$(nourl "$@")
cd445739
AM
1204 if [ -n "$CHMOD_FILES" ]; then
1205 chmod $CHMOD_MODE $CHMOD_FILES
1206 fi
1207 fi
cd445739
AM
1208 fi
1209}
1210
1211make_tagver() {
ce40491a 1212 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1213 set -x
1214 set -v
ce40491a 1215 fi
78eab2a1 1216
ce40491a
ER
1217 # Check whether first character of PACKAGE_NAME is legal for tag name
1218 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1219 TAG_PREFIX=tag_
1220 fi
d712cc12
ER
1221
1222 # NOTE: CVS tags may must not contain the characters `$,.:;@'
392187d9 1223 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE | tr '[.@]' '[_#]')
d712cc12 1224
ce40491a
ER
1225 # Remove #kernel.version_release from TAGVER because tagging sources
1226 # could occur with different kernel-headers than kernel-headers used at build time.
d712cc12
ER
1227 # besides, %{_kernel_ver_str} is not expanded.
1228
1229 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1#%{_kernel_ver_str}
1230 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1231
1232 TAGVER=${TAGVER%#*}
ce40491a 1233 echo -n "$TAGVER"
cd445739
AM
1234}
1235
c713aac3
AG
1236# bool is_tag_a_branch(tag)
1237#
1238# returns 1 if a tag is a branch set on SPECFILE
1239is_tag_a_branch() {
1240 if [ -n "$DEBUG" ]; then
1241 set -x
1242 set -v
1243 fi
1244
1245 if [ $# -ne 1 ]; then
1246 return 0;
1247 fi
1248
1249 TAG=$1
f5141bbc 1250
9c909460 1251 cd "$PACKAGE_DIR"
939f2c12 1252 $CVS_COMMAND status -v $SPECFILE | grep -Eiq "${TAG}.+(branch: [0-9.]+)"
c713aac3
AG
1253 return $?
1254}
1255
f6711e2a 1256tag_files() {
cd445739
AM
1257 TAG_FILES="$@"
1258
1259 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1260 set -x
1261 set -v
cd445739
AM
1262 fi
1263
73ef63d8
ER
1264 echo "Version: $PACKAGE_VERSION"
1265 echo "Release: $PACKAGE_RELEASE"
cd445739 1266
a18a9761 1267 local TAGVER
73ef63d8 1268 if [ "$TAG_VERSION" = "yes" ]; then
a18a9761 1269 TAGVER=`make_tagver`
73ef63d8
ER
1270 echo "CVS tag: $TAGVER"
1271 fi
1272 if [ -n "$TAG" ]; then
1273 echo "CVS tag: $TAG"
1274 fi
cd445739 1275
39dcc7de 1276 local OPTIONS="tag $CVS_FORCE"
73ef63d8
ER
1277 if [ -n "$CVSROOT" ]; then
1278 OPTIONS="-d $CVSROOT $OPTIONS"
1279 fi
cd445739 1280
c713aac3
AG
1281 # if a tagname we are about to set already exists
1282 # and happens to be a branch (common case with AC-branch)
1283 # pass -B (allows -F to disturb branch tag)
1284 local _tag=$TAG
1285 if [ "$TAG_VERSION" = "yes" ]; then
1286 _tag=$TAGVER
1287 fi;
1288 is_tag_a_branch $_tag
28c23a72 1289 if [ $? -eq 0 -a $CVS_NSERVER -eq 0 ]; then
c713aac3
AG
1290 OPTIONS="$OPTIONS -B"
1291 fi;
1292
9c909460 1293 cd "$PACKAGE_DIR"
73ef63d8
ER
1294 local tag_files
1295 for i in $TAG_FILES; do
1296 # don't tag files stored on distfiles
1297 [ -n "`src_md5 $i`" ] && continue
1298 local fp=`nourl "$i"`
1299 if [ -f "$fp" ]; then
1300 tag_files="$tag_files $fp"
cdbd30e8 1301 elif [ -n "GREEDSRC" ]; then
1302 get_greed_sources $i
73ef63d8
ER
1303 else
1304 Exit_error err_no_source_in_repo $i
03db3356 1305 fi
73ef63d8 1306 done
03db3356 1307
73ef63d8 1308 if [ "$tag_files" ]; then
cd445739 1309 if [ "$TAG_VERSION" = "yes" ]; then
73ef63d8 1310 update_shell_title "tag sources: $TAGVER"
19ca62ef 1311 printf "Tagging %d files\n" $(echo $tag_files | wc -w)
939f2c12 1312 $CVS_COMMAND $OPTIONS $TAGVER $tag_files || exit
cd445739
AM
1313 fi
1314 if [ -n "$TAG" ]; then
73ef63d8 1315 update_shell_title "tag sources: $TAG"
c4ff623e
ER
1316
1317 while [ "$tag_files" ]; do
1318 local chunk=$(echo $tag_files | tr ' ' '\n' | head -n 100)
1319 printf "Tagging %d files\n" $(echo $chunk | wc -w)
939f2c12 1320 $CVS_COMMAND $OPTIONS $TAG $chunk || exit
c4ff623e
ER
1321 tag_files=$(echo $tag_files | tr ' ' '\n' | tail +101)
1322 done
cd445739 1323 fi
73ef63d8
ER
1324 fi
1325
9c909460 1326 cd "$PACKAGE_DIR"
73ef63d8
ER
1327 if [ "$TAG_VERSION" = "yes" ]; then
1328 update_shell_title "tag spec: $TAGVER"
939f2c12 1329 $CVS_COMMAND $OPTIONS $TAGVER $SPECFILE || exit
73ef63d8
ER
1330 fi
1331 if [ -n "$TAG" ]; then
1332 update_shell_title "tag spec: $TAG"
939f2c12 1333 $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
73ef63d8 1334 fi
cd445739
AM
1335}
1336
f6711e2a 1337branch_files() {
cd445739
AM
1338 TAG=$1
1339 echo "CVS branch tag: $TAG"
518ff1fb 1340 shift
cd445739
AM
1341
1342 TAG_FILES="$@"
1343
1344 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1345 set -x
1346 set -v
cd445739
AM
1347 fi
1348
78a5a506 1349 local OPTIONS="tag $CVS_FORCE -b"
ec6b5dfc
AG
1350
1351 # branch exists?
1352 is_tag_a_branch $TAG
1353 if [ $? -eq 1 ]; then
1354 OPTIONS="$OPTIONS -B"
1355 fi
1356
78a5a506
ER
1357 if [ -n "$CVSROOT" ]; then
1358 OPTIONS="-d $CVSROOT $OPTIONS"
1359 fi
9c909460 1360 cd "$PACKAGE_DIR"
78a5a506
ER
1361 local tag_files
1362 for i in $TAG_FILES; do
1363 local fp=`nourl "$i"`
1364 if [ -f "$fp" ]; then
1365 tag_files="$tag_files $fp"
cdbd30e8 1366 elif [ -n "GREEDSRC" ]; then
1367 get_greed_sources $i
78a5a506
ER
1368 else
1369 Exit_error err_no_source_in_repo $i
c10fa4fa 1370 fi
78a5a506
ER
1371 done
1372 if [ "$tag_files" ]; then
939f2c12 1373 $CVS_COMMAND $OPTIONS $TAG $tag_files || exit
78a5a506 1374 fi
c10fa4fa 1375
9c909460 1376 cd "$PACKAGE_DIR"
939f2c12 1377 $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
cd445739
AM
1378}
1379
1380
3009b80d
ER
1381# this function should exit early if package can't be built for this arch
1382# this avoids unneccessary BR filling.
1383check_buildarch() {
1384 local out ret
13c3c336 1385 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
3009b80d
ER
1386 ret=$?
1387 if [ $ret -ne 0 ]; then
1388 echo >&2 "$out"
1389 exit $ret
1390 fi
1391}
1392
9d99a240
ER
1393# from relup.sh
1394set_release() {
1395 local specfile="$1"
1396 local rel="$2"
1397 local newrel="$3"
1398 sed -i -e "
1399 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1400 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1401 " $specfile
1402}
1403
1404set_version() {
1405 local specfile="$1"
1406 local ver="$2"
1407 local newver="$3"
1408 sed -i -e "
1409 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1410 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1411 " $specfile
1412}
1413
f6711e2a 1414build_package() {
2e5be021 1415 update_shell_title "build_package"
cd445739 1416 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1417 set -x
1418 set -v
cd445739 1419 fi
5a491465 1420
9c909460 1421 cd "$PACKAGE_DIR"
cd445739
AM
1422
1423 if [ -n "$TRY_UPGRADE" ]; then
9d99a240 1424 local TNOTIFY TNEWVER TOLDVER
ce40491a 1425 update_shell_title "build_package: try_upgrade"
9d99a240 1426
cd445739 1427 if [ -n "$FLOAT_VERSION" ]; then
9d99a240 1428 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
cd445739 1429 else
9d99a240 1430 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
cd445739
AM
1431 fi
1432
45e2a818 1433 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
cd445739
AM
1434
1435 if [ -n "$TNEWVER" ]; then
1436 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
9d99a240 1437 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
257af81b
ER
1438 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1439 cp -f $SPECFILE $SPECFILE.bak
1440 fi
cd445739 1441 chmod +w $SPECFILE
9d99a240
ER
1442 set_release $SPECFILE $PACKAGE_RELEASE 0.1
1443 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
518ff1fb
ER
1444 parse_spec
1445 NODIST="yes" get_files $SOURCES $PATCHES
6392b5fd 1446 update_md5 $SOURCES
cd445739
AM
1447 fi
1448 fi
9c909460 1449 cd "$PACKAGE_DIR"
2a5f078d 1450
cd445739
AM
1451 case "$COMMAND" in
1452 build )
1453 BUILD_SWITCH="-ba" ;;
1454 build-binary )
1455 BUILD_SWITCH="-bb" ;;
1456 build-source )
1457 BUILD_SWITCH="-bs --nodeps" ;;
1458 build-prep )
1459 BUILD_SWITCH="-bp --nodeps" ;;
6594293d
AG
1460 build-build )
1461 BUILD_SWITCH="-bc" ;;
1462 build-install )
1463 BUILD_SWITCH="-bi" ;;
1464 build-list )
1465 BUILD_SWITCH="-bl" ;;
1466
cd445739 1467 esac
c890b916 1468
2e5be021 1469 update_shell_title "build_package: $COMMAND"
cd445739
AM
1470 if [ -n "$LOGFILE" ]; then
1471 LOG=`eval echo $LOGFILE`
1472 if [ -d "$LOG" ]; then
1473 echo "Log file $LOG is a directory."
1474 echo "Parse error in the spec?"
518ff1fb 1475 Exit_error err_build_fail
cd445739
AM
1476 fi
1477 if [ -n "$LASTLOG_FILE" ]; then
1478 echo "LASTLOG=$LOG" > $LASTLOG_FILE
1479 fi
525bf240
ER
1480 RES_FILE=$(mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM)
1481
9c909460 1482 (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
1483 RETVAL=`cat $RES_FILE`
1484 rm $RES_FILE
1485 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1486 if [ "$RETVAL" -eq "0" ]; then
1487 mv $LOG $LOGDIROK
1488 else
1489 mv $LOG $LOGDIRFAIL
1490 fi
1491 fi
8ba5cdda 1492 else
9c909460 1493 eval ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPECFILE
cd445739 1494 RETVAL=$?
8ba5cdda 1495 fi
cd445739
AM
1496 if [ "$RETVAL" -ne "0" ]; then
1497 if [ -n "$TRY_UPGRADE" ]; then
796a8a95 1498 echo "\n!!! Package with new version cannot be built automagically\n"
257af81b
ER
1499 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1500 mv -f $SPECFILE.bak $SPECFILE
1501 fi
cd445739 1502 fi
518ff1fb 1503 Exit_error err_build_fail
cd445739
AM
1504 fi
1505 unset BUILD_SWITCH
1506}
1507
f6711e2a 1508nourl() {
cd445739
AM
1509 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1510}
1511
f6711e2a 1512install_required_packages() {
cd445739
AM
1513 run_poldek -vi $1
1514 return $?
1515}
1516
f6711e2a 1517find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
fa4bf1df 1518 local SPEC="$1"
fa4bf1df
ER
1519 awk -F"\n" '
1520 /^%changelog/ { exit }
fa4bf1df
ER
1521 /^%bcond_with/{
1522 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
8ff97f39
ER
1523 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1524 gsub(/[ \t]+/, "_", bcond);
fa4bf1df
ER
1525 print bcond
1526 }' $SPEC | LC_ALL=C sort -u
1527}
1528
117d9861 1529process_bcondrc() {
301cbfd4
ER
1530 # expand bconds from ~/.bcondrc
1531 # The file structure is like gentoo's package.use:
1532 # ---
1533 # * -selinux
1534 # samba -mysql -pgsql
47a8df12 1535 # w32codec-installer license_agreement
301cbfd4
ER
1536 # php +mysqli
1537 # ---
fa4bf1df 1538 if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then
117d9861
ER
1539 :
1540 else
1541 return
1542 fi
301cbfd4 1543
117d9861 1544 SN=${SPECFILE%%\.spec}
c8a3e2ac 1545
117d9861
ER
1546 local bcondrc=$HOME/.bcondrc
1547 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
301cbfd4 1548
117d9861 1549 local bcond_avail=$(find_spec_bcond $SPECFILE)
301cbfd4 1550
117d9861
ER
1551 while read pkg flags; do
1552 # ignore comments
1553 [[ "$pkg" == \#* ]] && continue
1554
1555 # any package or current package?
1556 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1557 for flag in $flags; do
1558 local opt=${flag#[+-]}
1559
1560 # use only flags which are in this package.
1561 if [[ $bcond_avail = *${opt}* ]]; then
1562 if [[ $flag = -* ]]; then
1563 if [[ $BCOND != *--with?${opt}* ]]; then
1564 BCOND="$BCOND --without $opt"
1565 fi
1566 else
1567 if [[ $BCOND != *--without?${opt}* ]]; then
1568 BCOND="$BCOND --with $opt"
301cbfd4
ER
1569 fi
1570 fi
117d9861
ER
1571 fi
1572 done
1573 fi
1574 done < $bcondrc
1575 update_shell_title "parse ~/.bcondrc: DONE!"
1576}
1577
8ff97f39 1578set_bconds_values() {
117d9861
ER
1579 update_shell_title "set bcond values"
1580
1581 AVAIL_BCONDS_WITHOUT=""
1582 AVAIL_BCONDS_WITH=""
8ff97f39
ER
1583
1584 if egrep -q '^# *_with' ${SPECFILE}; then
1585 echo >&2 "ERROR: This spec has old style bconds."
1586 exit 1
1587 fi
1588
1589 if ! grep -q '^%bcond' ${SPECFILE}; then
117d9861 1590 return
301cbfd4
ER
1591 fi
1592
117d9861
ER
1593 local bcond_avail=$(find_spec_bcond $SPECFILE)
1594 process_bcondrc "$SPECFILE"
1595
fa4bf1df 1596 update_shell_title "parse bconds"
2a5f078d 1597
8ff97f39
ER
1598 local opt bcond
1599 for opt in $bcond_avail; do
1600 case "$opt" in
1601 without_*)
1602 bcond=${opt#without_}
10d92f71
ER
1603 case "$BCOND" in
1604 *--without?${bcond}*)
8ff97f39 1605 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
10d92f71
ER
1606 ;;
1607 *)
8ff97f39 1608 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
10d92f71
ER
1609 ;;
1610 esac
cd445739 1611 ;;
8ff97f39
ER
1612 with_*)
1613 bcond=${opt#with_}
10d92f71
ER
1614 case "$BCOND" in
1615 *--with?${bcond}*)
8ff97f39 1616 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
10d92f71
ER
1617 ;;
1618 *)
8ff97f39 1619 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
10d92f71
ER
1620 ;;
1621 esac
cd445739 1622 ;;
8ff97f39
ER
1623 *)
1624 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1625 exit 1
1626 ;;
1627 esac
1628 done
cd445739
AM
1629}
1630
f6711e2a 1631run_sub_builder() {
cd445739 1632 package_name="${1}"
af6b168f 1633 update_shell_title "run_sub_builder $package_name"
cd445739
AM
1634 #
1635