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
15 # - builder -u fetches current version first
16 # - tries to get new version from distfiles without new md5
17 # - after fetching new version doesn't update md5
18 # - doesn't get sources for specs with %include /usr/lib/rpm/macros.python
19 # when there's no rpm-pythonprov (rpm's fault, but it's ugly anyway)
20 # - as above with %include /usr/lib/rpm/macros.perl and no rpm-perlprov
21 # - when Icon: field is present, -5 and -a5 doesn't work
24 Build package utility from PLD CVS repository
25 V 0.11 (C) 1999-2003 Free Penguins".
26 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
42 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
45 # It can be used i.e. in log file naming.
46 # See LOGFILE example.
47 DATE=`date +%Y-%m-%d_%H-%M-%S`
49 # Example: LOGFILE='../log.$PACKAGE_NAME'
50 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
51 # Yes, you can use variable name! Note _single_ quotes!
72 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
73 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
78 CVS_SERVER="cvs.pld-linux.org"
79 DISTFILES_SERVER="://distfiles.pld-linux.org"
83 FAIL_IF_NO_SOURCES="yes"
85 wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
86 wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
88 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
89 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
92 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
100 POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
102 POLDEK_CMD="/usr/bin/poldek"
104 # Here we load saved user environment used to
105 # predefine options set above, or passed to builder
107 # This one reads global system environment settings:
108 if [ -f ~/etc/builderrc ]; then
111 # And this one cascades settings using user personal
113 # Example of ~/.builderrc:
115 #UPDATE_POLDEK_INDEXES="yes"
116 #FETCH_BUILD_REQUIRES="yes"
117 #REMOVE_BUILD_REQUIRES="force"
119 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
121 if [ -n "$HOME_ETC" ]; then
122 USER_CFG=$HOME_ETC/.builderrc
124 USER_CFG=~/.builderrc
127 [ -f $USER_CFG ] && . $USER_CFG
131 RES_FILE=~/tmp/poldek-exit-status.$RANDOM
132 if [ -n "$LOGFILE" ]; then
133 LOG=`eval echo $LOGFILE`
134 if [ -n "$LASTLOG_FILE" ]; then
135 echo "LASTLOG=$LOG" > $LASTLOG_FILE
137 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee $LOG
140 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
141 return `cat ${RES_FILE}`
146 # Example grep cvs /etc/poldek.conf:
147 # source = cvs /home/users/yoshi/rpm/RPMS/
148 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
149 run_poldek -l -n ${POLDEK_SOURCE} 1>&2 > /dev/null
150 if [ ! "$?" == "0" ]; then
151 echo "Using improper source '${POLDEK_SOURCE}' in /etc/poldek.conf"
152 echo "Fix it and try to continue"
157 #---------------------------------------------
162 if [ -n "$DEBUG" ]; then set -xv; fi
164 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
166 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
167 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
168 [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
169 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
170 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
171 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
172 [{-Tp|--tag-prefix} <prefix>]
173 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
174 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
176 -5, --update-md5 - update md5 comments in spec, implies -nd -ncs
177 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
178 -D, --debug - enable script debugging mode,
179 -V, --version - output builder version
180 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
181 -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
183 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
184 only package from <package>.spec,
185 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
187 -bp, --build-prep - execute the %prep phase of <package>.spec,
188 -B, --branch - add branch
189 -c, --clean - clean all temporarily created files (in BUILD, SOURCES,
190 SPECS and \$RPM_BUILD_ROOT),
191 -d <cvsroot>, --cvsroot <cvsroot>
193 --define <macro> <value>
194 - define a macro <macro> with value <value>,
195 --nodeps - rpm won't check any dependences
196 -g, --get - get <package>.spec and all related files from CVS repo
198 -h, --help - this message,
199 --http - use http instead of ftp,
200 -l <logfile>, --logtofile <logfile>
202 -m, --mr-proper - only remove all files related to spec file and all work
204 -nc, --no-cvs - don't download sources from CVS, if source URL is given,
206 - don't check specs in CVS
207 -nd, --no-distfiles - don't download from distfiles
208 -nm, --no-mirrors - don't download from mirror, if source URL is given,
209 -nu, --no-urls - don't try to download from FTP/HTTP location,
210 -ns, --no-srcs - don't download Sources
211 -ns0, --no-source0 - don't download Source0
212 --opts <rpm opts> - additional options for rpm
213 -q, --quiet - be quiet,
214 --date yyyy-mm-dd - build package using resources from specified CVS date,
215 -r <cvstag>, --cvstag <cvstag>
216 - build package using resources from specified CVS tag,
217 -R, --fetch-build-requires
218 - fetch what is BuildRequired,
219 -RB, --remove-build-requires
220 - remove all you fetched with -R or --fetch-build-requires
221 remember, this option requires confirmation,
222 -FRB, --force-remove-build-requires
223 - remove all you fetched with -R or --fetch-build-requires
224 remember, this option works without confirmation,
225 -T <cvstag> , --tag <cvstag>
226 - add cvs tag <cvstag> for files,
227 -Tvs, --tag-version-stable
228 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
229 -Tvn, --tag-version-nest
230 - add cvs tags NEST and NAME-VERSION-RELESE for files,
232 - add cvs tag STABLE for files,
234 - add cvs tag NEST for files,
236 - add cvs tag NAME-VERSION-RELESE for files,
237 -Tp, --tag-prefix <prefix>
238 - add <prefix> to NAME-VERSION-RELEASE tags,
239 -v, --verbose - be verbose,
240 -u, --try-upgrade - check version, and try to upgrade package
241 -un, --try-upgrade-with-float-version
242 - as above, but allow float version
243 -U, --update - refetch sources, don't use distfiles, and update md5 comments
244 -Upi, --update-poldek-indexes
245 - refresh or make poldek package index files.
246 --with/--without <feature>
247 - conditional build package depending on %_with_<feature>/
248 %_without_<feature> macro switch. You may now use
249 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
250 constructions. Set GROUP_BCONDS to yes to make use of it.
258 rpm -bp --nodeps --define 'prep %dump' $BCOND $SPECFILE 2>&1
261 rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $SPECFILE 2>&1
267 if [ -z "$rpm_dump_cache" ] ; then
268 echo "internal error: cache_rpm_dump not called!" 1>&2
270 echo "$rpm_dump_cache"
275 if [ -n "$DEBUG" ]; then
284 if [ "$NOSRCS" != "yes" ]; then
285 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
287 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
288 FAIL_IF_NO_SOURCES="no"
291 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
292 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
293 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
294 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
295 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
297 if [ -n "$BE_VERBOSE" ]; then
298 echo "- Sources : `nourl $SOURCES`"
299 if [ -n "$PATCHES" ]; then
300 echo "- Patches : `nourl $PATCHES`"
302 echo "- Patches : *no patches needed*"
304 if [ -n "$ICONS" ]; then
305 echo "- Icon : `nourl $ICONS`"
307 echo "- Icon : *no package icon*"
309 echo "- Name : $PACKAGE_NAME"
310 echo "- Version : $PACKAGE_VERSION"
311 echo "- Release : $PACKAGE_RELEASE"
317 if [ -n "$DEBUG" ]; then
325 "err_no_spec_in_cmdl" )
326 remove_build_requires
327 echo "ERROR: spec file name not specified.";
329 "err_no_spec_in_repo" )
330 remove_build_requires
331 echo "Error: spec file not stored in CVS repo.";
333 "err_no_source_in_repo" )
334 remove_build_requires
335 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
338 remove_build_requires
339 echo "Error: package build failed. (${2:-no more info})";
346 if [ -n "$DEBUG" ]; then
351 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
352 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
359 if [ -n "$DEBUG" ]; then
364 if [ "$NOCVSSPEC" != "yes" ]; then
369 if [ -n "$CVSROOT" ]; then
370 OPTIONS="-d $CVSROOT $OPTIONS"
372 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
373 echo "warning: No cvs access defined - using local .spec file"
378 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
379 OPTIONS="$OPTIONS -A"
381 if [ -n "$CVSDATE" ]; then
382 OPTIONS="$OPTIONS -D $CVSDATE"
384 if [ -n "$CVSTAG" ]; then
385 OPTIONS="$OPTIONS -r $CVSTAG"
391 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
393 retries_counter=$(( $retries_counter + 1 ))
394 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
396 [ -n "$output" ] && echo "$output"
397 if [ "$result" -ne "0" ]; then
398 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
399 echo "Trying again [$SPECFILE]... ($retries_counter)"
403 Exit_error err_no_spec_in_repo;
407 if [ ! -f "$SPECFILE" ]; then
408 Exit_error err_no_spec_in_repo;
411 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
412 chmod $CHMOD_MODE $SPECFILE
415 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
422 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
423 cvs update mirrors >&2
427 while read origin mirror name rest
429 ol=`echo -n "$origin"|wc -c`
430 prefix="`echo -n "$url" | head -c $ol`"
431 if [ "$prefix" = "$origin" ] ; then
432 suffix="`echo "$url"|cut -b $ol-`"
433 echo -n "$mirror$suffix"
444 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
445 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
452 [ -z "$no" ] && return
454 spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
455 if [ -z "$spec_rev" ]; then
456 spec_rev="$(head -1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
458 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
459 md5=$(grep -s -v '^#' additional-md5sums | \
460 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
461 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
462 grep -E '^[0-9a-f]{32}$')
463 if [ X"$md5" = X"" ] ; then
464 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
466 if [ $(echo "$md5" | wc -l) != 1 ] ; then
467 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
469 echo "$md5" | tail -1
475 echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
482 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
489 if [ -n "$DEBUG" ]; then
494 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
498 if [ -n "$CVSROOT" ]; then
499 OPTIONS="-d $CVSROOT $OPTIONS"
501 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
502 echo "warning: No cvs access defined for SOURCES"
506 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
507 OPTIONS="$OPTIONS -A"
509 if [ -n "$CVSDATE" ]; then
510 OPTIONS="$OPTIONS -D $CVSDATE"
512 if [ -n "$CVSTAG" ]; then
513 OPTIONS="$OPTIONS -r $CVSTAG"
518 if [ -n "$UPDATE5" ]; then
519 if [ -n "$ADD5" ]; then
520 [ `nourl $i` = "$i" ] && continue
521 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
523 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
527 if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
528 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
529 echo "Warning: no URL given for $i"
532 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
533 if good_md5 "$i"; then
534 echo "$(nourl "$i") having proper md5sum already exists"
538 url=$(distfiles_url "$i")
539 if [ `echo $url | grep -E '^(\.|/)'` ]; then
540 ${GETLOCAL} $url $target
543 if [ -z "$NOMIRRORS" ]; then
544 url="`find_mirror "$url"`"
546 ${GETURI} -O "$target" "$url" || \
547 if [ `echo $url | grep -E 'ftp://'` ]; then
548 ${GETURI2} -O "$target" "$url"
550 if ! test -s "$target"; then
555 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
556 # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
559 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
561 retries_counter=$(( $retries_counter + 1 ))
562 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
564 [ -n "$output" ] && echo "$output"
565 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
566 echo "Trying again [`nourl $i`]... ($retries_counter)"
575 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
576 if [ -z "$NOMIRRORS" ]; then
577 im="`find_mirror "$i"`"
582 if [ `echo $im | grep -E 'ftp://'` ]; then
590 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
591 Exit_error err_no_source_in_repo $i;
592 elif [ -n "$UPDATE5" ] && \
593 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
594 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
595 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
597 echo "Updating source-$srcno md5."
598 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
600 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
601 print "# Source'$srcno'-md5:\t'$md5'\n"
602 if /^Source'$srcno'\s*:\s+/;
607 if good_md5 "$i"; then
609 elif [ "$FROM_DISTFILES" = 1 ]; then
610 # wrong md5 from distfiles: remove the file and try again
612 echo "MD5 sum mismatch. Trying full fetch."
615 ${GETURI} -O "$target" "$url" || \
616 if [ `echo $url | grep -E 'ftp://'` ]; then
617 ${GETURI2} -O "$target" "$url"
619 test -s "$target" || rm -f "$target"
622 if good_md5 "$i"; then
625 echo "MD5 sum mismatch. Use -U to refetch sources,"
626 echo "or -5 to update md5 sums, if you're sure files are correct."
627 Exit_error err_no_source_in_repo $i
631 if [ "$CHMOD" = "yes" ]; then
632 CHMOD_FILES="`nourl $GET_FILES`"
633 if [ -n "$CHMOD_FILES" ]; then
634 chmod $CHMOD_MODE $CHMOD_FILES
645 if [ -n "$DEBUG" ]; then
650 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
651 echo "Version: $PACKAGE_VERSION"
652 echo "Release: $PACKAGE_RELEASE"
653 # Check whether first character of PACKAGE_NAME is legal for tag name
654 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
657 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"`
658 # Remove #kernel.version_release from TAGVER because tagging sources
659 # could occur with different kernel-headers than kernel-headers used at build time.
660 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
661 if [ "$TAG_VERSION" = "yes" ]; then
662 echo "CVS tag: $TAGVER"
664 if [ -n "$TAG" ]; then
669 if [ -n "$CVSROOT" ]; then
670 OPTIONS="-d $CVSROOT $OPTIONS"
676 # don't tag non cvs files (ie. stored on distfiles)
677 [ "`nourl $i`" != "$i" ] && continue
678 if [ -f "`nourl $i`" ]; then
679 if [ "$TAG_VERSION" = "yes" ]; then
680 cvs $OPTIONS $TAGVER `nourl $i`
682 if [ -n "$TAG" ]; then
683 cvs $OPTIONS $TAG `nourl $i`
686 Exit_error err_no_source_in_repo $i
691 if [ "$TAG_VERSION" = "yes" ]; then
692 cvs $OPTIONS $TAGVER $SPECFILE
694 if [ -n "$TAG" ]; then
695 cvs $OPTIONS $TAG $SPECFILE
705 echo "CVS branch tag: $TAG"
710 if [ -n "$DEBUG" ]; then
715 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
718 if [ -n "$CVSROOT" ]; then
719 OPTIONS="-d $CVSROOT $OPTIONS"
724 if [ -f `nourl $i` ]; then
725 cvs $OPTIONS $TAG `nourl $i`
727 Exit_error err_no_source_in_repo $i
731 cvs $OPTIONS $TAG $SPECFILE
741 if [ -n "$DEBUG" ]; then
748 if [ -n "$TRY_UPGRADE" ]; then
749 if [ -n "$FLOAT_VERSION" ]; then
750 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
752 TNOTIFY=`./pldnotify.awk $SPECFILE`
755 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
757 if [ -n "$TNEWVER" ]; then
758 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
759 echo "New version found, updating spec file to version " $TNEWVER
760 cp -f $SPECFILE $SPECFILE.bak
762 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
763 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
765 get_files "$SOURCES $PATCHES";
766 unset TOLDVER TNEWVER TNOTIFY
773 BUILD_SWITCH="-ba" ;;
775 BUILD_SWITCH="-bb" ;;
777 BUILD_SWITCH="-bs --nodeps" ;;
779 BUILD_SWITCH="-bp --nodeps" ;;
781 if [ -n "$LOGFILE" ]; then
782 LOG=`eval echo $LOGFILE`
783 if [ -n "$LASTLOG_FILE" ]; then
784 echo "LASTLOG=$LOG" > $LASTLOG_FILE
786 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
787 (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
788 RETVAL=`cat $RES_FILE`
790 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
791 if [ "$RETVAL" -eq "0" ]; then
798 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
801 if [ "$RETVAL" -ne "0" ]; then
802 if [ -n "$TRY_UPGRADE" ]; then
803 echo "\n!!! Package with new version cannot be build automagically\n"
804 mv -f $SPECFILE.bak $SPECFILE
806 Exit_error err_build_fail;
813 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
817 install_required_packages()
825 AVAIL_BCONDS_WITHOUT=""
827 if `grep -q ^%bcond ${SPECFILE}`; then
829 elif `grep -q bcond ${SPECFILE}`; then
834 case "${BCOND_VERSION}" in
839 echo "Warning: This spec has old style bconds. Fix it || die."
840 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
842 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
843 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
844 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
846 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
850 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
852 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
853 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
854 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
856 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
861 cond_type="" # with || without
862 for opt in `$RPMBUILD --bcond $SPECFILE`
875 AVAIL_BCOND_WITH="$opt"
876 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
877 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
879 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
884 AVAIL_BCOND_WITHOUT="$opt"
885 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
886 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
888 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
902 echo -ne "Package installation failed:\t$package_name\n"
904 # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
905 # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
906 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
907 # jakby nie bylo tego kawalka kodu.
909 # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
910 # Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
918 # Istnieje taki spec? ${package}.spec
919 if [ -f "${SPECS_DIR}${package}.spec" ]; then
920 parent_spec_name=${package}.spec
921 elif [ -f "${SPECS_DIR}`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
922 parent_spec_name="`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec"
924 for provides_line in `grep ^Provides:.*$package ${SPECS_DIR} -R`
930 if [ "${parent_spec_name}" != "" ]; then
932 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
933 sub_builder_opts="${sub_builder_opts} -R"
935 if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
936 sub_builder_opts="${sub_builder_opts} -RB"
937 elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
938 sub_builder_opts="${sub_builder_opts} -FRB"
940 if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
941 sub_builder_opts="${sub_builder_opts} -Upi"
944 ./builder ${sub_builder_opts} ${parent_spec_name}
946 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
949 remove_build_requires()
951 if [ "$INSTALLED_PACKAGES" != "" ]; then
952 case "$REMOVE_BUILD_REQUIRES" in
954 run_poldek --noask -ve $INSTALLED_PACKAGES
957 run_poldek --ask -ve $INSTALLED_PACKAGES
960 echo You may want to manually remove following BuildRequires fetched:
961 echo $INSTALLED_PACKAGES
962 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
970 if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
971 echo -ne "We are going to build $SPECFILE with the following conditional flags:\n"
972 if [ "$BCOND" != "" ]; then
975 echo -ne "No --with || --without conditions passed to $0!"
977 echo -ne "\n\nfrom available:\n\n"
978 echo -ne "--with :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
982 fetch_build_requires()
984 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
985 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
986 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
987 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
988 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
989 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
990 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`
992 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`"
994 package=`basename "$package_item"|sed -e "s/}$//g"`
995 COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
998 COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
999 if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1000 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
1005 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1008 if `echo $COND_TST|grep -q 'without_'`; then
1009 COND_NAME=`echo $COND_NAME|sed -e s,^.*_without_,,g`
1010 if `echo $COND_TST|grep -q !`; then
1015 if `echo $AVAIL_BCONDS_WITHOUT|grep -q "<$COND_NAME>"`; then
1021 elif `echo $COND_TST|grep -q 'with_'`; then
1022 COND_NAME=`echo $COND_NAME|sed -e s,^.*_with_,,g`
1023 if `echo $COND_TST|grep -q !`; then
1028 if `echo $AVAIL_BCONDS_WITH|grep -q "<$COND_NAME>"`; then
1034 RESULT="${COND_STATE}-${COND_ARGV}"
1036 "with-wout" | "wout-with" )
1039 "wout-wout" | "with-with" )
1043 echo "Action '$RESULT' was not defined for package '$package_item'"
1049 if [ "$GO" = "yes" ]; then
1050 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1051 echo "Testing if $package has subrequirements..."
1052 run_poldek -t -i $package --dumpn=".$package-req.txt"
1053 if [ -f ".$package-req.txt" ]; then
1054 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1056 if [ "$package_name" = "$package" ]; then
1057 echo -ne "Installing BuildRequired package:\t$package_name\n"
1058 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing BuildRequired package: ${package_name}\007"`
1059 install_required_packages $package;
1061 echo -ne "Installing (sub)Required package:\t$package_name\n"
1062 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing (sub)Required package: ${package_name}\007"`
1063 install_required_packages $package_name;
1067 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1068 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1071 echo "Attempting to run spawn sub - builder..."
1072 run_sub_builder $package_name
1073 if [ $? -eq 0 ]; then
1074 install_required_packages $package_name;
1077 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1078 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1081 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1088 rm -f ".$package-req.txt"
1090 echo "Attempting to run spawn sub - builder..."
1091 run_sub_builder $package
1092 if [ $? -eq 0 ]; then
1093 install_required_packages $package;
1096 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1097 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1100 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1106 echo "Package $package is already installed. BuildRequirement satisfied."
1110 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1111 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1112 echo "Nie uda³o siê zainstalowaæ nastêpuj±cych pakietów i ich zale¿no¶ci:"
1113 for pkg in "$NOT_INSTALLED_PACKAGES"
1117 remove_build_requires
1123 #---------------------------------------------
1126 if [ "$#" = 0 ]; then
1149 DEBUG="yes"; shift ;;
1151 COMMAND="version"; shift ;;
1153 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1154 -b | -ba | --build )
1155 COMMAND="build"; shift ;;
1156 -bb | --build-binary )
1157 COMMAND="build-binary"; shift ;;
1158 -bs | --build-source )
1159 COMMAND="build-source"; shift ;;
1160 -bp | --build-prep )
1161 COMMAND="build-prep"; shift ;;
1163 COMMAND="branch"; shift; TAG="${1}"; shift;;
1165 CLEAN="--clean --rmspec --rmsource"; shift ;;
1167 shift; CVSROOT="${1}"; shift ;;
1169 COMMAND="get"; shift ;;
1171 COMMAND="usage"; shift ;;
1173 PROTOCOL="http"; shift ;;
1175 shift; LOGFILE="${1}"; shift ;;
1177 shift; DEF_NICE_LEVEL=${1}; shift ;;
1179 COMMAND="mr-proper"; shift ;;
1181 NOCVS="yes"; shift ;;
1182 -ncs | --no-cvs-specs )
1183 NOCVSSPEC="yes"; shift ;;
1184 -nd | --no-distfiles )
1185 NODIST="yes"; shift ;;
1186 -nm | --no-mirrors )
1187 NOMIRRORS="yes"; shift ;;
1189 NOURLS="yes"; shift ;;
1191 NOSRCS="yes"; shift ;;
1192 -ns0 | --no-source0 )
1193 NOSOURCE0="yes"; shift ;;
1195 shift; RPMOPTS="${1}"; shift ;;
1196 --with | --without )
1197 case $GROUP_BCONDS in
1201 while ! `echo ${1}|grep -qE '(^-|spec)'`
1203 BCOND="$BCOND $COND $1"
1207 BCOND="$BCOND $1 $2" ; shift 2 ;;
1211 QUIET="--quiet"; shift ;;
1213 CVSDATE="${2}"; shift 2 ;;
1215 shift; CVSTAG="${1}"; shift ;;
1216 -R | --fetch-build-requires)
1217 FETCH_BUILD_REQUIRES="yes"
1218 NOT_INSTALLED_PACKAGES=
1220 -RB | --remove-build-requires)
1221 REMOVE_BUILD_REQUIRES="nice"
1223 -FRB | --force-remove-build-requires)
1224 REMOVE_BUILD_REQUIRES="force"
1226 -Tvs | --tag-version-stable )
1231 -Tvn | --tag-version-nest )
1236 -Ts | --tag-stable )
1246 -Tv | --tag-version )
1251 -Tp | --tag-prefix )
1267 -Upi | --update-poldek-indexes )
1268 UPDATE_POLDEK_INDEXES="yes"
1270 -u | --try-upgrade )
1271 TRY_UPGRADE="1"; shift ;;
1272 -un | --try-upgrade-with-float-version )
1273 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1275 BE_VERBOSE="1"; shift ;;
1281 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1285 RPMOPTS="${RPMOPTS} --nodeps"
1288 SPECFILE="`basename ${1} .spec`.spec";
1289 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1294 if [ -n "$DEBUG" ]; then
1300 "build" | "build-binary" | "build-source" | "build-prep" )
1302 if [ -n "$SPECFILE" ]; then
1306 fetch_build_requires;
1309 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
1310 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
1311 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
1312 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1314 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
1315 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
1319 if [ -n "$ICONS" ]; then
1323 if [ -n "$NOSOURCE0" ] ; then
1324 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1326 get_files "$SOURCES $PATCHES";
1328 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
1329 run_poldek --sn ${POLDEK_SOURCE} --mkidx="${POLDEK_INDEX_DIR}/packages.dir.gz"
1330 run_poldek --sn ${POLDEK_SOURCE} --up
1332 remove_build_requires;
1334 Exit_error err_no_spec_in_cmdl;
1339 if [ -n "$SPECFILE" ]; then
1342 if [ -n "$ICONS" ]; then
1346 get_files $SOURCES $PATCHES;
1347 branch_files $TAG "$SOURCES $PATCHES $ICONS";
1349 Exit_error err_no_spec_in_cmdl;
1354 if [ -n "$SPECFILE" ]; then
1357 if [ -n "$ICONS" ]; then
1361 if [ -n "$NOSOURCE0" ] ; then
1362 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1364 get_files $SOURCES $PATCHES
1366 Exit_error err_no_spec_in_cmdl;
1371 if [ -n "$SPECFILE" ]; then
1374 if [ -n "$ICONS" ]; then
1378 # don't fetch sources from remote locations
1380 for file in $SOURCES
1382 [ "`nourl $file`" != "$file" ] && continue
1383 new_SOURCES="$new_SOURCES $file"
1385 SOURCES="$new_SOURCES"
1386 get_files $SOURCES $PATCHES;
1387 tag_files "$SOURCES $PATCHES $ICONS";
1389 Exit_error err_no_spec_in_cmdl;
1393 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1400 test -f `pwd`/.${SPECFILE}_INSTALLED_PACKAGES && rm `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1403 # vi:syntax=sh:ts=3:sw=4