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()
109 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
111 CVS_COMMAND=${CVS_COMMAND:-cvs}
114 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
115 CVS_SERVER="cvs.pld-linux.org"
120 DISTFILES_SERVER="://distfiles.pld-linux.org"
121 ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
126 FAIL_IF_NO_SOURCES="yes"
128 # let get_files skip over files which are present to get those damn files fetched
129 SKIP_EXISTING_FILES="no"
132 # should the specfile be restored if upgrade failed?
133 REVERT_BROKEN_UPGRADE="yes"
135 if rpm --specsrpm 2>/dev/null; then
136 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
137 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
139 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
140 if [ -x /usr/bin/rpm-getdeps ]; then
141 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
143 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
148 # Here we load saved user environment used to
149 # predefine options set above, or passed to builder
151 # This one reads global system environment settings:
152 if [ -f ~/etc/builderrc ]; then
155 # And this one cascades settings using user personal
157 # Example of ~/.builderrc:
159 #UPDATE_POLDEK_INDEXES="yes"
160 #FETCH_BUILD_REQUIRES="yes"
161 #REMOVE_BUILD_REQUIRES="force"
163 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
167 if [ -n "$HOME_ETC" ]; then
168 USER_CFG="$HOME_ETC/.builderrc"
169 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
171 USER_CFG=~/.builderrc
172 BUILDER_MACROS=~/.builder-rpmmacros
175 [ -f "$USER_CFG" ] && . "$USER_CFG"
177 if [ "$SCHEDTOOL" = "auto" ]; then
178 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
179 SCHEDTOOL="schedtool -B -e"
185 if [ -n "$USE_PROZILLA" ]; then
186 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
189 elif [ -n "$USE_AXEL" ]; then
190 GETURI="axel -a $AXEL_OPTS"
193 elif [ -n "$USE_LFTP" ]; then
195 local url outfile retval
198 lftp -c "set net:max-retries $WGET_RETRIES; set http:user-agent \"$USER_AGENT\"; pget -n 10 -c \"$url\" -o \"$outfile.tmp\""
200 if [ $retval -eq 0 ]; then
201 mv -f "$outfile.tmp" "$outfile"
211 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
212 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
213 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
214 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
216 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
217 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
223 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
234 if [ -d $HOME/rpm/SOURCES ]; then
235 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
236 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
241 # are we using cvs-nserver ?
244 $CVS_COMMAND --version 2>&1 | grep -q 'CVS-nserver'
245 [ $? -eq 0 ] && CVS_NSERVER=1
247 POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
248 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
252 if [ -n "$LOGFILE" ]; then
253 LOG=`eval echo $LOGFILE`
254 if [ -n "$LASTLOG_FILE" ]; then
255 echo "LASTLOG=$LOG" > $LASTLOG_FILE
257 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
260 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
261 return `cat ${RES_FILE}`
266 #---------------------------------------------
270 if [ -n "$DEBUG" ]; then set -xv; fi
272 Usage: builder [-D|--debug] [-V|--version] [--short-version] [--as_anon] [-a|--add_cvs] [-b|-ba|--build]
273 [-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
274 [{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>]
275 [-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
276 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T|--tag <cvstag>]
277 [-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
278 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}] [--use-greed-sources]
279 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
280 [--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
281 <package>[.spec][:cvstag]
283 -4 - force ipv4 when transferring files
284 -5, --update-md5 - update md5 comments in spec, implies -nd -ncs
285 -6 - force ipv6 when transferring files
286 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
287 -n5, --no-md5 - ignore md5 comments in spec
288 -D, --debug - enable builder script debugging mode,
289 -debug - produce rpm debug package (same as --opts -debug)
290 -V, --version - output builder version string
291 --short-version - output builder short version
292 --as_anon - get files via pserver as cvs@$CVS_SERVER,
293 -a, --add_cvs - try add new package to CVS.
294 -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
296 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
297 only package from <package>.spec,
298 -bp, --build-prep - execute the %prep phase of <package>.spec,
299 -bc - execute the %build phase of <package>.spec,
300 -bi - execute the %install phase of <package>.spec
301 -bl - execute the %files phase of <package>.spec
302 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
304 --short-circuit - short-circuit build
305 -B, --branch - add branch
306 -c, --clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
307 may be used with building process.
308 -m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES, SPECS and \$RPM_BUILD_ROOT
309 and CVS/Entries). Doesn't run any rpm building.
310 -cf, --cvs-force - use -F when tagging (useful when moving branches)
311 -d <cvsroot>, --cvsroot <cvsroot>
313 --define <macro> <value> - define a macro <macro> with value <value>,
314 --alt_kernel <kernel> - same as --define 'alt_kernel <kernel>'
315 --nodeps - rpm won't check any dependences
316 -g, --get - get <package>.spec and all related files from CVS repo or HTTP/FTP
317 -h, --help - this message
318 -jN, -j N - set %_smp_mflags to propagate concurrent jobs
319 --ftp, --http - use ftp or http protocol to access distfiles server
320 -l <logfile>, --logtofile <logfile>
322 -nc, --no-cvs - don't download sources from CVS, if source URL is given,
323 -ncs, --no-cvs-specs - don't check specs in CVS
324 -nd, --no-distfiles - don't download from distfiles
325 -nm, --no-mirrors - don't download from mirror, if source URL is given,
326 -nu, --no-urls - don't try to download from FTP/HTTP location,
327 -ns, --no-srcs - don't download Sources/Patches
328 -ns0, --no-source0 - don't download Source0
329 -nn, --no-net - don't download anything from the net
330 -pm, --prefer-mirrors - prefer mirrors (if any) over distfiles for SOURCES
331 --no-init - don't initialize builder paths (SPECS and SOURCES)
333 --skip-existing-files - skip existing files in get_files
334 --opts <rpm opts> - additional options for rpm
335 -q, --quiet - be quiet,
336 --date yyyy-mm-dd - build package using resources from specified CVS date,
337 -r <cvstag>, --cvstag <cvstag>
338 - build package using resources from specified CVS tag,
339 -A - build package using CVS resources as any sticky tags/date/kopts being reset.
340 -R, --fetch-build-requires
341 - fetch what is BuildRequired,
342 -RB, --remove-build-requires
343 - remove all you fetched with -R or --fetch-build-requires
344 remember, this option requires confirmation,
345 -FRB, --force-remove-build-requires
346 - remove all you fetched with -R or --fetch-build-requires
347 remember, this option works without confirmation,
348 -sd, --source-distfiles - list sources available from distfiles (intended for offline
349 operations; does not work when Icon field is present
350 but icon file is absent),
351 -sc, --source-cvs - list sources available from CVS
352 -sdp, --source-distfiles-paths - list sources available from distfiles -
353 paths relative to distfiles directory (intended for offline
354 operations; does not work when Icon field is present
355 but icon file is absent),
356 -sf, --source-files - list sources - bare filenames (intended for offline
357 operations; does not work when Icon field is present
358 but icon file is absent),
359 -lsp, --source-paths - list sources - filenames with full local paths (intended for
360 offline operations; does not work when Icon field is present
361 but icon file is absent),
362 -su, --source-urls - list urls - urls to sources and patches
363 intended for copying urls with spec with lots of macros in urls
364 -T <cvstag> , --tag <cvstag>
365 - add cvs tag <cvstag> for files,
366 -Tvs, --tag-version-stable
367 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
368 -Ts, --tag-stable - add cvs tag STABLE for files,
369 -Tv, --tag-version - add cvs tag NAME-VERSION-RELEASE for files,
370 -Tp, --tag-prefix <prefix>
371 - add <prefix> to NAME-VERSION-RELEASE tags,
372 -tt, --test-tag <prefix>
373 - fail if tag is already present,
374 -ir, --integer-release-only
375 - allow only integer and snapshot releases
376 -v, --verbose - be verbose,
377 -u, --try-upgrade - check version, and try to upgrade package
378 -un, --try-upgrade-with-float-version
379 - as above, but allow float version
380 php-pear-Services_Digg/
381 --upgrade-version - upgrade to specified version in try-upgrade
383 - try download source from tag head if don't find it in
385 -U, --update - refetch sources, don't use distfiles, and update md5 comments
386 -Upi, --update-poldek-indexes
387 - refresh or make poldek package index files.
388 -sp, --skip-patch <patchnumber>
389 - don't apply <patchnumber>. may be repeated.
390 -np, --nopatch <patchnumber>
391 - abort instead of applying patch <patchnumber>
392 --show-bconds - show available conditional builds, which can be used
393 - with --with and/or --without switches.
394 --show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
395 In other words, the output is parseable by scripts.
396 --show-avail-bconds - show available bconds
397 --with/--without <feature>
398 - conditional build package depending on %_with_<feature>/
399 %_without_<feature> macro switch. You may now use
400 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
401 constructions. Set GROUP_BCONDS to yes to make use of it.
402 --target <platform>, --target=<platform>
403 - build for platform <platform>.
404 --init-rpm-dir - initialize ~/rpm directory structure
408 # create tempfile. as secure as possible
410 mktemp -t builder.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
413 # change dependency to specname
415 # - perl(Package::Name) -> perl-Package-Name
419 package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
423 update_shell_title() {
425 local len=${COLUMNS:-80}
426 local msg="$(echo "$*" | cut -c-$len)"
428 if [ -n "$BE_VERBOSE" ]; then
429 echo >&2 "$(date +%s.%N) $*"
432 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
434 if [ -n "$PACKAGE_NAME" ]; then
435 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
440 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
441 msg=$(echo $msg | tr -d '\n\r')
444 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
447 echo >&2 -ne "\033]0;$msg\007"
453 # set TARGET from BuildArch: from SPECFILE
455 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
456 tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
458 target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
462 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
464 TARGET_SWITCH="--target=$TARGET" ;;
470 # runs rpm with minimal macroset
472 # we reset macros not to contain macros.build as all the %() macros are
473 # executed here, while none of them are actually needed.
474 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
475 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); gsub(/:.*macros.build:/, ":", $0); print $0 } ')
477 # TODO: move these to /usr/lib/rpm/macros
478 cat > $BUILDER_MACROS <<'EOF'
479 %x8664 x86_64 amd64 ia32e
482 %bootstrap_release() %{1}
483 %requires_releq_kernel_up(s:n:) %{nil}
484 %requires_releq_kernel_smp(s:n:) %{nil}
485 %requires_releq_kernel(s:n:) %{nil}
486 %requires_releq() %{nil}
487 %pyrequires_eq() %{nil}
488 %requires_eq() %{nil}
489 %requires_eq_to() %{nil}
490 %requires_ge() %{nil}
491 %requires_ge_to() %{nil}
492 %requires_ge() %{nil}
493 %releq_kernel_up(n:) ERROR
494 %releq_kernel_smp(n:) ERROR
495 %releq_kernel(n:) ERROR
499 %ruby_ver_requires_eq() %{nil}
500 %ruby_mod_ver_requires_eq() %{nil}
501 %__php_api_requires() %{nil}
502 %php_major_version ERROR
503 %php_api_version ERROR
504 %requires_xorg_xserver_extension %{nil}
505 %requires_xorg_xserver_xinput %{nil}
506 %requires_xorg_xserver_font %{nil}
507 %requires_xorg_xserver_videodrv %{nil}
509 %perl_vendorarch ERROR
510 %perl_vendorlib ERROR
511 # damn. need it here! - copied from /usr/lib/rpm/macros.build
512 %tmpdir %(echo "${TMPDIR:-/tmp}")
513 %patchset_source(f:b:) %(
514 base=%{-b*}%{!-b*:10000};
515 start=$(expr $base + %1);
516 end=$(expr $base + %{?2}%{!?2:%{1}});
517 # we need to call seq twice as it doesn't allow two formats
518 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
519 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
520 paste %{tmpdir}/__ps{1,2};
521 rm -f %{tmpdir}/__ps{1,2};
524 %add_etc_shells(p) %{p:<lua>}
525 %remove_etc_shells(p) %{p:<lua>}
526 %lua_add_etc_shells() %{nil}
527 %lua_remove_etc_shells() %{nil}
529 %buildrequires_jdk %{nil}
530 %pear_package_print_optionalpackages %{nil}
532 if [ "$NOINIT" = "yes" ] ; then
533 cat >> $BUILDER_MACROS <<'EOF'
538 eval $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
542 if [ -n "$DEBUG" ]; then
547 if [ -x /usr/bin/rpm-specdump ]; then
548 update_shell_title "cache_rpm_dump using rpm-specdump command"
549 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND $SPECFILE)
551 update_shell_title "cache_rpm_dump using rpmbuild command"
554 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
555 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
561 ARGS='--nodigest --nosignature --nobuild'
564 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
566 if [ $? -gt 0 ]; then
567 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
569 Exit_error err_build_fail
572 # make small dump cache
573 rpm_dump_cache=`echo "$rpm_dump" | awk '
574 $2 ~ /^SOURCEURL/ {print}
575 $2 ~ /^PATCHURL/ {print}
576 $2 ~ /^nosource/ {print}
577 $2 ~ /^PACKAGE_/ {print}
581 update_shell_title "cache_rpm_dump: OK!"
585 if [ -z "$rpm_dump_cache" ] ; then
586 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
588 echo "$rpm_dump_cache"
592 update_shell_title "get icons"
593 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
594 if [ -z "$ICONS" ]; then
598 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
602 update_shell_title "parsing specfile"
603 if [ -n "$DEBUG" ]; then
608 # icons are needed for successful spec parse
614 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
615 FAIL_IF_NO_SOURCES="no"
618 if [ "$NOSRCS" != "yes" ]; then
619 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
620 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
621 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
624 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
625 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
626 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
628 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
629 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
632 if [ -n "$BE_VERBOSE" ]; then
633 echo "- Sources : `nourl $SOURCES`"
634 if [ -n "$PATCHES" ]; then
635 echo "- Patches : `nourl $PATCHES`"
637 echo "- Patches : *no patches needed*"
639 if [ -n "$ICONS" ]; then
640 echo "- Icon : `nourl $ICONS`"
642 echo "- Icon : *no package icon*"
644 echo "- Name : $PACKAGE_NAME"
645 echo "- Version : $PACKAGE_VERSION"
646 echo "- Release : $PACKAGE_RELEASE"
649 update_shell_title "parse_spec: OK!"
653 if [ -n "$DEBUG" ]; then
661 "err_no_spec_in_cmdl" )
662 remove_build_requires
663 echo >&2 "ERROR: spec file name not specified."
665 "err_invalid_cmdline" )
666 echo >&2 "ERROR: invalid command line arg ($2)."
668 "err_no_spec_in_repo" )
669 remove_build_requires
670 echo >&2 "Error: spec file not stored in CVS repo."
672 "err_no_source_in_repo" )
673 remove_build_requires
674 echo >&2 "Error: some source, patch or icon files not stored in CVS repo. ($2)"
676 "err_cvs_add_failed" )
677 echo >&2 "Error: failed to add package to CVS repo."
680 remove_build_requires
681 echo >&2 "Error: package build failed. (${2:-no more info})"
683 "err_no_package_data" )
684 remove_build_requires
685 echo >&2 "Error: couldn't get out package name/version/release from spec file."
688 remove_build_requires
689 echo >&2 "Tag ${2} already exists (spec release: ${3})."
692 remove_build_requires
693 echo >&2 "Release ${2} not integer and not a snapshot."
695 "err_branch_exists" )
696 remove_build_requires
697 echo >&2 "Tree branch already exists (${2})."
700 remove_build_requires
701 echo >&2 "Error: conditions reject building this spec (${2})."
704 echo >&2 "Unknown error."
709 if [ -n "$DEBUG" ]; then
714 if [ "$NOINIT" != "yes" ] ; then
715 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
717 local macros_ver=$(rpm -E %?rpm_build_macros)
718 if [ -z "$macros_ver" ]; then
719 REPO_DIR=$TOP_DIR/packages
720 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
722 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
723 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
727 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
739 update_shell_title "get_spec"
741 if [ -n "$DEBUG" ]; then
747 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
749 SPECFILE=$(basename $SPECFILE)
752 if [ "$NOCVSSPEC" != "yes" ]; then
753 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
754 echo "Warning: No CVS access defined - using local .spec file"
758 if [ -d "$ASSUMED_NAME" -a -s "$ASSUMED_NAME/CVS/Root" ]; then
759 cvsup "$ASSUMED_NAME/$SPECFILE" || Exit_error err_no_spec_in_repo
760 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
761 if [ ! -r "$ASSUMED_NAME/$SPECFILE" ]; then
762 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
765 if [ ! -s "$ASSUMED_NAME/CVS/Root" ]; then
766 cvsup -a $ASSUMED_NAME || Exit_error err_cvs_add_failed
768 cvsup -a "$ASSUMED_NAME/$SPECFILE" || Exit_error err_cvs_add_failed
770 cvsup -c -d $ASSUMED_NAME "packages/$ASSUMED_NAME/$SPECFILE" || {
771 # softfail if new package, i.e not yet added to cvs
772 [ ! -f "$ASSUMED_NAME/$SPECFILE" ] && Exit_error err_no_spec_in_repo
773 echo "Warning: package not in CVS - assuming new package"
778 # remove Entries.Static -- so 'cvs up' would update all files in a repo
779 rm -f "$ASSUMED_NAME/CVS/Entries.Static"
782 cvsignore_df .cvsignore
784 # add default log format to .cvsignore if it is relative to package dir
785 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
786 # substitute known "macros" to glob
787 local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\),*,g')
788 if [ "$logfile" ]; then
789 cvsignore_df "$logfile"
793 # create symlinks for tools
794 if [ "$SYMLINK_TOOLS" != "no" ]; then
795 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
796 # skip tools that don't exist in top dir
797 [ -f $a ] || continue
798 # skip tools that already exist
799 [ -f $ASSUMED_NAME/$a ] && continue
800 ln -s ../$a $ASSUMED_NAME
806 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
807 Exit_error err_no_spec_in_repo
810 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
811 chmod $CHMOD_MODE $ASSUMED_NAME/$SPECFILE
814 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $ASSUMED_NAME/$SPECFILE
822 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
823 $CVS_COMMAND update mirrors >&2
827 local origin mirror name rest ol prefix
828 while read origin mirror name rest; do
829 # skip comments and empty lines
830 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
833 ol=$(echo -n "$origin" | wc -c)
834 prefix=$(echo -n "$url" | head -c $ol)
835 if [ "$prefix" = "$origin" ] ; then
836 suffix=$(echo "$url" | cut -b $((ol+1))-)
837 echo -n "$mirror$suffix"
844 # Warning: unpredictable results if same URL used twice
847 # escape some regexp characters if part of file name
848 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
851 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
852 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
853 head -n 1 | tr OURCEATH ourceath | xargs
857 [ "$NO5" = "yes" ] && return
859 [ -z "$no" ] && return
863 if [ -f additional-md5sums ]; then
864 local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
865 if [ -z "$spec_rev" ]; then
866 spec_rev=$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')
868 local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
869 md5=$(grep -s -v '^#' additional-md5sums | \
870 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
871 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
872 grep -E '^[0-9a-f]{32}$')
875 if [ $(echo "$md5" | wc -l) != 1 ] ; then
876 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
878 echo "$md5" | tail -n 1
883 source_md5=`grep -i "^#[ ]*$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
884 if [ -n "$source_md5" ]; then
887 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
888 if [ -n "$source_md5" ]; then
891 # we have empty SourceX-md5, but it is still possible
892 # that we have NoSourceX-md5 AND NoSource: X
893 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
894 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
902 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
906 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
909 distfiles_attic_url() {
910 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
916 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
920 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
921 [ -n "$size" -a "$size" -gt 0 ]
925 if [ "$CVSIGNORE_DF" != "yes" ]; then
928 cvsignore=${PACKAGE_DIR}/.cvsignore
930 # add only if not yet there
931 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
932 echo "$1" >> $cvsignore
937 update_shell_title "cvsup"
938 local OPTIONS="" ACTION="up"
941 if [ "$1" = "-c" ]; then
946 if [ "$1" = "-a" ]; then
953 if [ -n "$CVSROOT" ]; then
954 OPTIONS="-d $CVSROOT $OPTIONS"
957 if [ "$ACTION" != "add" ]; then
958 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
959 OPTIONS="$OPTIONS -A"
961 if [ -n "$CVSDATE" ]; then
962 OPTIONS="$OPTIONS -D $CVSDATE"
964 if [ -n "$CVSTAG" ]; then
965 # FIXME: cvs add actually works with -r ?
966 OPTIONS="$OPTIONS -r $CVSTAG"
972 local retries_counter=0
974 update_shell_title "cvsup: $*"
976 update_shell_title "cvsup: $# files"
978 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
979 retries_counter=$(( $retries_counter + 1 ))
980 output=$(LC_ALL=C $CVS_COMMAND $OPTIONS "$@" 2>&1)
982 [ -n "$output" ] && echo "$output"
983 if echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)" \
984 && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
985 echo "Trying again [$*]... ($retries_counter)"
986 update_shell_title "cvsup: retry #$retries_counter"
993 update_shell_title "cvsup: done!"
997 # returns true if "$1" is ftp, http or https protocol url
1000 ftp://*|http://*|https://*)
1008 if [ $# -eq 0 ]; then
1012 update_shell_title "update md5"
1013 if [ -n "$DEBUG" ]; then
1020 # pass 1: check files to be fetched
1024 local fp=$(nourl "$i")
1025 local srcno=$(src_no "$i")
1026 if [ -n "$ADD5" ]; then
1027 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
1028 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
1029 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
1031 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
1033 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1034 need_files="$need_files $i"
1038 # pass 1a: get needed files
1039 if [ "$need_files" ]; then
1040 get_files $need_files
1043 # pass 2: proceed with md5 adding or updating
1045 local fp=$(nourl "$i")
1046 local srcno=$(src_no "$i")
1047 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
1048 if [ -z "$md5" ]; then
1049 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
1051 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
1052 local tag="# $srcno-md5:\t"
1053 if [[ "$md5" == *NoSource* ]]; then
1054 tag="# NoSource$srcno-md5:\t"
1055 elif [ -n "$USEDIGEST" ]; then
1056 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
1058 md5=$(md5sum "$fp" | cut -f1 -d' ')
1059 echo "Updating $srcno ($md5: $fp)."
1061 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1062 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
1064 $PACKAGE_DIR/$SPECFILE
1071 [ "$NO5" = "yes" ] && return
1073 update_shell_title "check md5"
1077 if ! good_md5 "$i"; then
1078 echo -n "MD5 sum mismatch."
1081 if ! good_size "$i"; then
1082 echo -n "0 sized file."
1086 if [ $bad -eq 1 ]; then
1087 echo " Use -U to refetch sources,"
1088 echo "or -5 to update md5 sums, if you're sure files are correct."
1089 Exit_error err_no_source_in_repo $i
1095 update_shell_title "get_files"
1097 if [ -n "$DEBUG" ]; then
1102 if [ $# -gt 0 ]; then
1105 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
1106 echo "Warning: No CVS access defined for SOURCES"
1111 local get_files_cvs=""
1115 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
1116 update_shell_title "$i"
1117 local fp=`nourl "$i"`
1118 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
1123 local srcmd5=$(src_md5 "$i")
1125 # we know if source/patch is present in cvs/distfiles
1126 # - has md5 (in distfiles)
1127 # - in cvs... ideas?
1129 # CHECK: local file didn't exist or always cvs up (first) requested.
1130 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1131 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1132 echo "Warning: no URL given for $i"
1136 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
1137 if good_md5 "$i" && good_size "$i"; then
1138 echo "$fp having proper md5sum already exists"
1142 # optionally prefer mirror over distfiles if there's mirror
1143 # TODO: build url list and then try each url from the list
1144 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
1147 url=$(distfiles_url "$i")
1150 url_attic=$(distfiles_attic_url "$i")
1152 # is $url local file?
1153 if [[ "$url" = [./]* ]]; then
1154 update_shell_title "${GETLOCAL%% *}: $url"
1155 ${GETLOCAL} $url $target
1157 if [ -z "$NOMIRRORS" ]; then
1158 url=$(find_mirror "$url")
1162 # make shorter message for distfiles urls
1163 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1164 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1165 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1168 update_shell_title "${GETURI%% *}: $uri"
1169 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1170 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1171 update_shell_title "${GETURI2%% *}: $url"
1172 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1177 if [ ! -s "$target" ]; then
1179 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
1180 update_shell_title "${GETLOCAL%% *}: $url_attic"
1181 ${GETLOCAL} $url_attic $target
1183 if [ -z "$NOMIRRORS" ]; then
1184 url_attic=$(find_mirror "$url_attic")
1186 update_shell_title "${GETURI%% *}: $url_attic"
1187 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1188 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1189 update_shell_title "${GETURI2%% *}: $url_attic"
1190 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1192 test -s "$target" || rm -f "$target"
1196 if [ -s "$target" ]; then
1197 cvsignore_df $target
1202 elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then
1203 if [ $# -gt 1 ]; then
1204 get_files_cvs="$get_files_cvs $fp"
1205 update_shell_title "$fp (will cvs up later)"
1212 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
1213 if [ -z "$NOMIRRORS" ]; then
1214 im=$(find_mirror "$i")
1218 update_shell_title "${GETURI%% *}: $im"
1219 ${GETURI} "$im" ${OUTFILEOPT} "$target" || \
1220 if [ "`echo $im | grep -E 'ftp://'`" ]; then
1221 update_shell_title "${GETURI2%% *}: $im"
1222 ${GETURI2} "$im" ${OUTFILEOPT} "$target"
1224 test -s "$target" || rm -f "$target"
1227 if [ "$cvsup" = 1 ]; then
1233 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
1234 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
1235 if [ -n "GREEDSRC" ]; then
1236 get_greed_sources $i
1238 Exit_error err_no_source_in_repo $i
1242 # we check md5 here just only to refetch immediately
1243 if good_md5 "$i" && good_size "$i"; then
1245 elif [ "$FROM_DISTFILES" = 1 ]; then
1246 # wrong md5 from distfiles: remove the file and try again
1248 echo "MD5 sum mismatch. Trying full fetch."
1251 update_shell_title "${GETURI%% *}: $url"
1252 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
1253 if [ "`echo $url | grep -E 'ftp://'`" ]; then
1254 update_shell_title "${GETURI2%% *}: $url"
1255 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
1257 if [ ! -s "$target" ]; then
1259 update_shell_title "${GETURI%% *}: $url_attic"
1260 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
1261 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
1262 update_shell_title "${GETURI2%% *}: $url_attic"
1263 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
1266 test -s "$target" || rm -f "$target"
1269 SHELL_TITLE_PREFIX=""
1271 if [ "$get_files_cvs" ]; then
1272 cvsup $get_files_cvs
1275 if [ "$CHMOD" = "yes" ]; then
1276 CHMOD_FILES=$(nourl "$@")
1277 if [ -n "$CHMOD_FILES" ]; then
1278 chmod $CHMOD_MODE $CHMOD_FILES
1285 if [ -n "$DEBUG" ]; then
1290 # Check whether first character of PACKAGE_NAME is legal for tag name
1291 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1295 # NOTE: CVS tags may must not contain the characters `$,.:;@'
1296 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE | tr '[.@]' '[_#]')
1298 # Remove #kernel.version_release from TAGVER because tagging sources
1299 # could occur with different kernel-headers than kernel-headers used at build time.
1300 # besides, %{_kernel_ver_str} is not expanded.
1302 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1#%{_kernel_ver_str}
1303 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1309 # bool is_tag_a_branch(tag)
1311 # returns 1 if a tag is a branch set on SPECFILE
1313 if [ -n "$DEBUG" ]; then
1318 if [ $# -ne 1 ]; then
1323 # escape some regexp characters if part of TAG
1324 TAG=$(echo "$TAG" | sed -e 's#\([\+\*\.]\)#\\\1#g')
1328 $CVS_COMMAND status -v $SPECFILE | grep -Eiq "${TAG}.+(branch: [0-9.]+)"
1335 if [ -n "$DEBUG" ]; then
1340 echo "Version: $PACKAGE_VERSION"
1341 echo "Release: $PACKAGE_RELEASE"
1344 if [ "$TAG_VERSION" = "yes" ]; then
1345 TAGVER=`make_tagver`
1346 echo "CVS tag: $TAGVER"
1348 if [ -n "$TAG" ]; then
1349 echo "CVS tag: $TAG"
1352 local OPTIONS="tag $CVS_FORCE"
1353 if [ -n "$CVSROOT" ]; then
1354 OPTIONS="-d $CVSROOT $OPTIONS"
1357 # if a tagname we are about to set already exists
1358 # and happens to be a branch (common case with AC-branch)
1359 # pass -B (allows -F to disturb branch tag)
1361 if [ "$TAG_VERSION" = "yes" ]; then
1364 is_tag_a_branch $_tag
1365 if [ $? -eq 0 -a $CVS_NSERVER -eq 0 ]; then
1366 OPTIONS="$OPTIONS -B"
1371 for i in $TAG_FILES; do
1372 # don't tag files stored on distfiles
1373 [ -n "`src_md5 $i`" ] && continue
1374 local fp=`nourl "$i"`
1375 if [ -f "$fp" ]; then
1376 tag_files="$tag_files $fp"
1377 elif [ -n "GREEDSRC" ]; then
1378 get_greed_sources $i
1380 Exit_error err_no_source_in_repo $i
1384 if [ "$tag_files" ]; then
1385 if [ "$TAG_VERSION" = "yes" ]; then
1386 update_shell_title "tag sources: $TAGVER"
1387 printf "Tagging %d files\n" $(echo $tag_files | wc -w)
1388 $CVS_COMMAND $OPTIONS $TAGVER $tag_files || exit
1390 if [ -n "$TAG" ]; then
1391 update_shell_title "tag sources: $TAG"
1393 while [ "$tag_files" ]; do
1394 local chunk=$(echo $tag_files | tr ' ' '\n' | head -n 100)
1395 printf "Tagging %d files\n" $(echo $chunk | wc -w)
1396 $CVS_COMMAND $OPTIONS $TAG $chunk || exit
1397 tag_files=$(echo $tag_files | tr ' ' '\n' | tail +101)
1403 if [ "$TAG_VERSION" = "yes" ]; then
1404 update_shell_title "tag spec: $TAGVER"
1405 $CVS_COMMAND $OPTIONS $TAGVER $SPECFILE || exit
1407 if [ -n "$TAG" ]; then
1408 update_shell_title "tag spec: $TAG"
1409 $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
1415 echo "CVS branch tag: $TAG"
1420 if [ -n "$DEBUG" ]; then
1425 local OPTIONS="tag $CVS_FORCE -b"
1428 is_tag_a_branch $TAG
1429 if [ $? -eq 1 ]; then
1430 OPTIONS="$OPTIONS -B"
1433 if [ -n "$CVSROOT" ]; then
1434 OPTIONS="-d $CVSROOT $OPTIONS"
1438 for i in $TAG_FILES; do
1439 local fp=`nourl "$i"`
1440 if [ -f "$fp" ]; then
1441 tag_files="$tag_files $fp"
1442 elif [ -n "GREEDSRC" ]; then
1443 get_greed_sources $i
1445 Exit_error err_no_source_in_repo $i
1448 if [ "$tag_files" ]; then
1449 $CVS_COMMAND $OPTIONS $TAG $tag_files || exit
1453 $CVS_COMMAND $OPTIONS $TAG $SPECFILE || exit
1457 # this function should exit early if package can't be built for this arch
1458 # this avoids unneccessary BR filling.
1461 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
1463 if [ $ret -ne 0 ]; then
1475 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1476 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1482 local ver="$2" subver=$ver
1483 local newver="$3" newsubver=$newver
1485 # try handling subver, everything that's not numeric-dotted in version
1486 if grep -Eq '%define\s+subver' $specfile; then
1487 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1489 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1490 newver=${newver%$newsubver}
1493 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
1494 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
1495 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1500 if [ -n "$TRY_UPGRADE" ]; then
1501 local TNOTIFY TNEWVER TOLDVER
1502 update_shell_title "build_package: try_upgrade"
1506 if [ "$UPGRADE_VERSION" ]; then
1507 TNEWVER=$UPGRADE_VERSION
1509 if [ -n "$FLOAT_VERSION" ]; then
1510 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1512 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1515 # pldnotify.awk does not set exit codes, but it has match for ERROR
1516 # in output which means so.
1517 if [[ "$TNOTIFY" = *ERROR* ]]; then
1522 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1525 if [ -n "$TNEWVER" ]; then
1526 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1527 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1528 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1529 cp -f $SPECFILE $SPECFILE.bak
1532 set_release $SPECFILE $PACKAGE_RELEASE 1
1533 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1535 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1536 echo >&2 "Upgrading version failed, you need to update spec yourself"
1546 update_shell_title "build_package"
1547 if [ -n "$DEBUG" ]; then
1556 BUILD_SWITCH="-ba" ;;
1558 BUILD_SWITCH="-bb" ;;
1560 BUILD_SWITCH="-bs --nodeps" ;;
1562 BUILD_SWITCH="-bp --nodeps" ;;
1564 BUILD_SWITCH="-bc" ;;
1566 BUILD_SWITCH="-bi" ;;
1568 BUILD_SWITCH="-bl" ;;
1572 update_shell_title "build_package: $COMMAND"
1573 if [ -n "$LOGFILE" ]; then
1574 LOG=`eval echo $LOGFILE`
1575 if [ -d "$LOG" ]; then
1576 echo "Log file $LOG is a directory."
1577 echo "Parse error in the spec?"
1578 Exit_error err_build_fail
1580 if [ -n "$LASTLOG_FILE" ]; then
1581 echo "LASTLOG=$LOG" > $LASTLOG_FILE
1583 RES_FILE=$(tempfile)
1585 (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
1586 RETVAL=`cat $RES_FILE`
1588 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1589 if [ "$RETVAL" -eq "0" ]; then
1596 eval ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $SPECFILE
1599 if [ "$RETVAL" -ne "0" ]; then
1600 if [ -n "$TRY_UPGRADE" ]; then
1601 echo "\nUpgrade package to new version failed."
1602 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1603 echo "Restoring old spec file."
1604 mv -f $SPECFILE.bak $SPECFILE
1608 Exit_error err_build_fail
1614 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1617 install_required_packages() {
1622 find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
1625 /^%changelog/ { exit }
1627 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1628 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1629 gsub(/[ \t]+/, "_", bcond);
1631 }' $SPEC | LC_ALL=C sort -u
1635 # expand bconds from ~/.bcondrc
1636 # The file structure is like gentoo's package.use:
1639 # samba -mysql -pgsql
1640 # w32codec-installer license_agreement
1643 if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then
1649 SN=${SPECFILE%%\.spec}
1651 local bcondrc=$HOME/.bcondrc
1652 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1654 local bcond_avail=$(find_spec_bcond $SPECFILE)
1656 while read pkg flags; do
1658 [[ "$pkg" == \#* ]] && continue
1660 # any package or current package?
1661 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1662 for flag in $flags; do
1663 local opt=${flag#[+-]}
1665 # use only flags which are in this package.
1666 if [[ $bcond_avail = *${opt}* ]]; then
1667 if [[ $flag = -* ]]; then
1668 if [[ $BCOND != *--with?${opt}* ]]; then
1669 BCOND="$BCOND --without $opt"
1672 if [[ $BCOND != *--without?${opt}* ]]; then
1673 BCOND="$BCOND --with $opt"
1680 update_shell_title "parse ~/.bcondrc: DONE!"
1683 set_bconds_values() {
1684 update_shell_title "set bcond values"
1686 AVAIL_BCONDS_WITHOUT=""
1687 AVAIL_BCONDS_WITH=""
1689 if grep -Eq '^# *_with' ${SPECFILE}; then
1690 echo >&2 "ERROR: This spec has old style bconds."
1694 if ! grep -q '^%bcond' ${SPECFILE}; then
1698 local bcond_avail=$(find_spec_bcond $SPECFILE)
1699 process_bcondrc "$SPECFILE"
1701 update_shell_title "parse bconds"
1704 for opt in $bcond_avail; do
1707 bcond=${opt#without_}
1709 *--without?${bcond}*)
1710 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
1713 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
1721 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
1724 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
1729 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1738 update_shell_title "run_sub_builder $package_name"
1740 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1741 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1742 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1743 # jakby nie bylo tego kawalka kodu.
1745 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1746 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1750 # kurwa. translate that ^^^^
1754 # Istnieje taki spec? ${package}.spec
1755 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
1756 parent_spec_name=${package}.spec
1757 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
1758 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
1760 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
1765 if [ "${parent_spec_name}" != "" ]; then
1766 spawn_sub_builder $parent_spec_name
1768 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1771 spawn_sub_builder() {
1773 update_shell_title "spawn_sub_builder $package_name"
1776 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1777 sub_builder_opts="${sub_builder_opts} -R"
1779 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
1780 sub_builder_opts="${sub_builder_opts} -RB"
1781 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
1782 sub_builder_opts="${sub_builder_opts} -FRB"
1784 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
1785 sub_builder_opts="${sub_builder_opts} -Upi"
1789 ./builder ${sub_builder_opts} "$@"
1792 remove_build_requires() {
1793 if [ "$INSTALLED_PACKAGES" != "" ]; then
1794 case "$REMOVE_BUILD_REQUIRES" in
1796 run_poldek --noask -ve $INSTALLED_PACKAGES
1799 run_poldek --ask -ve $INSTALLED_PACKAGES
1802 echo You may want to manually remove following BuildRequires fetched:
1803 echo $INSTALLED_PACKAGES
1804 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
1811 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1812 if [ "$BCOND" ]; then
1814 echo "Building $SPECFILE with the following conditional flags:"
1818 echo "No conditional flags passed"
1821 echo "from available:"
1822 echo "--with :\t$AVAIL_BCONDS_WITH"
1823 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1828 display_branches() {
1829 if [ "$NOCVSSPEC" != "yes" ]; then
1830 echo -n "Available branches: "
1831 $CVS_COMMAND status -v "${SPECFILE}" | awk '!/Sticky Tag:/ && /\(branch:/ { print $1 } ' | xargs
1835 # checks a given list of packages/files/provides agains current rpmdb.
1836 # outputs all dependencies which current rpmdb doesn't satisfy.
1837 # input can be either STDIN or parameters
1841 if [ $# -gt 0 ]; then
1847 DEPS=$(LANG=C rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1850 echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1852 # other deps (files)
1853 echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1856 # checks if given package/files/provides exists in rpmdb.
1857 # input can be either stdin or parameters
1858 # returns packages which are present in the rpmdb
1862 if [ $# -gt 0 ]; then
1868 LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1871 # install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
1872 install_build_requires_rpmdeps() {
1873 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1874 # TODO: Conflicts list doesn't check versions
1875 local CNFL=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1876 local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1878 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1879 local CNFL=$(rpm -q --specsrpm --conflicts $BCOND $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
1880 local DEPS=$(rpm -q --specsrpm --requires $BCOND $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
1883 if [ -n "$CNFL" ] || [ -n "$DEPS" ]; then
1884 echo "fetch BuildRequires: install [$DEPS]; remove [$CNFL]"
1885 update_shell_title "poldek: install [$DEPS]; remove [$CNFL]"
1886 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1888 if [ -n "$CNFL" ]; then
1889 update_shell_title "uninstall conflicting packages: $CNFL"
1890 echo "Trying to uninstall conflicting packages ($CNFL):"
1891 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CNFL
1894 while [ "$DEPS" ]; do
1895 update_shell_title "install deps: $DEPS"
1896 echo "Trying to install dependencies ($DEPS):"
1897 local log=.${SPECFILE}_poldek.log
1898 LANG=C $SU_SUDO /usr/bin/poldek --noask --caplookup -uGqQ $DEPS | tee $log
1899 failed=$(awk '/^error:/{a=$2; sub(/^error: /, "", a); sub(/:$/, "", a); print a}' $log)
1902 if [ -n "$failed" ]; then
1903 for package in $failed; do
1904 spawn_sub_builder -bb $(depspecname $package) && ok="$ok $package"
1913 fetch_build_requires()
1915 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
1919 update_shell_title "fetch build requires"
1920 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
1921 install_build_requires_rpmdeps
1925 # XXX is this ugliest code written in human history still needed?
1926 echo "All packages installed by fetch_build_requires() are written to:"
1927 echo "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
1929 echo "If anything fails, you may get rid of them by executing:"
1930 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`"
1932 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1933 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)
1935 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)
1937 package=$(basename "$package_item"|sed -e "s/}$//g")
1938 COND_ARCH_TST=$(cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g")
1941 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1942 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1943 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
1948 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1951 if `echo $COND_TST|grep -q 'without_'`; then
1952 COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
1953 if `echo $COND_TST|grep -q !`; then
1958 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1959 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1960 if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
1966 elif `echo $COND_TST|grep -q 'with_'`; then
1967 COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
1968 if `echo $COND_TST|grep -q !`; then
1973 COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1974 COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1975 if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
1981 RESULT="${COND_STATE}-${COND_ARGV}"
1983 "with-wout" | "wout-with" )
1986 "wout-wout" | "with-with" )
1990 echo "Action '$RESULT' was not defined for package '$package_item'"
1996 if [ "$GO" = "yes" ]; then
1997 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1998 echo "Testing if $package has subrequirements..."
1999 run_poldek -t -i $package --dumpn=".$package-req.txt"
2000 if [ -f ".$package-req.txt" ]; then
2001 for package_name in `cat ".$package-req.txt"|grep -v ^#`
2003 if [ "$package_name" = "$package" ]; then
2004 echo "Installing BuildRequired package:\t$package_name"
2005 update_shell_title "Installing BuildRequired package: ${package_name}"
2006 install_required_packages $package
2008 echo "Installing (sub)Required package:\t$package_name"
2009 update_shell_title "Installing (sub)Required package: ${package_name}"
2010 install_required_packages $package_name
2014 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2015 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2018 echo "Attempting to run spawn sub - builder..."
2019 echo "Package installation failed:\t$package_name"
2020 run_sub_builder $package_name
2021 if [ $? -eq 0 ]; then
2022 install_required_packages $package_name
2025 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2026 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2029 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2036 rm -f ".$package-req.txt"
2038 echo "Attempting to run spawn sub - builder..."
2039 echo "Package installation failed:\t$package"
2040 run_sub_builder $package
2041 if [ $? -eq 0 ]; then
2042 install_required_packages $package
2045 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
2046 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
2049 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
2055 echo "Package $package is already installed. BuildRequirement satisfied."
2059 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
2060 echo >&2 "Unable to install following packages and their dependencies:"
2061 for pkg in "$NOT_INSTALLED_PACKAGES"
2065 remove_build_requires
2071 local CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"
2072 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2073 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2074 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2075 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
2078 echo "Initializing rpm directories to $TOP_DIR from $CVSROOT"
2079 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2081 # need to checkout to tmp dir or we can't name our topdir
2082 tmp=$(TMPDIR= TEMPDIR= mktemp -p $TOP_DIR -d) || exit 1
2084 $CVS_COMMAND -d $CVSROOT co packages/{.cvsignore,rpm.groups,dropin,mirrors,md5,adapter{,.awk},fetchsrc_request,builder,{relup,compile,repackage}.sh,ci,civim}
2086 mv $tmp/packages/* $TOP_DIR
2091 echo "To checkout *all* .spec files (read-only):"
2092 echo "- run cvs co SPECS"
2094 echo "To checkout *all* packages:"
2095 echo "- run cvs up -dP in $TOP_DIR dir"
2098 echo "To commit with your developer account:"
2099 echo "- edit $TOP_DIR/CVS/Root"
2102 get_greed_sources() {
2103 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"
2104 if [ -n "BE_VERBOSE" ]; then
2105 echo "Try greed download: $1 from: $CVSROOT"
2107 $CVS_COMMAND -d $CVSROOT get SOURCES/$1
2108 if [ $? != 0 ]; then
2109 Exit_error err_no_source_in_repo $1
2114 # remove entries from CVS/Entries
2115 cvs_entry_remove() {
2116 local cvsdir="$1"; shift
2117 if [ ! -d "$cvsdir" ]; then
2118 echo >&2 "cvs_entry_remove: $cvsdir is not a directory"
2122 for file in "$@"; do
2123 rm -f $cvsdir/CVS/Entries.new || return 1
2124 awk -ve="${file##*/}" -F/ '$2 != e {print}' $cvsdir/CVS/Entries > $cvsdir/CVS/Entries.new || return 1
2125 mv -f $cvsdir/CVS/Entries.new $cvsdir/CVS/Entries || return 1
2133 DONT_PRINT_REVISION="yes"
2137 local builddir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2139 # remove from CVS/Entries
2140 cvs_entry_remove $PACKAGE_DIR $SPECFILE $SOURCES $PATCHES
2142 # remove spec and sources
2143 $RPMBUILD --clean --rmsource --rmspec --nodeps --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" --define "_builddir $builddir" $SPECFILE
2146 #---------------------------------------------
2154 while [ $# -gt 0 ]; do
2157 # NOTE: we should be fetcher specific, like fille WGET_OPTS, but
2158 # unfortunately $GETURI is already formed
2163 COMMAND="update_md5"
2168 COMMAND="update_md5"
2178 DEBUG="yes"; shift ;;
2180 COMMAND="version"; shift ;;
2182 COMMAND="short-version"; shift ;;
2184 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
2188 -b | -ba | --build )
2189 COMMAND="build"; shift ;;
2190 -bb | --build-binary )
2191 COMMAND="build-binary"; shift ;;
2193 COMMAND="build-build"; shift ;;
2195 COMMAND="build-install"; shift ;;
2197 COMMAND="build-list"; shift ;;
2198 -bp | --build-prep )
2199 COMMAND="build-prep"; shift ;;
2200 -bs | --build-source )
2201 COMMAND="build-source"; shift ;;
2203 COMMAND="branch"; shift; TAG="${1}"; shift;;
2205 CLEAN="--clean"; shift ;;
2207 CVS_FORCE="-F"; shift;;
2209 shift; CVSROOT="${1}"; shift ;;
2211 COMMAND="get"; shift ;;
2213 COMMAND="usage"; shift ;;
2215 PROTOCOL="ftp"; shift ;;
2217 PROTOCOL="http"; shift ;;
2219 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2223 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2227 shift; LOGFILE="${1}"; shift ;;
2229 shift; DEF_NICE_LEVEL=${1}; shift ;;
2230 -ske | --skip-existing-files)
2231 SKIP_EXISTING_FILES="yes"; shift ;;
2233 COMMAND="mr-proper"; shift ;;
2235 NOCVS="yes"; shift ;;
2236 -ncs | --no-cvs-specs )
2237 NOCVSSPEC="yes"; shift ;;
2238 -nd | --no-distfiles )
2239 NODIST="yes"; shift ;;
2240 -nm | --no-mirrors )
2241 NOMIRRORS="yes"; shift ;;
2243 NOURLS="yes"; shift ;;
2245 NOSRCS="yes"; shift ;;
2246 -ns0 | --no-source0 )
2247 NOSOURCE0="yes"; shift ;;
2257 -pm | --prefer-mirrors )
2264 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
2266 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
2267 --skip-patch | -sp )
2268 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
2270 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2273 --with | --without )
2274 case $GROUP_BCONDS in
2278 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
2279 while ! `echo ${1}|grep -qE '(^-|spec)'`
2281 BCOND="$BCOND $COND $1"
2285 if [[ "$2" = *,* ]]; then
2286 for a in $(echo "$2" | tr , ' '); do
2287 BCOND="$BCOND $1 $a"
2290 BCOND="$BCOND $1 $2"
2296 shift; TARGET="${1}"; shift ;;
2298 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
2300 QUIET="--quiet"; shift ;;
2302 CVSDATE="${2}"; shift 2 ;;
2311 -R | --fetch-build-requires)
2312 FETCH_BUILD_REQUIRES="yes"
2313 NOT_INSTALLED_PACKAGES=
2315 -RB | --remove-build-requires)
2316 REMOVE_BUILD_REQUIRES="nice"
2318 -FRB | --force-remove-build-requires)
2319 REMOVE_BUILD_REQUIRES="force"
2321 -sc | --sources-cvs)
2322 COMMAND="list-sources-cvs"
2324 -sd | --source-distfiles)
2325 COMMAND="list-sources-distfiles"
2327 -sdp | --source-distfiles-paths)
2328 COMMAND="list-sources-distfiles-paths"
2330 -sf | --source-files)
2331 COMMAND="list-sources-files"
2333 -lsp | --source-paths)
2334 COMMAND="list-sources-local-paths"
2336 -su | --source-urls)
2337 COMMAND="list-sources-urls"
2339 -Tvs | --tag-version-stable )
2344 -Ts | --tag-stable )
2349 -Tv | --tag-version )
2354 -Tp | --tag-prefix )
2366 -ir | --integer-release-only )
2367 INTEGER_RELEASE="yes"
2370 COMMAND="update_md5"
2375 -Upi | --update-poldek-indexes )
2376 UPDATE_POLDEK_INDEXES="yes"
2379 COMMAND="init_rpm_dir"
2381 --use-greed-sources )
2384 -u | --try-upgrade )
2385 TRY_UPGRADE="1"; shift ;;
2387 shift; UPGRADE_VERSION="$1"; shift;;
2388 -un | --try-upgrade-with-float-version )
2389 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2391 BE_VERBOSE="1"; shift ;;
2396 if echo "${MACRO}" | grep -q '\W'; then
2397 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2401 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2406 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\""
2410 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2413 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
2414 COMMAND="show_bconds"
2418 COMMAND="show_bcond_args"
2421 --show-avail-bconds)
2422 COMMAND="show_avail_bconds"
2427 RPMOPTS="${RPMOPTS} --nodeps"
2430 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2433 Exit_error err_invalid_cmdline "$1"
2436 SPECFILE=${1%/}; shift
2437 # check if specname was passed as specname:cvstag
2438 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
2439 CVSTAG="${SPECFILE##*:}"
2440 SPECFILE="${SPECFILE%%:*}"
2442 # always have SPECFILE ending with .spec extension
2443 SPECFILE=${SPECFILE%%.spec}.spec
2444 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
2448 [ -d "$ASSUMED_NAME" ] && CVS_ENTRIES="$ASSUMED_NAME/CVS/Entries" || CVS_ENTRIES="CVS/Entries"
2449 if [ -f "$CVS_ENTRIES" ] && [ -z "$CVSTAG" ]; then
2450 CVSTAG=$(awk -vSPECFILE=$(basename $SPECFILE) -F/ '$2 == SPECFILE && $6 ~ /^T/{print substr($6, 2)}' ${CVS_ENTRIES})
2451 if [ "$CVSTAG" ]; then
2452 echo >&2 "builder: Sticky tag $CVSTAG active. Use -r TAGNAME to override."
2454 elif [ "$CVSTAG" = "HEAD" ]; then
2455 # assume -r HEAD is same as -A
2459 if [ "$CVSTAG" ]; then
2460 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2461 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2464 if [ -n "$DEBUG" ]; then
2469 if [ -n "$TARGET" ]; then
2472 TARGET_SWITCH="--target $TARGET" ;;
2474 TARGET_SWITCH="--target=$TARGET" ;;
2478 if [ "$SCHEDTOOL" != "no" ]; then
2479 NICE_COMMAND="$SCHEDTOOL"
2481 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2484 update_shell_title "$COMMAND"
2488 if [ -z "$SPECFILE" ]; then
2489 Exit_error err_no_spec_in_cmdl
2491 get_spec > /dev/null
2498 if [ -z "$SPECFILE" ]; then
2499 Exit_error err_no_spec_in_cmdl
2501 get_spec > /dev/null
2506 "show_avail_bconds")
2508 if [ -z "$SPECFILE" ]; then
2509 Exit_error err_no_spec_in_cmdl
2512 get_spec > /dev/null
2514 local bcond_avail=$(find_spec_bcond $SPECFILE)
2515 local opt bcond bconds
2516 for opt in $bcond_avail; do
2519 bcond=${opt#without_}
2520 bconds="$bconds $bcond"
2524 bconds="$bconds $bcond"
2527 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2535 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
2537 if [ -z "$SPECFILE" ]; then
2538 Exit_error err_no_spec_in_cmdl
2541 # display SMP make flags if set
2542 smp_mflags=$(rpm -E %{?_smp_mflags})
2543 if [ "$smp_mflags" ]; then
2544 echo "builder: SMP make flags are set to $smp_mflags"
2552 if [ "$COMMAND" != "build-source" ]; then
2555 fetch_build_requires
2556 if [ "$INTEGER_RELEASE" = "yes" ]; then
2557 echo "Checking release $PACKAGE_RELEASE..."
2558 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2559 Exit_error err_fract_rel "$PACKAGE_RELEASE"
2563 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2564 if [ -n "$TEST_TAG" ]; then
2565 local TAGVER=`make_tagver`
2566 # escape some regexp characters if part of TAGVER
2567 TAGVER=$(echo "$TAGVER" | sed -e 's#\([\+\*\.]\)#\\\1#g')
2568 echo "Searching for tag $TAGVER..."
2569 TAGREL=$($CVS_COMMAND status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
2570 if [ -n "$TAGREL" ]; then
2571 Exit_error err_tag_exists "$TAGVER" "$TAGREL"
2574 # - do not allow to build from HEAD when XX-branch exists
2575 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto-\([a-zA-Z]\+\)-.*#\1#g')
2576 if [ "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
2577 TAG_BRANCH="${TREE_PREFIX}-branch"
2578 TAG_STATUS=$($CVS_COMMAND status -v $SPECFILE | grep -Ei "${TAG_BRANCH}.+(branch: [0-9.]+)")
2579 if [ -n "$TAG_STATUS" -a "$CVSTAG" = "HEAD" ]; then
2580 Exit_error err_branch_exists "$TAG_STATUS"
2586 if [ -n "$NOSOURCE0" ] ; then
2587 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2592 get_files $SOURCES $PATCHES
2596 NODIST="yes" get_files $SOURCES $PATCHES
2597 update_md5 $SOURCES $PATCHES
2601 if [ "$UPDATE_POLDEK_INDEXES" = "yes" -a "$COMMAND" != "build-prep" ]; then
2602 run_poldek --sdir="${POLDEK_INDEX_DIR}" --mkidxz
2604 remove_build_requires
2608 if [ -z "$SPECFILE" ]; then
2609 Exit_error err_no_spec_in_cmdl
2614 # don't fetch sources from remote locations
2616 for file in $SOURCES; do
2617 [ -n "`src_md5 $file`" ] && continue
2618 new_SOURCES="$new_SOURCES $file"
2620 SOURCES="$new_SOURCES"
2621 get_files $SOURCES $PATCHES
2623 branch_files $TAG $SOURCES $PATCHES $ICONS
2627 if [ -z "$SPECFILE" ]; then
2628 Exit_error err_no_spec_in_cmdl
2631 ADD_PACKAGE_CVS=yes get_spec
2634 if [ -n "$NOSOURCE0" ] ; then
2635 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2637 get_files $SOURCES $PATCHES
2642 if [ -z "$SPECFILE" ]; then
2643 Exit_error err_no_spec_in_cmdl
2649 if [ -n "$NOSOURCE0" ] ; then
2650 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2652 get_files $SOURCES $PATCHES
2657 if [ -z "$SPECFILE" ]; then
2658 Exit_error err_no_spec_in_cmdl
2664 if [ -n "$NOSOURCE0" ] ; then
2665 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2667 update_md5 $SOURCES $PATCHES
2673 if [ -z "$SPECFILE" ]; then
2674 Exit_error err_no_spec_in_cmdl
2680 # don't fetch sources from remote locations
2682 for file in $SOURCES; do
2683 [ -n "`src_md5 $file`" ] && continue
2684 new_SOURCES="$new_SOURCES $file"
2686 SOURCES="$new_SOURCES"
2687 get_files $SOURCES $PATCHES
2689 tag_files $SOURCES $PATCHES $ICONS
2694 "list-sources-files" )
2697 DONT_PRINT_REVISION="yes"
2700 for SAP in $SOURCES $PATCHES; do
2701 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2704 "list-sources-urls" )
2707 DONT_PRINT_REVISION="yes"
2710 SAPS="$SOURCES $PATCHES"
2711 for SAP in $SAPS ; do
2715 "list-sources-local-paths" )
2718 DONT_PRINT_REVISION="yes"
2721 for SAP in $SOURCES $PATCHES; do
2722 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
2725 "list-sources-distfiles-paths" )
2728 DONT_PRINT_REVISION="yes"
2731 for SAP in $SOURCES $PATCHES; do
2732 if [ -n "$(src_md5 "$SAP")" ]; then
2733 distfiles_path "$SAP"
2737 "list-sources-distfiles" )
2740 DONT_PRINT_REVISION="yes"
2743 for SAP in $SOURCES $PATCHES; do
2744 if [ -n "$(src_md5 "$SAP")" ]; then
2745 distfiles_url "$SAP"
2749 "list-sources-cvs" )
2752 DONT_PRINT_REVISION="yes"
2755 for SAP in $SOURCES $PATCHES; do
2756 if [ -z "$(src_md5 "$SAP")" ]; then
2757 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2771 echo "$VERSIONSTRING"
2774 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2775 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
2779 # vi:syntax=sh:ts=4:sw=4:noet