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