3 # Make whichever packages the system supports
5 # Copyright (c) 2012-2016 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
32 echo "Error: can only be run from within the PCP git repository"
36 if [ ! -f VERSION.pcp
]
38 echo "Error: can only be run from within the PCP source tree"
42 # Find where a GNU tool is hiding, look for this line:
43 # "Report bugs to <bug-$gnutool@gnu.org>"
45 # "FreeBSD $gnutool YYYYMMDD"
46 # in the $gnutool --help output
57 # Not in the environment, go search for it in the known locations.
61 for command in $oldcmd $@
63 exec=`which $command 2>/dev/null`
66 if $command --help 2>&1 |
egrep "(bug-$oldcmd@gnu.org)|(FreeBSD $gnutool)|(NetBSD $gnutool)|(Apple $gnutool)" >/dev
/null
73 if [ "$target" = openbsd
-a $command = gzip ]
80 echo >&2 "$prefix: can't find GNU $oldcmd in the commands $oldcmd or $@"
81 [ $prefix = Error
] && exit 1
85 # Use the environment request and ensure it is a full path (do not
86 # change this behaviour, it is required for backward-compatibility
87 # - QA failures will result if you choose to ignore this warning).
89 command=`which $envvar 2>/dev/null`
92 echo >&2 "$prefix: $oldcmd (from the environment) does not exist!"
93 [ $prefix = Error
] && exit 1
100 target
=`uname -s | tr 'A-Z' 'a-z'`
102 export MAKE
=`gnu_tool Error "$MAKE" make gmake`
103 export TAR
=`gnu_tool Warning "$TAR" tar gtar gnutar`
104 export ZIP
=`gnu_tool Error "$ZIP" gzip gnuzip`
106 # check if tar supports --transform else we must use git-archive later on (e.g. RHEL5)
107 [ ! -z "$TAR" ] && $TAR --help |
2>&1 grep -q transform || USE_GIT_ARCHIVE
=1
109 tmp
=`mktemp -d /tmp/pcp.XXXXXXXXX` ||
exit 1
110 trap "rm -rf $tmp" 0 1 2 3 15
112 configure
=.
/configure
113 cmdline_configopts
=''
119 # we always clean nowadays, so silently ignore
148 cmdline_configopts
="$cmdline_configopts $opt"
153 cmdline_configopts
="$cmdline_configopts $opt"
158 cmdline_configopts
="$cmdline_configopts $opt"
179 # Add remaining options to the ./configure command line
180 cmdline_configopts
="$cmdline_configopts $opt"
186 if [ $dorpm = unknown
]
189 [ -x /usr
/bin
/rpmbuild
] && dorpm
=true
191 if [ $dodeb = unknown
]
194 [ -x /usr
/bin
/dpkg-buildpackage
] && dodeb
=true
201 echo >&2 "Do not know how to build RPM and Debian packages at the same time!"
202 echo >&2 "Suggest --nonrpm or --nondeb on the command line."
208 # On Debian-based platforms, the debian/rules file already captures
209 # most of the required configure settings in $(configure_paths)
214 # On RPM-based platforms, rpm macros provide an excellent set of defaults.
215 # This set is based on Fedora 22 %configure macro from /usr/lib/rpm/macros,
216 # and is known to work as far back as RHEL5.
217 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`"
218 # rpmbuild clears the environment, so force these settings into the
219 # rpm build configure
221 configopts
="$configopts --with-make=$MAKE --with-tar=$TAR --with-zip=$ZIP"
222 elif [ $target = darwin
]
224 # On Mac OS X platforms, we install away from /usr/bin, /usr/lib
225 # and so on because of security requirements in recent versions.
227 configopts
="--prefix=/usr/local --sysconfdir=/etc --localstatedir=/var"
228 elif [ $target = netbsd
]
230 # Try to mimic where pkgsrc/pkgin place things
232 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"
234 # Bog-standard options suitable for a package on any platform.
235 # Command line can be used to extend this set, and any unusual
236 # platform-specific requirements are also appended later on.
237 configopts
="--prefix=/usr --sysconfdir=/etc --localstatedir=/var"
240 # Platform-specific variants ...
244 mingw|mingw64|windows
)
248 echo >&2 "Warning: --dorpm ignored for Windows build"
251 configopts
="$configopts --disable-ssp"
252 export configure
="/usr/bin/mingw64-configure"
253 export MAKE
="/usr/bin/mingw64-make"
254 export QMAKE
="/usr/bin/mingw64-qmake-qt4"
255 export PKG_CONFIG
="/usr/bin/mingw64-pkg-config"
259 [ -f /etc
/slackware-version
-a "$ARCH" = x86_64
] && configopts
="$configopts --libdir=/usr/lib64"
263 [ "$ARCH" = amd64
-o "$ARCH" = sparcv9
] && configopts
="$configopts --libdir=/usr/lib/64"
269 # now some specific QA/development hosts with special needs ...
273 vm04|vm04.localdomain|vm11|vm11.localdomain
)
274 # gcc -O2 is broken here (for the linux PMDA)
276 configopts
="$configopts --with-optimization=no"
277 # over-ride the settings from dpkg-buildflags
279 export DEB_CFLAGS_SET
=''
280 export DEB_CXXFLAGS_SET
=''
284 # and finally add in any from the command line
286 [ -n "$cmdline_configopts" ] && configopts
="$configopts $cmdline_configopts"
289 VERSION
=${PACKAGE_MAJOR}.${PACKAGE_MINOR}.${PACKAGE_REVISION}
295 source=pcp-
${VERSION}
296 SRCDIR
=$topdir/$source
297 SRCTAR
=$topdir/build
/tar
/$source.src.
tar.gz
298 SRCWEBJS
=$topdir/build
/tar
/webjs.
tar.gz
299 SRCVECTOR
=$topdir/build
/tar
/vector.
tar.gz
300 SRCPARFAIT
=$topdir/build
/tar
/parfait.
tar.gz
304 # only print in non-verbose mode, otherwise we see double
306 echo $@ failed
, see log
in $LOGDIR/pcp
315 echo "== Cleaning build tree for packaging build"
316 rm -rf "$SRCDIR" "$SRCTAR" .gitcensus
321 if [ -f "$1" -a -f "$2" ]
323 # as expected, both present
324 if diff "$1" "$2" >/dev
/null
2>&1
328 # must be using git-archive(1) and VERSION.pcp has been
329 # modified, e.g. by pcp-daily script ... use the modified
330 # one to bump the build number in the packages
335 echo "Arrgh ... expect both these to exist ..."
341 # Download sources from external repositories that we might want
342 # to include with the PCP packages.
348 if [ ! -f "$SRCPARFAIT" ]
350 echo "== Downloading Parfait package"
351 url
=https
://github.com
/performancecopilot
/parfait
/archive
/master.
zip
352 wget
-H -q -O $tmp/java.
zip "$url"
353 [ $?
-eq 0 ] && .
/scripts
/zip2tar
$tmp/java.
zip "$SRCPARFAIT"
355 if [ -f "$SRCPARFAIT" ]
357 DESTPARFAIT
="$topdir/$source/build/tar/"`basename "$SRCPARFAIT"`
358 cp "$SRCPARFAIT" "$DESTPARFAIT"
364 if [ ! -f "$SRCVECTOR" ]
366 echo "== Downloading Vector webapp"
367 url
=https
://bintray.com
/artifact
/download
/netflixoss
/downloads
/vector.
tar.gz
368 wget
-H -q -O "$SRCVECTOR" "$url"
369 [ $?
-eq 0 ] && echo "Wrote: $SRCVECTOR"
371 if [ -f "$SRCVECTOR" ]
373 DESTVECTOR
="$topdir/$source/build/tar/"`basename "$SRCVECTOR"`
374 cp "$SRCVECTOR" "$DESTVECTOR"
380 if [ ! -f "$SRCWEBJS" ]
382 echo "== Downloading webjs webapps"
383 url
=https
://github.com
/performancecopilot
/pcp-webjs
/archive
/master.
zip
384 wget
-H -q -O $tmp/js.
zip "$url"
385 [ $?
-eq 0 ] && .
/scripts
/zip2tar
$tmp/js.
zip "$SRCWEBJS"
387 if [ -f "$SRCWEBJS" ]
389 DESTWEBJS
="$topdir/$source/build/tar/"`basename "$SRCWEBJS"`
390 cp "$SRCWEBJS" "$DESTWEBJS"
395 # Generate a list of all the files git knows about, create the
396 # source tarball and then unpack it. We'll then do the package
397 # build in a guaranteed pristine environment.
401 if [ -z "$TAR" -o ! -z "$USE_GIT_ARCHIVE" ]
403 # no suitable GNU tar is available, use git-archive(1) - no local changes
404 if git status
-s src man |
grep '^.M'
406 echo "Arrgh, modified src files and either no tar ($TAR) or no --transform"
407 echo "support in tar, so local changes would not be included in the build."
410 git archive
--format=tar --prefix=$source/ HEAD |
$ZIP > $SRCTAR
412 # build git file list and make tarball by hand to pick up any changes
413 git ls-files
> .gitcensus
414 $TAR -cz --transform="s,^,$source/," --files-from=.gitcensus \
418 echo "Wrote: $SRCTAR"
421 # On sanity checks :- this is sick, but I'm really tired of QA failing
422 # because of bad binaries being built from the Debian/Ubuntu toolchain
423 # for # i?86 platforms
424 # - Ken McDonell Apr 2010
426 sanity_check_settings
()
429 ARCH
=`uname -m | sed -e 's/i.86/ia32/'`
430 if [ "$ARCH" != "ia32" ]
432 OPT
=true
# no workarounds needed for non-i?86 platforms
433 elif [ -f /etc
/lsb-release
]
435 if grep -q 'DISTRIB_ID=Ubuntu' /etc
/lsb-release
437 eval `grep DISTRIB_RELEASE= /etc/lsb-release`
438 XDISTRIB_RELEASE
=`echo $DISTRIB_RELEASE | sed -e 's/[^0-9]//g'`
439 [ -z "$XDISTRIB_RELEASE" ] && XDISTRIB_RELEASE
=0000
440 if [ $XDISTRIB_RELEASE -gt 1110 ]
442 # Hope the problem is fixed after Ubuntu 11.10
446 $OPT ||
echo "Building without optimization for Ubuntu $DISTRIB_RELEASE"
447 elif [ -f /etc
/debian_version
]
449 DISTRIB_RELEASE
=`cat /etc/debian_version`
450 XDISTRIB_RELEASE
=`echo $DISTRIB_RELEASE | sed -e 's/[^0-9]//g'`
451 [ -z "$XDISTRIB_RELEASE" ] && XDISTRIB_RELEASE
=0000
452 if [ $XDISTRIB_RELEASE -ge 700 ]
454 # Hope the problem is fixed in Debian 7.0.0
457 $OPT ||
echo "Building without optimization for Debian $DISTRIB_RELEASE"
463 if grep -q '^my $default_flags .*O2' /usr
/bin
/dpkg-buildpackage
465 echo 'dpkg-buildpackage: need to remove O2 from $default_flags'
468 if grep -q '^[ ]*LDFLAGS.*-Bsymbolic-functions' /usr
/bin
/dpkg-buildpackage
470 echo 'dpkg-buildpackage: need to remove -Bsymbolic-function from LDFLAGS'
475 echo "Refer to Debian/Ubuntu notes in PCP's ./INSTALL"
478 # as of Debian 6.0.1 and Ubuntu 10.10, build flags are hidden and
479 # extracted using dpkg-buildflags which fortunately honours some
480 # environment variable settings
482 export DEB_CFLAGS_SET
=''
483 export DEB_CXXFLAGS_SET
=''
484 export DEB_LDFLAGS_SET
=''
488 # Build Debian packages using the dpkg-buildpackage utility which runs
489 # the complete build, from configure through to final deb preparation.
491 debian_buildpackage
()
494 echo "== Building deb packages using dpkg-buildpackage"
496 SUDO
=${SUDO:-fakeroot}
497 # don't sign by default
499 # sign if --signed and $DEB_SIGN_KEYID set in the environment
500 $signed && [ -n "$DEB_SIGN_KEYID" ] && sign
=''
503 (dpkg-buildpackage
$sign -r$SUDO ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
505 (dpkg-buildpackage
$sign -r$SUDO ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
507 [ -f $tmp/failed
] && build_failure debian buildpackage
510 prepare_debian_sources
()
512 # shortcut for dpkg-buildpackage which does everything itself from here
513 SRCDIR
="${topdir}/build/deb"
515 mkdir
-p "$SRCDIR" 2>/dev
/null
516 cd "$SRCDIR" ||
exit 1
517 $TAR -zxf "$SRCTAR" ||
exit 1
518 cd "$SRCDIR/$source" ||
exit 1
519 fix_version
${topdir}/VERSION.pcp VERSION.pcp
522 prepare_debian_control
()
525 echo "== Preparing source tree for dpkg-buildpackage"
526 rm -f $tmp/failed debian
/control
528 ($MAKE -C debian control
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
530 ($MAKE -C debian control
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
532 [ -f $tmp/failed
] && build_failure debian control
537 prepare_debian_sources
538 # Note: we need to run configure here to get things like builddefs
539 # created, but configure will be run _again_ from
540 # debian_buildpackage, but we need to make sure the same
541 # configure options are used in both places
543 export configure_opts
="$configopts"
544 if [ ! -f debian
/rules
]
546 echo "Botch: cannot find debian/rules"
549 debian_opts
=`sed -n <debian/rules -e '/^configure_paths/s/^[^=]*= *//p'`
550 if [ -z "$debian_opts" ]
552 echo "Botch: cannot get config options from configure_paths in debian/rules"
555 configopts
="$debian_opts $configopts"
557 prepare_debian_control
558 sanity_check_settings
563 grep ^dpkg-deb
$LOGDIR/pcp | \
564 sed -e 's,\.$,,g' -e "s,',,g" -e "s,\.\.,$topdir/build/deb,g" | \
565 awk '{ print "Wrote:", $NF }'
573 echo "== Preparing fresh build tree for packaging build"
575 if [ ! -d "$SRCDIR" ]; then
576 # extract gzipped tar archive
577 $TAR -xz --file="$SRCTAR" ||
exit 1
578 fix_version VERSION.pcp
$SRCDIR/VERSION.pcp
585 echo "== Configuring pcp, log is in $LOGDIR/pcp ($configopts)"
590 ($configure $configopts 2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
592 ($configure $configopts 2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
594 [ -f $tmp/failed
] && build_failure Configure
600 echo "== Building pcp, log is in $LOGDIR/pcp"
604 ($MAKE default_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
606 ($MAKE default_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
608 [ -f $tmp/failed
] && build_failure Make default_pcp
614 echo "== Packaging pcp, log is in $LOGDIR/pcp" |
tee -a $LOGDIR/pcp
618 ($MAKE -C build pack_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
620 ($MAKE -C build pack_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
622 [ -f $tmp/failed
] && build_failure Packaging via pack_pcp
628 echo "== Building rpm packages, log is in $LOGDIR/pcp" |
tee -a $LOGDIR/pcp
631 export DIST_ROOT
=${topdir}/build
/rpm
/${source}
632 # sign if --signed and $RPM_SIGN_KEYID set in the environment
633 $signed && [ -z "$RPM_SIGN_KEYID" ] && unset RPM_SIGN_KEYID
635 ($MAKE -C build
/rpm pack_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
637 ($MAKE -C build
/rpm pack_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
639 [ -f $tmp/failed
] && build_failure Packaging RPMs via pack_pcp
645 echo "== Building docker container images, log is in $LOGDIR/pcp" |
tee -a $LOGDIR/pcp
648 if docker version
>/dev
/null
2>&1; then
649 v
=`docker version | sed -e 's/\./ /g' | \
650 awk '/^Server/ {s=1; if($2 == "version:") {print 10*$3+$4; exit}}
651 /Version:/ {if (s) {print 10*$2+$3; exit}}'`
652 if [ -z "$v" -o "$v" -lt 14 ]; then
653 echo 'Error: docker version too old. Containers build skipped.'
657 echo 'Error: docker not enabled or not properly configured for non-root access.'
658 echo 'Check the docker service is enabled and running. You can allow non-root access'
659 echo 'as follows: edit /etc/sysconfig/docker and add OPTIONS="-G gid" where gid is a'
660 echo 'group name that you are a member of. Then restart the docker service.'
664 [ -f $tmp/failed
] && build_failure Packaging docker images
, docker configuration
667 ($MAKE -C build
/containers pack_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
669 ($MAKE -C build
/containers pack_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
672 [ -f $tmp/failed
] && build_failure Packaging docker containers via pack_pcp
675 # real build starts here
680 # short-circuit for performing builds with dpkg-buildpackage
681 $dodeb && debian_build
685 # download any requested third party sources we're packaging
688 # shift into the clean packaging build tree from here onward
693 # short-circuit for performing rpm-only builds with rpmbuild
694 # (skips over the default_build stage as rpmbuild does that).
699 default_build
# perform a complete build in-situ
700 packaging_pcp
# create all known package formats
704 # --with-docker, currently only for RPM platforms with docker
712 grep '^Wrote:' $LOGDIR/pcp |
sed -e 's/\.\.\/\.\.\///'