3 # Make whichever packages the system supports
5 # Copyright (c) 2012-2015 Red Hat.
6 # Copyright (c) 2004 Silicon Graphics, Inc. All Rights Reserved.
8 # This program is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by the
10 # Free Software Foundation; either version 2 of the License, or (at your
11 # option) any later version.
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
31 echo "Error: can only be run from within the PCP git repository"
35 if [ ! -f VERSION.pcp
]
37 echo "Error: can only be run from within the PCP source tree"
41 # Find where a GNU tool is hiding, look for this line:
42 # "Report bugs to <bug-$gnutool@gnu.org>"
44 # "FreeBSD $gnutool YYYYMMDD"
45 # in the $gnutool --help output
56 # Not in the environment, go search for it in the known locations.
60 for command in $oldcmd $@
62 exec=`which $command 2>/dev/null`
65 if $command --help 2>&1 |
egrep "(bug-$oldcmd@gnu.org)|(FreeBSD $gnutool)|(NetBSD $gnutool)|(Apple $gnutool)" >/dev
/null
72 echo >&2 "$prefix: can't find GNU $oldcmd in the commands $oldcmd or $@"
73 [ $prefix = Error
] && exit 1
77 # Use the environment request and ensure it is a full path (do not
78 # change this behaviour, it is required for backward-compatibility
79 # - QA failures will result if you choose to ignore this warning).
81 command=`which $envvar 2>/dev/null`
84 echo >&2 "$prefix: $oldcmd (from the environment) does not exist!"
85 [ $prefix = Error
] && exit 1
92 export MAKE
=`gnu_tool Error "$MAKE" make gmake`
93 export TAR
=`gnu_tool Warning "$TAR" tar gtar gnutar`
94 export ZIP
=`gnu_tool Error "$ZIP" gzip gnuzip`
96 # check if tar supports --transform else we must use git-archive later on (e.g. RHEL5)
97 [ ! -z "$TAR" ] && $TAR --help |
2>&1 grep -q transform || USE_GIT_ARCHIVE
=1
99 tmp
=`mktemp -d /tmp/pcp.XXXXXXXXX` ||
exit 1
100 trap "rm -rf $tmp" 0 1 2 3 15
102 configure
=.
/configure
103 target
=`uname -s | tr 'A-Z' 'a-z'`
105 if [ -x /usr
/bin
/rpmbuild
]
107 # On RPM-based platforms, rpm macros provide an excellent set of defaults.
108 # This set is based on Fedora 22 %configure macro from /usr/lib/rpm/macros,
109 # and is known to work as far back as RHEL5.
110 configopts
=`rpmbuild --eval '--prefix=%{_prefix} --exec-prefix=%{_exec_prefix} --bindir=%{_bindir} --sbindir=%{_sbindir} --sysconfdir=%{_sysconfdir} --datadir=%{_datadir} --includedir=%{_includedir} --libdir=%{_libdir} --libexecdir=%{_libexecdir} --localstatedir=%{_localstatedir} --sharedstatedir=%{_sharedstatedir} --mandir=%{_mandir}' 2>/dev/null`
111 # rpmbuild clears the environment, so force these settings into the
112 # rpm build configure
114 configopt
="$configopts --with-make=$MAKE --with-tar=$TAR --with-zip=$ZIP"
115 elif [ -f /etc
/debian_version
]
117 # On Debian-based platforms, the debian/rules file already captures
118 # most of the required configure settings in $(configure_paths)
121 elif [ $target = darwin
]
123 # On Mac OS X platforms, we install away from /usr/bin, /usr/lib
124 # and so on because of security requirements in recent versions.
126 configopts
="--prefix=/usr/local --sysconfdir=/etc --localstatedir=/var"
127 elif [ $target = netbsd
]
129 # Try to mimic where pkgsrc/pkgin place things
131 configopts
="--prefix=/usr/pkg --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"
133 # Bog-standard options suitable for a package on any platform.
134 # Command line can be used to extend this set, and any unusual
135 # platform-specific requirements are also appended later on.
136 configopts
="--prefix=/usr --sysconfdir=/etc --localstatedir=/var"
143 # we always clean nowadays, so silently ignore
172 configopts
="$configopts $opt"
177 configopts
="$configopts $opt"
198 # Add remaining options to the ./configure command line
199 configopts
="$configopts $opt"
205 # now some specific QA/development hosts with special needs ...
209 vm04|vm04.localdomain|vm11|vm11.localdomain
)
210 # gcc -O2 is broken here (for the linux PMDA)
212 configopts
="$configopts --with-optimization=no"
213 # over-ride the settings from dpkg-buildflags
215 export DEB_CFLAGS_SET
=''
216 export DEB_CXXFLAGS_SET
=''
220 if [ "$nonrpm" = "unknown" ]
223 test -x /usr
/bin
/rpmbuild
&& nonrpm
=false
225 if [ "$nondeb" = "unknown" ]
228 test -x /usr
/bin
/dpkg-buildpackage
&& nondeb
=false
233 mingw|mingw64|windows
)
236 configopts
="$configopts --disable-ssp"
237 export configure
="/usr/bin/mingw64-configure"
238 export MAKE
="/usr/bin/mingw64-make"
239 export QMAKE
="/usr/bin/mingw64-qmake-qt4"
240 export PKG_CONFIG
="/usr/bin/mingw64-pkg-config"
244 [ -f /etc
/slackware-version
-a "$ARCH" = x86_64
] && configopts
="$configopts --libdir=/usr/lib64"
248 [ "$ARCH" = amd64
-o "$ARCH" = sparcv9
] && configopts
="$configopts --libdir=/usr/lib/64"
255 VERSION
=${PACKAGE_MAJOR}.${PACKAGE_MINOR}.${PACKAGE_REVISION}
261 source=pcp-
${VERSION}
262 SRCDIR
=$topdir/$source
263 SRCTAR
=$topdir/build
/tar
/$source.src.
tar.gz
264 SRCWEBJS
=$topdir/build
/tar
/webjs.
tar.gz
265 SRCVECTOR
=$topdir/build
/tar
/vector.
tar.gz
269 # only print in non-verbose mode, otherwise we see double
271 echo $@ failed
, see log
in $LOGDIR/pcp
280 echo "== Cleaning build tree for packaging build"
281 rm -rf "$SRCDIR" "$SRCTAR" .gitcensus
286 if [ -f "$1" -a -f "$2" ]
288 # as expected, both present
289 if diff "$1" "$2" >/dev
/null
2>&1
293 # must be using git-archive(1) and VERSION.pcp has been
294 # modified, e.g. by pcp-daily script ... use the modified
295 # one to bump the build number in the packages
300 echo "Arrgh ... expect both these to exist ..."
306 # Download sources from external repositories that we might want
307 # to include with the PCP packages.
313 if [ ! -f "$SRCVECTOR" ]
315 echo "== Downloading Vector webapp"
316 wget
-q -O "$SRCVECTOR" \
317 https
://bintray.com
/artifact
/download
/netflixoss
/downloads
/vector.
tar.gz
318 [ $?
-eq 0 ] && echo "Wrote: $SRCVECTOR"
320 if [ -f "$SRCVECTOR" ]
322 DESTVECTOR
="$topdir/$source/build/tar/"`basename $SRCVECTOR`
323 cp "$SRCVECTOR" "$DESTVECTOR"
329 if [ ! -f "$SRCWEBJS" ]
331 echo "== Downloading webjs webapps"
332 wget
-q -O $tmp/js.
zip \
333 https
://github.com
/performancecopilot
/pcp-webjs
/archive
/master.
zip
334 [ $?
-eq 0 ] && .
/scripts
/zip2tar
$tmp/js.
zip $SRCWEBJS
336 if [ -f "$SRCWEBJS" ]
338 DESTWEBJS
="$topdir/$source/build/tar/"`basename $SRCWEBJS`
339 cp "$SRCWEBJS" "$DESTWEBJS"
344 # Generate a list of all the files git knows about, create the
345 # source tarball and then unpack it. We'll then do the package
346 # build in a guaranteed pristine environment.
350 if [ -z "$TAR" -o ! -z "$USE_GIT_ARCHIVE" ]
352 # no suitable GNU tar is available, use git-archive(1) - no local changes
353 if git status
-s src man |
grep '^.M'
355 echo "Arrgh, modified src files and either no tar ($TAR) or no --transform"
356 echo "support in tar, so local changes would not be included in the build."
359 git archive
--format=tar --prefix=$source/ HEAD |
$ZIP > $SRCTAR
361 # build git file list and make tarball by hand to pick up any changes
362 git ls-files
> .gitcensus
363 $TAR -cz --transform="s,^,$source/," --files-from=.gitcensus \
367 echo "Wrote: $SRCTAR"
370 # On sanity checks :- this is sick, but I'm really tired of QA failing
371 # because of bad binaries being built from the Debian/Ubuntu toolchain
372 # for # i?86 platforms
373 # - Ken McDonell Apr 2010
375 sanity_check_settings
()
378 ARCH
=`uname -m | sed -e 's/i.86/ia32/'`
379 if [ "$ARCH" != "ia32" ]
381 OPT
=true
# no workarounds needed for non-i?86 platforms
382 elif [ -f /etc
/lsb-release
]
384 if grep -q 'DISTRIB_ID=Ubuntu' /etc
/lsb-release
386 eval `grep DISTRIB_RELEASE= /etc/lsb-release`
387 XDISTRIB_RELEASE
=`echo $DISTRIB_RELEASE | sed -e 's/[^0-9]//g'`
388 [ -z "$XDISTRIB_RELEASE" ] && XDISTRIB_RELEASE
=0000
389 if [ $XDISTRIB_RELEASE -gt 1110 ]
391 # Hope the problem is fixed after Ubuntu 11.10
395 $OPT ||
echo "Building without optimization for Ubuntu $DISTRIB_RELEASE"
396 elif [ -f /etc
/debian_version
]
398 DISTRIB_RELEASE
=`cat /etc/debian_version`
399 XDISTRIB_RELEASE
=`echo $DISTRIB_RELEASE | sed -e 's/[^0-9]//g'`
400 [ -z "$XDISTRIB_RELEASE" ] && XDISTRIB_RELEASE
=0000
401 if [ $XDISTRIB_RELEASE -ge 700 ]
403 # Hope the problem is fixed in Debian 7.0.0
406 $OPT ||
echo "Building without optimization for Debian $DISTRIB_RELEASE"
412 if grep -q '^my $default_flags .*O2' /usr
/bin
/dpkg-buildpackage
414 echo 'dpkg-buildpackage: need to remove O2 from $default_flags'
417 if grep -q '^[ ]*LDFLAGS.*-Bsymbolic-functions' /usr
/bin
/dpkg-buildpackage
419 echo 'dpkg-buildpackage: need to remove -Bsymbolic-function from LDFLAGS'
424 echo "Refer to Debian/Ubuntu notes in PCP's ./INSTALL"
427 # as of Debian 6.0.1 and Ubuntu 10.10, build flags are hidden and
428 # extracted using dpkg-buildflags which fortunately honours some
429 # environment variable settings
431 export DEB_CFLAGS_SET
=''
432 export DEB_CXXFLAGS_SET
=''
433 export DEB_LDFLAGS_SET
=''
437 # Build Debian packages using the dpkg-buildpackage utility which runs
438 # the complete build, from configure through to final deb preparation.
440 debian_buildpackage
()
443 echo "== Building deb packages using dpkg-buildpackage"
445 SUDO
=${SUDO:-fakeroot}
446 # don't sign by default
448 # sign if --signed and $DEB_SIGN_KEYID set in the environment
449 $signed && [ -n "$DEB_SIGN_KEYID" ] && sign
=''
452 (dpkg-buildpackage
$sign -r$SUDO ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
454 (dpkg-buildpackage
$sign -r$SUDO ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
456 [ -f $tmp/failed
] && build_failure debian buildpackage
459 prepare_debian_sources
()
461 # shortcut for dpkg-buildpackage which does everything itself from here
462 SRCDIR
="${topdir}/build/deb"
464 mkdir
-p "$SRCDIR" 2>/dev
/null
465 cd "$SRCDIR" ||
exit 1
466 $TAR -zxf "$SRCTAR" ||
exit 1
467 cd "$SRCDIR/$source" ||
exit 1
468 fix_version
${topdir}/VERSION.pcp VERSION.pcp
471 prepare_debian_control
()
474 echo "== Preparing source tree for dpkg-buildpackage"
475 rm -f $tmp/failed debian
/control
477 ($MAKE -C debian control
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
479 ($MAKE -C debian control
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
481 [ -f $tmp/failed
] && build_failure debian control
486 prepare_debian_sources
487 # Note: we need to run configure here to get things like builddefs
488 # created, but configure will be run _again_ from
489 # debian_buildpackage, but we need to make sure the same
490 # configure options are used in both places
492 export configure_opts
="$configopts"
493 if [ ! -f debian
/rules
]
495 echo "Botch: cannot find debian/rules"
498 debian_opts
=`sed -n <debian/rules -e '/^configure_paths/s/^[^=]*= *//p'`
499 if [ -z "$debian_opts" ]
501 echo "Botch: cannot get config options from configure_paths in debian/rules"
504 configopts
="$debian_opts $configopts"
506 prepare_debian_control
507 sanity_check_settings
515 echo "== Preparing fresh build tree for packaging build"
517 if [ ! -d "$SRCDIR" ]; then
518 # extract gzipped tar archive
519 $TAR -xz --file="$SRCTAR" ||
exit 1
520 fix_version VERSION.pcp
$SRCDIR/VERSION.pcp
527 echo "== Configuring pcp, log is in $LOGDIR/pcp ($configopts)"
532 ($configure $configopts 2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
534 ($configure $configopts 2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
536 [ -f $tmp/failed
] && build_failure Configure
542 echo "== Building pcp, log is in $LOGDIR/pcp"
546 ($MAKE default_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
548 ($MAKE default_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
550 [ -f $tmp/failed
] && build_failure Make default_pcp
556 echo "== Packaging pcp, log is in $LOGDIR/pcp" |
tee -a $LOGDIR/pcp
560 ($MAKE -C build pack_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
562 ($MAKE -C build pack_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
564 [ -f $tmp/failed
] && build_failure Packaging via pack_pcp
570 echo "== Building rpm packages, log is in $LOGDIR/pcp" |
tee -a $LOGDIR/pcp
573 export DIST_ROOT
=${topdir}/build
/rpm
/${source}
575 ($MAKE -C build
/rpm pack_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
577 ($MAKE -C build
/rpm pack_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
579 [ -f $tmp/failed
] && build_failure Packaging RPMs via pack_pcp
585 echo "== Building docker container images, log is in $LOGDIR/pcp" |
tee -a $LOGDIR/pcp
588 if docker version
>/dev
/null
2>&1; then
589 v
=`docker version | sed -e 's/\./ /g' | \
590 awk '/^Server/ {s=1; if($2 == "version:") {print 10*$3+$4; exit}}
591 /Version:/ {if (s) {print 10*$2+$3; exit}}'`
592 if [ -z "$v" -o "$v" -lt 14 ]; then
593 echo 'Error: docker version too old. Containers build skipped.'
597 echo 'Error: docker not enabled or not properly configured for non-root access.'
598 echo 'Check the docker service is enabled and running. You can allow non-root access'
599 echo 'as follows: edit /etc/sysconfig/docker and add OPTIONS="-G gid" where gid is a'
600 echo 'group name that you are a member of. Then restart the docker service.'
604 [ -f $tmp/failed
] && build_failure Packaging docker images
, docker configuration
607 ($MAKE -C build
/containers pack_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
609 ($MAKE -C build
/containers pack_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
612 [ -f $tmp/failed
] && build_failure Packaging docker containers via pack_pcp
615 # real build starts here
620 # short-circuit for performing builds with dpkg-buildpackage
621 $nondeb || debian_build
625 # download any requested third party sources we're packaging
628 # shift into the clean packaging build tree from here onward
633 # short-circuit for performing rpm-only builds with rpmbuild
634 # (skips over the default_build stage as rpmbuild does that).
637 default_build
# perform a complete build in-situ
638 packaging_pcp
# create all known package formats
644 # --with-docker, currently only for RPM platforms with docker
652 grep '^Wrote:' $LOGDIR/pcp |
sed -e 's/\.\.\/\.\.\///'