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