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