3 # This program is free software, distributed under the terms of
4 # the GNU General Public License Version 2.
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)
22 # - when Icon: field is present, -5 and -a5 doesn't work
23 # - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
24 # - does not respect NoSource: X, and tries to cvs up such files [ example: VirtualBox-bin.spec and its Source0 ]
26 # - ability to do ./builder -bb foo.spec foo2.spec foo3.spec
27 # - funny bug, if source-md5 is set then builder will download from distfiles even if there is no url present:
28 # Source10: forwardfix.pl
29 # # Source10-md5: 8bf85f7368933a4e0cb4f875bac28733
31 # basename: missing operand
32 # Try `basename --help' for more information.
33 # -- and the normal usage info --
36 APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
37 RCSID='$Id$' r=${RCSID#* * } rev=${r%% *}
40 Build package utility from PLD Linux Packages repository
41 $VERSION (C) 1999-2011 Free Penguins".
43 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
45 # required rpm-build-macros
65 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
69 # use rpm 4.4.6+ digest format instead of comments if non-zero
72 # user agent when fetching files
73 USER_AGENT="PLD/Builder($VERSION)"
75 # It can be used i.e. in log file naming.
76 # See LOGFILE example.
77 DATE=`date +%Y-%m-%d_%H-%M-%S`
79 # Example: LOGFILE='../log.$PACKAGE_NAME'
80 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
81 # Example: LOGFILE='$PACKAGE_NAME/$PACKAGE_NAME.$DATE.log'
82 # Example: LOGFILE='$PACKAGE_NAME.$DATE.log'
83 # Yes, you can use variable name! Note _single_ quotes!
98 # create symlinks for tools in PACKAGE_DIR, see get_spec()
110 # use lftp by default when available
112 lftp --version > /dev/null 2>&1 && USE_LFTP=yes
114 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
116 CVS_COMMAND=${CVS_COMMAND:-cvs}
119 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
120 CVS_SERVER="cvs.pld-linux.org"
125 DISTFILES_SERVER="://distfiles.pld-linux.org"
126 ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
131 FAIL_IF_NO_SOURCES="yes"
133 # let get_files skip over files which are present to get those damn files fetched
134 SKIP_EXISTING_FILES="no"
137 # should the specfile be restored if upgrade failed?
138 REVERT_BROKEN_UPGRADE="yes"
140 if rpm --specsrpm 2>/dev/null; then
141 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
142 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
144 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
145 if [ -x /usr/bin/rpm-getdeps ]; then
146 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
148 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
153 # Here we load saved user environment used to
154 # predefine options set above, or passed to builder
156 # This one reads global system environment settings:
157 if [ -f ~/etc/builderrc ]; then
160 # And this one cascades settings using user personal
162 # Example of ~/.builderrc:
164 #UPDATE_POLDEK_INDEXES="yes"
165 #FETCH_BUILD_REQUIRES="yes"
166 #REMOVE_BUILD_REQUIRES="force"
168 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
172 if [ -n "$HOME_ETC" ]; then
173 USER_CFG="$HOME_ETC/.builderrc"
174 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
176 USER_CFG=~/.builderrc
177 BUILDER_MACROS=~/.builder-rpmmacros
180 [ -f "$USER_CFG" ] && . "$USER_CFG"
182 if [ "$SCHEDTOOL" = "auto" ]; then
183 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
184 SCHEDTOOL="schedtool -B -e"
190 if [ -n "$USE_PROZILLA" ]; then
191 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
194 elif [ -n "$USE_AXEL" ]; then
195 GETURI="axel -a $AXEL_OPTS"
198 elif [ -n "$USE_LFTP" ]; then
203 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
204 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
205 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
206 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
208 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
209 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
215 if rpm --version 2>&1 | grep -q '4.0.[0-2]'; then
226 if [ -d $HOME/rpm/SOURCES ]; then
227 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
228 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
233 # are we using cvs-nserver ?
236 $CVS_COMMAND --version 2>&1 | grep -q 'CVS-nserver'
237 [ $? -eq 0 ] && CVS_NSERVER=1
239 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
240 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
244 if [ -n "$LOGFILE" ]; then
245 LOG=`eval echo $LOGFILE`
246 if [ -n "$LASTLOG_FILE" ]; then
247 echo "LASTLOG=$LOG" > $LASTLOG_FILE
249 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
252 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
253 return `cat ${RES_FILE}`
258 #---------------------------------------------
262 local outfile=$1 url=$2 retval tmpfile
266 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
267 set net:max-retries $WGET_RETRIES;
268 set http:user-agent \"$USER_AGENT\";
269 pget -n 10 -c \"$url\" -o \"$tmpfile\"
273 if [ $retval -eq 0 ]; then
274 mv -f "$tmpfile" "$outfile"
282 if [ -n "$DEBUG" ]; then set -xv; fi
284 Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--add_cvs] [-b|-ba|--build]
285 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
286 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>]
287 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
288 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T|--tag <cvstag>]
289 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
290 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}] [--use-greed-sources]
291 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
292 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
293 <package>[.spec][:cvstag]
295 -4 - force ipv4 when transferring files
296 -5, --update-md5 - update md5 comments in spec, implies -nd -ncs
297 -6 - force ipv6 when transferring files
298 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
299 -n5, --no-md5 - ignore md5 comments in spec
300 -D, --debug - enable builder script debugging mode,
301 -debug - produce rpm debug package (same as --opts -debug)
302 -V, --version - output builder version string
303 --short-version - output builder short version
304 --as_anon - get files via pserver as cvs@$CVS_SERVER,
305 -a, --add_cvs - try add new package to CVS.
306 -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
308 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
309 only package from <package>.spec,
310 -bp, --build-prep - execute the %prep phase of <package>.spec,
311 -bc - execute the %build phase of <package>.spec,
312 -bi - execute the %install phase of <package>.spec
313 -bl - execute the %files phase of <package>.spec
314 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
316 --short-circuit - short-circuit build
317 -B, --branch - add branch
318 -c, --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
319 may be used with building process.
320 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES, SPECS and \$RPM_BUILD_ROOT
321 and CVS/Entries). Doesn't run any rpm building.
322 -cf, --cvs-force - use -F when tagging (useful when moving branches)
323 -d <cvsroot>, --cvsroot <cvsroot>
325 --define <macro> <value> - define a macro <macro> with value <value>,
326 --alt_kernel <kernel> - same as --define 'alt_kernel <kernel>'
327 --nodeps - rpm won't check any dependences
328 -g, --get - get <package>.spec and all related files from CVS repo or HTTP/FTP
329 -h, --help - this message
330 -jN, -j N - set %_smp_mflags to propagate concurrent jobs
331 --ftp, --http - use ftp or http protocol to access distfiles server
332 -l <logfile>, --logtofile <logfile>
334 -nc, --no-cvs - don't download sources from CVS, if source URL is given,
335 -ncs, --no-cvs-specs - don't check specs in CVS
336 -nd, --no-distfiles - don't download from distfiles
337 -nm, --no-mirrors - don't download from mirror, if source URL is given,
338 -nu, --no-urls - don't try to download from FTP/HTTP location,
339 -ns, --no-srcs - don't download Sources/Patches
340 -ns0, --no-source0 - don't download Source0
341 -nn, --no-net - don't download anything from the net
342 -pm, --prefer-mirrors - prefer mirrors (if any) over distfiles for SOURCES
343 --no-init - don't initialize builder paths (SPECS and SOURCES)
345 --skip-existing-files - skip existing files in get_files
346 --opts <rpm opts> - additional options for rpm
347 -q, --quiet - be quiet,
348 --date yyyy-mm-dd - build package using resources from specified CVS date,
349 -r <cvstag>, --cvstag <cvstag>
350 - build package using resources from specified CVS tag,
351 -A - build package using CVS resources as any sticky tags/date/kopts being reset.
352 -R, --fetch-build-requires
353 - fetch what is BuildRequired,
354 -RB, --remove-build-requires
355 - remove all you fetched with -R or --fetch-build-requires
356 remember, this option requires confirmation,
357 -FRB, --force-remove-build-requires
358 - remove all you fetched with -R or --fetch-build-requires
359 remember, this option works without confirmation,
360 -sd, --source-distfiles - list sources available from distfiles (intended for offline
361 operations; does not work when Icon field is present
362 but icon file is absent),
363 -sc, --source-cvs - list sources available from CVS
364 -sdp, --source-distfiles-paths - list sources available from distfiles -
365 paths relative to distfiles directory (intended for offline
366 operations; does not work when Icon field is present
367 but icon file is absent),
368 -sf, --source-files - list sources - bare filenames (intended for offline
369 operations; does not work when Icon field is present
370 but icon file is absent),
371 -lsp, --source-paths - list sources - filenames with full local paths (intended for
372 offline operations; does not work when Icon field is present
373 but icon file is absent),
374 -su, --source-urls - list urls - urls to sources and patches
375 intended for copying urls with spec with lots of macros in urls
376 -T <cvstag> , --tag <cvstag>
377 - add cvs tag <cvstag> for files,
378 -Tvs, --tag-version-stable
379 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
380 -Ts, --tag-stable - add cvs tag STABLE for files,
381 -Tv, --tag-version - add cvs tag NAME-VERSION-RELEASE for files,
382 -Tp, --tag-prefix <prefix>
383 - add <prefix> to NAME-VERSION-RELEASE tags,
384 -tt, --test-tag <prefix>
385 - fail if tag is already present,
386 -ir, --integer-release-only
387 - allow only integer and snapshot releases
388 -v, --verbose - be verbose,
389 -u, --try-upgrade - check version, and try to upgrade package
390 -un, --try-upgrade-with-float-version
391 - as above, but allow float version
392 php-pear-Services_Digg/
393 --upgrade-version - upgrade to specified version in try-upgrade
395 - try download source from tag head if don't find it in
397 -U, --update - refetch sources, don't use distfiles, and update md5 comments
398 -Upi, --update-poldek-indexes
399 - refresh or make poldek package index files.
400 -sp, --skip-patch <patchnumber>
401 - don't apply <patchnumber>. may be repeated.
402 -np, --nopatch <patchnumber>
403 - abort instead of applying patch <patchnumber>
404 --show-bconds - show available conditional builds, which can be used
405 - with --with and/or --without switches.
406 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
407 In other words, the output is parseable by scripts.
408 --show-avail-bconds - show available bconds
409 --with/--without <feature>
410 - conditional build package depending on %_with_<feature>/
411 %_without_<feature> macro switch. You may now use
412 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
413 constructions. Set GROUP_BCONDS to yes to make use of it.
414 --target <platform>, --target=<platform>
415 - build for platform <platform>.
416 --init-rpm-dir - initialize ~/rpm directory structure
420 # create tempfile. as secure as possible
422 mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
425 # change dependency to specname
427 # - perl(Package::Name) -> perl-Package-Name
431 package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
435 update_shell_title() {
437 local len=${COLUMNS:-80}
438 local msg="$(echo "$*" | cut -c-$len)"
440 if [ -n "$BE_VERBOSE" ]; then
441 echo >&2 "$(date +%s.%N) $*"
444 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
446 if [ -n "$PACKAGE_NAME" ]; then
447 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
452 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
453 msg=$(echo $msg | tr -d '\n\r')
456 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
459 echo >&2 -ne "\033]0;$msg\007"
465 # set TARGET from BuildArch: from SPECFILE
467 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
468 tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
470 target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
474 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
476 TARGET_SWITCH="--target=$TARGET" ;;
482 # runs rpm with minimal macroset
484 # we reset macros not to contain macros.build as all the %() macros are
485 # executed here, while none of them are actually needed.
486 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
487 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ')
489 # TODO: move these to /usr/lib/rpm/macros
490 cat > $BUILDER_MACROS <<'EOF'
491 %x8664 x86_64 amd64 ia32e
494 %bootstrap_release() %{1}
495 %requires_releq_kernel_up(s:n:) %{nil}
496 %requires_releq_kernel_smp(s:n:) %{nil}
497 %requires_releq_kernel(s:n:) %{nil}
498 %requires_releq() %{nil}
499 %pyrequires_eq() %{nil}
500 %requires_eq() %{nil}
501 %requires_eq_to() %{nil}
502 %requires_ge() %{nil}
503 %requires_ge_to() %{nil}
504 %requires_ge() %{nil}
505 %releq_kernel_up(n:) ERROR
506 %releq_kernel_smp(n:) ERROR
507 %releq_kernel(n:) ERROR
511 %ruby_ver_requires_eq() %{nil}
512 %ruby_mod_ver_requires_eq() %{nil}
513 %__php_api_requires() %{nil}
514 %php_major_version ERROR
515 %php_api_version ERROR
516 %requires_xorg_xserver_extension %{nil}
517 %requires_xorg_xserver_xinput %{nil}
518 %requires_xorg_xserver_font %{nil}
519 %requires_xorg_xserver_videodrv %{nil}
521 %perl_vendorarch ERROR
522 %perl_vendorlib ERROR
523 # damn. need it here! - copied from /usr/lib/rpm/macros.build
524 %tmpdir %(echo "${TMPDIR:-/tmp}")
525 %patchset_source(f:b:) %(
526 base=%{-b*}%{!-b*:10000};
527 start=$(expr $base + %1);
528 end=$(expr $base + %{?2}%{!?2:%{1}});
529 # we need to call seq twice as it doesn't allow two formats
530 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
531 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
532 paste %{tmpdir}/__ps{1,2};
533 rm -f %{tmpdir}/__ps{1,2};
536 %add_etc_shells(p) %{p:<lua>}
537 %remove_etc_shells(p) %{p:<lua>}
538 %lua_add_etc_shells() %{nil}
539 %lua_remove_etc_shells() %{nil}
541 %buildrequires_jdk %{nil}
542 %pear_package_print_optionalpackages %{nil}
544 if [ "$NOINIT" = "yes" ] ; then
545 cat >> $BUILDER_MACROS <<'EOF'
550 eval $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
554 if [ -n "$DEBUG" ]; then
559 if [ -x /usr/bin/rpm-specdump ]; then
560 update_shell_title "cache_rpm_dump using rpm-specdump command"
561 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND $SPECFILE)
563 update_shell_title "cache_rpm_dump using rpmbuild command"
566 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
567 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
573 ARGS='--nodigest --nosignature --nobuild'
576 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
578 if [ $? -gt 0 ]; then
579 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
581 Exit_error err_build_fail
584 # make small dump cache
585 rpm_dump_cache=`echo "$rpm_dump" | awk '
586 $2 ~ /^SOURCEURL/ {print}
587 $2 ~ /^PATCHURL/ {print}
588 $2 ~ /^nosource/ {print}
589 $2 ~ /^PACKAGE_/ {print}
593 update_shell_title "cache_rpm_dump: OK!"
597 if [ -z "$rpm_dump_cache" ] ; then
598 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
600 echo "$rpm_dump_cache"
604 update_shell_title "get icons"
605 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
606 if [ -z "$ICONS" ]; then
610 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
614 update_shell_title "parsing specfile"
615 if [ -n "$DEBUG" ]; then
620 # icons are needed for successful spec parse
626 if rpm_dump | grep -qEi ":.*nosource.*1"; then
627 FAIL_IF_NO_SOURCES="no"
630 if [ "$NOSRCS" != "yes" ]; then
631 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
632 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
633 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
636 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
637 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
638 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
640 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
641 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
644 if [ -n "$BE_VERBOSE" ]; then
645 echo "- Sources : `nourl $SOURCES`"
646 if [ -n "$PATCHES" ]; then
647 echo "- Patches : `nourl $PATCHES`"
649 echo "- Patches : *no patches needed*"
651 if [ -n "$ICONS" ]; then
652 echo "- Icon : `nourl $ICONS`"
654 echo "- Icon : *no package icon*"
656 echo "- Name : $PACKAGE_NAME"
657 echo "- Version : $PACKAGE_VERSION"
658 echo "- Release : $PACKAGE_RELEASE"
661 update_shell_title "parse_spec: OK!"
665 if [ -n "$DEBUG" ]; then
673 "err_no_spec_in_cmdl" )
674 remove_build_requires
675 echo >&2 "ERROR: spec file name not specified."
677 "err_invalid_cmdline" )
678 echo >&2 "ERROR: invalid command line arg ($2)."
680 "err_no_spec_in_repo" )
681 remove_build_requires
682 echo >&2 "Error: spec file not stored in CVS repo."
684 "err_no_source_in_repo" )
685 remove_build_requires
686 echo >&2 "Error: some source, patch or icon files not stored in CVS repo. ($2)"
688 "err_cvs_add_failed" )
689 echo >&2 "Error: failed to add package to CVS repo."
692 remove_build_requires
693 echo >&2 "Error: package build failed. (${2:-no more info})"
695 "err_no_package_data" )
696 remove_build_requires
697 echo >&2 "Error: couldn't get out package name/version/release from spec file."
700 remove_build_requires
701 echo >&2 "Tag ${2} already exists (spec release: ${3})."
704 remove_build_requires
705 echo >&2 "Release ${2} not integer and not a snapshot."
707 "err_branch_exists" )
708 remove_build_requires
709 echo >&2 "Tree branch already exists (${2})."
712 remove_build_requires
713 echo >&2 "Error: conditions reject building this spec (${2})."
716 echo >&2 "Unknown error."
721 if [ -n "$DEBUG" ]; then
726 if [ "$NOINIT" != "yes" ] ; then
727 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
729 local macros_ver=$(rpm -E %?rpm_build_macros)
730 if [ -z "$macros_ver" ]; then
731 REPO_DIR=$TOP_DIR/packages
732 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
734 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
735 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
739 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
751 update_shell_title "get_spec"
753 if [ -n "$DEBUG" ]; then
759 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
761 SPECFILE=$(basename $SPECFILE)
764 if [ "$NOCVSSPEC" != "yes" ]; then
765 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
766 echo "Warning: No CVS access defined in $(pwd)- using local .spec file"
770 if [ -d "$ASSUMED_NAME" -a -s "$ASSUMED_NAME/CVS/Root" ]; then
771 cvsup "$ASSUMED_NAME/$SPECFILE" || Exit_error err_no_spec_in_repo
772 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
773 if [ ! -r "$ASSUMED_NAME/$SPECFILE" ]; then
774 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
777 if [ ! -s "$ASSUMED_NAME/CVS/Root" ]; then
778 cvsup -a $ASSUMED_NAME || Exit_error err_cvs_add_failed
780 cvsup -a "$ASSUMED_NAME/$SPECFILE" || Exit_error err_cvs_add_failed
782 cvsup -c -d $ASSUMED_NAME "packages/$ASSUMED_NAME/$SPECFILE" || {
783 # softfail if new package, i.e not yet added to cvs
784 [ ! -f "$ASSUMED_NAME/$SPECFILE" ] && Exit_error err_no_spec_in_repo
785 echo "Warning: package not in CVS - assuming new package"
790 # remove Entries.Static -- so 'cvs up' would update all files in a repo
791 rm -f "$ASSUMED_NAME/CVS/Entries.Static"
794 cvsignore_df .cvsignore
796 # add default log format to .cvsignore if it is relative to package dir
797 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
798 # substitute known "macros" to glob
799 local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\),*,g')
800 if [ "$logfile" ]; then
801 cvsignore_df "$logfile"
805 # create symlinks for tools
806 if [ "$SYMLINK_TOOLS" != "no" ]; then
807 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
808 # skip tools that don't exist in top dir
809 [ -f $a ] || continue
810 # skip tools that already exist
811 [ -f $ASSUMED_NAME/$a ] && continue
812 ln -s ../$a $ASSUMED_NAME
818 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
819 Exit_error err_no_spec_in_repo
822 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
823 chmod $CHMOD_MODE $ASSUMED_NAME/$SPECFILE
826 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $ASSUMED_NAME/$SPECFILE
834 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
835 $CVS_COMMAND update mirrors >&2
839 local origin mirror name rest ol prefix
840 while read origin mirror name rest; do
841 # skip comments and empty lines
842 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
845 ol=$(echo -n "$origin" | wc -c)
846 prefix=$(echo -n "$url" | head -c $ol)
847 if [ "$prefix" = "$origin" ] ; then
848 suffix=$(echo "$url" | cut -b $((ol+1))-)
849 echo -n "$mirror$suffix"
856 # Warning: unpredictable results if same URL used twice
859 # escape some regexp characters if part of file name
860 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
863 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
864 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
865 head -n 1 | tr OURCEATH ourceath | xargs
869 [ "$NO5" = "yes" ] && return
871 [ -z "$no" ] && return
875 if [ -f additional-md5sums ]; then
876 local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
877 if [ -z "$spec_rev" ]; then
878 spec_rev=$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')
880 local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
881 md5=$(grep -s -v '^#' additional-md5sums | \
882 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
883 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
884 grep -E '^[0-9a-f]{32}$')
887 if [ $(echo "$md5" | wc -l) != 1 ] ; then
888 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
890 echo "$md5" | tail -n 1
895 source_md5=`grep -i "^#[ ]*$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
896 if [ -n "$source_md5" ]; then
899 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
900 if [ -n "$source_md5" ]; then
903 # we have empty SourceX-md5, but it is still possible
904 # that we have NoSourceX-md5 AND NoSource: X
905 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
906 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
914 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
918 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
921 distfiles_attic_url() {
922 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
928 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
932 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
933 [ -n "$size" -a "$size" -gt 0 ]
937 if [ "$CVSIGNORE_DF" != "yes" ]; then
940 cvsignore=${PACKAGE_DIR}/.cvsignore
942 # add only if not yet there
943 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
944 echo "$1" >> $cvsignore
949 update_shell_title "cvsup"
950 local OPTIONS="" ACTION="up"
953 if [ "$1" = "-c" ]; then
958 if [ "$1" = "-a" ]; then
965 if [ -n "$CVSROOT" ]; then
966 OPTIONS="-d $CVSROOT $OPTIONS"
969 if [ "$ACTION" != "add" ]; then
970 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
971 OPTIONS="$OPTIONS -A"
973 if [ -n "$CVSDATE" ]; then
974 OPTIONS="$OPTIONS -D $CVSDATE"
976 if [ -n "$CVSTAG" ]; then
977 # FIXME: cvs add actually works with -r ?
978 OPTIONS="$OPTIONS -r $CVSTAG"
984 local retries_counter=0
986 update_shell_title "cvsup: $*"
988 update_shell_title "cvsup: $# files"
990 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
991 retries_counter=$(( $retries_counter + 1 ))
992 output=$(LC_ALL=C $CVS_COMMAND $OPTIONS "$@" 2>&1)
994 [ -n "$output" ] && echo "$output"
995 if echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)" \
996 && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
997 echo "Trying again [$*]... ($retries_counter)"
998 update_shell_title "cvsup: retry #$retries_counter"
1005 update_shell_title "cvsup: done!"
1009 # returns true if "$1" is ftp, http or https protocol url
1012 ftp://*|http://*|https://*)
1020 if [ $# -eq 0 ]; then
1024 update_shell_title "update md5"
1025 if [ -n "$DEBUG" ]; then
1032 # pass 1: check files to be fetched
1036 local fp=$(nourl "$i")
1037 local srcno=$(src_no "$i")
1038 if [ -n "$ADD5" ]; then
1039 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1040 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1041 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1043 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1045 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1046 need_files="$need_files $i"
1050 # pass 1a: get needed files
1051 if [ "$need_files" ]; then
1052 get_files $need_files
1055 # pass 2: proceed with md5 adding or updating
1057 local fp=$(nourl "$i")
1058 local srcno=$(src_no "$i")
1059 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1060 if [ -z "$md5" ]; then
1061 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1063 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1064 local tag="# $srcno-md5:\t"
1065 if [[ "$md5" == *NoSource* ]]; then
1066 tag="# No$srcno-md5:\t"
1067 elif [ -n "$USEDIGEST" ]; then
1068 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1070 md5=$(md5sum "$fp" | cut -f1 -d' ')
1071 echo "Updating $srcno ($md5: $fp)."
1073 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1074 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1076 $PACKAGE_DIR/$SPECFILE
1083 [ "$NO5" = "yes" ] && return
1085 update_shell_title "check md5"
1089 if ! good_md5 "$i"; then
1090 echo -n "MD5 sum mismatch."
1093 if ! good_size "$i"; then
1094 echo -n "0 sized file."
1098 if [ $bad -eq 1 ]; then
1099 echo " Use -U to refetch sources,"
1100 echo "or -5 to update md5 sums, if you're sure files are correct."
1101 Exit_error err_no_source_in_repo $i
1107 update_shell_title "get_files"
1109 if [ -n "$DEBUG" ]; then
1114 if [ $# -gt 0 ]; then
1117 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
1118 echo "Warning: No CVS access defined for SOURCES"
1123 local get_files_cvs=""
1127 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1128 update_shell_title "$i"
1129 local fp=`nourl "$i"`
1130 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1135 local srcmd5=$(src_md5 "$i")
1137 # we know if source/patch is present in cvs/distfiles
1138 # - has md5 (in distfiles)
1139 # - in cvs... ideas?
1141 # CHECK: local file didn't exist or always cvs up (first) requested.
1142 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1143 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1144 echo "Warning: no URL given for $i"
1148 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1149 if good_md5 "$i" && good_size "$i"; then
1150 echo "$fp having proper md5sum already exists"
1154 # optionally prefer mirror over distfiles if there's mirror
1155 # TODO: build url list and then try each url from the list
1156 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1159 url=$(distfiles_url "$i")
1162 url_attic=$(distfiles_attic_url "$i")
1164 # is $url local file?
1165 if [[ "$url" = [./]* ]]; then
1166 update_shell_title "${GETLOCAL%% *}: $url"
1167 ${GETLOCAL} $url $target
1169 if [ -z "$NOMIRRORS" ]; then
1170 url=$(find_mirror "$url")
1174 # make shorter message for distfiles urls
1175 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1176 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1177 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1180 update_shell_title "${GETURI%% *}: $uri"
1181 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1182 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1183 update_shell_title "${GETURI2%% *}: $url"
1184 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1189 if [ ! -s "$target" ]; then
1191 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
1192 update_shell_title "${GETLOCAL%% *}: $url_attic"
1193 ${GETLOCAL} $url_attic $target
1195 if [ -z "$NOMIRRORS" ]; then
1196 url_attic=$(find_mirror "$url_attic")
1198 update_shell_title "${GETURI%% *}: $url_attic"
1199 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1200 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1201 update_shell_title "${GETURI2%% *}: $url_attic"
1202 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1204 test -s "$target" || rm -f "$target"
1208 if [ -s "$target" ]; then
1209 cvsignore_df $target
1214 elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then
1215 if [ $# -gt 1 ]; then
1216 get_files_cvs="$get_files_cvs $fp"
1217 update_shell_title "$fp (will cvs up later)"
1224 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1225 if [ -z "$NOMIRRORS" ]; then
1226 im=$(find_mirror "$i")
1230 update_shell_title "${GETURI%% *}: $im"
1231 ${GETURI} ${OUTFILEOPT} "$target" "$im" || \
1232 if [ "`echo $im | grep -E 'ftp://'`" ]; then
1233 update_shell_title "${GETURI2%% *}: $im"
1234 ${GETURI2} ${OUTFILEOPT} "$target" "$im"
1236 test -s "$target" || rm -f "$target"
1239 if [ "$cvsup" = 1 ]; then
1245 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1246 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1247 if [ -n "GREEDSRC" ]; then
1248 get_greed_sources $i
1250 Exit_error err_no_source_in_repo $i
1254 # we check md5 here just only to refetch immediately
1255 if good_md5 "$i" && good_size "$i"; then
1257 elif [ "$FROM_DISTFILES" = 1 ]; then
1258 # wrong md5 from distfiles: remove the file and try again
1260 echo "MD5 sum mismatch. Trying full fetch."
1263 update_shell_title "${GETURI%% *}: $url"
1264 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1265 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1266 update_shell_title "${GETURI2%% *}: $url"
1267 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1269 if [ ! -s "$target" ]; then
1271 update_shell_title "${GETURI%% *}: $url_attic"
1272 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1273 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1274 update_shell_title "${GETURI2%% *}: $url_attic"
1275 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1278 test -s "$target" || rm -f "$target"
1281 SHELL_TITLE_PREFIX=""
1283 if [ "$get_files_cvs" ]; then
1284 cvsup $get_files_cvs
1287 if [ "$CHMOD" = "yes" ]; then
1288 CHMOD_FILES=$(nourl "$@")
1289 if [ -n "$CHMOD_FILES" ]; then
1290 chmod $CHMOD_MODE $CHMOD_FILES
1297 if [ -n "$DEBUG" ]; then
1302 # Check whether first character of PACKAGE_NAME is legal for tag name
1303 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1307 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1308 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE | tr '[.@]' '[_#]')
1310 # Remove #kernel.version_release from TAGVER because tagging sources
1311 # could occur with different kernel-headers than kernel-headers used at build time.
1312 # besides, %{_kernel_ver_str} is not expanded.
1314 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1#%{_kernel_ver_str}
1315 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1321 # bool is_tag_a_branch(tag)
1323 # returns 1 if a tag is a branch set on SPECFILE
1325 if [ -n "$DEBUG" ]; then
1330 if [ $# -ne 1 ]; then
1335 # escape some regexp characters if part of TAG
1336 TAG=$(echo "$TAG" | sed -e 's#\([\+\*\.]\)#\\\1#g')
1340 $CVS_COMMAND status -v $SPECFILE | grep -Eiq "${TAG}.+(branch: [0-9.]+)"
1347 if [ -n "$DEBUG" ]; then
1352 echo "Version: $PACKAGE_VERSION"
1353 echo "Release: $PACKAGE_RELEASE"
1356 if [ "$TAG_VERSION" = "yes" ]; then
1357 TAGVER=`make_tagver`
1358 echo "CVS tag: $TAGVER"
1360 if [ -n "$TAG" ]; then
1361 echo "CVS tag: $TAG"
1364 local OPTIONS="tag $CVS_FORCE"
1365 if [ -n "$CVSROOT" ]; then
1366 OPTIONS="-d $CVSROOT $OPTIONS"
1369 # if a tagname we are about to set already exists
1370 # and happens to be a branch (common case with AC-branch)
1371 # pass -B (allows -F to disturb branch tag)
1373 if [ "$TAG_VERSION" = "yes" ]; then
1376 is_tag_a_branch $_tag
1377 if [ $? -eq 0 -a $CVS_NSERVER -eq 0 ]; then
1378 OPTIONS="$OPTIONS -B"
1383 for i in $TAG_FILES; do
1384 # don't tag files stored on distfiles
1385 [ -n "`src_md5 $i`" ] && continue
1386 local fp=`nourl "$i"`
1387 if [ -f "$fp" ]; then
1388 tag_files="$tag_files $fp"
1389 elif [ -n "GREEDSRC" ]; then
1390 get_greed_sources $i
1392 Exit_error err_no_source_in_repo $i
1396 if [ "$tag_files" ]; then
1397 if [ "$TAG_VERSION" = "yes" ]; then
1398 update_shell_title "tag sources: $TAGVER"
1399 printf "Tagging %d files\n" $(echo $tag_files | wc -w)
1400 $CVS_COMMAND $OPTIONS $TAGVER $tag_files || exit
1402 if [ -n "$TAG" ]; then
1403 update_shell_title "tag sources: $TAG"
1405 while [ "$tag_files" ]; do
1406 local chunk=$(echo $tag_files | tr ' ' '\n' | head -n 100)
1407 printf "Tagging %d files\n" $(echo $chunk | wc -w)
1408 $CVS_COMMAND $OPTIONS $TAG $chunk || exit
1409 tag_files=$(echo $tag_files | tr ' ' '\n' | tail +101)
1415 if [ "$TAG_VERSION" = "yes" ]; then
1416 update_shell_title "tag spec: $TAGVER"
1417 $CVS_COMMAND $OPTIONS $TAGVER $SPECFILE || exit
1419 if [ -n "$TAG" ]; then
1420 update_shell_title "tag spec: $TAG"
1421 $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
1427 echo "CVS branch tag: $TAG"
1432 if [ -n "$DEBUG" ]; then
1437 local OPTIONS="tag $CVS_FORCE -b"
1440 is_tag_a_branch $TAG
1441 if [ $? -eq 1 ]; then
1442 OPTIONS="$OPTIONS -B"
1445 if [ -n "$CVSROOT" ]; then
1446 OPTIONS="-d $CVSROOT $OPTIONS"
1450 for i in $TAG_FILES; do
1451 local fp=`nourl "$i"`
1452 if [ -f "$fp" ]; then
1453 tag_files="$tag_files $fp"
1454 elif [ -n "GREEDSRC" ]; then
1455 get_greed_sources $i
1457 Exit_error err_no_source_in_repo $i
1460 if [ "$tag_files" ]; then
1461 $CVS_COMMAND $OPTIONS $TAG $tag_files || exit
1465 $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
1469 # this function should exit early if package can't be built for this arch
1470 # this avoids unneccessary BR filling.
1473 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1475 if [ $ret -ne 0 ]; then
1487 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1488 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1494 local ver="$2" subver=$ver
1495 local newver="$3" newsubver=$newver
1497 # try handling subver, everything that's not numeric-dotted in version
1498 if grep -Eq '%define\s+subver' $specfile; then
1499 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1501 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1502 newver=${newver%$newsubver}
1505 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1506 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1507 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1512 if [ -n "$TRY_UPGRADE" ]; then
1513 local TNOTIFY TNEWVER TOLDVER
1514 update_shell_title "build_package: try_upgrade"
1518 if [ "$UPGRADE_VERSION" ]; then
1519 TNEWVER=$UPGRADE_VERSION
1521 if [ -n "$FLOAT_VERSION" ]; then
1522 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1524 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1527 # pldnotify.awk does not set exit codes, but it has match for ERROR
1528 # in output which means so.
1529 if [[ "$TNOTIFY" = *ERROR* ]]; then
1534 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1537 if [ -n "$TNEWVER" ]; then
1538 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1539 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1540 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1541 cp -f $SPECFILE $SPECFILE.bak
1544 set_release $SPECFILE $PACKAGE_RELEASE 1
1545 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1547 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1548 echo >&2 "Upgrading version failed, you need to update spec yourself"
1558 update_shell_title "build_package"
1559 if [ -n "$DEBUG" ]; then
1568 BUILD_SWITCH="-ba" ;;
1570 BUILD_SWITCH="-bb" ;;
1572 BUILD_SWITCH="-bs --nodeps" ;;
1574 BUILD_SWITCH="-bp --nodeps" ;;
1576 BUILD_SWITCH="-bc" ;;
1578 BUILD_SWITCH="-bi" ;;
1580 BUILD_SWITCH="-bl" ;;
1584 update_shell_title "build_package: $COMMAND"
1585 if [ -n "$LOGFILE" ]; then
1586 LOG=`eval echo $LOGFILE`
1587 if [ -d "$LOG" ]; then
1588 echo "Log file $LOG is a directory."
1589 echo "Parse error in the spec?"
1590 Exit_error err_build_fail
1592 if [ -n "$LASTLOG_FILE" ]; then
1593 echo "LASTLOG=$LOG" > $LASTLOG_FILE
1595 RES_FILE=$(tempfile)
1597 (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
1598 RETVAL=`cat $RES_FILE`
1600 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1601 if [ "$RETVAL" -eq "0" ]; then
1608 eval ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPECFILE
1611 if [ "$RETVAL" -ne "0" ]; then
1612 if [ -n "$TRY_UPGRADE" ]; then
1613 echo "\nUpgrade package to new version failed."
1614 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1615 echo "Restoring old spec file."
1616 mv -f $SPECFILE.bak $SPECFILE
1620 Exit_error err_build_fail
1626 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1629 install_required_packages() {
1634 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1637 /^%changelog/ { exit }
1639 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1640 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1641 gsub(/[ \t]+/, "_", bcond);
1643 }' $SPEC | LC_ALL=C sort -u
1647 # expand bconds from ~/.bcondrc
1648 # The file structure is like gentoo's package.use:
1651 # samba -mysql -pgsql
1652 # w32codec-installer license_agreement
1655 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1661 SN=${SPECFILE%%\.spec}
1663 local bcondrc=$HOME/.bcondrc
1664 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1666 local bcond_avail=$(find_spec_bcond $SPECFILE)
1668 while read pkg flags; do
1670 [[ "$pkg" == \#* ]] && continue
1672 # any package or current package?
1673 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1674 for flag in $flags; do
1675 local opt=${flag#[+-]}
1677 # use only flags which are in this package.
1678 if [[ $bcond_avail = *${opt}* ]]; then
1679 if [[ $flag = -* ]]; then
1680 if [[ $BCOND != *--with?${opt}* ]]; then
1681 BCOND="$BCOND --without $opt"
1684 if [[ $BCOND != *--without?${opt}* ]]; then
1685 BCOND="$BCOND --with $opt"
1692 update_shell_title "parse ~/.bcondrc: DONE!"
1695 set_bconds_values() {
1696 update_shell_title "set bcond values"
1698 AVAIL_BCONDS_WITHOUT=""
1699 AVAIL_BCONDS_WITH=""
1701 if grep -Eq '^# *_with' ${SPECFILE}; then
1702 echo >&2 "ERROR: This spec has old style bconds."
1706 if ! grep -q '^%bcond' ${SPECFILE}; then
1710 local bcond_avail=$(find_spec_bcond $SPECFILE)
1711 process_bcondrc "$SPECFILE"
1713 update_shell_title "parse bconds"
1716 for opt in $bcond_avail; do
1719 bcond=${opt#without_}
1721 *--without?${bcond}*)
1722 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1725 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1733 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1736 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1741 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1750 update_shell_title "run_sub_builder $package_name"
1752 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1753 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1754 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1755 # jakby nie bylo tego kawalka kodu.
1757 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1758 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1762 # kurwa. translate that ^^^^
1766 # Istnieje taki spec? ${package}.spec
1767 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1768 parent_spec_name=${package}.spec
1769 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1770 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1772 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1777 if [ "${parent_spec_name}" != "" ]; then
1778 spawn_sub_builder $parent_spec_name
1780 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1783 spawn_sub_builder() {
1785 update_shell_title "spawn_sub_builder $package_name"
1788 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1789 sub_builder_opts="${sub_builder_opts} -R"
1791 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1792 sub_builder_opts="${sub_builder_opts} -RB"
1793 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1794 sub_builder_opts="${sub_builder_opts} -FRB"
1796 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1797 sub_builder_opts="${sub_builder_opts} -Upi"
1801 ./builder ${sub_builder_opts} "$@"
1804 remove_build_requires() {
1805 if [ "$INSTALLED_PACKAGES" != "" ]; then
1806 case "$REMOVE_BUILD_REQUIRES" in
1808 run_poldek --noask -ve $INSTALLED_PACKAGES
1811 run_poldek --ask -ve $INSTALLED_PACKAGES
1814 echo You may want to manually remove following BuildRequires fetched:
1815 echo $INSTALLED_PACKAGES
1816 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1823 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1824 if [ "$BCOND" ]; then
1826 echo "Building $SPECFILE with the following conditional flags:"
1830 echo "No conditional flags passed"
1833 echo "from available:"
1834 echo "--with :\t$AVAIL_BCONDS_WITH"
1835 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1840 display_branches() {
1841 if [ "$NOCVSSPEC" != "yes" ]; then
1842 echo -n "Available branches: "
1843 $CVS_COMMAND status -v "${SPECFILE}" | awk '!/Sticky Tag:/ && /\(branch:/ { print $1 } ' | xargs
1847 # checks a given list of packages/files/provides agains current rpmdb.
1848 # outputs all dependencies which current rpmdb doesn't satisfy.
1849 # input can be either STDIN or parameters
1853 if [ $# -gt 0 ]; then
1859 DEPS=$(LANG=C rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1862 echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1864 # other deps (files)
1865 echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1868 # checks if given package/files/provides exists in rpmdb.
1869 # input can be either stdin or parameters
1870 # returns packages which are present in the rpmdb
1874 if [ $# -gt 0 ]; then
1880 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1883 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
1884 install_build_requires_rpmdeps() {
1885 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1886 # TODO: Conflicts list doesn't check versions
1887 local CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1888 local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1890 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1891 local CNFL=$(rpm -q --specsrpm --conflicts $BCOND $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
1892 local DEPS=$(rpm -q --specsrpm --requires $BCOND $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
1895 if [ -n "$CNFL" ] || [ -n "$DEPS" ]; then
1896 echo "fetch BuildRequires: install [$DEPS]; remove [$CNFL]"
1897 update_shell_title "poldek: install [$DEPS]; remove [$CNFL]"
1898 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1900 if [ -n "$CNFL" ]; then
1901 update_shell_title "uninstall conflicting packages: $CNFL"
1902 echo "Trying to uninstall conflicting packages ($CNFL):"
1903 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CNFL
1906 while [ "$DEPS" ]; do
1907 update_shell_title "install deps: $DEPS"
1908 echo "Trying to install dependencies ($DEPS):"
1909 local log=.${SPECFILE}_poldek.log
1910 LANG=C $SU_SUDO /usr/bin/poldek --noask --caplookup -uGqQ $DEPS | tee $log
1911 failed=$(awk '/^error:/{a=$2; sub(/^error: /, "", a); sub(/:$/, "", a); print a}' $log)
1914 if [ -n "$failed" ]; then
1915 for package in $failed; do
1916 spawn_sub_builder -bb $(depspecname $package) && ok="$ok $package"
1925 fetch_build_requires()
1927 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
1931 update_shell_title "fetch build requires"
1932 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1933 install_build_requires_rpmdeps
1937 # XXX is this ugliest code written in human history still needed?
1938 echo "All packages installed by fetch_build_requires() are written to:"
1939 echo "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
1941 echo "If anything fails, you may get rid of them by executing:"
1942 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`"
1944 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1945 for package_item in $(cat $SPECFILE | grep -B100000 ^%changelog|grep -v ^#|grep BuildRequires|grep -v ^-|sed -e "s/^.*BuildRequires://g"|awk '{print $1}'|sed -e s,perl\(,perl-,g -e s,::,-,g -e s,\(.*\),,g -e s,%{,,g -e s,},,g|grep -v OpenGL-devel|sed -e s,sh-utils,coreutils,g -e s,fileutils,coreutils,g -e s,textutils,coreutils,g -e s,kgcc_package,gcc,g -e s,\),,g)
1947 package_item=$(echo $package_item|sed -e s,rpmbuild,rpm-build,g |sed -e s,__perl,perl,g |sed -e s,gasp,binutils-gasp,g -e s,binutils-binutils,binutils,g -e s,apxs,apache,g|sed -e s,apache\(EAPI\)-devel,apache-devel,g -e s,kernel-headers\(netfilter\),kernel-headers,g -e s,awk,mawk,g -e s,mmawk,mawk,g -e s,motif,openmotif,g -e s,openopenmotif,openmotif,g)
1949 package=$(basename "$package_item"|sed -e "s/}$//g")
1950 COND_ARCH_TST=$(cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g")
1953 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1954 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1955 if [ "$COND_ARCH_TST" != "" ] && [ "`echo $COND_ARCH_TST|sed -e "s/i.86/ix86/g"`" != "`echo $mach|sed -e "s/i.86/ix86/g"`" ]; then
1960 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1963 if `echo $COND_TST|grep -q 'without_'`; then
1964 COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
1965 if `echo $COND_TST|grep -q !`; then
1970 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1971 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1972 if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
1978 elif `echo $COND_TST|grep -q 'with_'`; then
1979 COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
1980 if `echo $COND_TST|grep -q !`; then
1985 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1986 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1987 if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
1993 RESULT="${COND_STATE}-${COND_ARGV}"
1995 "with-wout" | "wout-with" )
1998 "wout-wout" | "with-with" )
2002 echo "Action '$RESULT' was not defined for package '$package_item'"
2008 if [ "$GO" = "yes" ]; then
2009 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
2010 echo "Testing if $package has subrequirements..."
2011 run_poldek -t -i $package --dumpn=".$package-req.txt"
2012 if [ -f ".$package-req.txt" ]; then
2013 for package_name in `cat ".$package-req.txt"|grep -v ^#`
2015 if [ "$package_name" = "$package" ]; then
2016 echo "Installing BuildRequired package:\t$package_name"
2017 update_shell_title "Installing BuildRequired package: ${package_name}"
2018 install_required_packages $package
2020 echo "Installing (sub)Required package:\t$package_name"
2021 update_shell_title "Installing (sub)Required package: ${package_name}"
2022 install_required_packages $package_name
2026 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2027 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2030 echo "Attempting to run spawn sub - builder..."
2031 echo "Package installation failed:\t$package_name"
2032 run_sub_builder $package_name
2033 if [ $? -eq 0 ]; then
2034 install_required_packages $package_name
2037 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2038 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2041 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2048 rm -f ".$package-req.txt"
2050 echo "Attempting to run spawn sub - builder..."
2051 echo "Package installation failed:\t$package"
2052 run_sub_builder $package
2053 if [ $? -eq 0 ]; then
2054 install_required_packages $package
2057 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2058 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2061 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2067 echo "Package $package is already installed. BuildRequirement satisfied."
2071 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
2072 echo >&2 "Unable to install following packages and their dependencies:"
2073 for pkg in "$NOT_INSTALLED_PACKAGES"
2077 remove_build_requires
2083 local CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"
2084 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2085 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2086 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2087 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2090 echo "Initializing rpm directories to $TOP_DIR from $CVSROOT"
2091 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2093 # need to checkout to tmp dir or we can't name our topdir
2094 tmp=$(TMPDIR= TEMPDIR= mktemp -p $TOP_DIR -d) || exit 1
2096 $CVS_COMMAND -d $CVSROOT co packages/{.cvsignore,rpm.groups,dropin,mirrors,md5,adapter{,.awk},fetchsrc_request,builder,{relup,compile,repackage}.sh,ci,civim}
2098 mv $tmp/packages/* $TOP_DIR
2103 echo "To checkout *all* .spec files (read-only):"
2104 echo "- run cvs co SPECS"
2106 echo "To checkout *all* packages:"
2107 echo "- run cvs up -dP in $TOP_DIR dir"
2110 echo "To commit with your developer account:"
2111 echo "- edit $TOP_DIR/CVS/Root"
2114 get_greed_sources() {
2115 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"
2116 if [ -n "BE_VERBOSE" ]; then
2117 echo "Try greed download: $1 from: $CVSROOT"
2119 $CVS_COMMAND -d $CVSROOT get SOURCES/$1
2120 if [ $? != 0 ]; then
2121 Exit_error err_no_source_in_repo $1
2126 # remove entries from CVS/Entries
2127 cvs_entry_remove() {
2128 local cvsdir="$1"; shift
2129 if [ ! -d "$cvsdir" ]; then
2130 echo >&2 "cvs_entry_remove: $cvsdir is not a directory"
2134 for file in "$@"; do
2135 rm -f $cvsdir/CVS/Entries.new || return 1
2136 awk -ve="${file##*/}" -F/ '$2 != e {print}' $cvsdir/CVS/Entries > $cvsdir/CVS/Entries.new || return 1
2137 mv -f $cvsdir/CVS/Entries.new $cvsdir/CVS/Entries || return 1
2145 DONT_PRINT_REVISION="yes"
2149 local builddir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2151 # remove from CVS/Entries
2152 cvs_entry_remove $PACKAGE_DIR $SPECFILE $SOURCES $PATCHES
2154 # remove spec and sources
2155 $RPMBUILD --clean --rmsource --rmspec --nodeps --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" --define "_builddir $builddir" $SPECFILE
2158 #---------------------------------------------
2166 while [ $# -gt 0 ]; do
2169 # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
2170 # unfortunately $GETURI is already formed
2175 COMMAND="update_md5"
2180 COMMAND="update_md5"
2190 DEBUG="yes"; shift ;;
2192 COMMAND="version"; shift ;;
2194 COMMAND="short-version"; shift ;;
2196 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
2200 -b | -ba | --build )
2201 COMMAND="build"; shift ;;
2202 -bb | --build-binary )
2203 COMMAND="build-binary"; shift ;;
2205 COMMAND="build-build"; shift ;;
2207 COMMAND="build-install"; shift ;;
2209 COMMAND="build-list"; shift ;;
2210 -bp | --build-prep )
2211 COMMAND="build-prep"; shift ;;
2212 -bs | --build-source )
2213 COMMAND="build-source"; shift ;;
2215 COMMAND="branch"; shift; TAG="${1}"; shift;;
2217 CLEAN="--clean"; shift ;;
2219 CVS_FORCE="-F"; shift;;
2221 shift; CVSROOT="${1}"; shift ;;
2223 COMMAND="get"; shift ;;
2225 COMMAND="usage"; shift ;;
2227 PROTOCOL="ftp"; shift ;;
2229 PROTOCOL="http"; shift ;;
2231 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2235 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2239 shift; LOGFILE="${1}"; shift ;;
2241 shift; DEF_NICE_LEVEL=${1}; shift ;;
2242 -ske | --skip-existing-files)
2243 SKIP_EXISTING_FILES="yes"; shift ;;
2245 COMMAND="mr-proper"; shift ;;
2247 NOCVS="yes"; shift ;;
2248 -ncs | --no-cvs-specs )
2249 NOCVSSPEC="yes"; shift ;;
2250 -nd | --no-distfiles )
2251 NODIST="yes"; shift ;;
2252 -nm | --no-mirrors )
2253 NOMIRRORS="yes"; shift ;;
2255 NOURLS="yes"; shift ;;
2257 NOSRCS="yes"; shift ;;
2258 -ns0 | --no-source0 )
2259 NOSOURCE0="yes"; shift ;;
2269 -pm | --prefer-mirrors )
2276 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2278 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2279 --skip-patch | -sp )
2280 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2282 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2285 --with | --without )
2286 case $GROUP_BCONDS in
2290 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2291 while ! `echo ${1}|grep -qE '(^-|spec)'`
2293 BCOND="$BCOND $COND $1"
2297 if [[ "$2" = *,* ]]; then
2298 for a in $(echo "$2" | tr , ' '); do
2299 BCOND="$BCOND $1 $a"
2302 BCOND="$BCOND $1 $2"
2308 shift; TARGET="${1}"; shift ;;
2310 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2312 QUIET="--quiet"; shift ;;
2314 CVSDATE="${2}"; shift 2 ;;
2323 -R | --fetch-build-requires)
2324 FETCH_BUILD_REQUIRES="yes"
2325 NOT_INSTALLED_PACKAGES=
2327 -RB | --remove-build-requires)
2328 REMOVE_BUILD_REQUIRES="nice"
2330 -FRB | --force-remove-build-requires)
2331 REMOVE_BUILD_REQUIRES="force"
2333 -sc | --sources-cvs)
2334 COMMAND="list-sources-cvs"
2336 -sd | --source-distfiles)
2337 COMMAND="list-sources-distfiles"
2339 -sdp | --source-distfiles-paths)
2340 COMMAND="list-sources-distfiles-paths"
2342 -sf | --source-files)
2343 COMMAND="list-sources-files"
2345 -lsp | --source-paths)
2346 COMMAND="list-sources-local-paths"
2348 -su | --source-urls)
2349 COMMAND="list-sources-urls"
2351 -Tvs | --tag-version-stable )
2356 -Ts | --tag-stable )
2361 -Tv | --tag-version )
2366 -Tp | --tag-prefix )
2378 -ir | --integer-release-only )
2379 INTEGER_RELEASE="yes"
2382 COMMAND="update_md5"
2387 -Upi | --update-poldek-indexes )
2388 UPDATE_POLDEK_INDEXES="yes"
2391 COMMAND="init_rpm_dir"
2393 --use-greed-sources )
2396 -u | --try-upgrade )
2397 TRY_UPGRADE="1"; shift ;;
2399 shift; UPGRADE_VERSION="$1"; shift;;
2400 -un | --try-upgrade-with-float-version )
2401 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2403 BE_VERBOSE="1"; shift ;;
2408 if echo "${MACRO}" | grep -q '\W'; then
2409 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2413 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2418 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\""
2422 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2425 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2426 COMMAND="show_bconds"
2430 COMMAND="show_bcond_args"
2433 --show-avail-bconds)
2434 COMMAND="show_avail_bconds"
2439 RPMOPTS="${RPMOPTS} --nodeps"
2442 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2445 Exit_error err_invalid_cmdline "$1"
2448 SPECFILE=${1%/}; shift
2449 # check if specname was passed as specname:cvstag
2450 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2451 CVSTAG="${SPECFILE##*:}"
2452 SPECFILE="${SPECFILE%%:*}"
2454 # always have SPECFILE ending with .spec extension
2455 SPECFILE=${SPECFILE%%.spec}.spec
2456 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2460 [ -d "$ASSUMED_NAME" ] && CVS_ENTRIES="$ASSUMED_NAME/CVS/Entries" || CVS_ENTRIES="CVS/Entries"
2461 if [ -f "$CVS_ENTRIES" ] && [ -z "$CVSTAG" ]; then
2462 CVSTAG=$(awk -vSPECFILE=$(basename $SPECFILE) -F/ '$2 == SPECFILE && $6 ~ /^T/{print substr($6, 2)}' ${CVS_ENTRIES})
2463 if [ "$CVSTAG" ]; then
2464 echo >&2 "builder: Sticky tag $CVSTAG active. Use -r TAGNAME to override."
2466 elif [ "$CVSTAG" = "HEAD" ]; then
2467 # assume -r HEAD is same as -A
2471 if [ "$CVSTAG" ]; then
2472 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2473 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2476 if [ -n "$DEBUG" ]; then
2481 if [ -n "$TARGET" ]; then
2484 TARGET_SWITCH="--target $TARGET" ;;
2486 TARGET_SWITCH="--target=$TARGET" ;;
2490 if [ "$SCHEDTOOL" != "no" ]; then
2491 NICE_COMMAND="$SCHEDTOOL"
2493 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2496 update_shell_title "$COMMAND"
2500 if [ -z "$SPECFILE" ]; then
2501 Exit_error err_no_spec_in_cmdl
2503 get_spec > /dev/null
2510 if [ -z "$SPECFILE" ]; then
2511 Exit_error err_no_spec_in_cmdl
2513 get_spec > /dev/null
2518 "show_avail_bconds")
2520 if [ -z "$SPECFILE" ]; then
2521 Exit_error err_no_spec_in_cmdl
2524 get_spec > /dev/null
2526 local bcond_avail=$(find_spec_bcond $SPECFILE)
2527 local opt bcond bconds
2528 for opt in $bcond_avail; do
2531 bcond=${opt#without_}
2532 bconds="$bconds $bcond"
2536 bconds="$bconds $bcond"
2539 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2547 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2549 if [ -z "$SPECFILE" ]; then
2550 Exit_error err_no_spec_in_cmdl
2553 # display SMP make flags if set
2554 smp_mflags=$(rpm -E %{?_smp_mflags})
2555 if [ "$smp_mflags" ]; then
2556 echo "builder: SMP make flags are set to $smp_mflags"
2564 if [ "$COMMAND" != "build-source" ]; then
2567 fetch_build_requires
2568 if [ "$INTEGER_RELEASE" = "yes" ]; then
2569 echo "Checking release $PACKAGE_RELEASE..."
2570 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2571 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2575 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2576 if [ -n "$TEST_TAG" ]; then
2577 local TAGVER=`make_tagver`
2578 # escape some regexp characters if part of TAGVER
2579 TAGVER=$(echo "$TAGVER" | sed -e 's#\([\+\*\.]\)#\\\1#g')
2580 echo "Searching for tag $TAGVER..."
2581 TAGREL=$($CVS_COMMAND status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
2582 if [ -n "$TAGREL" ]; then
2583 Exit_error err_tag_exists "$TAGVER" "$TAGREL"
2586 # - do not allow to build from HEAD when XX-branch exists
2587 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto-\([a-zA-Z]\+\)-.*#\1#g')
2588 if [ "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2589 TAG_BRANCH="${TREE_PREFIX}-branch"
2590 TAG_STATUS=$($CVS_COMMAND status -v $SPECFILE | grep -Ei "${TAG_BRANCH}.+(branch: [0-9.]+)")
2591 if [ -n "$TAG_STATUS" -a "$CVSTAG" = "HEAD" ]; then
2592 Exit_error err_branch_exists "$TAG_STATUS"
2598 if [ -n "$NOSOURCE0" ] ; then
2599 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2604 get_files $SOURCES $PATCHES
2608 NODIST="yes" get_files $SOURCES $PATCHES
2609 update_md5 $SOURCES $PATCHES
2613 if [ "$UPDATE_POLDEK_INDEXES" = "yes" -a "$COMMAND" != "build-prep" ]; then
2614 run_poldek --sdir="${POLDEK_INDEX_DIR}" --mkidxz
2616 remove_build_requires
2620 if [ -z "$SPECFILE" ]; then
2621 Exit_error err_no_spec_in_cmdl
2626 # don't fetch sources from remote locations
2628 for file in $SOURCES; do
2629 [ -n "`src_md5 $file`" ] && continue
2630 new_SOURCES="$new_SOURCES $file"
2632 SOURCES="$new_SOURCES"
2633 get_files $SOURCES $PATCHES
2635 branch_files $TAG $SOURCES $PATCHES $ICONS
2639 if [ -z "$SPECFILE" ]; then
2640 Exit_error err_no_spec_in_cmdl
2643 ADD_PACKAGE_CVS=yes get_spec
2646 if [ -n "$NOSOURCE0" ] ; then
2647 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2649 get_files $SOURCES $PATCHES
2654 if [ -z "$SPECFILE" ]; then
2655 Exit_error err_no_spec_in_cmdl
2661 if [ -n "$NOSOURCE0" ] ; then
2662 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2664 get_files $SOURCES $PATCHES
2669 if [ -z "$SPECFILE" ]; then
2670 Exit_error err_no_spec_in_cmdl
2676 if [ -n "$NOSOURCE0" ] ; then
2677 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2679 update_md5 $SOURCES $PATCHES
2685 if [ -z "$SPECFILE" ]; then
2686 Exit_error err_no_spec_in_cmdl
2692 # don't fetch sources from remote locations
2694 for file in $SOURCES; do
2695 [ -n "`src_md5 $file`" ] && continue
2696 new_SOURCES="$new_SOURCES $file"
2698 SOURCES="$new_SOURCES"
2699 get_files $SOURCES $PATCHES
2701 tag_files $SOURCES $PATCHES $ICONS
2706 "list-sources-files" )
2709 DONT_PRINT_REVISION="yes"
2712 for SAP in $SOURCES $PATCHES; do
2713 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2716 "list-sources-urls" )
2719 DONT_PRINT_REVISION="yes"
2722 SAPS="$SOURCES $PATCHES"
2723 for SAP in $SAPS ; do
2727 "list-sources-local-paths" )
2730 DONT_PRINT_REVISION="yes"
2733 for SAP in $SOURCES $PATCHES; do
2734 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2737 "list-sources-distfiles-paths" )
2740 DONT_PRINT_REVISION="yes"
2743 for SAP in $SOURCES $PATCHES; do
2744 if [ -n "$(src_md5 "$SAP")" ]; then
2745 distfiles_path "$SAP"
2749 "list-sources-distfiles" )
2752 DONT_PRINT_REVISION="yes"
2755 for SAP in $SOURCES $PATCHES; do
2756 if [ -n "$(src_md5 "$SAP")" ]; then
2757 distfiles_url "$SAP"
2761 "list-sources-cvs" )
2764 DONT_PRINT_REVISION="yes"
2767 for SAP in $SOURCES $PATCHES; do
2768 if [ -z "$(src_md5 "$SAP")" ]; then
2769 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2783 echo "$VERSIONSTRING"
2786 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2787 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2791 # vi:syntax=sh:ts=4:sw=4:noet