7 # 2 - no spec file name in cmdl parameters
8 # 3 - spec file not stored in repo
9 # 4 - some source, patch or icon files not stored in repo
10 # 5 - package build failed
11 # 6 - spec file with errors
12 # 7 - wrong source in /etc/poldek.conf
13 # 8 - Failed installing buildrequirements and subrequirements
16 # - builder -u fetches current version first
17 # - tries to get new version from distfiles without new md5
18 # - after fetching new version doesn't update md5
19 # - doesn't get sources for specs with %include /usr/lib/rpm/macros.python
20 # when there's no rpm-pythonprov (rpm's fault, but it's ugly anyway)
21 # - as above with %include /usr/lib/rpm/macros.perl and no rpm-perlprov
22 # - when Icon: field is present, -5 and -a5 doesn't work
25 Build package utility from PLD CVS repository
26 V 0.11 (C) 1999-2003 Free Penguins".
27 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
43 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
46 # It can be used i.e. in log file naming.
47 # See LOGFILE example.
48 DATE=`date +%Y-%m-%d_%H-%M-%S`
50 # Example: LOGFILE='../log.$PACKAGE_NAME'
51 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
52 # Yes, you can use variable name! Note _single_ quotes!
73 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
74 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
79 CVS_SERVER="cvs.pld-linux.org"
80 DISTFILES_SERVER="://distfiles.pld-linux.org"
84 FAIL_IF_NO_SOURCES="yes"
86 wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
87 wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
89 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
90 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
93 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
101 POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
103 POLDEK_CMD="/usr/bin/poldek"
105 # Here we load saved user environment used to
106 # predefine options set above, or passed to builder
108 # This one reads global system environment settings:
109 if [ -f ~/etc/builderrc ]; then
112 # And this one cascades settings using user personal
114 # Example of ~/.builderrc:
116 #UPDATE_POLDEK_INDEXES="yes"
117 #FETCH_BUILD_REQUIRES="yes"
118 #REMOVE_BUILD_REQUIRES="force"
120 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
122 if [ -n "$HOME_ETC" ]; then
123 USER_CFG=$HOME_ETC/.builderrc
125 USER_CFG=~/.builderrc
128 [ -f $USER_CFG ] && . $USER_CFG
132 RES_FILE=~/tmp/poldek-exit-status.$RANDOM
133 if [ -n "$LOGFILE" ]; then
134 LOG=`eval echo $LOGFILE`
135 if [ -n "$LASTLOG_FILE" ]; then
136 echo "LASTLOG=$LOG" > $LASTLOG_FILE
138 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee $LOG
141 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
142 return `cat ${RES_FILE}`
147 # Example grep cvs /etc/poldek.conf:
148 # source = cvs /home/users/yoshi/rpm/RPMS/
149 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
150 run_poldek -l -n ${POLDEK_SOURCE} 1>&2 > /dev/null
151 if [ ! "$?" == "0" ]; then
152 echo "Using improper source '${POLDEK_SOURCE}' in /etc/poldek.conf"
153 echo "Fix it and try to continue"
158 #---------------------------------------------
163 if [ -n "$DEBUG" ]; then set -xv; fi
165 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
167 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
168 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
169 [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
170 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
171 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
172 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
173 [{-Tp|--tag-prefix} <prefix>]
174 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
175 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
177 -5, --update-md5 - update md5 comments in spec, implies -nd -ncs
178 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
179 -D, --debug - enable script debugging mode,
180 -V, --version - output builder version
181 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
182 -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
184 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
185 only package from <package>.spec,
186 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
188 -bp, --build-prep - execute the %prep phase of <package>.spec,
189 -B, --branch - add branch
190 -c, --clean - clean all temporarily created files (in BUILD, SOURCES,
191 SPECS and \$RPM_BUILD_ROOT),
192 -d <cvsroot>, --cvsroot <cvsroot>
194 --define <macro> <value>
195 - define a macro <macro> with value <value>,
196 --nodeps - rpm won't check any dependences
197 -g, --get - get <package>.spec and all related files from CVS repo
199 -h, --help - this message,
200 --http - use http instead of ftp,
201 -l <logfile>, --logtofile <logfile>
203 -m, --mr-proper - only remove all files related to spec file and all work
205 -nc, --no-cvs - don't download sources from CVS, if source URL is given,
207 - don't check specs in CVS
208 -nd, --no-distfiles - don't download from distfiles
209 -nm, --no-mirrors - don't download from mirror, if source URL is given,
210 -nu, --no-urls - don't try to download from FTP/HTTP location,
211 -ns, --no-srcs - don't download Sources
212 -ns0, --no-source0 - don't download Source0
213 --opts <rpm opts> - additional options for rpm
214 -q, --quiet - be quiet,
215 --date yyyy-mm-dd - build package using resources from specified CVS date,
216 -r <cvstag>, --cvstag <cvstag>
217 - build package using resources from specified CVS tag,
218 -R, --fetch-build-requires
219 - fetch what is BuildRequired,
220 -RB, --remove-build-requires
221 - remove all you fetched with -R or --fetch-build-requires
222 remember, this option requires confirmation,
223 -FRB, --force-remove-build-requires
224 - remove all you fetched with -R or --fetch-build-requires
225 remember, this option works without confirmation,
226 -T <cvstag> , --tag <cvstag>
227 - add cvs tag <cvstag> for files,
228 -Tvs, --tag-version-stable
229 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
230 -Tvn, --tag-version-nest
231 - add cvs tags NEST and NAME-VERSION-RELESE for files,
233 - add cvs tag STABLE for files,
235 - add cvs tag NEST for files,
237 - add cvs tag NAME-VERSION-RELESE for files,
238 -Tp, --tag-prefix <prefix>
239 - add <prefix> to NAME-VERSION-RELEASE tags,
240 -v, --verbose - be verbose,
241 -u, --try-upgrade - check version, and try to upgrade package
242 -un, --try-upgrade-with-float-version
243 - as above, but allow float version
244 -U, --update - refetch sources, don't use distfiles, and update md5 comments
245 -Upi, --update-poldek-indexes
246 - refresh or make poldek package index files.
247 --with/--without <feature>
248 - conditional build package depending on %_with_<feature>/
249 %_without_<feature> macro switch. You may now use
250 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
251 constructions. Set GROUP_BCONDS to yes to make use of it.
259 rpm -bp --nodeps --define 'prep %dump' $BCOND $SPECFILE 2>&1
262 rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $SPECFILE 2>&1
268 if [ -z "$rpm_dump_cache" ] ; then
269 echo "internal error: cache_rpm_dump not called!" 1>&2
271 echo "$rpm_dump_cache"
276 if [ -n "$DEBUG" ]; then
285 if [ "$NOSRCS" != "yes" ]; then
286 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
288 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
289 FAIL_IF_NO_SOURCES="no"
292 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
293 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
294 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
295 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -n 1`"
296 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
298 if [ -n "$BE_VERBOSE" ]; then
299 echo "- Sources : `nourl $SOURCES`"
300 if [ -n "$PATCHES" ]; then
301 echo "- Patches : `nourl $PATCHES`"
303 echo "- Patches : *no patches needed*"
305 if [ -n "$ICONS" ]; then
306 echo "- Icon : `nourl $ICONS`"
308 echo "- Icon : *no package icon*"
310 echo "- Name : $PACKAGE_NAME"
311 echo "- Version : $PACKAGE_VERSION"
312 echo "- Release : $PACKAGE_RELEASE"
318 if [ -n "$DEBUG" ]; then
326 "err_no_spec_in_cmdl" )
327 remove_build_requires
328 echo "ERROR: spec file name not specified.";
330 "err_no_spec_in_repo" )
331 remove_build_requires
332 echo "Error: spec file not stored in CVS repo.";
334 "err_no_source_in_repo" )
335 remove_build_requires
336 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
339 remove_build_requires
340 echo "Error: package build failed. (${2:-no more info})";
347 if [ -n "$DEBUG" ]; then
352 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
353 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
360 if [ -n "$DEBUG" ]; then
365 if [ "$NOCVSSPEC" != "yes" ]; then
370 if [ -n "$CVSROOT" ]; then
371 OPTIONS="-d $CVSROOT $OPTIONS"
373 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
374 echo "warning: No cvs access defined - using local .spec file"
379 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
380 OPTIONS="$OPTIONS -A"
382 if [ -n "$CVSDATE" ]; then
383 OPTIONS="$OPTIONS -D $CVSDATE"
385 if [ -n "$CVSTAG" ]; then
386 OPTIONS="$OPTIONS -r $CVSTAG"
392 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
394 retries_counter=$(( $retries_counter + 1 ))
395 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
397 [ -n "$output" ] && echo "$output"
398 if [ "$result" -ne "0" ]; then
399 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
400 echo "Trying again [$SPECFILE]... ($retries_counter)"
404 Exit_error err_no_spec_in_repo;
408 if [ ! -f "$SPECFILE" ]; then
409 Exit_error err_no_spec_in_repo;
412 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
413 chmod $CHMOD_MODE $SPECFILE
416 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
423 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
424 cvs update mirrors >&2
428 while read origin mirror name rest
430 ol=`echo -n "$origin"|wc -c`
431 prefix="`echo -n "$url" | head -c $ol`"
432 if [ "$prefix" = "$origin" ] ; then
433 suffix="`echo "$url"|cut -b $ol-`"
434 echo -n "$mirror$suffix"
445 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
446 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
453 [ -z "$no" ] && return
455 spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
456 if [ -z "$spec_rev" ]; then
457 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
459 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
460 md5=$(grep -s -v '^#' additional-md5sums | \
461 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
462 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
463 grep -E '^[0-9a-f]{32}$')
464 if [ X"$md5" = X"" ] ; then
465 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
467 if [ $(echo "$md5" | wc -l) != 1 ] ; then
468 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
470 echo "$md5" | tail -n 1
476 echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
479 distfiles_attic_url ()
481 echo "$PROTOCOL$DISTFILES_SERVER/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
488 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
495 if [ -n "$DEBUG" ]; then
500 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
504 if [ -n "$CVSROOT" ]; then
505 OPTIONS="-d $CVSROOT $OPTIONS"
507 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
508 echo "warning: No cvs access defined for SOURCES"
512 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
513 OPTIONS="$OPTIONS -A"
515 if [ -n "$CVSDATE" ]; then
516 OPTIONS="$OPTIONS -D $CVSDATE"
518 if [ -n "$CVSTAG" ]; then
519 OPTIONS="$OPTIONS -r $CVSTAG"
524 if [ -n "$UPDATE5" ]; then
525 if [ -n "$ADD5" ]; then
526 [ `nourl $i` = "$i" ] && continue
527 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
529 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
533 if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
534 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
535 echo "Warning: no URL given for $i"
538 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
539 if good_md5 "$i"; then
540 echo "$(nourl "$i") having proper md5sum already exists"
544 url=$(distfiles_url "$i")
545 url_attic=$(distfiles_attic_url "$i")
547 if [ `echo $url | grep -E '^(\.|/)'` ]; then
548 ${GETLOCAL} $url $target
550 if [ -z "$NOMIRRORS" ]; then
551 url="`find_mirror "$url"`"
553 ${GETURI} -O "$target" "$url" || \
554 if [ `echo $url | grep -E 'ftp://'` ]; then
555 ${GETURI2} -O "$target" "$url"
558 if ! test -s "$target"; then
560 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
561 ${GETLOCAL} $url_attic $target
563 if [ -z "$NOMIRRORS" ]; then
564 url_attic="`find_mirror "$url_attic"`"
566 ${GETURI} -O "$target" "$url_attic" || \
567 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
568 ${GETURI2} -O "$target" "$url_attic"
572 if ! test -s "$target"; then
576 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
577 # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
580 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
582 retries_counter=$(( $retries_counter + 1 ))
583 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
585 [ -n "$output" ] && echo "$output"
586 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
587 echo "Trying again [`nourl $i`]... ($retries_counter)"
596 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
597 if [ -z "$NOMIRRORS" ]; then
598 im="`find_mirror "$i"`"
603 if [ `echo $im | grep -E 'ftp://'` ]; then
610 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
611 Exit_error err_no_source_in_repo $i;
612 elif [ -n "$UPDATE5" ] && \
613 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
614 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
615 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
617 echo "Updating source-$srcno md5."
618 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
620 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
621 print "# Source'$srcno'-md5:\t'$md5'\n"
622 if /^Source'$srcno'\s*:\s+/;
627 if good_md5 "$i"; then
629 elif [ "$FROM_DISTFILES" = 1 ]; then
630 # wrong md5 from distfiles: remove the file and try again
632 echo "MD5 sum mismatch. Trying full fetch."
635 ${GETURI} -O "$target" "$url" || \
636 if [ `echo $url | grep -E 'ftp://'` ]; then
637 ${GETURI2} -O "$target" "$url"
639 if ! test -s "$target"; then
641 ${GETURI} -O "$target" "$url_attic" || \
642 if [ `echo $url_attic | grep -E 'ftp://'` ]; then
643 ${GETURI2} -O "$target" "$url_attic"
646 test -s "$target" || rm -f "$target"
649 if good_md5 "$i"; then
652 echo "MD5 sum mismatch. Use -U to refetch sources,"
653 echo "or -5 to update md5 sums, if you're sure files are correct."
654 Exit_error err_no_source_in_repo $i
658 if [ "$CHMOD" = "yes" ]; then
659 CHMOD_FILES="`nourl $GET_FILES`"
660 if [ -n "$CHMOD_FILES" ]; then
661 chmod $CHMOD_MODE $CHMOD_FILES
672 if [ -n "$DEBUG" ]; then
677 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
678 echo "Version: $PACKAGE_VERSION"
679 echo "Release: $PACKAGE_RELEASE"
680 # Check whether first character of PACKAGE_NAME is legal for tag name
681 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
684 TAGVER=$TAG_PREFIX$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
685 # Remove #kernel.version_release from TAGVER because tagging sources
686 # could occur with different kernel-headers than kernel-headers used at build time.
687 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
688 if [ "$TAG_VERSION" = "yes" ]; then
689 echo "CVS tag: $TAGVER"
691 if [ -n "$TAG" ]; then
696 if [ -n "$CVSROOT" ]; then
697 OPTIONS="-d $CVSROOT $OPTIONS"
703 # don't tag files stored on distfiles
704 [ -n "`src_md5 $i`" ] && continue
705 if [ -f "`nourl $i`" ]; then
706 if [ "$TAG_VERSION" = "yes" ]; then
707 cvs $OPTIONS $TAGVER `nourl $i`
709 if [ -n "$TAG" ]; then
710 cvs $OPTIONS $TAG `nourl $i`
713 Exit_error err_no_source_in_repo $i
718 if [ "$TAG_VERSION" = "yes" ]; then
719 cvs $OPTIONS $TAGVER $SPECFILE
721 if [ -n "$TAG" ]; then
722 cvs $OPTIONS $TAG $SPECFILE
732 echo "CVS branch tag: $TAG"
737 if [ -n "$DEBUG" ]; then
742 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
745 if [ -n "$CVSROOT" ]; then
746 OPTIONS="-d $CVSROOT $OPTIONS"
751 if [ -f `nourl $i` ]; then
752 cvs $OPTIONS $TAG `nourl $i`
754 Exit_error err_no_source_in_repo $i
758 cvs $OPTIONS $TAG $SPECFILE
768 if [ -n "$DEBUG" ]; then
775 if [ -n "$TRY_UPGRADE" ]; then
776 if [ -n "$FLOAT_VERSION" ]; then
777 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
779 TNOTIFY=`./pldnotify.awk $SPECFILE`
782 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
784 if [ -n "$TNEWVER" ]; then
785 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
786 echo "New version found, updating spec file to version " $TNEWVER
787 cp -f $SPECFILE $SPECFILE.bak
789 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
790 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
792 get_files "$SOURCES $PATCHES";
793 unset TOLDVER TNEWVER TNOTIFY
800 BUILD_SWITCH="-ba" ;;
802 BUILD_SWITCH="-bb" ;;
804 BUILD_SWITCH="-bs --nodeps" ;;
806 BUILD_SWITCH="-bp --nodeps" ;;
808 if [ -n "$LOGFILE" ]; then
809 LOG=`eval echo $LOGFILE`
810 if [ -n "$LASTLOG_FILE" ]; then
811 echo "LASTLOG=$LOG" > $LASTLOG_FILE
813 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
814 (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
815 RETVAL=`cat $RES_FILE`
817 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
818 if [ "$RETVAL" -eq "0" ]; then
825 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
828 if [ "$RETVAL" -ne "0" ]; then
829 if [ -n "$TRY_UPGRADE" ]; then
830 echo "\n!!! Package with new version cannot be build automagically\n"
831 mv -f $SPECFILE.bak $SPECFILE
833 Exit_error err_build_fail;
840 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
844 install_required_packages()
852 AVAIL_BCONDS_WITHOUT=""
854 if `grep -q ^%bcond ${SPECFILE}`; then
856 elif `grep -q bcond ${SPECFILE}`; then
861 case "${BCOND_VERSION}" in
866 echo "Warning: This spec has old style bconds. Fix it || die."
867 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
869 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
870 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
871 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
873 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
877 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
879 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
880 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
881 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
883 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
888 cond_type="" # with || without
889 for opt in `$RPMBUILD --bcond $SPECFILE`
902 AVAIL_BCOND_WITH="$opt"
903 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
904 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
906 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
911 AVAIL_BCOND_WITHOUT="$opt"
912 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
913 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
915 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
929 echo -ne "Package installation failed:\t$package_name\n"
931 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
932 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
933 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
934 # jakby nie bylo tego kawalka kodu.
936 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
937 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
945 # Istnieje taki spec? ${package}.spec
946 if [ -f "${SPECS_DIR}${package}.spec" ]; then
947 parent_spec_name=${package}.spec
948 elif [ -f "${SPECS_DIR}`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
949 parent_spec_name="`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec"
951 for provides_line in `grep ^Provides:.*$package ${SPECS_DIR} -R`
957 if [ "${parent_spec_name}" != "" ]; then
959 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
960 sub_builder_opts="${sub_builder_opts} -R"
962 if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
963 sub_builder_opts="${sub_builder_opts} -RB"
964 elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
965 sub_builder_opts="${sub_builder_opts} -FRB"
967 if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
968 sub_builder_opts="${sub_builder_opts} -Upi"
971 ./builder ${sub_builder_opts} ${parent_spec_name}
973 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
976 remove_build_requires()
978 if [ "$INSTALLED_PACKAGES" != "" ]; then
979 case "$REMOVE_BUILD_REQUIRES" in
981 run_poldek --noask -ve $INSTALLED_PACKAGES
984 run_poldek --ask -ve $INSTALLED_PACKAGES
987 echo You may want to manually remove following BuildRequires fetched:
988 echo $INSTALLED_PACKAGES
989 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
997 if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
998 echo -ne "We are going to build $SPECFILE with the following conditional flags:\n"
999 if [ "$BCOND" != "" ]; then
1002 echo -ne "No --with || --without conditions passed to $0!"
1004 echo -ne "\n\nfrom available:\n\n"
1005 echo -ne "--with :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
1009 fetch_build_requires()
1011 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
1012 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
1013 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
1014 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
1015 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
1016 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1017 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,kgcc_package,gcc,g -e s,\),,g`
1019 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`"
1021 package=`basename "$package_item"|sed -e "s/}$//g"`
1022 COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
1025 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1026 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1027 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
1032 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1035 if `echo $COND_TST|grep -q 'without_'`; then
1036 COND_NAME=`echo $COND_NAME|sed -e s,^.*_without_,,g`
1037 if `echo $COND_TST|grep -q !`; then
1042 if `echo $AVAIL_BCONDS_WITHOUT|grep -q "<$COND_NAME>"`; then
1048 elif `echo $COND_TST|grep -q 'with_'`; then
1049 COND_NAME=`echo $COND_NAME|sed -e s,^.*_with_,,g`
1050 if `echo $COND_TST|grep -q !`; then
1055 if `echo $AVAIL_BCONDS_WITH|grep -q "<$COND_NAME>"`; then
1061 RESULT="${COND_STATE}-${COND_ARGV}"
1063 "with-wout" | "wout-with" )
1066 "wout-wout" | "with-with" )
1070 echo "Action '$RESULT' was not defined for package '$package_item'"
1076 if [ "$GO" = "yes" ]; then
1077 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1078 echo "Testing if $package has subrequirements..."
1079 run_poldek -t -i $package --dumpn=".$package-req.txt"
1080 if [ -f ".$package-req.txt" ]; then
1081 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1083 if [ "$package_name" = "$package" ]; then
1084 echo -ne "Installing BuildRequired package:\t$package_name\n"
1085 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing BuildRequired package: ${package_name}\007"`
1086 install_required_packages $package;
1088 echo -ne "Installing (sub)Required package:\t$package_name\n"
1089 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing (sub)Required package: ${package_name}\007"`
1090 install_required_packages $package_name;
1094 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1095 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1098 echo "Attempting to run spawn sub - builder..."
1099 run_sub_builder $package_name
1100 if [ $? -eq 0 ]; then
1101 install_required_packages $package_name;
1104 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1105 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1108 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1115 rm -f ".$package-req.txt"
1117 echo "Attempting to run spawn sub - builder..."
1118 run_sub_builder $package
1119 if [ $? -eq 0 ]; then
1120 install_required_packages $package;
1123 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1124 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1127 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1133 echo "Package $package is already installed. BuildRequirement satisfied."
1137 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1138 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1139 echo "Nie uda³o siê zainstalowaæ nastêpuj±cych pakietów i ich zale¿no¶ci:"
1140 for pkg in "$NOT_INSTALLED_PACKAGES"
1144 remove_build_requires
1150 #---------------------------------------------
1153 if [ "$#" = 0 ]; then
1176 DEBUG="yes"; shift ;;
1178 COMMAND="version"; shift ;;
1180 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1181 -b | -ba | --build )
1182 COMMAND="build"; shift ;;
1183 -bb | --build-binary )
1184 COMMAND="build-binary"; shift ;;
1185 -bs | --build-source )
1186 COMMAND="build-source"; shift ;;
1187 -bp | --build-prep )
1188 COMMAND="build-prep"; shift ;;
1190 COMMAND="branch"; shift; TAG="${1}"; shift;;
1192 CLEAN="--clean --rmspec --rmsource"; shift ;;
1194 shift; CVSROOT="${1}"; shift ;;
1196 COMMAND="get"; shift ;;
1198 COMMAND="usage"; shift ;;
1200 PROTOCOL="http"; shift ;;
1202 shift; LOGFILE="${1}"; shift ;;
1204 shift; DEF_NICE_LEVEL=${1}; shift ;;
1206 COMMAND="mr-proper"; shift ;;
1208 NOCVS="yes"; shift ;;
1209 -ncs | --no-cvs-specs )
1210 NOCVSSPEC="yes"; shift ;;
1211 -nd | --no-distfiles )
1212 NODIST="yes"; shift ;;
1213 -nm | --no-mirrors )
1214 NOMIRRORS="yes"; shift ;;
1216 NOURLS="yes"; shift ;;
1218 NOSRCS="yes"; shift ;;
1219 -ns0 | --no-source0 )
1220 NOSOURCE0="yes"; shift ;;
1222 shift; RPMOPTS="${1}"; shift ;;
1223 --with | --without )
1224 case $GROUP_BCONDS in
1228 while ! `echo ${1}|grep -qE '(^-|spec)'`
1230 BCOND="$BCOND $COND $1"
1234 BCOND="$BCOND $1 $2" ; shift 2 ;;
1238 QUIET="--quiet"; shift ;;
1240 CVSDATE="${2}"; shift 2 ;;
1242 shift; CVSTAG="${1}"; shift ;;
1243 -R | --fetch-build-requires)
1244 FETCH_BUILD_REQUIRES="yes"
1245 NOT_INSTALLED_PACKAGES=
1247 -RB | --remove-build-requires)
1248 REMOVE_BUILD_REQUIRES="nice"
1250 -FRB | --force-remove-build-requires)
1251 REMOVE_BUILD_REQUIRES="force"
1253 -Tvs | --tag-version-stable )
1258 -Tvn | --tag-version-nest )
1263 -Ts | --tag-stable )
1273 -Tv | --tag-version )
1278 -Tp | --tag-prefix )
1294 -Upi | --update-poldek-indexes )
1295 UPDATE_POLDEK_INDEXES="yes"
1297 -u | --try-upgrade )
1298 TRY_UPGRADE="1"; shift ;;
1299 -un | --try-upgrade-with-float-version )
1300 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1302 BE_VERBOSE="1"; shift ;;
1308 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1312 RPMOPTS="${RPMOPTS} --nodeps"
1315 SPECFILE="`basename ${1} .spec`.spec";
1316 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1321 if [ -n "$DEBUG" ]; then
1327 "build" | "build-binary" | "build-source" | "build-prep" )
1329 if [ -n "$SPECFILE" ]; then
1333 fetch_build_requires;
1336 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
1337 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
1338 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
1339 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1341 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
1342 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
1346 if [ -n "$ICONS" ]; then
1350 if [ -n "$NOSOURCE0" ] ; then
1351 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1353 get_files "$SOURCES $PATCHES";
1355 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
1356 run_poldek --sn ${POLDEK_SOURCE} --mkidx="${POLDEK_INDEX_DIR}/packages.dir.gz"
1357 run_poldek --sn ${POLDEK_SOURCE} --up
1359 remove_build_requires;
1361 Exit_error err_no_spec_in_cmdl;
1366 if [ -n "$SPECFILE" ]; then
1369 if [ -n "$ICONS" ]; then
1373 get_files $SOURCES $PATCHES;
1374 branch_files $TAG "$SOURCES $PATCHES $ICONS";
1376 Exit_error err_no_spec_in_cmdl;
1381 if [ -n "$SPECFILE" ]; then
1384 if [ -n "$ICONS" ]; then
1388 if [ -n "$NOSOURCE0" ] ; then
1389 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1391 get_files $SOURCES $PATCHES
1393 Exit_error err_no_spec_in_cmdl;
1400 if [ -n "$SPECFILE" ]; then
1403 if [ -n "$ICONS" ]; then
1407 # don't fetch sources from remote locations
1409 for file in $SOURCES
1411 [ -n "`src_md5 $file`" ] && continue
1412 new_SOURCES="$new_SOURCES $file"
1414 SOURCES="$new_SOURCES"
1415 get_files $SOURCES $PATCHES;
1416 tag_files "$SOURCES $PATCHES $ICONS";
1418 Exit_error err_no_spec_in_cmdl;
1422 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1429 test -f `pwd`/.${SPECFILE}_INSTALLED_PACKAGES && rm `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1432 # vi:syntax=sh:ts=3:sw=4