]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder_.sh
- correct md5
[packages/rpm-build-tools.git] / builder_.sh
CommitLineData
ed997e04 1#!/bin/ksh
7ee7ebf2 2#
5efdb475
ER
3# This program is free software, distributed under the terms of
4# the GNU General Public License Version 2.
5#
528b4058 6# -----------
528b4058 7# Exit codes:
6cc67f17
ER
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)
528b4058 20
78e86f68 21# Notes (todo/bugs):
78e86f68
ER
22# - when Icon: field is present, -5 and -a5 doesn't work
23# - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
87a659b0 24# - does not respect NoSource: X, and tries to cvs up such files [ example: VirtualBox-bin.spec and its Source0 ]
78e86f68
ER
25# TODO:
26# - ability to do ./builder -bb foo.spec foo2.spec foo3.spec
41f549c5 27# - funny bug, if source-md5 is set then builder will download from distfiles even if there is no url present:
28# Source10: forwardfix.pl
29# # Source10-md5: 8bf85f7368933a4e0cb4f875bac28733
c748b5e1
ZU
30# - builder --help:
31# basename: missing operand
32# Try `basename --help' for more information.
33# -- and the normal usage info --
34
c335e23a 35PROGRAM=${0##*/}
36APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
37RCSID='$Id$' r=${RCSID#* * } rev=${r%% *}
b0f031e7 38VERSION="v0.35/$rev"
00c7b5f1 39VERSIONSTRING="\
f1080274 40Build package utility from PLD Linux CVS repository
41f549c5 41$VERSION (C) 1999-2010 Free Penguins".
00c7b5f1 42
528b4058
JB
43PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
44
41f549c5 45# required rpm-build-macros
46RPM_MACROS_VER=1.534
47
528b4058 48COMMAND="build"
0b75058f 49TARGET=""
528b4058
JB
50
51SPECFILE=""
52BE_VERBOSE=""
53QUIET=""
54CLEAN=""
55DEBUG=""
56NOURLS=""
57NOCVS=""
58NOCVSSPEC=""
59NODIST=""
0466ad31 60NOINIT=""
477f03e6 61PREFMIRRORS=""
528b4058 62UPDATE=""
528b4058
JB
63ADD5=""
64NO5=""
65ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
66CVSROOT=""
477f03e6 67GREEDSRC=""
528b4058 68
7ee7ebf2
ER
69# use rpm 4.4.6+ digest format instead of comments if non-zero
70USEDIGEST=
71
00c7b5f1
ER
72# user agent when fetching files
73USER_AGENT="PLD/Builder($VERSION)"
74
528b4058
JB
75# It can be used i.e. in log file naming.
76# See LOGFILE example.
77DATE=`date +%Y-%m-%d_%H-%M-%S`
78
79# Example: LOGFILE='../log.$PACKAGE_NAME'
80# Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
b854b2c1
ER
81# Example: LOGFILE='$PACKAGE_NAME/$PACKAGE_NAME.$DATE.log'
82# Example: LOGFILE='$PACKAGE_NAME.$DATE.log'
528b4058
JB
83# Yes, you can use variable name! Note _single_ quotes!
84LOGFILE=''
85
86LOGDIR=""
87LOGDIROK=""
88LOGDIRFAIL=""
89LASTLOG_FILE=""
90
91CHMOD="no"
78e86f68 92CHMOD_MODE="0644"
528b4058 93RPMOPTS=""
0466ad31 94RPMBUILDOPTS=""
528b4058
JB
95BCOND=""
96GROUP_BCONDS="no"
b854b2c1
ER
97
98# create symlinks for tools in PACKAGE_DIR, see get_spec()
87a659b0 99SYMLINK_TOOLS="no"
528b4058
JB
100
101PATCHES=""
102SOURCES=""
103ICONS=""
104PACKAGE_RELEASE=""
105PACKAGE_VERSION=""
106PACKAGE_NAME=""
00c7b5f1 107ASSUMED_NAME=""
528b4058
JB
108PROTOCOL="ftp"
109WGET_RETRIES=${MAX_WGET_RETRIES:-0}
528b4058 110
b854b2c1
ER
111CVS_COMMAND=${CVS_COMMAND:-cvs}
112CVS_FORCE=""
113CVSIGNORE_DF="yes"
114CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
115CVS_SERVER="cvs.pld-linux.org"
528b4058 116CVSTAG=""
b854b2c1 117
528b4058
JB
118RES_FILE=""
119
528b4058 120DISTFILES_SERVER="://distfiles.pld-linux.org"
6cc67f17 121ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
528b4058 122
6cc67f17 123DEF_NICE_LEVEL=19
0466ad31 124SCHEDTOOL="auto"
528b4058
JB
125
126FAIL_IF_NO_SOURCES="yes"
127
f1080274
ER
128# let get_files skip over files which are present to get those damn files fetched
129SKIP_EXISTING_FILES="no"
130
ed997e04
ER
131TRY_UPGRADE=""
132# should the specfile be restored if upgrade failed?
133REVERT_BROKEN_UPGRADE="yes"
134
7ee7ebf2
ER
135if rpm --specsrpm 2>/dev/null; then
136 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
0466ad31 137 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
7ee7ebf2
ER
138else
139 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
140 if [ -x /usr/bin/rpm-getdeps ]; then
141 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
142 else
143 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
144 fi
528b4058
JB
145fi
146
7ee7ebf2 147
528b4058
JB
148# Here we load saved user environment used to
149# predefine options set above, or passed to builder
150# in command line.
151# This one reads global system environment settings:
152if [ -f ~/etc/builderrc ]; then
153 . ~/etc/builderrc
154fi
155# And this one cascades settings using user personal
156# builder settings.
157# Example of ~/.builderrc:
158#
159#UPDATE_POLDEK_INDEXES="yes"
160#FETCH_BUILD_REQUIRES="yes"
161#REMOVE_BUILD_REQUIRES="force"
162#GROUP_BCONDS="yes"
163#LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
0466ad31 164#TITLECHANGE=no
528b4058 165#
6cc67f17 166SU_SUDO=""
528b4058
JB
167if [ -n "$HOME_ETC" ]; then
168 USER_CFG="$HOME_ETC/.builderrc"
00c7b5f1 169 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
528b4058
JB
170else
171 USER_CFG=~/.builderrc
00c7b5f1 172 BUILDER_MACROS=~/.builder-rpmmacros
528b4058
JB
173fi
174
175[ -f "$USER_CFG" ] && . "$USER_CFG"
176
0466ad31
ER
177if [ "$SCHEDTOOL" = "auto" ]; then
178 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
179 SCHEDTOOL="schedtool -B -e"
180 else
181 SCHEDTOOL="no"
182 fi
183fi
f1080274 184
6cc67f17
ER
185if [ -n "$USE_PROZILLA" ]; then
186 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
187 GETURI2="$GETURI"
188 OUTFILEOPT="-O"
189elif [ -n "$USE_AXEL" ]; then
190 GETURI="axel -a $AXEL_OPTS"
191 GETURI2="$GETURI"
192 OUTFILEOPT="-o"
193else
0466ad31
ER
194 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
195 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
196 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
00c7b5f1 197 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
f1080274 198
6cc67f17
ER
199 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
200 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
201 OUTFILEOPT="-O"
202fi
203
204GETLOCAL="cp -a"
205
206if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
207 RPM="rpm"
208 RPMBUILD="rpm"
209else
210 RPM="rpm"
211 RPMBUILD="rpmbuild"
212fi
213
c335e23a 214#
215# sanity checks
216#
217if [ -d $HOME/rpm/SOURCES ]; then
218 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
219 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
220 exit 1
221fi
222
14f5c80f
ER
223#
224# are we using cvs-nserver ?
225#
226CVS_NSERVER=0
b854b2c1 227$CVS_COMMAND --version 2>&1 | grep -q 'CVS-nserver'
14f5c80f
ER
228[ $? -eq 0 ] && CVS_NSERVER=1
229
78e86f68 230POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
6cc67f17
ER
231POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
232
b854b2c1 233run_poldek() {
78e86f68 234 RES_FILE=$(mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM)
528b4058
JB
235 if [ -n "$LOGFILE" ]; then
236 LOG=`eval echo $LOGFILE`
237 if [ -n "$LASTLOG_FILE" ]; then
238 echo "LASTLOG=$LOG" > $LASTLOG_FILE
239 fi
0466ad31 240 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
528b4058
JB
241 return $exit_pldk
242 else
0466ad31 243 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
528b4058
JB
244 return `cat ${RES_FILE}`
245 rm -rf ${RES_FILE}
246 fi
247}
248
528b4058
JB
249#---------------------------------------------
250# functions
251
b854b2c1 252usage() {
528b4058
JB
253 if [ -n "$DEBUG" ]; then set -xv; fi
254 echo "\
00c7b5f1 255Usage: builder [-D|--debug] [-V|--version] [--short-version] [-a|--as_anon] [-b|-ba|--build]
01a86c2c 256[-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
ed997e04
ER
257[{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>]
258[-g|--get] [-h|--help] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
259[-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T|--tag <cvstag>]
260[-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
477f03e6 261[{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}] [--use-greed-sources]
01a86c2c 262[-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
00c7b5f1 263[--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
01a86c2c 264<package>[.spec][:cvstag]
6cc67f17 265
528b4058
JB
266-5, --update-md5 - update md5 comments in spec, implies -nd -ncs
267-a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
268-n5, --no-md5 - ignore md5 comments in spec
6cc67f17
ER
269-D, --debug - enable builder script debugging mode,
270-debug - produce rpm debug package (same as --opts -debug)
00c7b5f1
ER
271-V, --version - output builder version string
272--short-version - output builder short version
528b4058
JB
273-a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
274-b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
275 from <package>.spec,
276-bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
277 only package from <package>.spec,
f1080274 278-bp, --build-prep - execute the %prep phase of <package>.spec,
01a86c2c
ER
279-bc - execute the %build phase of <package>.spec,
280-bi - execute the %install phase of <package>.spec
281-bl - execute the %files phase of <package>.spec
528b4058
JB
282-bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
283 them into src.rpm,
01a86c2c 284--short-circuit - short-circuit build
528b4058 285-B, --branch - add branch
87a659b0 286-c, --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
287 may be used with building process.
7ee7ebf2
ER
288-m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
289 SPECS and \$RPM_BUILD_ROOT and CVS/Entries). Doesn't run
290 any rpm building.
ed997e04 291-cf, --cvs-force - use -F when tagging (useful when moving branches)
6cc67f17 292-d <cvsroot>, --cvsroot <cvsroot>
528b4058
JB
293 - setup \$CVSROOT,
294--define <macro> <value>
295 - define a macro <macro> with value <value>,
7ee7ebf2
ER
296--alt_kernel <kernel>
297 - same as --define 'alt_kernel <kernel>'
528b4058
JB
298--nodeps - rpm won't check any dependences
299-g, --get - get <package>.spec and all related files from CVS repo
300 or HTTP/FTP,
301-h, --help - this message,
302--http - use http instead of ftp,
303-l <logfile>, --logtofile <logfile>
304 - log all to file,
528b4058
JB
305-nc, --no-cvs - don't download sources from CVS, if source URL is given,
306-ncs, --no-cvs-specs
307 - don't check specs in CVS
308-nd, --no-distfiles - don't download from distfiles
309-nm, --no-mirrors - don't download from mirror, if source URL is given,
310-nu, --no-urls - don't try to download from FTP/HTTP location,
b854b2c1 311-ns, --no-srcs - don't download Sources/Patches
528b4058
JB
312-ns0, --no-source0 - don't download Source0
313-nn, --no-net - don't download anything from the net
477f03e6 314-pm, --prefer-mirrors - prefer mirrors (if any) over distfiles for SOURCES
0466ad31 315--no-init - don't initialize builder paths (SPECS and SOURCES)
f1080274
ER
316-ske,
317--skip-existing-files - skip existing files in get_files
528b4058
JB
318--opts <rpm opts> - additional options for rpm
319-q, --quiet - be quiet,
320--date yyyy-mm-dd - build package using resources from specified CVS date,
321-r <cvstag>, --cvstag <cvstag>
322 - build package using resources from specified CVS tag,
ed997e04 323-A - build package using CVS resources as any sticky tags/date/kopts being reset.
528b4058
JB
324-R, --fetch-build-requires
325 - fetch what is BuildRequired,
326-RB, --remove-build-requires
327 - remove all you fetched with -R or --fetch-build-requires
328 remember, this option requires confirmation,
329-FRB, --force-remove-build-requires
330 - remove all you fetched with -R or --fetch-build-requires
331 remember, this option works without confirmation,
0466ad31
ER
332-sd, --source-distfiles - list sources available from distfiles (intended for offline
333 operations; does not work when Icon field is present
334 but icon file is absent),
00c7b5f1 335-sc, --source-cvs - list sources available from CVS
0466ad31
ER
336-sdp, --source-distfiles-paths - list sources available from distfiles -
337 paths relative to distfiles directory (intended for offline
338 operations; does not work when Icon field is present
339 but icon file is absent),
6cc67f17
ER
340-sf, --source-files - list sources - bare filenames (intended for offline
341 operations; does not work when Icon field is present
0466ad31 342 but icon file is absent),
6cc67f17
ER
343-sp, --source-paths - list sources - filenames with full local paths (intended for
344 offline operations; does not work when Icon field is present
0466ad31 345 but icon file is absent),
f1080274
ER
346-su, --source-urls - list urls - urls to sources and patches
347 intended for copying urls with spec with lots of macros in urls
528b4058
JB
348-T <cvstag> , --tag <cvstag>
349 - add cvs tag <cvstag> for files,
350-Tvs, --tag-version-stable
6cc67f17 351 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
528b4058
JB
352-Ts, --tag-stable
353 - add cvs tag STABLE for files,
528b4058 354-Tv, --tag-version
6cc67f17 355 - add cvs tag NAME-VERSION-RELEASE for files,
528b4058
JB
356-Tp, --tag-prefix <prefix>
357 - add <prefix> to NAME-VERSION-RELEASE tags,
358-tt, --test-tag <prefix>
359 - fail if tag is already present,
6cc67f17
ER
360-ir, --integer-release-only
361 - allow only integer and snapshot releases
528b4058
JB
362-v, --verbose - be verbose,
363-u, --try-upgrade - check version, and try to upgrade package
364-un, --try-upgrade-with-float-version
365 - as above, but allow float version
477f03e6
ER
366--use-greed-sources
367 - try download source from tag head if don't find it in
14f5c80f 368 current tag
528b4058
JB
369-U, --update - refetch sources, don't use distfiles, and update md5 comments
370-Upi, --update-poldek-indexes
371 - refresh or make poldek package index files.
f1080274
ER
372-np, --nopatch <patchnumber>
373 - don't apply <patchnumber>
374--show-bconds - show available conditional builds, which can be used
375 - with --with and/or --without switches.
ed997e04
ER
376--show-bcond-args - show active bconds, from ~/.bcondrc. this is used by
377 ./repackage.sh script. in other words, the output is
378 parseable by scripts.
41f549c5 379--show-avail-bconds - show available bconds
528b4058
JB
380--with/--without <feature>
381 - conditional build package depending on %_with_<feature>/
382 %_without_<feature> macro switch. You may now use
383 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
384 constructions. Set GROUP_BCONDS to yes to make use of it.
6cc67f17 385--target <platform>, --target=<platform>
0466ad31
ER
386 - build for platform <platform>.
387--init-rpm-dir - initialize ~/rpm directory structure
528b4058
JB
388"
389}
390
7ee7ebf2
ER
391# change dependency to specname
392# common changes:
393# - perl(Package::Name) -> perl-Package-Name
394depspecname() {
395 local package="$1"
396
87a659b0 397 package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
7ee7ebf2
ER
398 echo "$package"
399}
400
f1080274
ER
401update_shell_title() {
402 [ -t 1 ] || return
403 local len=${COLUMNS:-80}
41f549c5 404 local msg="$(echo "$*" | cut -c-$len)"
f1080274
ER
405
406 if [ -n "$BE_VERBOSE" ]; then
407 echo >&2 "$(date +%s.%N) $*"
408 fi
409
41f549c5 410 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
0466ad31
ER
411 local pkg
412 if [ -n "$PACKAGE_NAME" ]; then
413 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
414 else
415 pkg=${SPECFILE}
416 fi
417
418 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
78e86f68 419 msg=$(echo $msg | tr -d '\n\r')
0466ad31
ER
420 case "$TERM" in
421 cygwin|xterm*)
422 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
423 ;;
424 screen*)
425 echo >&2 -ne "\033]0;$msg\007"
426 ;;
427 esac
428 fi
f1080274
ER
429}
430
431# set TARGET from BuildArch: from SPECFILE
432set_spec_target() {
0466ad31 433 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
87a659b0 434 tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
0466ad31 435 if [ "$tmp" ]; then
01a86c2c 436 target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
f1080274
ER
437 TARGET="$tmp"
438 case "$RPMBUILD" in
439 "rpmbuild")
01a86c2c 440 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
f1080274 441 "rpm")
0466ad31 442 TARGET_SWITCH="--target=$TARGET" ;;
f1080274 443 esac
0466ad31
ER
444 fi
445 fi
f1080274
ER
446}
447
00c7b5f1
ER
448# runs rpm with minimal macroset
449minirpm() {
f1080274
ER
450 # we reset macros not to contain macros.build as all the %() macros are
451 # executed here, while none of them are actually needed.
f1080274 452 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
78e86f68 453 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ')
00c7b5f1
ER
454
455 # TODO: move these to /usr/lib/rpm/macros
456 cat > $BUILDER_MACROS <<'EOF'
457%x8664 x86_64 amd64 ia32e
01a86c2c
ER
458%alt_kernel %{nil}
459%_alt_kernel %{nil}
8e43e5c1 460%bootstrap_release() %{1}
87a659b0 461%requires_releq_kernel_up(s:n:) %{nil}
462%requires_releq_kernel_smp(s:n:) %{nil}
463%requires_releq_kernel(s:n:) %{nil}
f1080274
ER
464%requires_releq() %{nil}
465%pyrequires_eq() %{nil}
466%requires_eq() %{nil}
467%requires_eq_to() %{nil}
f262e062 468%requires_ge() %{nil}
87a659b0 469%releq_kernel_up(n:) ERROR
470%releq_kernel_smp(n:) ERROR
471%releq_kernel(n:) ERROR
f1080274
ER
472%kgcc_package ERROR
473%_fontsdir ERROR
474%ruby_version ERROR
475%ruby_ver_requires_eq() %{nil}
476%ruby_mod_ver_requires_eq() %{nil}
477%__php_api_requires() %{nil}
478%php_major_version ERROR
479%php_api_version ERROR
5efdb475
ER
480%requires_xorg_xserver_extension %{nil}
481%requires_xorg_xserver_xinput %{nil}
482%requires_xorg_xserver_font %{nil}
483%requires_xorg_xserver_videodrv %{nil}
f1080274 484%py_ver ERROR
ed997e04
ER
485%perl_vendorarch ERROR
486%perl_vendorlib ERROR
01a86c2c
ER
487# damn. need it here! - copied from /usr/lib/rpm/macros.build
488%tmpdir %(echo "${TMPDIR:-/tmp}")
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}
78e86f68
ER
500%add_etc_shells(p) %{p:<lua>}
501%remove_etc_shells(p) %{p:<lua>}
502%lua_add_etc_shells() %{nil}
503%lua_remove_etc_shells() %{nil}
8e43e5c1 504%required_jdk %{nil}
505%buildrequires_jdk %{nil}
f1080274 506EOF
0466ad31 507 if [ "$NOINIT" = "yes" ] ; then
00c7b5f1 508 cat >> $BUILDER_MACROS <<'EOF'
0466ad31
ER
509%_specdir ./
510%_sourcedir ./
511EOF
512 fi
78e86f68 513 eval $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
00c7b5f1
ER
514}
515
516cache_rpm_dump() {
517 if [ -n "$DEBUG" ]; then
518 set -x
519 set -v
520 fi
521
7ee7ebf2 522 if [ -x /usr/bin/rpm-specdump ]; then
78e86f68
ER
523 update_shell_title "cache_rpm_dump using rpm-specdump command"
524 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND $SPECFILE)
7ee7ebf2 525 else
78e86f68 526 update_shell_title "cache_rpm_dump using rpmbuild command"
7ee7ebf2
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
f1080274 546
7ee7ebf2
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
f1080274
ER
555
556 update_shell_title "cache_rpm_dump: OK!"
528b4058
JB
557}
558
00c7b5f1 559rpm_dump() {
528b4058 560 if [ -z "$rpm_dump_cache" ] ; then
78e86f68 561 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
528b4058
JB
562 fi
563 echo "$rpm_dump_cache"
564}
565
b854b2c1 566get_icons() {
f1080274 567 update_shell_title "get icons"
c335e23a 568 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
f1080274
ER
569 if [ -z "$ICONS" ]; then
570 return
571 fi
572
ed997e04 573 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
f1080274
ER
574}
575
b854b2c1 576parse_spec() {
f1080274 577 update_shell_title "parsing specfile"
528b4058 578 if [ -n "$DEBUG" ]; then
ed997e04
ER
579 set -x
580 set -v
528b4058
JB
581 fi
582
f1080274 583 # icons are needed for successful spec parse
ed997e04 584 get_icons
528b4058 585
b854b2c1 586 cd $PACKAGE_DIR
528b4058
JB
587 cache_rpm_dump
588
528b4058
JB
589 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
590 FAIL_IF_NO_SOURCES="no"
591 fi
592
b854b2c1
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
00c7b5f1
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}')
602
603 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
477f03e6 604 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
00c7b5f1 605 fi
6cc67f17 606
528b4058
JB
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
f1080274
ER
623
624 update_shell_title "parse_spec: OK!"
528b4058
JB
625}
626
b854b2c1 627Exit_error() {
528b4058 628 if [ -n "$DEBUG" ]; then
ed997e04
ER
629 set -x
630 set -v
528b4058
JB
631 fi
632
633 cd "$__PWD"
634
635 case "$1" in
636 "err_no_spec_in_cmdl" )
637 remove_build_requires
78e86f68 638 echo >&2 "ERROR: spec file name not specified."
528b4058 639 exit 2 ;;
01a86c2c 640 "err_invalid_cmdline" )
78e86f68 641 echo >&2 "ERROR: invalid command line arg ($2)."
01a86c2c 642 exit 2 ;;
528b4058
JB
643 "err_no_spec_in_repo" )
644 remove_build_requires
78e86f68 645 echo >&2 "Error: spec file not stored in CVS repo."
528b4058
JB
646 exit 3 ;;
647 "err_no_source_in_repo" )
648 remove_build_requires
78e86f68 649 echo >&2 "Error: some source, patch or icon files not stored in CVS repo. ($2)"
528b4058
JB
650 exit 4 ;;
651 "err_build_fail" )
652 remove_build_requires
78e86f68 653 echo >&2 "Error: package build failed. (${2:-no more info})"
528b4058 654 exit 5 ;;
6cc67f17
ER
655 "err_no_package_data" )
656 remove_build_requires
78e86f68 657 echo >&2 "Error: couldn't get out package name/version/release from spec file."
6cc67f17 658 exit 6 ;;
0466ad31 659 "err_tag_exists" )
6cc67f17 660 remove_build_requires
78e86f68 661 echo >&2 "Tag ${2} already exists (spec release: ${3})."
6cc67f17 662 exit 9 ;;
0466ad31 663 "err_fract_rel" )
6cc67f17 664 remove_build_requires
78e86f68 665 echo >&2 "Release ${2} not integer and not a snapshot."
6cc67f17 666 exit 10 ;;
f1080274
ER
667 "err_branch_exists" )
668 remove_build_requires
78e86f68 669 echo >&2 "Tree branch already exists (${2})."
f1080274 670 exit 11 ;;
01a86c2c
ER
671 "err_acl_deny" )
672 remove_build_requires
78e86f68 673 echo >&2 "Error: conditions reject building this spec (${2})."
01a86c2c 674 exit 12 ;;
528b4058 675 esac
78e86f68 676 echo >&2 "Unknown error."
ed997e04 677 exit 100
528b4058
JB
678}
679
b854b2c1 680init_builder() {
528b4058 681 if [ -n "$DEBUG" ]; then
ed997e04
ER
682 set -x
683 set -v
528b4058
JB
684 fi
685
0466ad31 686 if [ "$NOINIT" != "yes" ] ; then
b854b2c1 687 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
41f549c5 688
689 local macros_ver=$(rpm -E %?rpm_build_macros)
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
0466ad31 701 else
b854b2c1
ER
702 REPO_DIR="."
703 PACKAGE_DIR="."
0466ad31 704 fi
528b4058 705
78e86f68 706 __PWD=$(pwd)
528b4058
JB
707}
708
b854b2c1 709get_spec() {
f1080274
ER
710
711 update_shell_title "get_spec"
712
528b4058 713 if [ -n "$DEBUG" ]; then
ed997e04
ER
714 set -x
715 set -v
528b4058
JB
716 fi
717
b854b2c1
ER
718 cd "$REPO_DIR"
719 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
87a659b0 720 # XXX: still needed?
721 SPECFILE=$(basename $SPECFILE)
528b4058
JB
722 fi
723 if [ "$NOCVSSPEC" != "yes" ]; then
528b4058 724
f1080274
ER
725 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
726 echo "Warning: No CVS access defined - using local .spec file"
727 NOCVSSPEC="yes"
528b4058
JB
728 fi
729
b854b2c1
ER
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
734
735 # remove Entries.Static -- so 'cvs up' would update all files in a repo
736 rm "$ASSUMED_NAME/CVS/Entries.Static"
737 cvsignore_df .cvsignore
738
739 # create symlinks for tools
740 if [ "$SYMLINK_TOOLS" != "no" ]; then
f262e062 741 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
b854b2c1
ER
742 [ -f $a ] || continue
743 ln -s ../$a $ASSUMED_NAME
744 cvsignore_df $a
745 done
746 fi
747 fi
528b4058 748 fi
f1080274 749
b854b2c1 750 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
ed997e04 751 Exit_error err_no_spec_in_repo
528b4058
JB
752 fi
753
754 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
b854b2c1 755 chmod $CHMOD_MODE $ASSUMED_NAME/$SPECFILE
528b4058
JB
756 fi
757 unset OPTIONS
b854b2c1 758 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $ASSUMED_NAME/$SPECFILE
f1080274 759
0466ad31 760 set_spec_target
528b4058
JB
761}
762
b854b2c1
ER
763find_mirror() {
764 cd "$REPO_DIR"
0466ad31 765 local url="$1"
528b4058 766 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
b854b2c1 767 $CVS_COMMAND update mirrors >&2
528b4058
JB
768 fi
769
770 IFS="|"
0466ad31
ER
771 local origin mirror name rest ol prefix
772 while read origin mirror name rest; do
773 # skip comments and empty lines
41f549c5 774 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
0466ad31
ER
775 continue
776 fi
78e86f68
ER
777 ol=$(echo -n "$origin" | wc -c)
778 prefix=$(echo -n "$url" | head -c $ol)
528b4058 779 if [ "$prefix" = "$origin" ] ; then
78e86f68 780 suffix=$(echo "$url" | cut -b $((ol+1))-)
528b4058
JB
781 echo -n "$mirror$suffix"
782 return 0
783 fi
784 done < mirrors
785 echo "$url"
786}
787
ed997e04 788# Warning: unpredictable results if same URL used twice
b854b2c1
ER
789src_no() {
790 cd $PACKAGE_DIR
528b4058
JB
791 rpm_dump | \
792 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
793 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
794 head -n 1 | xargs
795}
796
b854b2c1 797src_md5() {
ed997e04 798 [ "$NO5" = "yes" ] && return
528b4058
JB
799 no=$(src_no "$1")
800 [ -z "$no" ] && return
b854b2c1 801 cd $PACKAGE_DIR
ed997e04
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
78e86f68 807 spec_rev=$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')
ed997e04
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
822 fi
823
41f549c5 824 source_md5=`grep -i "^#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
ed997e04
ER
825 if [ -n "$source_md5" ]; then
826 echo $source_md5
528b4058 827 else
7ee7ebf2
ER
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
41f549c5 834 nosource_md5=`grep -i "^#[ ]*NoSource$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
7ee7ebf2
ER
835 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
836 echo $nosource_md5
837 fi
528b4058 838 fi
528b4058
JB
839 fi
840}
841
b854b2c1 842distfiles_path() {
0466ad31
ER
843 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
844}
845
b854b2c1 846distfiles_url() {
0466ad31 847 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
528b4058
JB
848}
849
b854b2c1 850distfiles_attic_url() {
0466ad31 851 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
528b4058
JB
852}
853
b854b2c1 854good_md5() {
528b4058
JB
855 md5=$(src_md5 "$1")
856 [ "$md5" = "" ] || \
857 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
858}
859
b854b2c1 860good_size() {
78e86f68 861 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
0466ad31 862 [ -n "$size" -a "$size" -gt 0 ]
6cc67f17
ER
863}
864
b854b2c1 865cvsignore_df() {
6cc67f17
ER
866 if [ "$CVSIGNORE_DF" != "yes" ]; then
867 return
868 fi
b854b2c1
ER
869 cvsignore=${PACKAGE_DIR}/.cvsignore
870
871 # add only if not yet there
872 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
6cc67f17
ER
873 echo "$1" >> $cvsignore
874 fi
875}
876
b854b2c1 877cvsup() {
0466ad31
ER
878 update_shell_title "cvsup"
879 local OPTIONS="up "
b854b2c1
ER
880
881 if [ "$1" = "-c" ]; then
882 OPTIONS="co "
883 shift
884 fi
0466ad31
ER
885 if [ -n "$CVSROOT" ]; then
886 OPTIONS="-d $CVSROOT $OPTIONS"
887 fi
f1080274 888
0466ad31
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
f1080274 899
0466ad31
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 ))
b854b2c1 909 output=$(LC_ALL=C $CVS_COMMAND $OPTIONS "$@" 2>&1)
0466ad31
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
f1080274
ER
923}
924
ed997e04 925# returns true if "$1" is ftp, http or https protocol url
b854b2c1 926is_url() {
ed997e04
ER
927 case "$1" in
928 ftp://*|http://*|https://*)
929 return 0
930 ;;
931 esac
932 return 1
933}
934
b854b2c1 935update_md5() {
ed997e04
ER
936 if [ $# -eq 0 ]; then
937 return
938 fi
939
940 update_shell_title "update md5"
941 if [ -n "$DEBUG" ]; then
942 set -x
943 set -v
944 fi
945
b854b2c1 946 cd "$PACKAGE_DIR"
ed997e04
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")
954 if [ -n "$ADD5" ]; then
955 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
b854b2c1
ER
956 grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
957 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
ed997e04 958 else
b854b2c1 959 grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
ed997e04
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")
b854b2c1 975 local md5=$(grep -iE '^#[ ]*(No)?Source'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
7ee7ebf2 976 if [ -z "$md5" ]; then
b854b2c1 977 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
7ee7ebf2 978 fi
ed997e04 979 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
7ee7ebf2 980 local tag="# Source$srcno-md5:\t"
ed997e04 981 if [[ "$md5" == *NoSource* ]]; then
7ee7ebf2
ER
982 tag="# NoSource$srcno-md5:\t"
983 elif [ -n "$USEDIGEST" ]; then
984 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
ed997e04
ER
985 fi
986 md5=$(md5sum "$fp" | cut -f1 -d' ')
7ee7ebf2 987 echo "Updating Source$srcno ($md5: $fp)."
ed997e04 988 perl -i -ne '
7ee7ebf2
ER
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+/;
ed997e04 991 ' \
b854b2c1 992 $PACKAGE_DIR/$SPECFILE
ed997e04
ER
993 fi
994 done
995}
996
b854b2c1 997check_md5() {
87a659b0 998 local bad
78e86f68
ER
999 [ "$NO5" = "yes" ] && return
1000
ed997e04
ER
1001 update_shell_title "check md5"
1002
1003 for i in "$@"; do
87a659b0 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
ed997e04
ER
1012 fi
1013
87a659b0 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
ed997e04
ER
1019 done
1020}
1021
b854b2c1 1022get_files() {
f1080274 1023 update_shell_title "get_files"
528b4058
JB
1024
1025 if [ -n "$DEBUG" ]; then
ed997e04
ER
1026 set -x
1027 set -v
528b4058
JB
1028 fi
1029
f1080274 1030 if [ $# -gt 0 ]; then
b854b2c1 1031 cd "$PACKAGE_DIR"
528b4058 1032
f1080274
ER
1033 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
1034 echo "Warning: No CVS access defined for SOURCES"
1035 NOCVS="yes"
528b4058 1036 fi
f1080274
ER
1037
1038 local nc=0
1039 local get_files_cvs=""
1040 for i in "$@"; do
1041 nc=$((nc + 1))
1042 local cvsup=0
1043 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1044 update_shell_title "$i"
1045 local fp=`nourl "$i"`
ed997e04 1046 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
0466ad31 1047 continue
528b4058 1048 fi
ed997e04 1049
528b4058 1050 FROM_DISTFILES=0
ed997e04
ER
1051 local srcmd5=$(src_md5 "$i")
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.
f1080274 1058 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
528b4058
JB
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
87a659b0 1062 target="$fp"
528b4058 1063
ed997e04 1064 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
6cc67f17 1065 if good_md5 "$i" && good_size "$i"; then
ed997e04 1066 echo "$fp having proper md5sum already exists"
528b4058
JB
1067 continue
1068 fi
01a86c2c 1069
477f03e6 1070 # optionally prefer mirror over distfiles if there's mirror
01a86c2c 1071 # TODO: build url list and then try each url from the list
477f03e6 1072 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
01a86c2c
ER
1073 url="$im"
1074 else
1075 url=$(distfiles_url "$i")
1076 fi
1077
528b4058
JB
1078 url_attic=$(distfiles_attic_url "$i")
1079 FROM_DISTFILES=1
ed997e04
ER
1080 # is $url local file?
1081 if [[ "$url" = [./]* ]]; then
f1080274 1082 update_shell_title "${GETLOCAL%% *}: $url"
528b4058
JB
1083 ${GETLOCAL} $url $target
1084 else
1085 if [ -z "$NOMIRRORS" ]; then
01a86c2c
ER
1086 url=$(find_mirror "$url")
1087 fi
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"
528b4058 1095 fi
01a86c2c 1096 update_shell_title "${GETURI%% *}: $uri"
6cc67f17 1097 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
f1080274
ER
1098 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1099 update_shell_title "${GETURI2%% *}: $url"
6cc67f17 1100 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
528b4058
JB
1101 fi
1102 fi
ed997e04
ER
1103
1104 # is it empty file?
1105 if [ ! -s "$target" ]; then
528b4058
JB
1106 rm -f "$target"
1107 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
f1080274 1108 update_shell_title "${GETLOCAL%% *}: $url_attic"
528b4058
JB
1109 ${GETLOCAL} $url_attic $target
1110 else
1111 if [ -z "$NOMIRRORS" ]; then
78e86f68 1112 url_attic=$(find_mirror "$url_attic")
528b4058 1113 fi
f1080274 1114 update_shell_title "${GETURI%% *}: $url_attic"
6cc67f17 1115 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
f1080274 1116 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
0466ad31 1117 update_shell_title "${GETURI2%% *}: $url_attic"
6cc67f17 1118 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
528b4058 1119 fi
87a659b0 1120 test -s "$target" || rm -f "$target"
528b4058
JB
1121 fi
1122 fi
ed997e04
ER
1123
1124 if [ -s "$target" ]; then
6cc67f17
ER
1125 cvsignore_df $target
1126 else
528b4058
JB
1127 rm -f "$target"
1128 FROM_DISTFILES=0
1129 fi
ed997e04 1130 elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then
f1080274
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
528b4058
JB
1138 fi
1139
f1080274 1140 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
528b4058 1141 if [ -z "$NOMIRRORS" ]; then
78e86f68 1142 im=$(find_mirror "$i")
528b4058
JB
1143 else
1144 im="$i"
1145 fi
0466ad31 1146 update_shell_title "${GETURI%% *}: $im"
87a659b0 1147 ${GETURI} "$im" ${OUTFILEOPT} "$target" || \
f1080274 1148 if [ "`echo $im | grep -E 'ftp://'`" ]; then
0466ad31 1149 update_shell_title "${GETURI2%% *}: $im"
87a659b0 1150 ${GETURI2} "$im" ${OUTFILEOPT} "$target"
6cc67f17 1151 fi
87a659b0 1152 test -s "$target" || rm -f "$target"
528b4058
JB
1153 fi
1154
f1080274
ER
1155 if [ "$cvsup" = 1 ]; then
1156 continue
1157 fi
1158
528b4058 1159 fi
ed997e04
ER
1160
1161 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
f1080274 1162 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
477f03e6
ER
1163 if [ -n "GREEDSRC" ]; then
1164 get_greed_sources $i
1165 else
1166 Exit_error err_no_source_in_repo $i
1167 fi
528b4058 1168 fi
6cc67f17 1169
ed997e04 1170 # we check md5 here just only to refetch immediately
6cc67f17 1171 if good_md5 "$i" && good_size "$i"; then
528b4058
JB
1172 :
1173 elif [ "$FROM_DISTFILES" = 1 ]; then
1174 # wrong md5 from distfiles: remove the file and try again
1175 # but only once ...
1176 echo "MD5 sum mismatch. Trying full fetch."
1177 FROM_DISTFILES=2
1178 rm -f $target
f1080274 1179 update_shell_title "${GETURI%% *}: $url"
6cc67f17 1180 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
f1080274 1181 if [ "`echo $url | grep -E 'ftp://'`" ]; then
0466ad31 1182 update_shell_title "${GETURI2%% *}: $url"
6cc67f17 1183 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
528b4058 1184 fi
ed997e04 1185 if [ ! -s "$target" ]; then
528b4058 1186 rm -f "$target"
f1080274 1187 update_shell_title "${GETURI%% *}: $url_attic"
6cc67f17 1188 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
f1080274 1189 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
0466ad31 1190 update_shell_title "${GETURI2%% *}: $url_attic"
6cc67f17 1191 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
528b4058
JB
1192 fi
1193 fi
1194 test -s "$target" || rm -f "$target"
1195 fi
528b4058 1196 done
f1080274
ER
1197 SHELL_TITLE_PREFIX=""
1198
1199 if [ "$get_files_cvs" ]; then
0466ad31 1200 cvsup $get_files_cvs
f1080274 1201 fi
528b4058
JB
1202
1203 if [ "$CHMOD" = "yes" ]; then
78e86f68 1204 CHMOD_FILES=$(nourl "$@")
528b4058
JB
1205 if [ -n "$CHMOD_FILES" ]; then
1206 chmod $CHMOD_MODE $CHMOD_FILES
1207 fi
1208 fi
528b4058
JB
1209 fi
1210}
1211
1212make_tagver() {
0466ad31 1213 if [ -n "$DEBUG" ]; then
ed997e04
ER
1214 set -x
1215 set -v
0466ad31 1216 fi
6cc67f17 1217
0466ad31
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
00c7b5f1
ER
1222
1223 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1224 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE | tr '[.@]' '[_#]')
1225
0466ad31
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.
00c7b5f1
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%#*}
0466ad31 1234 echo -n "$TAGVER"
528b4058
JB
1235}
1236
14f5c80f
ER
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
1251
b854b2c1
ER
1252 cd "$PACKAGE_DIR"
1253 $CVS_COMMAND status -v $SPECFILE | grep -Eiq "${TAG}.+(branch: [0-9.]+)"
14f5c80f
ER
1254 return $?
1255}
1256
b854b2c1 1257tag_files() {
528b4058
JB
1258 TAG_FILES="$@"
1259
1260 if [ -n "$DEBUG" ]; then
ed997e04
ER
1261 set -x
1262 set -v
528b4058
JB
1263 fi
1264
ed997e04
ER
1265 echo "Version: $PACKAGE_VERSION"
1266 echo "Release: $PACKAGE_RELEASE"
528b4058 1267
00c7b5f1 1268 local TAGVER
ed997e04 1269 if [ "$TAG_VERSION" = "yes" ]; then
00c7b5f1 1270 TAGVER=`make_tagver`
ed997e04
ER
1271 echo "CVS tag: $TAGVER"
1272 fi
1273 if [ -n "$TAG" ]; then
1274 echo "CVS tag: $TAG"
1275 fi
528b4058 1276
ed997e04
ER
1277 local OPTIONS="tag $CVS_FORCE"
1278 if [ -n "$CVSROOT" ]; then
1279 OPTIONS="-d $CVSROOT $OPTIONS"
1280 fi
528b4058 1281
14f5c80f
ER
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
1290 if [ $? -eq 0 -a $CVS_NSERVER -eq 0 ]; then
1291 OPTIONS="$OPTIONS -B"
1292 fi;
1293
b854b2c1 1294 cd "$PACKAGE_DIR"
ed997e04
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"
477f03e6
ER
1302 elif [ -n "GREEDSRC" ]; then
1303 get_greed_sources $i
ed997e04
ER
1304 else
1305 Exit_error err_no_source_in_repo $i
1306 fi
1307 done
528b4058 1308
ed997e04 1309 if [ "$tag_files" ]; then
528b4058 1310 if [ "$TAG_VERSION" = "yes" ]; then
ed997e04 1311 update_shell_title "tag sources: $TAGVER"
5efdb475 1312 printf "Tagging %d files\n" $(echo $tag_files | wc -w)
b854b2c1 1313 $CVS_COMMAND $OPTIONS $TAGVER $tag_files || exit
528b4058
JB
1314 fi
1315 if [ -n "$TAG" ]; then
ed997e04 1316 update_shell_title "tag sources: $TAG"
5efdb475
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)
b854b2c1 1321 $CVS_COMMAND $OPTIONS $TAG $chunk || exit
5efdb475
ER
1322 tag_files=$(echo $tag_files | tr ' ' '\n' | tail +101)
1323 done
528b4058 1324 fi
ed997e04 1325 fi
528b4058 1326
b854b2c1 1327 cd "$PACKAGE_DIR"
ed997e04
ER
1328 if [ "$TAG_VERSION" = "yes" ]; then
1329 update_shell_title "tag spec: $TAGVER"
b854b2c1 1330 $CVS_COMMAND $OPTIONS $TAGVER $SPECFILE || exit
ed997e04
ER
1331 fi
1332 if [ -n "$TAG" ]; then
1333 update_shell_title "tag spec: $TAG"
b854b2c1 1334 $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
528b4058
JB
1335 fi
1336}
1337
b854b2c1 1338branch_files() {
528b4058
JB
1339 TAG=$1
1340 echo "CVS branch tag: $TAG"
ed997e04 1341 shift
528b4058
JB
1342
1343 TAG_FILES="$@"
1344
1345 if [ -n "$DEBUG" ]; then
ed997e04
ER
1346 set -x
1347 set -v
528b4058
JB
1348 fi
1349
ed997e04 1350 local OPTIONS="tag $CVS_FORCE -b"
78e86f68
ER
1351
1352 # branch exists?
1353 is_tag_a_branch $TAG
1354 if [ $? -eq 1 ]; then
1355 OPTIONS="$OPTIONS -B"
1356 fi
1357
ed997e04
ER
1358 if [ -n "$CVSROOT" ]; then
1359 OPTIONS="-d $CVSROOT $OPTIONS"
1360 fi
b854b2c1 1361 cd "$PACKAGE_DIR"
ed997e04
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"
477f03e6
ER
1367 elif [ -n "GREEDSRC" ]; then
1368 get_greed_sources $i
ed997e04
ER
1369 else
1370 Exit_error err_no_source_in_repo $i
528b4058 1371 fi
ed997e04
ER
1372 done
1373 if [ "$tag_files" ]; then
b854b2c1 1374 $CVS_COMMAND $OPTIONS $TAG $tag_files || exit
528b4058 1375 fi
ed997e04 1376
b854b2c1
ER
1377 cd "$PACKAGE_DIR"
1378 $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
528b4058
JB
1379}
1380
1381
00c7b5f1
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
1386 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1387 ret=$?
1388 if [ $ret -ne 0 ]; then
1389 echo >&2 "$out"
1390 exit $ret
1391 fi
1392}
1393
c335e23a 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
f262e062 1415try_upgrade() {
528b4058 1416 if [ -n "$TRY_UPGRADE" ]; then
c335e23a 1417 local TNOTIFY TNEWVER TOLDVER
0466ad31 1418 update_shell_title "build_package: try_upgrade"
c335e23a 1419
f262e062 1420 cd "$PACKAGE_DIR"
1421
528b4058 1422 if [ -n "$FLOAT_VERSION" ]; then
c335e23a 1423 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
528b4058 1424 else
c335e23a 1425 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
528b4058
JB
1426 fi
1427
78e86f68 1428 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
528b4058
JB
1429
1430 if [ -n "$TNEWVER" ]; then
1431 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
c335e23a 1432 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
ed997e04
ER
1433 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1434 cp -f $SPECFILE $SPECFILE.bak
1435 fi
528b4058 1436 chmod +w $SPECFILE
f262e062 1437 set_release $SPECFILE $PACKAGE_RELEASE 1
c335e23a 1438 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
ed997e04 1439 parse_spec
f262e062 1440 return 1
528b4058
JB
1441 fi
1442 fi
f262e062 1443 return 0
1444}
1445
1446build_package() {
1447 update_shell_title "build_package"
1448 if [ -n "$DEBUG" ]; then
1449 set -x
1450 set -v
1451 fi
1452
b854b2c1 1453 cd "$PACKAGE_DIR"
6cc67f17 1454
528b4058
JB
1455 case "$COMMAND" in
1456 build )
1457 BUILD_SWITCH="-ba" ;;
1458 build-binary )
1459 BUILD_SWITCH="-bb" ;;
1460 build-source )
1461 BUILD_SWITCH="-bs --nodeps" ;;
1462 build-prep )
1463 BUILD_SWITCH="-bp --nodeps" ;;
01a86c2c
ER
1464 build-build )
1465 BUILD_SWITCH="-bc" ;;
1466 build-install )
1467 BUILD_SWITCH="-bi" ;;
1468 build-list )
1469 BUILD_SWITCH="-bl" ;;
1470
528b4058 1471 esac
f1080274
ER
1472
1473 update_shell_title "build_package: $COMMAND"
528b4058
JB
1474 if [ -n "$LOGFILE" ]; then
1475 LOG=`eval echo $LOGFILE`
1476 if [ -d "$LOG" ]; then
1477 echo "Log file $LOG is a directory."
1478 echo "Parse error in the spec?"
ed997e04 1479 Exit_error err_build_fail
528b4058
JB
1480 fi
1481 if [ -n "$LASTLOG_FILE" ]; then
1482 echo "LASTLOG=$LOG" > $LASTLOG_FILE
1483 fi
78e86f68
ER
1484 RES_FILE=$(mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM)
1485
b854b2c1 1486 (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
528b4058
JB
1487 RETVAL=`cat $RES_FILE`
1488 rm $RES_FILE
1489 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1490 if [ "$RETVAL" -eq "0" ]; then
1491 mv $LOG $LOGDIROK
1492 else
1493 mv $LOG $LOGDIRFAIL
1494 fi
1495 fi
1496 else
b854b2c1 1497 eval ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPECFILE
528b4058
JB
1498 RETVAL=$?
1499 fi
1500 if [ "$RETVAL" -ne "0" ]; then
1501 if [ -n "$TRY_UPGRADE" ]; then
f262e062 1502 echo "\nUpgrade package to new version failed."
ed997e04 1503 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
f262e062 1504 echo "Restoring old spec file."
ed997e04
ER
1505 mv -f $SPECFILE.bak $SPECFILE
1506 fi
f262e062 1507 echo ""
528b4058 1508 fi
ed997e04 1509 Exit_error err_build_fail
528b4058
JB
1510 fi
1511 unset BUILD_SWITCH
1512}
1513
b854b2c1 1514nourl() {
528b4058
JB
1515 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1516}
1517
b854b2c1 1518install_required_packages() {
528b4058
JB
1519 run_poldek -vi $1
1520 return $?
1521}
1522
b854b2c1 1523find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
f1080274 1524 local SPEC="$1"
f1080274
ER
1525 awk -F"\n" '
1526 /^%changelog/ { exit }
f1080274
ER
1527 /^%bcond_with/{
1528 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
b854b2c1
ER
1529 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1530 gsub(/[ \t]+/, "_", bcond);
f1080274
ER
1531 print bcond
1532 }' $SPEC | LC_ALL=C sort -u
1533}
1534
ed997e04 1535process_bcondrc() {
6cc67f17
ER
1536 # expand bconds from ~/.bcondrc
1537 # The file structure is like gentoo's package.use:
1538 # ---
1539 # * -selinux
1540 # samba -mysql -pgsql
1541 # w32codec-installer license_agreement
1542 # php +mysqli
1543 # ---
f1080274 1544 if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then
ed997e04
ER
1545 :
1546 else
1547 return
1548 fi
1549
1550 SN=${SPECFILE%%\.spec}
6cc67f17 1551
ed997e04
ER
1552 local bcondrc=$HOME/.bcondrc
1553 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
6cc67f17 1554
ed997e04 1555 local bcond_avail=$(find_spec_bcond $SPECFILE)
6cc67f17 1556
ed997e04
ER
1557 while read pkg flags; do
1558 # ignore comments
1559 [[ "$pkg" == \#* ]] && continue
6cc67f17 1560
ed997e04
ER
1561 # any package or current package?
1562 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1563 for flag in $flags; do
1564 local opt=${flag#[+-]}
1565
1566 # use only flags which are in this package.
1567 if [[ $bcond_avail = *${opt}* ]]; then
1568 if [[ $flag = -* ]]; then
1569 if [[ $BCOND != *--with?${opt}* ]]; then
6cc67f17 1570 BCOND="$BCOND --without $opt"
ed997e04
ER
1571 fi
1572 else
1573 if [[ $BCOND != *--without?${opt}* ]]; then
6cc67f17
ER
1574 BCOND="$BCOND --with $opt"
1575 fi
1576 fi
ed997e04
ER
1577 fi
1578 done
1579 fi
1580 done < $bcondrc
1581 update_shell_title "parse ~/.bcondrc: DONE!"
1582}
1583
b854b2c1 1584set_bconds_values() {
ed997e04
ER
1585 update_shell_title "set bcond values"
1586
1587 AVAIL_BCONDS_WITHOUT=""
1588 AVAIL_BCONDS_WITH=""
b854b2c1
ER
1589
1590 if egrep -q '^# *_with' ${SPECFILE}; then
1591 echo >&2 "ERROR: This spec has old style bconds."
1592 exit 1
1593 fi
1594
1595 if ! grep -q '^%bcond' ${SPECFILE}; then
ed997e04 1596 return
6cc67f17
ER
1597 fi
1598
ed997e04
ER
1599 local bcond_avail=$(find_spec_bcond $SPECFILE)
1600 process_bcondrc "$SPECFILE"
1601
f1080274 1602 update_shell_title "parse bconds"
6cc67f17 1603
b854b2c1
ER
1604 local opt bcond
1605 for opt in $bcond_avail; do
1606 case "$opt" in
1607 without_*)
1608 bcond=${opt#without_}
41f549c5 1609 case "$BCOND" in
1610 *--without?${bcond}*)
b854b2c1 1611 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
41f549c5 1612 ;;
1613 *)
b854b2c1 1614 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
41f549c5 1615 ;;
1616 esac
528b4058 1617 ;;
b854b2c1
ER
1618 with_*)
1619 bcond=${opt#with_}
41f549c5 1620 case "$BCOND" in
1621 *--with?${bcond}*)
b854b2c1 1622 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
41f549c5 1623 ;;
1624 *)
b854b2c1 1625 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
41f549c5 1626 ;;
1627 esac
528b4058 1628 ;;
b854b2c1
ER
1629 *)
1630 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1631 exit 1
1632 ;;
1633 esac
1634 done
528b4058
JB
1635}
1636
b854b2c1 1637run_sub_builder() {
528b4058 1638 package_name="${1}"
f1080274 1639 update_shell_title "run_sub_builder $package_name"
528b4058
JB
1640 #
1641