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
)
247 configopts
="$configopts --disable-ssp"
248 export configure
="/usr/bin/mingw64-configure"
249 export MAKE
="/usr/bin/mingw64-make"
250 export QMAKE
="/usr/bin/mingw64-qmake-qt4"
251 export PKG_CONFIG
="/usr/bin/mingw64-pkg-config"
255 [ -f /etc
/slackware-version
-a "$ARCH" = x86_64
] && configopts
="$configopts --libdir=/usr/lib64"
259 [ "$ARCH" = amd64
-o "$ARCH" = sparcv9
] && configopts
="$configopts --libdir=/usr/lib/64"
265 # now some specific QA/development hosts with special needs ...
269 vm04|vm04.localdomain|vm11|vm11.localdomain
)
270 # gcc -O2 is broken here (for the linux PMDA)
272 configopts
="$configopts --with-optimization=no"
273 # over-ride the settings from dpkg-buildflags
275 export DEB_CFLAGS_SET
=''
276 export DEB_CXXFLAGS_SET
=''
280 # and finally add in any from the command line
282 [ -n "$cmdline_configopts" ] && configopts
="$configopts $cmdline_configopts"
285 VERSION
=${PACKAGE_MAJOR}.${PACKAGE_MINOR}.${PACKAGE_REVISION}
291 source=pcp-
${VERSION}
292 SRCDIR
="$topdir/$source"
293 SRCTREE
="$topdir/$source"
294 SRCTAR
=$topdir/build
/tar
/$source.src.
tar.gz
295 SRCWEBJS
=$topdir/build
/tar
/webjs.
tar.gz
296 SRCVECTOR
=$topdir/build
/tar
/vector.
tar.gz
297 SRCPARFAIT
=$topdir/build
/tar
/parfait.
tar.gz
301 # only print in non-verbose mode, otherwise we see double
303 echo $@ failed
, see log
in $LOGDIR/pcp
312 echo "== Cleaning build tree for packaging build"
313 rm -rf "$SRCDIR" "$SRCTAR" .gitcensus
318 if [ -f "$1" -a -f "$2" ]
320 # as expected, both present
321 if diff "$1" "$2" >/dev
/null
2>&1
325 # must be using git-archive(1) and VERSION.pcp has been
326 # modified, e.g. by pcp-daily script ... use the modified
327 # one to bump the build number in the packages
332 echo "Arrgh ... expect both these to exist ..."
338 # Download sources from external repositories that we might want
339 # to include with the PCP packages.
345 if [ ! -f "$SRCPARFAIT" ]
347 echo "== Downloading Parfait package"
348 url
=https
://github.com
/performancecopilot
/parfait
/archive
/master.
zip
349 wget
-H -q -O $tmp/java.
zip "$url"
350 [ $?
-eq 0 ] && .
/scripts
/zip2tar
$tmp/java.
zip "$SRCPARFAIT"
352 if [ -f "$SRCPARFAIT" ]
354 DESTPARFAIT
="$SRCTREE/build/tar/"`basename "$SRCPARFAIT"`
355 cp "$SRCPARFAIT" "$DESTPARFAIT"
361 if [ ! -f "$SRCVECTOR" ]
363 echo "== Downloading Vector webapp"
364 url
=https
://bintray.com
/artifact
/download
/netflixoss
/downloads
/vector.
tar.gz
365 wget
-H -q -O "$SRCVECTOR" "$url"
366 [ $?
-eq 0 ] && echo "Wrote: $SRCVECTOR"
368 if [ -f "$SRCVECTOR" ]
370 DESTVECTOR
="$SRCTREE/build/tar/"`basename "$SRCVECTOR"`
371 mkdir
$tmp/vector
&& pushd $tmp/vector
&& $TAR -zxf "$SRCVECTOR"
372 $topdir/scripts
/build-vector
373 cd dist
&& $TAR -czf "$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
="$SRCTREE/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
414 git ls-files
> .gitcensus
416 # but first ensure a "build everything" debian/control has been
424 echo "Error: debian/pre-build failed when creating debian/control"
428 echo "debian/control" >> .gitcensus
430 $TAR -cz --transform="s,^,$source/," --files-from=.gitcensus \
434 echo "Wrote: $SRCTAR"
437 # On sanity checks :- this is sick, but I'm really tired of QA failing
438 # because of bad binaries being built from the Debian/Ubuntu toolchain
439 # for # i?86 platforms
440 # - Ken McDonell Apr 2010
442 sanity_check_settings
()
445 ARCH
=`uname -m | sed -e 's/i.86/ia32/'`
446 if [ "$ARCH" != "ia32" ]
448 OPT
=true
# no workarounds needed for non-i?86 platforms
449 elif [ -f /etc
/lsb-release
]
451 if grep -q 'DISTRIB_ID=Ubuntu' /etc
/lsb-release
453 eval `grep DISTRIB_RELEASE= /etc/lsb-release`
454 XDISTRIB_RELEASE
=`echo $DISTRIB_RELEASE | sed -e 's/[^0-9]//g'`
455 [ -z "$XDISTRIB_RELEASE" ] && XDISTRIB_RELEASE
=0000
456 if [ $XDISTRIB_RELEASE -gt 1110 ]
458 # Hope the problem is fixed after Ubuntu 11.10
462 $OPT ||
echo "Building without optimization for Ubuntu $DISTRIB_RELEASE"
463 elif [ -f /etc
/debian_version
]
465 DISTRIB_RELEASE
=`cat /etc/debian_version`
466 XDISTRIB_RELEASE
=`echo $DISTRIB_RELEASE | sed -e 's/[^0-9]//g'`
467 [ -z "$XDISTRIB_RELEASE" ] && XDISTRIB_RELEASE
=0000
468 if [ $XDISTRIB_RELEASE -ge 700 ]
470 # Hope the problem is fixed in Debian 7.0.0
473 $OPT ||
echo "Building without optimization for Debian $DISTRIB_RELEASE"
479 if grep -q '^my $default_flags .*O2' /usr
/bin
/dpkg-buildpackage
481 echo 'dpkg-buildpackage: need to remove O2 from $default_flags'
484 if grep -q '^[ ]*LDFLAGS.*-Bsymbolic-functions' /usr
/bin
/dpkg-buildpackage
486 echo 'dpkg-buildpackage: need to remove -Bsymbolic-function from LDFLAGS'
491 echo "Refer to Debian/Ubuntu notes in PCP's ./INSTALL"
494 # as of Debian 6.0.1 and Ubuntu 10.10, build flags are hidden and
495 # extracted using dpkg-buildflags which fortunately honours some
496 # environment variable settings
498 export DEB_CFLAGS_SET
=''
499 export DEB_CXXFLAGS_SET
=''
500 export DEB_LDFLAGS_SET
=''
504 # Build Debian packages using the dpkg-buildpackage utility which runs
505 # the complete build, from configure through to final deb preparation.
507 debian_buildpackage
()
510 echo "== Building deb packages using dpkg-buildpackage"
512 SUDO
=${SUDO:-fakeroot}
513 # don't sign by default
515 # sign if --signed and $DEB_SIGN_KEYID set in the environment
516 $signed && [ -n "$DEB_SIGN_KEYID" ] && sign
=''
519 (dpkg-buildpackage
$sign -r$SUDO ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
521 (dpkg-buildpackage
$sign -r$SUDO ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
523 [ -f $tmp/failed
] && build_failure debian buildpackage
526 prepare_debian_sources
()
528 # shortcut for dpkg-buildpackage which does everything itself from here
530 mkdir
-p "$SRCDIR" 2>/dev
/null
532 cd "$SRCDIR" ||
exit 1
533 $TAR -zxf "$SRCTAR" ||
exit 1
535 cd "$SRCTREE" ||
exit 1
538 fix_version
${topdir}/VERSION.pcp VERSION.pcp
541 prepare_debian_control
()
544 echo "== Preparing source tree for dpkg-buildpackage"
545 rm -f $tmp/failed debian
/control
547 ($MAKE -C debian control
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
549 ($MAKE -C debian control
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
551 [ -f $tmp/failed
] && build_failure debian control
556 SRCDIR
="${topdir}/build/deb"
557 SRCTREE
="${topdir}/build/deb/$source"
558 prepare_debian_sources
560 # Note: we need to run configure here to get things like builddefs
561 # created, but configure will be run _again_ from
562 # debian_buildpackage, but we need to make sure the same
563 # configure options are used in both places
565 export configure_opts
="$configopts"
566 if [ ! -f debian
/rules
]
568 echo "Botch: cannot find debian/rules"
571 debian_opts
=`sed -n <debian/rules -e '/^configure_paths/s/^[^=]*= *//p'`
572 if [ -z "$debian_opts" ]
574 echo "Botch: cannot get config options from configure_paths in debian/rules"
577 configopts
="$debian_opts $configopts"
579 prepare_debian_control
580 sanity_check_settings
585 grep ^dpkg-deb
$LOGDIR/pcp | \
586 sed -e 's,\.$,,g' -e "s,',,g" -e "s,\.\.,$topdir/build/deb,g" | \
587 awk '{ print "Wrote:", $NF }'
595 echo "== Preparing fresh build tree for packaging build"
597 if [ ! -d "$SRCDIR" ]; then
598 # extract gzipped tar archive
599 $TAR -xz --file="$SRCTAR" ||
exit 1
600 fix_version VERSION.pcp
$SRCDIR/VERSION.pcp
607 echo "== Configuring pcp, log is in $LOGDIR/pcp ($configopts)"
612 ($configure $configopts 2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
614 ($configure $configopts 2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
616 [ -f $tmp/failed
] && build_failure Configure
622 echo "== Building pcp, log is in $LOGDIR/pcp"
626 ($MAKE default_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
628 ($MAKE default_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
630 [ -f $tmp/failed
] && build_failure Make default_pcp
636 echo "== Packaging pcp, log is in $LOGDIR/pcp" |
tee -a $LOGDIR/pcp
640 ($MAKE -C build pack_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
642 ($MAKE -C build pack_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
644 [ -f $tmp/failed
] && build_failure Packaging via pack_pcp
650 echo "== Building rpm packages, log is in $LOGDIR/pcp" |
tee -a $LOGDIR/pcp
653 export DIST_ROOT
=${topdir}/build
/rpm
/${source}
654 # sign if --signed and $RPM_SIGN_KEYID set in the environment
655 $signed && [ -z "$RPM_SIGN_KEYID" ] && unset RPM_SIGN_KEYID
657 ($MAKE -C build
/rpm pack_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
659 ($MAKE -C build
/rpm pack_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
661 [ -f $tmp/failed
] && build_failure Packaging RPMs via pack_pcp
667 echo "== Building docker container images, log is in $LOGDIR/pcp" |
tee -a $LOGDIR/pcp
670 if docker version
>/dev
/null
2>&1; then
671 v
=`docker version | sed -e 's/\./ /g' | \
672 awk '/^Server/ {s=1; if($2 == "version:") {print 10*$3+$4; exit}}
673 /Version:/ {if (s) {print 10*$2+$3; exit}}'`
674 if [ -z "$v" -o "$v" -lt 14 ]; then
675 echo 'Error: docker version too old. Containers build skipped.'
679 echo 'Error: docker not enabled or not properly configured for non-root access.'
680 echo 'Check the docker service is enabled and running. You can allow non-root access'
681 echo 'as follows: edit /etc/sysconfig/docker and add OPTIONS="-G gid" where gid is a'
682 echo 'group name that you are a member of. Then restart the docker service.'
686 [ -f $tmp/failed
] && build_failure Packaging docker images
, docker configuration
689 ($MAKE -C build
/containers pack_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
691 ($MAKE -C build
/containers pack_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
694 [ -f $tmp/failed
] && build_failure Packaging docker containers via pack_pcp
697 # real build starts here
702 # short-circuit for performing builds with dpkg-buildpackage
703 $dodeb && debian_build
707 # download any requested third party sources we're packaging
710 # shift into the clean packaging build tree from here onward
715 # short-circuit for performing rpm-only builds with rpmbuild
716 # (skips over the default_build stage as rpmbuild does that).
721 default_build
# perform a complete build in-situ
722 packaging_pcp
# create all known package formats
726 # --with-docker, currently only for RPM platforms with docker
734 grep '^Wrote:' $LOGDIR/pcp |
sed -e 's/\.\.\/\.\.\///'