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
265 lftp -c "set net:max-retries $WGET_RETRIES; set http:user-agent \"$USER_AGENT\"; pget -n 10 -c \"$url\" -o \"$tmpfile\""
268 if [ $retval -eq 0 ]; then
269 mv -f "$tmpfile" "$outfile"
277 if [ -n "$DEBUG" ]; then set -xv; fi
279 Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--add_cvs] [-b|-ba|--build]
280 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
281 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>]
282 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
283 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T|--tag <cvstag>]
284 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
285 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}] [--use-greed-sources]
286 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
287 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
288 <package>[.spec][:cvstag]
290 -4 - force ipv4 when transferring files
291 -5, --update-md5 - update md5 comments in spec, implies -nd -ncs
292 -6 - force ipv6 when transferring files
293 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
294 -n5, --no-md5 - ignore md5 comments in spec
295 -D, --debug - enable builder script debugging mode,
296 -debug - produce rpm debug package (same as --opts -debug)
297 -V, --version - output builder version string
298 --short-version - output builder short version
299 --as_anon - get files via pserver as cvs@$CVS_SERVER,
300 -a, --add_cvs - try add new package to CVS.
301 -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
303 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
304 only package from <package>.spec,
305 -bp, --build-prep - execute the %prep phase of <package>.spec,
306 -bc - execute the %build phase of <package>.spec,
307 -bi - execute the %install phase of <package>.spec
308 -bl - execute the %files phase of <package>.spec
309 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
311 --short-circuit - short-circuit build
312 -B, --branch - add branch
313 -c, --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
314 may be used with building process.
315 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES, SPECS and \$RPM_BUILD_ROOT
316 and CVS/Entries). Doesn't run any rpm building.
317 -cf, --cvs-force - use -F when tagging (useful when moving branches)
318 -d <cvsroot>, --cvsroot <cvsroot>
320 --define <macro> <value> - define a macro <macro> with value <value>,
321 --alt_kernel <kernel> - same as --define 'alt_kernel <kernel>'
322 --nodeps - rpm won't check any dependences
323 -g, --get - get <package>.spec and all related files from CVS repo or HTTP/FTP
324 -h, --help - this message
325 -jN, -j N - set %_smp_mflags to propagate concurrent jobs
326 --ftp, --http - use ftp or http protocol to access distfiles server
327 -l <logfile>, --logtofile <logfile>
329 -nc, --no-cvs - don't download sources from CVS, if source URL is given,
330 -ncs, --no-cvs-specs - don't check specs in CVS
331 -nd, --no-distfiles - don't download from distfiles
332 -nm, --no-mirrors - don't download from mirror, if source URL is given,
333 -nu, --no-urls - don't try to download from FTP/HTTP location,
334 -ns, --no-srcs - don't download Sources/Patches
335 -ns0, --no-source0 - don't download Source0
336 -nn, --no-net - don't download anything from the net
337 -pm, --prefer-mirrors - prefer mirrors (if any) over distfiles for SOURCES
338 --no-init - don't initialize builder paths (SPECS and SOURCES)
340 --skip-existing-files - skip existing files in get_files
341 --opts <rpm opts> - additional options for rpm
342 -q, --quiet - be quiet,
343 --date yyyy-mm-dd - build package using resources from specified CVS date,
344 -r <cvstag>, --cvstag <cvstag>
345 - build package using resources from specified CVS tag,
346 -A - build package using CVS resources as any sticky tags/date/kopts being reset.
347 -R, --fetch-build-requires
348 - fetch what is BuildRequired,
349 -RB, --remove-build-requires
350 - remove all you fetched with -R or --fetch-build-requires
351 remember, this option requires confirmation,
352 -FRB, --force-remove-build-requires
353 - remove all you fetched with -R or --fetch-build-requires
354 remember, this option works without confirmation,
355 -sd, --source-distfiles - list sources available from distfiles (intended for offline
356 operations; does not work when Icon field is present
357 but icon file is absent),
358 -sc, --source-cvs - list sources available from CVS
359 -sdp, --source-distfiles-paths - list sources available from distfiles -
360 paths relative to distfiles directory (intended for offline
361 operations; does not work when Icon field is present
362 but icon file is absent),
363 -sf, --source-files - list sources - bare filenames (intended for offline
364 operations; does not work when Icon field is present
365 but icon file is absent),
366 -lsp, --source-paths - list sources - filenames with full local paths (intended for
367 offline operations; does not work when Icon field is present
368 but icon file is absent),
369 -su, --source-urls - list urls - urls to sources and patches
370 intended for copying urls with spec with lots of macros in urls
371 -T <cvstag> , --tag <cvstag>
372 - add cvs tag <cvstag> for files,
373 -Tvs, --tag-version-stable
374 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
375 -Ts, --tag-stable - add cvs tag STABLE for files,
376 -Tv, --tag-version - add cvs tag NAME-VERSION-RELEASE for files,
377 -Tp, --tag-prefix <prefix>
378 - add <prefix> to NAME-VERSION-RELEASE tags,
379 -tt, --test-tag <prefix>
380 - fail if tag is already present,
381 -ir, --integer-release-only
382 - allow only integer and snapshot releases
383 -v, --verbose - be verbose,
384 -u, --try-upgrade - check version, and try to upgrade package
385 -un, --try-upgrade-with-float-version
386 - as above, but allow float version
387 php-pear-Services_Digg/
388 --upgrade-version - upgrade to specified version in try-upgrade
390 - try download source from tag head if don't find it in
392 -U, --update - refetch sources, don't use distfiles, and update md5 comments
393 -Upi, --update-poldek-indexes
394 - refresh or make poldek package index files.
395 -sp, --skip-patch <patchnumber>
396 - don't apply <patchnumber>. may be repeated.
397 -np, --nopatch <patchnumber>
398 - abort instead of applying patch <patchnumber>
399 --show-bconds - show available conditional builds, which can be used
400 - with --with and/or --without switches.
401 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
402 In other words, the output is parseable by scripts.
403 --show-avail-bconds - show available bconds
404 --with/--without <feature>
405 - conditional build package depending on %_with_<feature>/
406 %_without_<feature> macro switch. You may now use
407 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
408 constructions. Set GROUP_BCONDS to yes to make use of it.
409 --target <platform>, --target=<platform>
410 - build for platform <platform>.
411 --init-rpm-dir - initialize ~/rpm directory structure
415 # create tempfile. as secure as possible
417 mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
420 # change dependency to specname
422 # - perl(Package::Name) -> perl-Package-Name
426 package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
430 update_shell_title() {
432 local len=${COLUMNS:-80}
433 local msg="$(echo "$*" | cut -c-$len)"
435 if [ -n "$BE_VERBOSE" ]; then
436 echo >&2 "$(date +%s.%N) $*"
439 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
441 if [ -n "$PACKAGE_NAME" ]; then
442 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
447 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
448 msg=$(echo $msg | tr -d '\n\r')
451 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
454 echo >&2 -ne "\033]0;$msg\007"
460 # set TARGET from BuildArch: from SPECFILE
462 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
463 tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
465 target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
469 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
471 TARGET_SWITCH="--target=$TARGET" ;;
477 # runs rpm with minimal macroset
479 # we reset macros not to contain macros.build as all the %() macros are
480 # executed here, while none of them are actually needed.
481 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
482 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ')
484 # TODO: move these to /usr/lib/rpm/macros
485 cat > $BUILDER_MACROS <<'EOF'
486 %x8664 x86_64 amd64 ia32e
489 %bootstrap_release() %{1}
490 %requires_releq_kernel_up(s:n:) %{nil}
491 %requires_releq_kernel_smp(s:n:) %{nil}
492 %requires_releq_kernel(s:n:) %{nil}
493 %requires_releq() %{nil}
494 %pyrequires_eq() %{nil}
495 %requires_eq() %{nil}
496 %requires_eq_to() %{nil}
497 %requires_ge() %{nil}
498 %requires_ge_to() %{nil}
499 %requires_ge() %{nil}
500 %releq_kernel_up(n:) ERROR
501 %releq_kernel_smp(n:) ERROR
502 %releq_kernel(n:) ERROR
506 %ruby_ver_requires_eq() %{nil}
507 %ruby_mod_ver_requires_eq() %{nil}
508 %__php_api_requires() %{nil}
509 %php_major_version ERROR
510 %php_api_version ERROR
511 %requires_xorg_xserver_extension %{nil}
512 %requires_xorg_xserver_xinput %{nil}
513 %requires_xorg_xserver_font %{nil}
514 %requires_xorg_xserver_videodrv %{nil}
516 %perl_vendorarch ERROR
517 %perl_vendorlib ERROR
518 # damn. need it here! - copied from /usr/lib/rpm/macros.build
519 %tmpdir %(echo "${TMPDIR:-/tmp}")
520 %patchset_source(f:b:) %(
521 base=%{-b*}%{!-b*:10000};
522 start=$(expr $base + %1);
523 end=$(expr $base + %{?2}%{!?2:%{1}});
524 # we need to call seq twice as it doesn't allow two formats
525 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
526 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
527 paste %{tmpdir}/__ps{1,2};
528 rm -f %{tmpdir}/__ps{1,2};
531 %add_etc_shells(p) %{p:<lua>}
532 %remove_etc_shells(p) %{p:<lua>}
533 %lua_add_etc_shells() %{nil}
534 %lua_remove_etc_shells() %{nil}
536 %buildrequires_jdk %{nil}
537 %pear_package_print_optionalpackages %{nil}
539 if [ "$NOINIT" = "yes" ] ; then
540 cat >> $BUILDER_MACROS <<'EOF'
545 eval $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
549 if [ -n "$DEBUG" ]; then
554 if [ -x /usr/bin/rpm-specdump ]; then
555 update_shell_title "cache_rpm_dump using rpm-specdump command"
556 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND $SPECFILE)
558 update_shell_title "cache_rpm_dump using rpmbuild command"
561 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
562 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
568 ARGS='--nodigest --nosignature --nobuild'
571 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
573 if [ $? -gt 0 ]; then
574 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
576 Exit_error err_build_fail
579 # make small dump cache
580 rpm_dump_cache=`echo "$rpm_dump" | awk '
581 $2 ~ /^SOURCEURL/ {print}
582 $2 ~ /^PATCHURL/ {print}
583 $2 ~ /^nosource/ {print}
584 $2 ~ /^PACKAGE_/ {print}
588 update_shell_title "cache_rpm_dump: OK!"
592 if [ -z "$rpm_dump_cache" ] ; then
593 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
595 echo "$rpm_dump_cache"
599 update_shell_title "get icons"
600 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
601 if [ -z "$ICONS" ]; then
605 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
609 update_shell_title "parsing specfile"
610 if [ -n "$DEBUG" ]; then
615 # icons are needed for successful spec parse
621 if rpm_dump | grep -qEi ":.*nosource.*1"; then
622 FAIL_IF_NO_SOURCES="no"
625 if [ "$NOSRCS" != "yes" ]; then
626 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
627 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
628 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
631 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
632 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
633 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
635 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
636 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
639 if [ -n "$BE_VERBOSE" ]; then
640 echo "- Sources : `nourl $SOURCES`"
641 if [ -n "$PATCHES" ]; then
642 echo "- Patches : `nourl $PATCHES`"
644 echo "- Patches : *no patches needed*"
646 if [ -n "$ICONS" ]; then
647 echo "- Icon : `nourl $ICONS`"
649 echo "- Icon : *no package icon*"
651 echo "- Name : $PACKAGE_NAME"
652 echo "- Version : $PACKAGE_VERSION"
653 echo "- Release : $PACKAGE_RELEASE"
656 update_shell_title "parse_spec: OK!"
660 if [ -n "$DEBUG" ]; then
668 "err_no_spec_in_cmdl" )
669 remove_build_requires
670 echo >&2 "ERROR: spec file name not specified."
672 "err_invalid_cmdline" )
673 echo >&2 "ERROR: invalid command line arg ($2)."
675 "err_no_spec_in_repo" )
676 remove_build_requires
677 echo >&2 "Error: spec file not stored in CVS repo."
679 "err_no_source_in_repo" )
680 remove_build_requires
681 echo >&2 "Error: some source, patch or icon files not stored in CVS repo. ($2)"
683 "err_cvs_add_failed" )
684 echo >&2 "Error: failed to add package to CVS repo."
687 remove_build_requires
688 echo >&2 "Error: package build failed. (${2:-no more info})"
690 "err_no_package_data" )
691 remove_build_requires
692 echo >&2 "Error: couldn't get out package name/version/release from spec file."
695 remove_build_requires
696 echo >&2 "Tag ${2} already exists (spec release: ${3})."
699 remove_build_requires
700 echo >&2 "Release ${2} not integer and not a snapshot."
702 "err_branch_exists" )
703 remove_build_requires
704 echo >&2 "Tree branch already exists (${2})."
707 remove_build_requires
708 echo >&2 "Error: conditions reject building this spec (${2})."
711 echo >&2 "Unknown error."
716 if [ -n "$DEBUG" ]; then
721 if [ "$NOINIT" != "yes" ] ; then
722 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
724 local macros_ver=$(rpm -E %?rpm_build_macros)
725 if [ -z "$macros_ver" ]; then
726 REPO_DIR=$TOP_DIR/packages
727 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
729 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
730 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
734 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
746 update_shell_title "get_spec"
748 if [ -n "$DEBUG" ]; then
754 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
756 SPECFILE=$(basename $SPECFILE)
759 if [ "$NOCVSSPEC" != "yes" ]; then
760 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
761 echo "Warning: No CVS access defined in $(pwd)- using local .spec file"
765 if [ -d "$ASSUMED_NAME" -a -s "$ASSUMED_NAME/CVS/Root" ]; then
766 cvsup "$ASSUMED_NAME/$SPECFILE" || Exit_error err_no_spec_in_repo
767 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
768 if [ ! -r "$ASSUMED_NAME/$SPECFILE" ]; then
769 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
772 if [ ! -s "$ASSUMED_NAME/CVS/Root" ]; then
773 cvsup -a $ASSUMED_NAME || Exit_error err_cvs_add_failed
775 cvsup -a "$ASSUMED_NAME/$SPECFILE" || Exit_error err_cvs_add_failed
777 cvsup -c -d $ASSUMED_NAME "packages/$ASSUMED_NAME/$SPECFILE" || {
778 # softfail if new package, i.e not yet added to cvs
779 [ ! -f "$ASSUMED_NAME/$SPECFILE" ] && Exit_error err_no_spec_in_repo
780 echo "Warning: package not in CVS - assuming new package"
785 # remove Entries.Static -- so 'cvs up' would update all files in a repo
786 rm -f "$ASSUMED_NAME/CVS/Entries.Static"
789 cvsignore_df .cvsignore
791 # add default log format to .cvsignore if it is relative to package dir
792 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
793 # substitute known "macros" to glob
794 local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\),*,g')
795 if [ "$logfile" ]; then
796 cvsignore_df "$logfile"
800 # create symlinks for tools
801 if [ "$SYMLINK_TOOLS" != "no" ]; then
802 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
803 # skip tools that don't exist in top dir
804 [ -f $a ] || continue
805 # skip tools that already exist
806 [ -f $ASSUMED_NAME/$a ] && continue
807 ln -s ../$a $ASSUMED_NAME
813 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
814 Exit_error err_no_spec_in_repo
817 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
818 chmod $CHMOD_MODE $ASSUMED_NAME/$SPECFILE
821 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $ASSUMED_NAME/$SPECFILE
829 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
830 $CVS_COMMAND update mirrors >&2
834 local origin mirror name rest ol prefix
835 while read origin mirror name rest; do
836 # skip comments and empty lines
837 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
840 ol=$(echo -n "$origin" | wc -c)
841 prefix=$(echo -n "$url" | head -c $ol)
842 if [ "$prefix" = "$origin" ] ; then
843 suffix=$(echo "$url" | cut -b $((ol+1))-)
844 echo -n "$mirror$suffix"
851 # Warning: unpredictable results if same URL used twice
854 # escape some regexp characters if part of file name
855 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
858 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
859 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
860 head -n 1 | tr OURCEATH ourceath | xargs
864 [ "$NO5" = "yes" ] && return
866 [ -z "$no" ] && return
870 if [ -f additional-md5sums ]; then
871 local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
872 if [ -z "$spec_rev" ]; then
873 spec_rev=$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')
875 local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
876 md5=$(grep -s -v '^#' additional-md5sums | \
877 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
878 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
879 grep -E '^[0-9a-f]{32}$')
882 if [ $(echo "$md5" | wc -l) != 1 ] ; then
883 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
885 echo "$md5" | tail -n 1
890 source_md5=`grep -i "^#[ ]*$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
891 if [ -n "$source_md5" ]; then
894 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
895 if [ -n "$source_md5" ]; then
898 # we have empty SourceX-md5, but it is still possible
899 # that we have NoSourceX-md5 AND NoSource: X
900 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
901 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
909 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
913 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
916 distfiles_attic_url() {
917 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
923 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
927 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
928 [ -n "$size" -a "$size" -gt 0 ]
932 if [ "$CVSIGNORE_DF" != "yes" ]; then
935 cvsignore=${PACKAGE_DIR}/.cvsignore
937 # add only if not yet there
938 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
939 echo "$1" >> $cvsignore
944 update_shell_title "cvsup"
945 local OPTIONS="" ACTION="up"
948 if [ "$1" = "-c" ]; then
953 if [ "$1" = "-a" ]; then
960 if [ -n "$CVSROOT" ]; then
961 OPTIONS="-d $CVSROOT $OPTIONS"
964 if [ "$ACTION" != "add" ]; then
965 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
966 OPTIONS="$OPTIONS -A"
968 if [ -n "$CVSDATE" ]; then
969 OPTIONS="$OPTIONS -D $CVSDATE"
971 if [ -n "$CVSTAG" ]; then
972 # FIXME: cvs add actually works with -r ?
973 OPTIONS="$OPTIONS -r $CVSTAG"
979 local retries_counter=0
981 update_shell_title "cvsup: $*"
983 update_shell_title "cvsup: $# files"
985 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
986 retries_counter=$(( $retries_counter + 1 ))
987 output=$(LC_ALL=C $CVS_COMMAND $OPTIONS "$@" 2>&1)
989 [ -n "$output" ] && echo "$output"
990 if echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)" \
991 && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
992 echo "Trying again [$*]... ($retries_counter)"
993 update_shell_title "cvsup: retry #$retries_counter"
1000 update_shell_title "cvsup: done!"
1004 # returns true if "$1" is ftp, http or https protocol url
1007 ftp://*|http://*|https://*)
1015 if [ $# -eq 0 ]; then
1019 update_shell_title "update md5"
1020 if [ -n "$DEBUG" ]; then
1027 # pass 1: check files to be fetched
1031 local fp=$(nourl "$i")
1032 local srcno=$(src_no "$i")
1033 if [ -n "$ADD5" ]; then
1034 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1035 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1036 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1038 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1040 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1041 need_files="$need_files $i"
1045 # pass 1a: get needed files
1046 if [ "$need_files" ]; then
1047 get_files $need_files
1050 # pass 2: proceed with md5 adding or updating
1052 local fp=$(nourl "$i")
1053 local srcno=$(src_no "$i")
1054 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1055 if [ -z "$md5" ]; then
1056 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1058 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1059 local tag="# $srcno-md5:\t"
1060 if [[ "$md5" == *NoSource* ]]; then
1061 tag="# NoSource$srcno-md5:\t"
1062 elif [ -n "$USEDIGEST" ]; then
1063 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1065 md5=$(md5sum "$fp" | cut -f1 -d' ')
1066 echo "Updating $srcno ($md5: $fp)."
1068 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1069 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1071 $PACKAGE_DIR/$SPECFILE
1078 [ "$NO5" = "yes" ] && return
1080 update_shell_title "check md5"
1084 if ! good_md5 "$i"; then
1085 echo -n "MD5 sum mismatch."
1088 if ! good_size "$i"; then
1089 echo -n "0 sized file."
1093 if [ $bad -eq 1 ]; then
1094 echo " Use -U to refetch sources,"
1095 echo "or -5 to update md5 sums, if you're sure files are correct."
1096 Exit_error err_no_source_in_repo $i
1102 update_shell_title "get_files"
1104 if [ -n "$DEBUG" ]; then
1109 if [ $# -gt 0 ]; then
1112 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
1113 echo "Warning: No CVS access defined for SOURCES"
1118 local get_files_cvs=""
1122 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1123 update_shell_title "$i"
1124 local fp=`nourl "$i"`
1125 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1130 local srcmd5=$(src_md5 "$i")
1132 # we know if source/patch is present in cvs/distfiles
1133 # - has md5 (in distfiles)
1134 # - in cvs... ideas?
1136 # CHECK: local file didn't exist or always cvs up (first) requested.
1137 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1138 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1139 echo "Warning: no URL given for $i"
1143 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1144 if good_md5 "$i" && good_size "$i"; then
1145 echo "$fp having proper md5sum already exists"
1149 # optionally prefer mirror over distfiles if there's mirror
1150 # TODO: build url list and then try each url from the list
1151 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1154 url=$(distfiles_url "$i")
1157 url_attic=$(distfiles_attic_url "$i")
1159 # is $url local file?
1160 if [[ "$url" = [./]* ]]; then
1161 update_shell_title "${GETLOCAL%% *}: $url"
1162 ${GETLOCAL} $url $target
1164 if [ -z "$NOMIRRORS" ]; then
1165 url=$(find_mirror "$url")
1169 # make shorter message for distfiles urls
1170 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1171 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1172 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1175 update_shell_title "${GETURI%% *}: $uri"
1176 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1177 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1178 update_shell_title "${GETURI2%% *}: $url"
1179 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1184 if [ ! -s "$target" ]; then
1186 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
1187 update_shell_title "${GETLOCAL%% *}: $url_attic"
1188 ${GETLOCAL} $url_attic $target
1190 if [ -z "$NOMIRRORS" ]; then
1191 url_attic=$(find_mirror "$url_attic")
1193 update_shell_title "${GETURI%% *}: $url_attic"
1194 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1195 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1196 update_shell_title "${GETURI2%% *}: $url_attic"
1197 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1199 test -s "$target" || rm -f "$target"
1203 if [ -s "$target" ]; then
1204 cvsignore_df $target
1209 elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then
1210 if [ $# -gt 1 ]; then
1211 get_files_cvs="$get_files_cvs $fp"
1212 update_shell_title "$fp (will cvs up later)"
1219 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1220 if [ -z "$NOMIRRORS" ]; then
1221 im=$(find_mirror "$i")
1225 update_shell_title "${GETURI%% *}: $im"
1226 ${GETURI} ${OUTFILEOPT} "$target" "$im" || \
1227 if [ "`echo $im | grep -E 'ftp://'`" ]; then
1228 update_shell_title "${GETURI2%% *}: $im"
1229 ${GETURI2} ${OUTFILEOPT} "$target" "$im"
1231 test -s "$target" || rm -f "$target"
1234 if [ "$cvsup" = 1 ]; then
1240 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1241 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1242 if [ -n "GREEDSRC" ]; then
1243 get_greed_sources $i
1245 Exit_error err_no_source_in_repo $i
1249 # we check md5 here just only to refetch immediately
1250 if good_md5 "$i" && good_size "$i"; then
1252 elif [ "$FROM_DISTFILES" = 1 ]; then
1253 # wrong md5 from distfiles: remove the file and try again
1255 echo "MD5 sum mismatch. Trying full fetch."
1258 update_shell_title "${GETURI%% *}: $url"
1259 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1260 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1261 update_shell_title "${GETURI2%% *}: $url"
1262 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1264 if [ ! -s "$target" ]; then
1266 update_shell_title "${GETURI%% *}: $url_attic"
1267 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1268 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1269 update_shell_title "${GETURI2%% *}: $url_attic"
1270 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1273 test -s "$target" || rm -f "$target"
1276 SHELL_TITLE_PREFIX=""
1278 if [ "$get_files_cvs" ]; then
1279 cvsup $get_files_cvs
1282 if [ "$CHMOD" = "yes" ]; then
1283 CHMOD_FILES=$(nourl "$@")
1284 if [ -n "$CHMOD_FILES" ]; then
1285 chmod $CHMOD_MODE $CHMOD_FILES
1292 if [ -n "$DEBUG" ]; then
1297 # Check whether first character of PACKAGE_NAME is legal for tag name
1298 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1302 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1303 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE | tr '[.@]' '[_#]')
1305 # Remove #kernel.version_release from TAGVER because tagging sources
1306 # could occur with different kernel-headers than kernel-headers used at build time.
1307 # besides, %{_kernel_ver_str} is not expanded.
1309 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1#%{_kernel_ver_str}
1310 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1316 # bool is_tag_a_branch(tag)
1318 # returns 1 if a tag is a branch set on SPECFILE
1320 if [ -n "$DEBUG" ]; then
1325 if [ $# -ne 1 ]; then
1330 # escape some regexp characters if part of TAG
1331 TAG=$(echo "$TAG" | sed -e 's#\([\+\*\.]\)#\\\1#g')
1335 $CVS_COMMAND status -v $SPECFILE | grep -Eiq "${TAG}.+(branch: [0-9.]+)"
1342 if [ -n "$DEBUG" ]; then
1347 echo "Version: $PACKAGE_VERSION"
1348 echo "Release: $PACKAGE_RELEASE"
1351 if [ "$TAG_VERSION" = "yes" ]; then
1352 TAGVER=`make_tagver`
1353 echo "CVS tag: $TAGVER"
1355 if [ -n "$TAG" ]; then
1356 echo "CVS tag: $TAG"
1359 local OPTIONS="tag $CVS_FORCE"
1360 if [ -n "$CVSROOT" ]; then
1361 OPTIONS="-d $CVSROOT $OPTIONS"
1364 # if a tagname we are about to set already exists
1365 # and happens to be a branch (common case with AC-branch)
1366 # pass -B (allows -F to disturb branch tag)
1368 if [ "$TAG_VERSION" = "yes" ]; then
1371 is_tag_a_branch $_tag
1372 if [ $? -eq 0 -a $CVS_NSERVER -eq 0 ]; then
1373 OPTIONS="$OPTIONS -B"
1378 for i in $TAG_FILES; do
1379 # don't tag files stored on distfiles
1380 [ -n "`src_md5 $i`" ] && continue
1381 local fp=`nourl "$i"`
1382 if [ -f "$fp" ]; then
1383 tag_files="$tag_files $fp"
1384 elif [ -n "GREEDSRC" ]; then
1385 get_greed_sources $i
1387 Exit_error err_no_source_in_repo $i
1391 if [ "$tag_files" ]; then
1392 if [ "$TAG_VERSION" = "yes" ]; then
1393 update_shell_title "tag sources: $TAGVER"
1394 printf "Tagging %d files\n" $(echo $tag_files | wc -w)
1395 $CVS_COMMAND $OPTIONS $TAGVER $tag_files || exit
1397 if [ -n "$TAG" ]; then
1398 update_shell_title "tag sources: $TAG"
1400 while [ "$tag_files" ]; do
1401 local chunk=$(echo $tag_files | tr ' ' '\n' | head -n 100)
1402 printf "Tagging %d files\n" $(echo $chunk | wc -w)
1403 $CVS_COMMAND $OPTIONS $TAG $chunk || exit
1404 tag_files=$(echo $tag_files | tr ' ' '\n' | tail +101)
1410 if [ "$TAG_VERSION" = "yes" ]; then
1411 update_shell_title "tag spec: $TAGVER"
1412 $CVS_COMMAND $OPTIONS $TAGVER $SPECFILE || exit
1414 if [ -n "$TAG" ]; then
1415 update_shell_title "tag spec: $TAG"
1416 $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
1422 echo "CVS branch tag: $TAG"
1427 if [ -n "$DEBUG" ]; then
1432 local OPTIONS="tag $CVS_FORCE -b"
1435 is_tag_a_branch $TAG
1436 if [ $? -eq 1 ]; then
1437 OPTIONS="$OPTIONS -B"
1440 if [ -n "$CVSROOT" ]; then
1441 OPTIONS="-d $CVSROOT $OPTIONS"
1445 for i in $TAG_FILES; do
1446 local fp=`nourl "$i"`
1447 if [ -f "$fp" ]; then
1448 tag_files="$tag_files $fp"
1449 elif [ -n "GREEDSRC" ]; then
1450 get_greed_sources $i
1452 Exit_error err_no_source_in_repo $i
1455 if [ "$tag_files" ]; then
1456 $CVS_COMMAND $OPTIONS $TAG $tag_files || exit
1460 $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
1464 # this function should exit early if package can't be built for this arch
1465 # this avoids unneccessary BR filling.
1468 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1470 if [ $ret -ne 0 ]; then
1482 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1483 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1489 local ver="$2" subver=$ver
1490 local newver="$3" newsubver=$newver
1492 # try handling subver, everything that's not numeric-dotted in version
1493 if grep -Eq '%define\s+subver' $specfile; then
1494 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1496 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1497 newver=${newver%$newsubver}
1500 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1501 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1502 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1507 if [ -n "$TRY_UPGRADE" ]; then
1508 local TNOTIFY TNEWVER TOLDVER
1509 update_shell_title "build_package: try_upgrade"
1513 if [ "$UPGRADE_VERSION" ]; then
1514 TNEWVER=$UPGRADE_VERSION
1516 if [ -n "$FLOAT_VERSION" ]; then
1517 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1519 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1522 # pldnotify.awk does not set exit codes, but it has match for ERROR
1523 # in output which means so.
1524 if [[ "$TNOTIFY" = *ERROR* ]]; then
1529 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1532 if [ -n "$TNEWVER" ]; then
1533 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1534 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1535 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1536 cp -f $SPECFILE $SPECFILE.bak
1539 set_release $SPECFILE $PACKAGE_RELEASE 1
1540 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1542 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1543 echo >&2 "Upgrading version failed, you need to update spec yourself"
1553 update_shell_title "build_package"
1554 if [ -n "$DEBUG" ]; then
1563 BUILD_SWITCH="-ba" ;;
1565 BUILD_SWITCH="-bb" ;;
1567 BUILD_SWITCH="-bs --nodeps" ;;
1569 BUILD_SWITCH="-bp --nodeps" ;;
1571 BUILD_SWITCH="-bc" ;;
1573 BUILD_SWITCH="-bi" ;;
1575 BUILD_SWITCH="-bl" ;;
1579 update_shell_title "build_package: $COMMAND"
1580 if [ -n "$LOGFILE" ]; then
1581 LOG=`eval echo $LOGFILE`
1582 if [ -d "$LOG" ]; then
1583 echo "Log file $LOG is a directory."
1584 echo "Parse error in the spec?"
1585 Exit_error err_build_fail
1587 if [ -n "$LASTLOG_FILE" ]; then
1588 echo "LASTLOG=$LOG" > $LASTLOG_FILE
1590 RES_FILE=$(tempfile)
1592 (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
1593 RETVAL=`cat $RES_FILE`
1595 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1596 if [ "$RETVAL" -eq "0" ]; then
1603 eval ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPECFILE
1606 if [ "$RETVAL" -ne "0" ]; then
1607 if [ -n "$TRY_UPGRADE" ]; then
1608 echo "\nUpgrade package to new version failed."
1609 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1610 echo "Restoring old spec file."
1611 mv -f $SPECFILE.bak $SPECFILE
1615 Exit_error err_build_fail
1621 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1624 install_required_packages() {
1629 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1632 /^%changelog/ { exit }
1634 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1635 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1636 gsub(/[ \t]+/, "_", bcond);
1638 }' $SPEC | LC_ALL=C sort -u
1642 # expand bconds from ~/.bcondrc
1643 # The file structure is like gentoo's package.use:
1646 # samba -mysql -pgsql
1647 # w32codec-installer license_agreement
1650 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
1656 SN=${SPECFILE%%\.spec}
1658 local bcondrc=$HOME/.bcondrc
1659 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1661 local bcond_avail=$(find_spec_bcond $SPECFILE)
1663 while read pkg flags; do
1665 [[ "$pkg" == \#* ]] && continue
1667 # any package or current package?
1668 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1669 for flag in $flags; do
1670 local opt=${flag#[+-]}
1672 # use only flags which are in this package.
1673 if [[ $bcond_avail = *${opt}* ]]; then
1674 if [[ $flag = -* ]]; then
1675 if [[ $BCOND != *--with?${opt}* ]]; then
1676 BCOND="$BCOND --without $opt"
1679 if [[ $BCOND != *--without?${opt}* ]]; then
1680 BCOND="$BCOND --with $opt"
1687 update_shell_title "parse ~/.bcondrc: DONE!"
1690 set_bconds_values() {
1691 update_shell_title "set bcond values"
1693 AVAIL_BCONDS_WITHOUT=""
1694 AVAIL_BCONDS_WITH=""
1696 if grep -Eq '^# *_with' ${SPECFILE}; then
1697 echo >&2 "ERROR: This spec has old style bconds."
1701 if ! grep -q '^%bcond' ${SPECFILE}; then
1705 local bcond_avail=$(find_spec_bcond $SPECFILE)
1706 process_bcondrc "$SPECFILE"
1708 update_shell_title "parse bconds"
1711 for opt in $bcond_avail; do
1714 bcond=${opt#without_}
1716 *--without?${bcond}*)
1717 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1720 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1728 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1731 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1736 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1745 update_shell_title "run_sub_builder $package_name"
1747 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1748 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1749 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1750 # jakby nie bylo tego kawalka kodu.
1752 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1753 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1757 # kurwa. translate that ^^^^
1761 # Istnieje taki spec? ${package}.spec
1762 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1763 parent_spec_name=${package}.spec
1764 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1765 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1767 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1772 if [ "${parent_spec_name}" != "" ]; then
1773 spawn_sub_builder $parent_spec_name
1775 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1778 spawn_sub_builder() {
1780 update_shell_title "spawn_sub_builder $package_name"
1783 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1784 sub_builder_opts="${sub_builder_opts} -R"
1786 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1787 sub_builder_opts="${sub_builder_opts} -RB"
1788 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1789 sub_builder_opts="${sub_builder_opts} -FRB"
1791 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1792 sub_builder_opts="${sub_builder_opts} -Upi"
1796 ./builder ${sub_builder_opts} "$@"
1799 remove_build_requires() {
1800 if [ "$INSTALLED_PACKAGES" != "" ]; then
1801 case "$REMOVE_BUILD_REQUIRES" in
1803 run_poldek --noask -ve $INSTALLED_PACKAGES
1806 run_poldek --ask -ve $INSTALLED_PACKAGES
1809 echo You may want to manually remove following BuildRequires fetched:
1810 echo $INSTALLED_PACKAGES
1811 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1818 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1819 if [ "$BCOND" ]; then
1821 echo "Building $SPECFILE with the following conditional flags:"
1825 echo "No conditional flags passed"
1828 echo "from available:"
1829 echo "--with :\t$AVAIL_BCONDS_WITH"
1830 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1835 display_branches() {
1836 if [ "$NOCVSSPEC" != "yes" ]; then
1837 echo -n "Available branches: "
1838 $CVS_COMMAND status -v "${SPECFILE}" | awk '!/Sticky Tag:/ && /\(branch:/ { print $1 } ' | xargs
1842 # checks a given list of packages/files/provides agains current rpmdb.
1843 # outputs all dependencies which current rpmdb doesn't satisfy.
1844 # input can be either STDIN or parameters
1848 if [ $# -gt 0 ]; then
1854 DEPS=$(LANG=C rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1857 echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1859 # other deps (files)
1860 echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1863 # checks if given package/files/provides exists in rpmdb.
1864 # input can be either stdin or parameters
1865 # returns packages which are present in the rpmdb
1869 if [ $# -gt 0 ]; then
1875 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1878 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
1879 install_build_requires_rpmdeps() {
1880 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1881 # TODO: Conflicts list doesn't check versions
1882 local CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1883 local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1885 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1886 local CNFL=$(rpm -q --specsrpm --conflicts $BCOND $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
1887 local DEPS=$(rpm -q --specsrpm --requires $BCOND $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
1890 if [ -n "$CNFL" ] || [ -n "$DEPS" ]; then
1891 echo "fetch BuildRequires: install [$DEPS]; remove [$CNFL]"
1892 update_shell_title "poldek: install [$DEPS]; remove [$CNFL]"
1893 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1895 if [ -n "$CNFL" ]; then
1896 update_shell_title "uninstall conflicting packages: $CNFL"
1897 echo "Trying to uninstall conflicting packages ($CNFL):"
1898 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CNFL
1901 while [ "$DEPS" ]; do
1902 update_shell_title "install deps: $DEPS"
1903 echo "Trying to install dependencies ($DEPS):"
1904 local log=.${SPECFILE}_poldek.log
1905 LANG=C $SU_SUDO /usr/bin/poldek --noask --caplookup -uGqQ $DEPS | tee $log
1906 failed=$(awk '/^error:/{a=$2; sub(/^error: /, "", a); sub(/:$/, "", a); print a}' $log)
1909 if [ -n "$failed" ]; then
1910 for package in $failed; do
1911 spawn_sub_builder -bb $(depspecname $package) && ok="$ok $package"
1920 fetch_build_requires()
1922 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
1926 update_shell_title "fetch build requires"
1927 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1928 install_build_requires_rpmdeps
1932 # XXX is this ugliest code written in human history still needed?
1933 echo "All packages installed by fetch_build_requires() are written to:"
1934 echo "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
1936 echo "If anything fails, you may get rid of them by executing:"
1937 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`"
1939 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1940 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)
1942 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)
1944 package=$(basename "$package_item"|sed -e "s/}$//g")
1945 COND_ARCH_TST=$(cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g")
1948 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1949 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1950 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
1955 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1958 if `echo $COND_TST|grep -q 'without_'`; then
1959 COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
1960 if `echo $COND_TST|grep -q !`; then
1965 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1966 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1967 if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
1973 elif `echo $COND_TST|grep -q 'with_'`; then
1974 COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
1975 if `echo $COND_TST|grep -q !`; then
1980 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1981 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1982 if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
1988 RESULT="${COND_STATE}-${COND_ARGV}"
1990 "with-wout" | "wout-with" )
1993 "wout-wout" | "with-with" )
1997 echo "Action '$RESULT' was not defined for package '$package_item'"
2003 if [ "$GO" = "yes" ]; then
2004 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
2005 echo "Testing if $package has subrequirements..."
2006 run_poldek -t -i $package --dumpn=".$package-req.txt"
2007 if [ -f ".$package-req.txt" ]; then
2008 for package_name in `cat ".$package-req.txt"|grep -v ^#`
2010 if [ "$package_name" = "$package" ]; then
2011 echo "Installing BuildRequired package:\t$package_name"
2012 update_shell_title "Installing BuildRequired package: ${package_name}"
2013 install_required_packages $package
2015 echo "Installing (sub)Required package:\t$package_name"
2016 update_shell_title "Installing (sub)Required package: ${package_name}"
2017 install_required_packages $package_name
2021 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2022 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2025 echo "Attempting to run spawn sub - builder..."
2026 echo "Package installation failed:\t$package_name"
2027 run_sub_builder $package_name
2028 if [ $? -eq 0 ]; then
2029 install_required_packages $package_name
2032 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2033 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2036 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2043 rm -f ".$package-req.txt"
2045 echo "Attempting to run spawn sub - builder..."
2046 echo "Package installation failed:\t$package"
2047 run_sub_builder $package
2048 if [ $? -eq 0 ]; then
2049 install_required_packages $package
2052 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2053 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2056 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2062 echo "Package $package is already installed. BuildRequirement satisfied."
2066 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
2067 echo >&2 "Unable to install following packages and their dependencies:"
2068 for pkg in "$NOT_INSTALLED_PACKAGES"
2072 remove_build_requires
2078 local CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"
2079 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2080 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2081 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2082 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2085 echo "Initializing rpm directories to $TOP_DIR from $CVSROOT"
2086 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2088 # need to checkout to tmp dir or we can't name our topdir
2089 tmp=$(TMPDIR= TEMPDIR= mktemp -p $TOP_DIR -d) || exit 1
2091 $CVS_COMMAND -d $CVSROOT co packages/{.cvsignore,rpm.groups,dropin,mirrors,md5,adapter{,.awk},fetchsrc_request,builder,{relup,compile,repackage}.sh,ci,civim}
2093 mv $tmp/packages/* $TOP_DIR
2098 echo "To checkout *all* .spec files (read-only):"
2099 echo "- run cvs co SPECS"
2101 echo "To checkout *all* packages:"
2102 echo "- run cvs up -dP in $TOP_DIR dir"
2105 echo "To commit with your developer account:"
2106 echo "- edit $TOP_DIR/CVS/Root"
2109 get_greed_sources() {
2110 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"
2111 if [ -n "BE_VERBOSE" ]; then
2112 echo "Try greed download: $1 from: $CVSROOT"
2114 $CVS_COMMAND -d $CVSROOT get SOURCES/$1
2115 if [ $? != 0 ]; then
2116 Exit_error err_no_source_in_repo $1
2121 # remove entries from CVS/Entries
2122 cvs_entry_remove() {
2123 local cvsdir="$1"; shift
2124 if [ ! -d "$cvsdir" ]; then
2125 echo >&2 "cvs_entry_remove: $cvsdir is not a directory"
2129 for file in "$@"; do
2130 rm -f $cvsdir/CVS/Entries.new || return 1
2131 awk -ve="${file##*/}" -F/ '$2 != e {print}' $cvsdir/CVS/Entries > $cvsdir/CVS/Entries.new || return 1
2132 mv -f $cvsdir/CVS/Entries.new $cvsdir/CVS/Entries || return 1
2140 DONT_PRINT_REVISION="yes"
2144 local builddir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2146 # remove from CVS/Entries
2147 cvs_entry_remove $PACKAGE_DIR $SPECFILE $SOURCES $PATCHES
2149 # remove spec and sources
2150 $RPMBUILD --clean --rmsource --rmspec --nodeps --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" --define "_builddir $builddir" $SPECFILE
2153 #---------------------------------------------
2161 while [ $# -gt 0 ]; do
2164 # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
2165 # unfortunately $GETURI is already formed
2170 COMMAND="update_md5"
2175 COMMAND="update_md5"
2185 DEBUG="yes"; shift ;;
2187 COMMAND="version"; shift ;;
2189 COMMAND="short-version"; shift ;;
2191 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
2195 -b | -ba | --build )
2196 COMMAND="build"; shift ;;
2197 -bb | --build-binary )
2198 COMMAND="build-binary"; shift ;;
2200 COMMAND="build-build"; shift ;;
2202 COMMAND="build-install"; shift ;;
2204 COMMAND="build-list"; shift ;;
2205 -bp | --build-prep )
2206 COMMAND="build-prep"; shift ;;
2207 -bs | --build-source )
2208 COMMAND="build-source"; shift ;;
2210 COMMAND="branch"; shift; TAG="${1}"; shift;;
2212 CLEAN="--clean"; shift ;;
2214 CVS_FORCE="-F"; shift;;
2216 shift; CVSROOT="${1}"; shift ;;
2218 COMMAND="get"; shift ;;
2220 COMMAND="usage"; shift ;;
2222 PROTOCOL="ftp"; shift ;;
2224 PROTOCOL="http"; shift ;;
2226 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2230 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2234 shift; LOGFILE="${1}"; shift ;;
2236 shift; DEF_NICE_LEVEL=${1}; shift ;;
2237 -ske | --skip-existing-files)
2238 SKIP_EXISTING_FILES="yes"; shift ;;
2240 COMMAND="mr-proper"; shift ;;
2242 NOCVS="yes"; shift ;;
2243 -ncs | --no-cvs-specs )
2244 NOCVSSPEC="yes"; shift ;;
2245 -nd | --no-distfiles )
2246 NODIST="yes"; shift ;;
2247 -nm | --no-mirrors )
2248 NOMIRRORS="yes"; shift ;;
2250 NOURLS="yes"; shift ;;
2252 NOSRCS="yes"; shift ;;
2253 -ns0 | --no-source0 )
2254 NOSOURCE0="yes"; shift ;;
2264 -pm | --prefer-mirrors )
2271 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2273 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2274 --skip-patch | -sp )
2275 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2277 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2280 --with | --without )
2281 case $GROUP_BCONDS in
2285 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2286 while ! `echo ${1}|grep -qE '(^-|spec)'`
2288 BCOND="$BCOND $COND $1"
2292 if [[ "$2" = *,* ]]; then
2293 for a in $(echo "$2" | tr , ' '); do
2294 BCOND="$BCOND $1 $a"
2297 BCOND="$BCOND $1 $2"
2303 shift; TARGET="${1}"; shift ;;
2305 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2307 QUIET="--quiet"; shift ;;
2309 CVSDATE="${2}"; shift 2 ;;
2318 -R | --fetch-build-requires)
2319 FETCH_BUILD_REQUIRES="yes"
2320 NOT_INSTALLED_PACKAGES=
2322 -RB | --remove-build-requires)
2323 REMOVE_BUILD_REQUIRES="nice"
2325 -FRB | --force-remove-build-requires)
2326 REMOVE_BUILD_REQUIRES="force"
2328 -sc | --sources-cvs)
2329 COMMAND="list-sources-cvs"
2331 -sd | --source-distfiles)
2332 COMMAND="list-sources-distfiles"
2334 -sdp | --source-distfiles-paths)
2335 COMMAND="list-sources-distfiles-paths"
2337 -sf | --source-files)
2338 COMMAND="list-sources-files"
2340 -lsp | --source-paths)
2341 COMMAND="list-sources-local-paths"
2343 -su | --source-urls)
2344 COMMAND="list-sources-urls"
2346 -Tvs | --tag-version-stable )
2351 -Ts | --tag-stable )
2356 -Tv | --tag-version )
2361 -Tp | --tag-prefix )
2373 -ir | --integer-release-only )
2374 INTEGER_RELEASE="yes"
2377 COMMAND="update_md5"
2382 -Upi | --update-poldek-indexes )
2383 UPDATE_POLDEK_INDEXES="yes"
2386 COMMAND="init_rpm_dir"
2388 --use-greed-sources )
2391 -u | --try-upgrade )
2392 TRY_UPGRADE="1"; shift ;;
2394 shift; UPGRADE_VERSION="$1"; shift;;
2395 -un | --try-upgrade-with-float-version )
2396 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2398 BE_VERBOSE="1"; shift ;;
2403 if echo "${MACRO}" | grep -q '\W'; then
2404 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2408 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2413 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\""
2417 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2420 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2421 COMMAND="show_bconds"
2425 COMMAND="show_bcond_args"
2428 --show-avail-bconds)
2429 COMMAND="show_avail_bconds"
2434 RPMOPTS="${RPMOPTS} --nodeps"
2437 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2440 Exit_error err_invalid_cmdline "$1"
2443 SPECFILE=${1%/}; shift
2444 # check if specname was passed as specname:cvstag
2445 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2446 CVSTAG="${SPECFILE##*:}"
2447 SPECFILE="${SPECFILE%%:*}"
2449 # always have SPECFILE ending with .spec extension
2450 SPECFILE=${SPECFILE%%.spec}.spec
2451 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2455 [ -d "$ASSUMED_NAME" ] && CVS_ENTRIES="$ASSUMED_NAME/CVS/Entries" || CVS_ENTRIES="CVS/Entries"
2456 if [ -f "$CVS_ENTRIES" ] && [ -z "$CVSTAG" ]; then
2457 CVSTAG=$(awk -vSPECFILE=$(basename $SPECFILE) -F/ '$2 == SPECFILE && $6 ~ /^T/{print substr($6, 2)}' ${CVS_ENTRIES})
2458 if [ "$CVSTAG" ]; then
2459 echo >&2 "builder: Sticky tag $CVSTAG active. Use -r TAGNAME to override."
2461 elif [ "$CVSTAG" = "HEAD" ]; then
2462 # assume -r HEAD is same as -A
2466 if [ "$CVSTAG" ]; then
2467 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2468 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2471 if [ -n "$DEBUG" ]; then
2476 if [ -n "$TARGET" ]; then
2479 TARGET_SWITCH="--target $TARGET" ;;
2481 TARGET_SWITCH="--target=$TARGET" ;;
2485 if [ "$SCHEDTOOL" != "no" ]; then
2486 NICE_COMMAND="$SCHEDTOOL"
2488 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2491 update_shell_title "$COMMAND"
2495 if [ -z "$SPECFILE" ]; then
2496 Exit_error err_no_spec_in_cmdl
2498 get_spec > /dev/null
2505 if [ -z "$SPECFILE" ]; then
2506 Exit_error err_no_spec_in_cmdl
2508 get_spec > /dev/null
2513 "show_avail_bconds")
2515 if [ -z "$SPECFILE" ]; then
2516 Exit_error err_no_spec_in_cmdl
2519 get_spec > /dev/null
2521 local bcond_avail=$(find_spec_bcond $SPECFILE)
2522 local opt bcond bconds
2523 for opt in $bcond_avail; do
2526 bcond=${opt#without_}
2527 bconds="$bconds $bcond"
2531 bconds="$bconds $bcond"
2534 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2542 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2544 if [ -z "$SPECFILE" ]; then
2545 Exit_error err_no_spec_in_cmdl
2548 # display SMP make flags if set
2549 smp_mflags=$(rpm -E %{?_smp_mflags})
2550 if [ "$smp_mflags" ]; then
2551 echo "builder: SMP make flags are set to $smp_mflags"
2559 if [ "$COMMAND" != "build-source" ]; then
2562 fetch_build_requires
2563 if [ "$INTEGER_RELEASE" = "yes" ]; then
2564 echo "Checking release $PACKAGE_RELEASE..."
2565 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2566 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2570 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2571 if [ -n "$TEST_TAG" ]; then
2572 local TAGVER=`make_tagver`
2573 # escape some regexp characters if part of TAGVER
2574 TAGVER=$(echo "$TAGVER" | sed -e 's#\([\+\*\.]\)#\\\1#g')
2575 echo "Searching for tag $TAGVER..."
2576 TAGREL=$($CVS_COMMAND status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
2577 if [ -n "$TAGREL" ]; then
2578 Exit_error err_tag_exists "$TAGVER" "$TAGREL"
2581 # - do not allow to build from HEAD when XX-branch exists
2582 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto-\([a-zA-Z]\+\)-.*#\1#g')
2583 if [ "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2584 TAG_BRANCH="${TREE_PREFIX}-branch"
2585 TAG_STATUS=$($CVS_COMMAND status -v $SPECFILE | grep -Ei "${TAG_BRANCH}.+(branch: [0-9.]+)")
2586 if [ -n "$TAG_STATUS" -a "$CVSTAG" = "HEAD" ]; then
2587 Exit_error err_branch_exists "$TAG_STATUS"
2593 if [ -n "$NOSOURCE0" ] ; then
2594 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2599 get_files $SOURCES $PATCHES
2603 NODIST="yes" get_files $SOURCES $PATCHES
2604 update_md5 $SOURCES $PATCHES
2608 if [ "$UPDATE_POLDEK_INDEXES" = "yes" -a "$COMMAND" != "build-prep" ]; then
2609 run_poldek --sdir="${POLDEK_INDEX_DIR}" --mkidxz
2611 remove_build_requires
2615 if [ -z "$SPECFILE" ]; then
2616 Exit_error err_no_spec_in_cmdl
2621 # don't fetch sources from remote locations
2623 for file in $SOURCES; do
2624 [ -n "`src_md5 $file`" ] && continue
2625 new_SOURCES="$new_SOURCES $file"
2627 SOURCES="$new_SOURCES"
2628 get_files $SOURCES $PATCHES
2630 branch_files $TAG $SOURCES $PATCHES $ICONS
2634 if [ -z "$SPECFILE" ]; then
2635 Exit_error err_no_spec_in_cmdl
2638 ADD_PACKAGE_CVS=yes get_spec
2641 if [ -n "$NOSOURCE0" ] ; then
2642 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2644 get_files $SOURCES $PATCHES
2649 if [ -z "$SPECFILE" ]; then
2650 Exit_error err_no_spec_in_cmdl
2656 if [ -n "$NOSOURCE0" ] ; then
2657 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2659 get_files $SOURCES $PATCHES
2664 if [ -z "$SPECFILE" ]; then
2665 Exit_error err_no_spec_in_cmdl
2671 if [ -n "$NOSOURCE0" ] ; then
2672 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2674 update_md5 $SOURCES $PATCHES
2680 if [ -z "$SPECFILE" ]; then
2681 Exit_error err_no_spec_in_cmdl
2687 # don't fetch sources from remote locations
2689 for file in $SOURCES; do
2690 [ -n "`src_md5 $file`" ] && continue
2691 new_SOURCES="$new_SOURCES $file"
2693 SOURCES="$new_SOURCES"
2694 get_files $SOURCES $PATCHES
2696 tag_files $SOURCES $PATCHES $ICONS
2701 "list-sources-files" )
2704 DONT_PRINT_REVISION="yes"
2707 for SAP in $SOURCES $PATCHES; do
2708 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2711 "list-sources-urls" )
2714 DONT_PRINT_REVISION="yes"
2717 SAPS="$SOURCES $PATCHES"
2718 for SAP in $SAPS ; do
2722 "list-sources-local-paths" )
2725 DONT_PRINT_REVISION="yes"
2728 for SAP in $SOURCES $PATCHES; do
2729 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2732 "list-sources-distfiles-paths" )
2735 DONT_PRINT_REVISION="yes"
2738 for SAP in $SOURCES $PATCHES; do
2739 if [ -n "$(src_md5 "$SAP")" ]; then
2740 distfiles_path "$SAP"
2744 "list-sources-distfiles" )
2747 DONT_PRINT_REVISION="yes"
2750 for SAP in $SOURCES $PATCHES; do
2751 if [ -n "$(src_md5 "$SAP")" ]; then
2752 distfiles_url "$SAP"
2756 "list-sources-cvs" )
2759 DONT_PRINT_REVISION="yes"
2762 for SAP in $SOURCES $PATCHES; do
2763 if [ -z "$(src_md5 "$SAP")" ]; then
2764 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2778 echo "$VERSIONSTRING"
2781 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2782 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2786 # vi:syntax=sh:ts=4:sw=4:noet