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