File: Makepkgs

package info (click to toggle)
pcp 5.2.6-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 185,908 kB
  • sloc: ansic: 307,504; sh: 138,932; xml: 90,613; cpp: 65,924; python: 18,517; perl: 16,958; yacc: 8,925; lex: 2,843; makefile: 1,502; fortran: 60; java: 52
file content (747 lines) | stat: -rwxr-xr-x 19,559 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
#!/bin/sh
#
# Make whichever packages the system supports
#
# Copyright (c) 2012-2017 Red Hat.
# Copyright (c) 2004 Silicon Graphics, Inc.  All Rights Reserved.
# 
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#

topdir=`pwd`
signed=false
verbose=false
srconly=false
cfgonly=false
dorpm=unknown
dodeb=unknown
docker=false
check=false

if [ ! -d .git ]
then
    echo "Error: can only be run from within the PCP git repository"
    exit 1
fi

if [ ! -f VERSION.pcp ]
then
    echo "Error: can only be run from within the PCP source tree"
    exit 1
fi

tmp=`mktemp -d /tmp/pcp.XXXXXXXXX` || exit 1
trap "rm -rf $tmp $tmp.help" 0 1 2 3 15
target=`uname -s | tr 'A-Z' 'a-z'`

# Find where a GNU tool is hiding, look for this line in the
# $gnutool --help output ...
# "Report bugs to <bug-$gnutool@gnu.org>"
# or lines like this:
# FreeBSD $gnutool
# NetBSD $gnutool
# OpenBSD $gnutool
# Apple $gnutool
# or these lines:
# *This* tar defaults to:
# --format=gnu ... or --format=posix
#
gnu_tool()
{
    prefix="$1"
    shift
    envvar="$1"
    shift
    oldcmd="$1"
    shift

    # Not in the environment, go search for it in the known locations.
    #
    if [ -z "$envvar" ]
    then
	for command in $oldcmd $@
	do
	    exec=`which $command 2>/dev/null`
	    if [ -n "$exec" ]
	    then
		LC_ALL=C $command --help >$tmp.help 2>&1
		if egrep "(bug-$oldcmd@gnu.org)|(FreeBSD $command)|(NetBSD $command)|(OpenBSD $command)|(Apple $command)" $tmp.help >/dev/null
		then
		    echo $exec
		    return 0
		fi
		awk <$tmp.help >$tmp.check '
BEGIN				{ want = 0 }
/This\** tar defaults to:/	{ want=1; next }
want == 1			{ print; exit }'
		if egrep '[-][-]format=(gnu)|(posix)' <$tmp.check >/dev/null
		then
		    echo $exec
		    return 0
		fi
		# special cases
		#
		if [ "$target" = openbsd -a $command = gzip ]
		then
		    echo $exec
		    return 0
		fi
	    fi
	done
	echo >&2 "$prefix: can't find GNU $oldcmd in the commands $oldcmd or $@"
	[ $prefix = Error ] && exit 1
	return 1
    fi

    # Use the environment request and ensure it is a full path (do not
    # change this behaviour, it is required for backward-compatibility
    # - QA failures will result if you choose to ignore this warning).
    #
    command=`which $envvar 2>/dev/null`
    if [ -z "$command" ]
    then
	echo >&2 "$prefix: $oldcmd (from the environment) does not exist!"
	[ $prefix = Error ] && exit 1
	return 1
    fi
    echo $command
    return 0
}

export MAKE=`gnu_tool Error "$MAKE" make gmake`
export TAR=`gnu_tool Warning "$TAR" tar gtar gnutar`
export ZIP=`gnu_tool Error "$ZIP" gzip gnuzip`

# check if tar supports --transform else we must use git-archive later on (e.g. RHEL5)
[ -n "$TAR" ] && $TAR --help | 2>&1 grep -q transform || USE_GIT_ARCHIVE=1
#debug# echo TAR=$TAR USE_GIT_ARCHIVE=$USE_GIT_ARCHIVE

configure=./configure
cmdline_configopts=''

for opt in $*
do
    case "$opt" in
    -clean|--clean)
	# we always clean nowadays, so silently ignore
	shift
	;;
    -verbose|--verbose)
	verbose=true
	shift
	;;
    --check)
	check=true
	shift
	;;
    --nonrpm)
	dorpm=false
	shift
	;;
    --nondeb)
	dodeb=false
	shift
	;;
    --signed)
	signed=true
	shift
	;;
    --source)
	srconly=true
	shift
	;;
    --configure)
	cfgonly=true
	shift
	;;
    --target)
	shift
	target=$1
	shift
	;;
    --with-docker)
	docker=true
	shift
	;;
    --with-make)
	MAKE=$1
	shift
	;;
    --with-tar)
	TAR=$1
	shift
	;;
    --with-zip)
	ZIP=$1
	shift
	;;
    *)
	# Add remaining options to the ./configure command line
	cmdline_configopts="$cmdline_configopts $opt"
	shift
	;;
    esac
done

if [ $dorpm = unknown ]
then
    dorpm=false
    if which slackpkg >/dev/null 2>&1
    then
	# Slackware has rpm(1) and rpmbuild(1), but don't build RPMs
	#
	:
    else
	[ -x /usr/bin/rpmbuild ] && dorpm=true
    fi
fi
if [ $dodeb = unknown ]
then
    dodeb=false
    [ -x /usr/bin/dpkg-buildpackage ] && dodeb=true
fi

# Hmm ...
#
if $dodeb && $dorpm
then
    echo >&2 "Do not know how to build RPM and Debian packages at the same time!"
    echo >&2 "Suggest --nonrpm or --nondeb on the command line."
    exit 1
fi

if $dodeb
then
    # On Debian-based platforms, the debian/rules file already captures 
    # most of the required configure settings in $(configure_paths) and
    # $(configure_tools)
    #
    configopts=''
elif $dorpm
then
    # On RPM-based platforms, rpm macros provide an excellent set of defaults.
    # This set is based on Fedora 22 %configure macro from /usr/lib/rpm/macros,
    # and is known to work as far back as RHEL5.
    configopts="`rpmbuild --eval '--exec-prefix=%{_exec_prefix} --bindir=%{_bindir} --sbindir=%{_sbindir} --sysconfdir=%{_sysconfdir} --datadir=%{_datadir} --includedir=%{_includedir} --libdir=%{_libdir} --libexecdir=%{_libexecdir} --localstatedir=%{_localstatedir} --sharedstatedir=%{_sharedstatedir} --mandir=%{_mandir} --prefix=%{_prefix}' 2>/dev/null`"
    # rpmbuild clears the environment, so force these settings into the
    # rpm build configure
    #
    configopts="$configopts --with-make=$MAKE --with-tar=$TAR --with-zip=$ZIP"
elif [ $target = darwin ]
then
    # On Mac OS X platforms, we install away from /usr/bin, /usr/lib
    # and so on because of security requirements in recent versions.
    #
    configopts="--sysconfdir=/etc --localstatedir=/var --prefix=/usr/local"
elif [ $target = netbsd ]
then
    # Try to mimic where pkgsrc/pkgin places things
    #
    configopts="--exec-prefix=/usr/pkg --mandir=/usr/pkg/man --with-rcdir=/etc/rc.d --localstatedir=/usr/pkg --with-rundir=/var/run --with-tmpdir=/var/tmp --with-logdir=/var/log/pcp --prefix=/usr/pkg"
elif [ $target = freebsd ]
then
    # Python build does not work on FreeBSD 9.3, so skip it
    # For FreeBSD 10.4 and 11.3 it seems to fail when trying to build
    # Python and Python3 at the same time ... so skip Python(2)
    #
    case `uname -r`
    in
	9.3*)
		# Bog-standard, just without python and without python3
		#
		configopts="--sysconfdir=/etc --localstatedir=/var --with-python=no --with-python3=no --prefix=/usr"
		;;
	10.*|11.*)
		# Bog-standard, just without python2
		#
		configopts="--sysconfdir=/etc --localstatedir=/var --with-python=no --prefix=/usr"
		;;
	*)
		# Bog-standard, as below ...
		#
		configopts="--sysconfdir=/etc --localstatedir=/var --prefix=/usr"
		;;
    esac
elif [ $target = sunos ]
then
    # Need to take control of the Python versions, otherwise standard.
    #
    configopts="--prefix=/usr --sysconfdir=/etc --localstatedir=/var --with-python=no --with-python3=check"
else
    # Bog-standard options suitable for a package on any platform.
    # Command line can be used to extend this set, and any unusual
    # platform-specific requirements are also appended later on.
    configopts="--sysconfdir=/etc --localstatedir=/var --prefix=/usr"
fi

# Platform-specific variants ...
#
case "$target"
in
    mingw|mingw64|windows)
	target=mingw
	dorpm=false
	configopts="$configopts --disable-ssp --without-qt3d"
	export configure="/usr/bin/mingw64-configure"
	export MAKE="/usr/bin/mingw64-make"
	export QMAKE="/usr/bin/mingw64-qmake-qt5"
	export PKG_CONFIG="/usr/bin/mingw64-pkg-config"
	;;
    linux)
	ARCH=`uname -m`
	[ -f /etc/slackware-version -a "$ARCH" = x86_64 ] && configopts="$configopts --libdir=/usr/lib64"
	[ -f /etc/gentoo-release ] && configopts="$configopts --without-python"
	;;
    sunos|SunOS|solaris)
	ARCH=`isainfo -k`
	[ "$ARCH" = amd64 -o "$ARCH" = sparcv9 ] && configopts="$configopts --libdir=/usr/lib/64"
	export YACC=bison
	export LEX=flex
	;;
esac

# now some specific QA/development hosts with special needs ...
#
case `hostname`
in
    vm11|vm11.localdomain)
	# gcc -O2 is broken here (for the linux PMDA)
	#
	configopts="$configopts --with-optimization=no"
	# over-ride the settings from dpkg-buildflags
	#
	export DEB_CFLAGS_SET=''
	export DEB_CXXFLAGS_SET=''
	;;
esac

# and finally add in any from the command line
#
[ -n "$cmdline_configopts" ] && configopts="$configopts $cmdline_configopts"

. ./VERSION.pcp
VERSION=${PACKAGE_MAJOR}.${PACKAGE_MINOR}.${PACKAGE_REVISION}

LOGDIR="$topdir/Logs"
rm -rf "$LOGDIR"
mkdir -p "$LOGDIR"

source="pcp-$VERSION"
SRCDIR="$topdir/$source"
SRCTREE="$topdir/$source"
SRCTAR="$topdir/build/tar/$source.src.tar.gz"

build_failure()
{
    # only print in non-verbose mode, otherwise we see double
    if ! $verbose ; then
	echo "$@ failed, see log in $LOGDIR/pcp"
	tail "$LOGDIR/pcp"
    fi
    exit 1
}

clean_packaging()
{
    echo
    echo "== Cleaning build tree for packaging build"
    rm -rf "$SRCDIR" "$SRCTAR" .gitcensus
}

fix_version()
{
    if [ -f "$1" -a -f "$2" ]
    then
	# as expected, both present
	if diff "$1" "$2" >/dev/null 2>&1
	then
	    :
	else
	    # must be using git-archive(1) and VERSION.pcp has been
	    # modified, e.g. by pcp-daily script ... use the modified
	    # one to bump the build number in the packages
	    #
	    cp "$1" "$2"
	fi
    else
	echo "Arrgh ... expect both these to exist ..."
	ls -l "$1" "$2"
	exit 1
    fi
}

# Generate a list of all the files git knows about, create the
# source tarball and then unpack it.  We'll then do the package
# build in a guaranteed pristine environment.
#
src_tar_build()
{
    if [ -z "$TAR" -o ! -z "$USE_GIT_ARCHIVE" ]
    then
	# no suitable GNU tar is available, use git-archive(1) - no local changes
	if git status -s src man | grep '^.M'
	then
	    echo "Arrgh, modified src files and either no tar ($TAR) or no --transform"
	    echo "support in tar, so local changes would not be included in the build."
	    exit 1
	fi
	git archive --format=tar --prefix=$source/ HEAD | $ZIP > "$SRCTAR"
    else
	# build git file list and make tarball by hand to pick up any changes
	#
	git ls-files > .gitcensus

	# but first ensure a "build everything" debian/control has been
	# recreated
	#
	cd debian
	if ./pre-build
	then
	    :
	else
	    echo "Error: debian/pre-build failed when creating debian/control"
	    exit 1
	fi
	cd ..
	echo "debian/control" >> .gitcensus

	$TAR -cz --transform="s,^,$source/," --files-from=.gitcensus \
		--file="$SRCTAR"
	rm .gitcensus
    fi
    echo "Wrote: $SRCTAR"
}

# On sanity checks :- this is sick, but I'm really tired of QA failing
# because of bad binaries being built from the Debian/Ubuntu toolchain
# for # i?86 platforms
# - Ken McDonell Apr 2010
#
sanity_check_settings()
{
    OPT=false
    ARCH=`uname -m | sed -e 's/i.86/ia32/'`
    if [ "$ARCH" != "ia32" ]
    then
	OPT=true	# no workarounds needed for non-i?86 platforms
    elif [ -f /etc/lsb-release ]
    then
	if grep -q 'DISTRIB_ID=Ubuntu' /etc/lsb-release
	then
	    eval `grep DISTRIB_RELEASE= /etc/lsb-release`
	    XDISTRIB_RELEASE=`echo $DISTRIB_RELEASE | sed -e 's/[^0-9]//g'`
	    [ -z "$XDISTRIB_RELEASE" ] && XDISTRIB_RELEASE=0000
	    if [ $XDISTRIB_RELEASE -gt 1110 ]
	    then
		# Hope the problem is fixed after Ubuntu 11.10
		OPT=true
	    fi
	fi
	$OPT || echo "Building without optimization for Ubuntu $DISTRIB_RELEASE"
    elif [ -f /etc/debian_version ]
    then
	DISTRIB_RELEASE=`cat /etc/debian_version`
	XDISTRIB_RELEASE=`echo $DISTRIB_RELEASE | sed -e 's/[^0-9]//g'`
	[ -z "$XDISTRIB_RELEASE" ] && XDISTRIB_RELEASE=0000
	if [ $XDISTRIB_RELEASE -ge 700 ]
	then
	    # Hope the problem is fixed in Debian 7.0.0
	    OPT=true
	fi
	$OPT || echo "Building without optimization for Debian $DISTRIB_RELEASE"
    fi

    if ! $OPT
    then
	ok=true
	if grep -q '^my $default_flags .*O2' /usr/bin/dpkg-buildpackage
	then
	    echo 'dpkg-buildpackage: need to remove O2 from $default_flags'
	    ok=false
	fi
	if grep -q '^[ 	]*LDFLAGS.*-Bsymbolic-functions' /usr/bin/dpkg-buildpackage
	then
	    echo 'dpkg-buildpackage: need to remove -Bsymbolic-function from LDFLAGS'
	    ok=false
	fi
	if ! $ok
	then
	    echo "Refer to Debian/Ubuntu notes in PCP's ./INSTALL"
	    exit 1
	fi
	# as of Debian 6.0.1 and Ubuntu 10.10, build flags are hidden and
	# extracted using dpkg-buildflags which fortunately honours some
	# environment variable settings
	#
	export DEB_CFLAGS_SET=''
	export DEB_CXXFLAGS_SET=''
	export DEB_LDFLAGS_SET=''
    fi
}

# Build Debian packages using the dpkg-buildpackage utility which runs
# the complete build, from configure through to final deb preparation.
#
debian_buildpackage()
{
    echo
    echo "== Building deb packages using dpkg-buildpackage"

    SUDO=${SUDO:-fakeroot}
    # don't sign by default
    sign='-us -uc'
    # sign if --signed and $DEB_SIGN_KEYID set in the environment
    # (always for an upload to Debian servers so its source only)
    $signed && [ -n "$DEB_SIGN_KEYID" ] && sign='-S'
    opts="$sign -r$SUDO -sa"
    rm -f $tmp/failed
    if $verbose ; then
	(dpkg-buildpackage $opts || touch $tmp/failed) 2>&1 | tee -a "$LOGDIR/pcp"
    else
	(dpkg-buildpackage $opts || touch $tmp/failed) >>"$LOGDIR/pcp" 2>&1
    fi
    [ -f $tmp/failed ] && build_failure debian buildpackage
}

prepare_debian_sources()
{
    # shortcut for dpkg-buildpackage which does everything itself from here
    rm -rf "$SRCDIR"
    mkdir -p "$SRCDIR" 2>/dev/null

    cd "$SRCDIR" || exit 1
    $TAR -zxf "$SRCTAR" || exit 1
    cd "$SRCTREE" || exit 1

    fix_version "$topdir"/VERSION.pcp VERSION.pcp
}

prepare_debian_control()
{
    echo
    echo "== Preparing source tree for dpkg-buildpackage"
    parent=`realpath ..`
    source="$parent/pcp_$VERSION.orig.tar.gz"
    mv "$SRCTAR" "$source"
    echo "Wrote: $source"
    rm -f $tmp/failed debian/control
    if $verbose ; then
	($MAKE -C debian control 2>&1 || touch $tmp/failed) 2>&1 | tee -a "$LOGDIR/pcp"
    else
	($MAKE -C debian control 2>&1 || touch $tmp/failed) >>"$LOGDIR/pcp" 2>&1
    fi
    [ -f $tmp/failed ] && build_failure debian control
}

debian_build()
{
    SRCDIR="$topdir/build/deb"
    SRCTREE="$topdir/build/deb/$source"
    prepare_debian_sources

    # Note: we need to run configure here to get things like builddefs
    #       created, but configure will be run _again_ from
    #       debian_buildpackage, but we need to make sure the same
    #       configure options are used in both places
    #
    export configure_opts="$configopts"
    if [ ! -f debian/rules ]
    then
	echo "Botch: cannot find debian/rules"
	exit 1
    fi
    debian_opts=`sed -n <debian/rules -e '/^configure_paths/s/^[^=]*= *//p'`
    if [ -z "$debian_opts" ]
    then
	echo "Botch: cannot get config options from configure_paths in debian/rules"
	exit 1
    fi
    configopts="$debian_opts $configopts"
    configure_pcp
    prepare_debian_control
    sanity_check_settings
    debian_buildpackage
    check_pcp

    # success!
    if ! $verbose ; then
	grep ^dpkg-deb "$LOGDIR/pcp" | \
	    sed -e 's,\.$,,g' -e "s,',,g" -e "s,\.\.,$topdir/build/deb,g" | \
	    awk '{ print "Wrote:", $NF }'
    fi
    exit 0
}

prepare_build()
{
    echo
    echo "== Preparing fresh build tree for packaging build"

    if [ ! -d "$SRCDIR" ]; then
	# extract gzipped tar archive
	$TAR -xz --file="$SRCTAR" || exit 1
	fix_version VERSION.pcp "$SRCDIR"/VERSION.pcp
    fi
}

configure_pcp()
{
    echo
    echo "== Configuring pcp, log is in $LOGDIR/pcp ($configopts)"

    rm -f $tmp/failed
    if $verbose
    then
	($configure $configopts 2>&1 || touch $tmp/failed) 2>&1 | tee -a "$LOGDIR/pcp"
    else
	($configure $configopts 2>&1 || touch $tmp/failed) >>"$LOGDIR/pcp" 2>&1
    fi
    [ -f $tmp/failed ] && build_failure Configure
    $cfgonly && exit 0
}

check_pcp()
{
    $check || return 0

    echo
    echo "== Checking pcp, log is in $LOGDIR/pcp" | tee -a "$LOGDIR/pcp"

    rm -f $tmp/failed
    if $verbose ; then
	($MAKE check 2>&1 || touch $tmp/failed) 2>&1 | tee -a "$LOGDIR/pcp"
    else
	($MAKE check 2>&1 || touch $tmp/failed) >>"$LOGDIR/pcp" 2>&1
    fi
    [ -f $tmp/failed ] && build_failure Checking
}

default_build()
{
    echo
    echo "== Building pcp, log is in $LOGDIR/pcp"

    rm -f $tmp/failed
    if $verbose ; then
	($MAKE default_pcp 2>&1 || touch $tmp/failed) 2>&1 | tee -a "$LOGDIR/pcp"
    else
	($MAKE default_pcp 2>&1 || touch $tmp/failed) >>"$LOGDIR/pcp" 2>&1
    fi
    [ -f $tmp/failed ] && build_failure Make default_pcp
}

packaging_pcp()
{
    echo
    echo "== Packaging pcp, log is in $LOGDIR/pcp" | tee -a "$LOGDIR/pcp"

    rm -f $tmp/failed
    if $verbose ; then
	($MAKE -C build pack_pcp 2>&1 || touch $tmp/failed) 2>&1 | tee -a "$LOGDIR/pcp"
    else
	($MAKE -C build pack_pcp 2>&1 || touch $tmp/failed) >>"$LOGDIR/pcp" 2>&1
    fi
    [ -f $tmp/failed ] && build_failure Packaging via pack_pcp
}

packaging_rpm()
{
    echo
    echo "== Building rpm packages, log is in $LOGDIR/pcp" | tee -a "$LOGDIR/pcp"

    rm -f $tmp/failed
    export DIST_ROOT="$topdir/build/rpm/$source"
    # sign if --signed and $RPM_SIGN_KEYID set in the environment
    $signed && [ -z "$RPM_SIGN_KEYID" ] && unset RPM_SIGN_KEYID
    if $verbose ; then
	($MAKE -C build/rpm pack_pcp 2>&1 || touch $tmp/failed) 2>&1 | tee -a "$LOGDIR/pcp"
    else
	($MAKE -C build/rpm pack_pcp 2>&1 || touch $tmp/failed) >>"$LOGDIR/pcp" 2>&1
    fi
    [ -f $tmp/failed ] && build_failure Packaging RPMs via pack_pcp
}

packaging_docker()
{
    echo
    echo "== Building docker container images, log is in $LOGDIR/pcp" | tee -a "$LOGDIR/pcp"
    rm -f $tmp/failed

    if docker version >/dev/null 2>&1; then
	v=`docker version | sed -e 's/\./ /g' | \
	    awk '/^Server/ {s=1; if($2 == "version:") {print 10*$3+$4; exit}}
	    	/Version:/ {if (s) {print 10*$2+$3; exit}}'`
	if [ -z "$v" -o "$v" -lt 14 ]; then
	    echo 'Error: docker version too old. Containers build skipped.'
	    touch $tmp/failed
	fi
    else
	echo 'Error: docker not enabled or not properly configured for non-root access.'
	echo 'Check the docker service is enabled and running. You can allow non-root access'
	echo 'as follows: edit /etc/sysconfig/docker and add OPTIONS="-G gid" where gid is a'
	echo 'group name that you are a member of. Then restart the docker service.'
	touch $tmp/failed
    fi

    [ -f $tmp/failed ] && build_failure Packaging docker images, docker configuration

    if $verbose ; then
	($MAKE -C build/containers pack_pcp 2>&1 || touch $tmp/failed) 2>&1 | tee -a "$LOGDIR/pcp"
    else
	($MAKE -C build/containers pack_pcp 2>&1 || touch $tmp/failed) >>"$LOGDIR/pcp" 2>&1
    fi

    [ -f $tmp/failed ] && build_failure Packaging docker containers via pack_pcp
}

# real build starts here
clean_packaging
src_tar_build
$srconly && exit 0

# short-circuit for performing builds with dpkg-buildpackage
if $dodeb
then
    debian_build
    # NOTREACHED
fi

prepare_build

# shift into the clean packaging build tree from here onward
cd "$SRCDIR"

configure_pcp

# short-circuit for performing rpm-only builds with rpmbuild
# (skips over the default_build stage as rpmbuild does that).
if $dorpm
then
    packaging_rpm
else
    default_build	# perform a complete build in-situ
    packaging_pcp	# create all known package formats
fi

#
# --with-docker, currently only for RPM platforms with docker
if $docker
then
    packaging_docker
fi

check_pcp		# static checking (should be last).

# success!
if ! $verbose ; then
    grep '^Wrote:' "$LOGDIR/pcp" | sed -e 's/\.\.\/\.\.\///'
fi
exit 0