]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder.sh
- unsplit also Provides: lines
[packages/rpm-build-tools.git] / builder.sh
CommitLineData
cd445739
AM
1#!/bin/sh
2# -----------
3# $Id$
4# Exit codes:
2a5f078d 5# 0 - succesful
6# 1 - help displayed
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
14# 9 - Requested tag already exist
15# 10 - Refused to build fractional release
16# 100 - Unknown error (should not happen)
cd445739
AM
17
18# Notes (todo):
f7b91886 19# - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?)
cd445739 20# - when Icon: field is present, -5 and -a5 doesn't work
f3ada241 21# - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
931a4acf 22
4003ad8c 23VERSION="\
c9acaed9 24Build package utility from PLD Linux CVS repository
cdb4a820 25v0.15 (C) 1999-2006 Free Penguins".
d6a77ddb 26PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
b03f053b 27
cd445739 28COMMAND="build"
64ea5308 29TARGET=""
cd445739 30
bde1c404 31SPECFILE=""
d287305c 32BE_VERBOSE=""
4003ad8c 33QUIET=""
cd445739
AM
34CLEAN=""
35DEBUG=""
36NOURLS=""
37NOCVS=""
38NOCVSSPEC=""
39NODIST=""
40UPDATE=""
41UPDATE5=""
42ADD5=""
43NO5=""
44ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
c8f50498 45CVSROOT=""
cd445739
AM
46
47# It can be used i.e. in log file naming.
48# See LOGFILE example.
49DATE=`date +%Y-%m-%d_%H-%M-%S`
50
51# Example: LOGFILE='../log.$PACKAGE_NAME'
52# Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
53# Yes, you can use variable name! Note _single_ quotes!
54LOGFILE=''
55
56LOGDIR=""
57LOGDIROK=""
58LOGDIRFAIL=""
59LASTLOG_FILE=""
60
61CHMOD="no"
62CHMOD_MODE="0444"
63RPMOPTS=""
d1c5a9a7 64RPMBUILDOPTS=""
cd445739
AM
65BCOND=""
66GROUP_BCONDS="no"
947025e5 67CVSIGNORE_DF="no"
d287305c 68
69PATCHES=""
70SOURCES=""
cd445739 71ICONS=""
d287305c 72PACKAGE_RELEASE=""
73PACKAGE_VERSION=""
74PACKAGE_NAME=""
cd445739
AM
75PROTOCOL="ftp"
76WGET_RETRIES=${MAX_WGET_RETRIES:-0}
77CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
78
79CVSTAG=""
80RES_FILE=""
81
82CVS_SERVER="cvs.pld-linux.org"
83DISTFILES_SERVER="://distfiles.pld-linux.org"
d4730dae 84ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
cd445739 85
36d03934 86DEF_NICE_LEVEL=19
cd445739
AM
87
88FAIL_IF_NO_SOURCES="yes"
89
18e5347d
ER
90# let get_files skip over files which are present to get those damn files fetched
91SKIP_EXISTING_FILES="no"
92
ab4a2b6e
ER
93if [ -x /usr/bin/rpm-getdeps ]; then
94 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
95else
96 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
97fi
98
cd445739
AM
99# Here we load saved user environment used to
100# predefine options set above, or passed to builder
101# in command line.
102# This one reads global system environment settings:
103if [ -f ~/etc/builderrc ]; then
104 . ~/etc/builderrc
105fi
106# And this one cascades settings using user personal
107# builder settings.
108# Example of ~/.builderrc:
109#
110#UPDATE_POLDEK_INDEXES="yes"
111#FETCH_BUILD_REQUIRES="yes"
112#REMOVE_BUILD_REQUIRES="force"
113#GROUP_BCONDS="yes"
114#LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
982e358c 115#TITLECHANGE=no
cd445739 116#
a83e5405 117SU_SUDO=""
cd445739
AM
118if [ -n "$HOME_ETC" ]; then
119 USER_CFG="$HOME_ETC/.builderrc"
120else
121 USER_CFG=~/.builderrc
122fi
123
124[ -f "$USER_CFG" ] && . "$USER_CFG"
125
06f3864d
AM
126wget --help 2>&1 | grep -q ' \-\-no-check\-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
127
ca2e6c31 128if [ -n "$USE_PROZILLA" ]; then
7e365483
KK
129 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
130 GETURI2="$GETURI"
131 OUTFILEOPT="-O"
ca2e6c31 132elif [ -n "$USE_AXEL" ]; then
cede92b3 133 GETURI="axel -a $AXEL_OPTS"
7e365483
KK
134 GETURI2="$GETURI"
135 OUTFILEOPT="-o"
ca2e6c31 136else
7e365483
KK
137 wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
138 wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
6f9a5d76 139
7e365483
KK
140 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
141 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
142 OUTFILEOPT="-O"
2bc5451f 143fi
11468b23 144
11468b23
AM
145GETLOCAL="cp -a"
146
147if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
148 RPM="rpm"
149 RPMBUILD="rpm"
150else
151 RPM="rpm"
152 RPMBUILD="rpmbuild"
153fi
154
155POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
a83e5405 156POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
11468b23 157
cd445739
AM
158run_poldek()
159{
160 RES_FILE=~/tmp/poldek-exit-status.$RANDOM
161 if [ -n "$LOGFILE" ]; then
162 LOG=`eval echo $LOGFILE`
163 if [ -n "$LASTLOG_FILE" ]; then
164 echo "LASTLOG=$LOG" > $LASTLOG_FILE
165 fi
040282bb 166 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
cd445739
AM
167 return $exit_pldk
168 else
169 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
170 return `cat ${RES_FILE}`
171 rm -rf ${RES_FILE}
172 fi
173}
174
cd445739
AM
175#---------------------------------------------
176# functions
da946cd6 177
5a491465 178usage()
179{
cd445739
AM
180 if [ -n "$DEBUG" ]; then set -xv; fi
181 echo "\
182Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
81f85806 183
cd445739
AM
184[-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
185[{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
186[-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
187[-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
188[-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
189[-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
190[{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
dfe2cb9a 191[-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--show-bconds]
f19103b5 192[--with/--without <feature>] [--define <macro> <value>] <package>[.spec][:cvstag]
2a5f078d 193
cd445739
AM
194-5, --update-md5 - update md5 comments in spec, implies -nd -ncs
195-a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
196-n5, --no-md5 - ignore md5 comments in spec
9243e80b
ER
197-D, --debug - enable builder script debugging mode,
198-debug - produce rpm debug package (same as --opts -debug)
cd445739
AM
199-V, --version - output builder version
200-a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
201-b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
202 from <package>.spec,
203-bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
204 only package from <package>.spec,
c56807e0
ER
205-bp, --build-prep - execute the %prep phase of <package>.spec,
206-bc - reserved (not implemented)
207-bi reserved (not implemented)
cd445739
AM
208-bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
209 them into src.rpm,
c56807e0 210--short-circuit - reserved (not implemented)
cd445739
AM
211-B, --branch - add branch
212-c, --clean - clean all temporarily created files (in BUILD, SOURCES,
213 SPECS and \$RPM_BUILD_ROOT),
2a5f078d 214-d <cvsroot>, --cvsroot <cvsroot>
cd445739
AM
215 - setup \$CVSROOT,
216--define <macro> <value>
217 - define a macro <macro> with value <value>,
218--nodeps - rpm won't check any dependences
219-g, --get - get <package>.spec and all related files from CVS repo
220 or HTTP/FTP,
221-h, --help - this message,
222--http - use http instead of ftp,
223-l <logfile>, --logtofile <logfile>
224 - log all to file,
225-m, --mr-proper - only remove all files related to spec file and all work
226 resources,
227-nc, --no-cvs - don't download sources from CVS, if source URL is given,
228-ncs, --no-cvs-specs
229 - don't check specs in CVS
230-nd, --no-distfiles - don't download from distfiles
231-nm, --no-mirrors - don't download from mirror, if source URL is given,
232-nu, --no-urls - don't try to download from FTP/HTTP location,
233-ns, --no-srcs - don't download Sources
234-ns0, --no-source0 - don't download Source0
235-nn, --no-net - don't download anything from the net
18e5347d
ER
236-ske,
237--skip-existing-files - skip existing files in get_files
cd445739
AM
238--opts <rpm opts> - additional options for rpm
239-q, --quiet - be quiet,
240--date yyyy-mm-dd - build package using resources from specified CVS date,
241-r <cvstag>, --cvstag <cvstag>
242 - build package using resources from specified CVS tag,
243-R, --fetch-build-requires
244 - fetch what is BuildRequired,
245-RB, --remove-build-requires
246 - remove all you fetched with -R or --fetch-build-requires
247 remember, this option requires confirmation,
248-FRB, --force-remove-build-requires
249 - remove all you fetched with -R or --fetch-build-requires
250 remember, this option works without confirmation,
a7eefc54 251-sf, --source-files - list sources - bare filenames (intended for offline
252 operations; does not work when Icon field is present
3621e588 253 but icon file is absent),
a7eefc54 254-sp, --source-paths - list sources - filenames with full local paths (intended for
255 offline operations; does not work when Icon field is present
3621e588 256 but icon file is absent),
2dddf439
ER
257-su, --source-urls - list urls - urls to sources and patches
258 intended for copying urls with spec with lots of macros in urls
cd445739
AM
259-T <cvstag> , --tag <cvstag>
260 - add cvs tag <cvstag> for files,
261-Tvs, --tag-version-stable
094bd95b 262 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
cd445739 263-Tvn, --tag-version-nest
1691a37b 264 - add cvs tags NEST and NAME-VERSION-RELEASE for files,
cd445739
AM
265-Ts, --tag-stable
266 - add cvs tag STABLE for files,
267-Tn, --tag-nest
268 - add cvs tag NEST for files,
269-Tv, --tag-version
1691a37b 270 - add cvs tag NAME-VERSION-RELEASE for files,
cd445739
AM
271-Tp, --tag-prefix <prefix>
272 - add <prefix> to NAME-VERSION-RELEASE tags,
273-tt, --test-tag <prefix>
274 - fail if tag is already present,
50321881
JK
275-ir, --integer-release-only
276 - allow only integer and snapshot releases
cd445739
AM
277-v, --verbose - be verbose,
278-u, --try-upgrade - check version, and try to upgrade package
279-un, --try-upgrade-with-float-version
280 - as above, but allow float version
deccc50e 281-U, --update - refetch sources, don't use distfiles, and update md5 comments
cd445739
AM
282-Upi, --update-poldek-indexes
283 - refresh or make poldek package index files.
c890b916 284-np, --nopatch <patchnumber>
bed98670 285 - don't apply <patchnumber>
dfe2cb9a
MK
286--show-bconds - show available conditional builds, which can be used
287 - with --with and/or --without switches.
cd445739
AM
288--with/--without <feature>
289 - conditional build package depending on %_with_<feature>/
290 %_without_<feature> macro switch. You may now use
291 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
292 constructions. Set GROUP_BCONDS to yes to make use of it.
6dd19291 293--target <platform>, --target=<platform>
3621e588
ER
294 - build for platform <platform>.
295--init-rpm-dir - initialize ~/rpm directory structure
5a491465 296"
297}
298
c890b916 299update_shell_title() {
a0d6396b 300 [ -t 1 ] || return
0b65d15e
ER
301 local len=${COLUMNS:-80}
302 local msg=$(echo "$*" | cut -c-$len)
303
e225de91
ER
304 if [ -n "$BE_VERBOSE" ]; then
305 echo >&2 "$(date +%s.%N) $*"
306 fi
307
982e358c 308 if [ "x$TITLECHANGE" == "xyes" -o "x$TITLECHANGE" == "x" ]; then
618b043c 309 msg="${SPECFILE}: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
982e358c
MP
310 case "$TERM" in
311 cygwin|xterm*)
312 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
313 ;;
314 screen*)
315 echo >&2 -ne "\033]0;$msg\007"
316 ;;
317 esac
318 fi
c890b916
ER
319}
320
7e40520f
ER
321# set TARGET from BuildArch: from SPECFILE
322set_spec_target() {
323 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
324 tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE)
325 if [ "$tmp" ]; then
326 TARGET="$tmp"
327 case "$RPMBUILD" in
328 "rpmbuild")
329 TARGET_SWITCH="--target $TARGET" ;;
330 "rpm")
331 TARGET_SWITCH="--target=$TARGET" ;;
332 esac
333 fi
334 fi
335}
336
cd445739 337cache_rpm_dump () {
b2aeec7d
AM
338 if [ -n "$DEBUG" ]; then
339 set -x;
340 set -v;
341 fi
7e40520f 342
13974367 343 update_shell_title "cache_rpm_dump"
237bd3f1
ER
344 local rpm_dump
345 rpm_dump=`
d05e8080 346
fa4bf1df 347 # we reset macros not to contain macros.build as all the %() macros are
559d511f 348 # executed here, while none of them are actually needed.
fa4bf1df 349 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
559d511f 350 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
36433112 351 macrofiles="/usr/lib/rpm/macros:$SPECS_DIR/.builder-rpmmacros:~/etc/.rpmmacros:~/.rpmmacros"
237bd3f1 352 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
7cb24972 353 # FIXME: better ideas than .rpmrc?
36433112 354 printf 'include:/usr/lib/rpm/rpmrc\nmacrofiles:%s\n' $macrofiles > .builder-rpmrc
fb198857 355# TODO: move these to /usr/lib/rpm/macros
36433112 356 cat > .builder-rpmmacros <<'EOF'
fb198857
ER
357%requires_releq_kernel_up %{nil}
358%requires_releq_kernel_smp %{nil}
6b8134e3 359%requires_releq() %{nil}
bb01dee9 360%pyrequires_eq() %{nil}
559d511f 361%requires_eq() %{nil}
c13be3d1 362%requires_eq_to() %{nil}
fb198857
ER
363%releq_kernel_up ERROR
364%releq_kernel_smp ERROR
74d9fd14 365%kgcc_package ERROR
237bd3f1 366%_fontsdir ERROR
7141278d 367%ruby_version ERROR
368%ruby_ver_requires_eq() %{nil}
369%ruby_mod_ver_requires_eq() %{nil}
c13be3d1 370%__php_api_requires() %{nil}
7141278d 371%php_major_version ERROR
372%php_api_version ERROR
373%py_ver ERROR
fb198857 374EOF
cd445739 375 case "$RPMBUILD" in
237bd3f1
ER
376 rpm)
377 ARGS='-bp'
378 ;;
379 rpmbuild)
380 ARGS='--nodigest --nosignature --nobuild'
381 ;;
382 esac
36433112 383 $RPMBUILD --rcfile .builder-rpmrc $ARGS --nodeps --define "prep $dump" $BCOND $TARGET_SWITCH $SPECFILE 2>&1
237bd3f1 384 `
fb198857 385 if [ $? -gt 0 ]; then
237bd3f1
ER
386 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
387 echo "$error" >&2
388 Exit_error err_build_fail;
fb198857 389 fi
d05e8080
ER
390
391 # make small dump cache
392 rpm_dump_cache=`echo "$rpm_dump" | awk '
4e8c3089
ER
393 $2 ~ /^SOURCEURL/ {print}
394 $2 ~ /^PATCHURL/ {print}
395 $2 ~ /^nosource/ {print}
396 $2 ~ /^PACKAGE_/ {print}
d05e8080
ER
397 '`
398
13974367 399 update_shell_title "cache_rpm_dump: OK!"
cd445739
AM
400}
401
402rpm_dump () {
403 if [ -z "$rpm_dump_cache" ] ; then
404 echo "internal error: cache_rpm_dump not called!" 1>&2
405 fi
406 echo "$rpm_dump_cache"
407}
408
d05e8080
ER
409get_icons()
410{
411 update_shell_title "get icons"
412 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
413 if [ -z "$ICONS" ]; then
414 return
415 fi
416
417