3 # Make whichever packages the system supports
5 # Copyright (c) 2012-2017 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
30 echo "Error: can only be run from within the PCP git repository"
34 if [ ! -f VERSION.pcp
]
36 echo "Error: can only be run from within the PCP source tree"
40 tmp
=`mktemp -d /tmp/pcp.XXXXXXXXX` ||
exit 1
41 trap "rm -rf $tmp $tmp.help" 0 1 2 3 15
42 target
=`uname -s | tr 'A-Z' 'a-z'`
44 # Find where a GNU tool is hiding, look for this line in the
45 # $gnutool --help output ...
46 # "Report bugs to <bug-$gnutool@gnu.org>"
53 # *This* tar defaults to:
65 # Not in the environment, go search for it in the known locations.
69 for command in $oldcmd $@
71 exec=`which $command 2>/dev/null`
74 $command --help >$tmp.
help 2>&1
75 if egrep "(bug-$oldcmd@gnu.org)|(FreeBSD $command)|(NetBSD $command)|(OpenBSD $command)|(Apple $command)" $tmp.
help >/dev
/null
80 awk <$tmp.
help >$tmp.check
'
82 /This\** tar defaults to:/ { want=1; next }
83 want == 1 { print; exit }'
84 if grep '[-][-]format=gnu' <$tmp.check
>/dev
/null
91 if [ "$target" = openbsd
-a $command = gzip ]
98 echo >&2 "$prefix: can't find GNU $oldcmd in the commands $oldcmd or $@"
99 [ $prefix = Error
] && exit 1
103 # Use the environment request and ensure it is a full path (do not
104 # change this behaviour, it is required for backward-compatibility
105 # - QA failures will result if you choose to ignore this warning).
107 command=`which $envvar 2>/dev/null`
110 echo >&2 "$prefix: $oldcmd (from the environment) does not exist!"
111 [ $prefix = Error
] && exit 1
118 export MAKE
=`gnu_tool Error "$MAKE" make gmake`
119 export TAR
=`gnu_tool Warning "$TAR" tar gtar gnutar`
120 export ZIP
=`gnu_tool Error "$ZIP" gzip gnuzip`
122 # check if tar supports --transform else we must use git-archive later on (e.g. RHEL5)
123 [ -n "$TAR" ] && $TAR --help |
2>&1 grep -q transform || USE_GIT_ARCHIVE
=1
124 #debug# echo TAR=$TAR USE_GIT_ARCHIVE=$USE_GIT_ARCHIVE
126 configure
=.
/configure
127 cmdline_configopts
=''
133 # we always clean nowadays, so silently ignore
162 cmdline_configopts
="$cmdline_configopts $opt"
183 # Add remaining options to the ./configure command line
184 cmdline_configopts
="$cmdline_configopts $opt"
190 if [ $dorpm = unknown
]
193 if which slackpkg
>/dev
/null
2>&1
195 # Slackware has rpm(1) and rpmbuild(1), but don't build RPMs
199 [ -x /usr
/bin
/rpmbuild
] && dorpm
=true
202 if [ $dodeb = unknown
]
205 [ -x /usr
/bin
/dpkg-buildpackage
] && dodeb
=true
212 echo >&2 "Do not know how to build RPM and Debian packages at the same time!"
213 echo >&2 "Suggest --nonrpm or --nondeb on the command line."
219 # On Debian-based platforms, the debian/rules file already captures
220 # most of the required configure settings in $(configure_paths)
225 # On RPM-based platforms, rpm macros provide an excellent set of defaults.
226 # This set is based on Fedora 22 %configure macro from /usr/lib/rpm/macros,
227 # and is known to work as far back as RHEL5.
228 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`"
229 # rpmbuild clears the environment, so force these settings into the
230 # rpm build configure
232 configopts
="$configopts --with-make=$MAKE --with-tar=$TAR --with-zip=$ZIP"
233 elif [ $target = darwin
]
235 # On Mac OS X platforms, we install away from /usr/bin, /usr/lib
236 # and so on because of security requirements in recent versions.
238 configopts
="--prefix=/usr/local --sysconfdir=/etc --localstatedir=/var"
239 elif [ $target = netbsd
]
241 # Try to mimic where pkgsrc/pkgin place things
243 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"
244 elif [ $target = freebsd
]
246 # Python build does not work on FreeBSD 9.3, so skip it
251 # Bog-standard, just without python
253 configopts
="--prefix=/usr --sysconfdir=/etc --localstatedir=/var --with-python=no --with-python3=no"
256 # Bog-standard, as below ...
258 configopts
="--prefix=/usr --sysconfdir=/etc --localstatedir=/var"
262 # Bog-standard options suitable for a package on any platform.
263 # Command line can be used to extend this set, and any unusual
264 # platform-specific requirements are also appended later on.
265 configopts
="--prefix=/usr --sysconfdir=/etc --localstatedir=/var"
268 # Platform-specific variants ...
272 mingw|mingw64|windows
)
275 configopts
="$configopts --disable-ssp"
276 export configure
="/usr/bin/mingw64-configure"
277 export MAKE
="/usr/bin/mingw64-make"
278 export QMAKE
="/usr/bin/mingw64-qmake-qt4"
279 export PKG_CONFIG
="/usr/bin/mingw64-pkg-config"
283 [ -f /etc
/slackware-version
-a "$ARCH" = x86_64
] && configopts
="$configopts --libdir=/usr/lib64"
287 [ "$ARCH" = amd64
-o "$ARCH" = sparcv9
] && configopts
="$configopts --libdir=/usr/lib/64"
293 # now some specific QA/development hosts with special needs ...
297 vm11|vm11.localdomain
)
298 # gcc -O2 is broken here (for the linux PMDA)
300 configopts
="$configopts --with-optimization=no"
301 # over-ride the settings from dpkg-buildflags
303 export DEB_CFLAGS_SET
=''
304 export DEB_CXXFLAGS_SET
=''
308 # and finally add in any from the command line
310 [ -n "$cmdline_configopts" ] && configopts
="$configopts $cmdline_configopts"
313 VERSION
=${PACKAGE_MAJOR}.${PACKAGE_MINOR}.${PACKAGE_REVISION}
319 source=pcp-
${VERSION}
320 SRCDIR
="$topdir/$source"
321 SRCTREE
="$topdir/$source"
322 SRCTAR
=$topdir/build
/tar
/$source.src.
tar.gz
326 # only print in non-verbose mode, otherwise we see double
328 echo $@ failed
, see log
in $LOGDIR/pcp
337 echo "== Cleaning build tree for packaging build"
338 rm -rf "$SRCDIR" "$SRCTAR" .gitcensus
343 if [ -f "$1" -a -f "$2" ]
345 # as expected, both present
346 if diff "$1" "$2" >/dev
/null
2>&1
350 # must be using git-archive(1) and VERSION.pcp has been
351 # modified, e.g. by pcp-daily script ... use the modified
352 # one to bump the build number in the packages
357 echo "Arrgh ... expect both these to exist ..."
363 # Check web applications from external repositories are available to
364 # be included with the PCP packages.
372 for APP
in vector grafana graphite blinkenlights
374 SRC
="$topdir/build/tar/pcp-webapp-$APP.tar.gz"
377 https
="https://github.com/performancecopilot"
378 echo "== Download to $SRC using:"
379 echo $https/pcp-webapp-
$APP/archive
/N.V.R
/pcp-webapp-
$APP-N.V.R.
tar.gz
388 # Generate a list of all the files git knows about, create the
389 # source tarball and then unpack it. We'll then do the package
390 # build in a guaranteed pristine environment.
394 if [ -z "$TAR" -o ! -z "$USE_GIT_ARCHIVE" ]
396 # no suitable GNU tar is available, use git-archive(1) - no local changes
397 if git status
-s src man |
grep '^.M'
399 echo "Arrgh, modified src files and either no tar ($TAR) or no --transform"
400 echo "support in tar, so local changes would not be included in the build."
403 git archive
--format=tar --prefix=$source/ HEAD |
$ZIP > $SRCTAR
405 # build git file list and make tarball by hand to pick up any changes
407 git ls-files
> .gitcensus
409 # but first ensure a "build everything" debian/control has been
417 echo "Error: debian/pre-build failed when creating debian/control"
421 echo "debian/control" >> .gitcensus
423 $TAR -cz --transform="s,^,$source/," --files-from=.gitcensus \
427 echo "Wrote: $SRCTAR"
430 # On sanity checks :- this is sick, but I'm really tired of QA failing
431 # because of bad binaries being built from the Debian/Ubuntu toolchain
432 # for # i?86 platforms
433 # - Ken McDonell Apr 2010
435 sanity_check_settings
()
438 ARCH
=`uname -m | sed -e 's/i.86/ia32/'`
439 if [ "$ARCH" != "ia32" ]
441 OPT
=true
# no workarounds needed for non-i?86 platforms
442 elif [ -f /etc
/lsb-release
]
444 if grep -q 'DISTRIB_ID=Ubuntu' /etc
/lsb-release
446 eval `grep DISTRIB_RELEASE= /etc/lsb-release`
447 XDISTRIB_RELEASE
=`echo $DISTRIB_RELEASE | sed -e 's/[^0-9]//g'`
448 [ -z "$XDISTRIB_RELEASE" ] && XDISTRIB_RELEASE
=0000
449 if [ $XDISTRIB_RELEASE -gt 1110 ]
451 # Hope the problem is fixed after Ubuntu 11.10
455 $OPT ||
echo "Building without optimization for Ubuntu $DISTRIB_RELEASE"
456 elif [ -f /etc
/debian_version
]
458 DISTRIB_RELEASE
=`cat /etc/debian_version`
459 XDISTRIB_RELEASE
=`echo $DISTRIB_RELEASE | sed -e 's/[^0-9]//g'`
460 [ -z "$XDISTRIB_RELEASE" ] && XDISTRIB_RELEASE
=0000
461 if [ $XDISTRIB_RELEASE -ge 700 ]
463 # Hope the problem is fixed in Debian 7.0.0
466 $OPT ||
echo "Building without optimization for Debian $DISTRIB_RELEASE"
472 if grep -q '^my $default_flags .*O2' /usr
/bin
/dpkg-buildpackage
474 echo 'dpkg-buildpackage: need to remove O2 from $default_flags'
477 if grep -q '^[ ]*LDFLAGS.*-Bsymbolic-functions' /usr
/bin
/dpkg-buildpackage
479 echo 'dpkg-buildpackage: need to remove -Bsymbolic-function from LDFLAGS'
484 echo "Refer to Debian/Ubuntu notes in PCP's ./INSTALL"
487 # as of Debian 6.0.1 and Ubuntu 10.10, build flags are hidden and
488 # extracted using dpkg-buildflags which fortunately honours some
489 # environment variable settings
491 export DEB_CFLAGS_SET
=''
492 export DEB_CXXFLAGS_SET
=''
493 export DEB_LDFLAGS_SET
=''
497 # Build Debian packages using the dpkg-buildpackage utility which runs
498 # the complete build, from configure through to final deb preparation.
500 debian_buildpackage
()
503 echo "== Building deb packages using dpkg-buildpackage"
505 SUDO
=${SUDO:-fakeroot}
506 # don't sign by default
508 # sign if --signed and $DEB_SIGN_KEYID set in the environment
509 # (always for an upload to Debian servers so its source only)
510 $signed && [ -n "$DEB_SIGN_KEYID" ] && sign
='-S'
513 (dpkg-buildpackage
$sign -r$SUDO ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
515 (dpkg-buildpackage
$sign -r$SUDO ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
517 [ -f $tmp/failed
] && build_failure debian buildpackage
520 prepare_debian_sources
()
522 # shortcut for dpkg-buildpackage which does everything itself from here
524 mkdir
-p "$SRCDIR" 2>/dev
/null
526 cd "$SRCDIR" ||
exit 1
527 $TAR -zxf "$SRCTAR" ||
exit 1
529 cd "$SRCTREE" ||
exit 1
532 fix_version
${topdir}/VERSION.pcp VERSION.pcp
535 prepare_debian_control
()
538 echo "== Preparing source tree for dpkg-buildpackage"
539 rm -f $tmp/failed debian
/control
541 ($MAKE -C debian control
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
543 ($MAKE -C debian control
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
545 [ -f $tmp/failed
] && build_failure debian control
550 SRCDIR
="${topdir}/build/deb"
551 SRCTREE
="${topdir}/build/deb/$source"
552 prepare_debian_sources
554 # Note: we need to run configure here to get things like builddefs
555 # created, but configure will be run _again_ from
556 # debian_buildpackage, but we need to make sure the same
557 # configure options are used in both places
559 export configure_opts
="$configopts"
560 if [ ! -f debian
/rules
]
562 echo "Botch: cannot find debian/rules"
565 debian_opts
=`sed -n <debian/rules -e '/^configure_paths/s/^[^=]*= *//p'`
566 if [ -z "$debian_opts" ]
568 echo "Botch: cannot get config options from configure_paths in debian/rules"
571 configopts
="$debian_opts $configopts"
573 prepare_debian_control
574 sanity_check_settings
579 grep ^dpkg-deb
$LOGDIR/pcp | \
580 sed -e 's,\.$,,g' -e "s,',,g" -e "s,\.\.,$topdir/build/deb,g" | \
581 awk '{ print "Wrote:", $NF }'
589 echo "== Preparing fresh build tree for packaging build"
591 if [ ! -d "$SRCDIR" ]; then
592 # extract gzipped tar archive
593 $TAR -xz --file="$SRCTAR" ||
exit 1
594 fix_version VERSION.pcp
$SRCDIR/VERSION.pcp
601 echo "== Configuring pcp, log is in $LOGDIR/pcp ($configopts)"
606 ($configure $configopts 2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
608 ($configure $configopts 2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
610 [ -f $tmp/failed
] && build_failure Configure
616 echo "== Building pcp, log is in $LOGDIR/pcp"
620 ($MAKE default_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
622 ($MAKE default_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
624 [ -f $tmp/failed
] && build_failure Make default_pcp
630 echo "== Packaging pcp, log is in $LOGDIR/pcp" |
tee -a $LOGDIR/pcp
634 ($MAKE -C build pack_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
636 ($MAKE -C build pack_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
638 [ -f $tmp/failed
] && build_failure Packaging via pack_pcp
644 echo "== Building rpm packages, log is in $LOGDIR/pcp" |
tee -a $LOGDIR/pcp
647 export DIST_ROOT
=${topdir}/build
/rpm
/${source}
648 # sign if --signed and $RPM_SIGN_KEYID set in the environment
649 $signed && [ -z "$RPM_SIGN_KEYID" ] && unset RPM_SIGN_KEYID
651 ($MAKE -C build
/rpm pack_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
653 ($MAKE -C build
/rpm pack_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
655 [ -f $tmp/failed
] && build_failure Packaging RPMs via pack_pcp
661 echo "== Building docker container images, log is in $LOGDIR/pcp" |
tee -a $LOGDIR/pcp
664 if docker version
>/dev
/null
2>&1; then
665 v
=`docker version | sed -e 's/\./ /g' | \
666 awk '/^Server/ {s=1; if($2 == "version:") {print 10*$3+$4; exit}}
667 /Version:/ {if (s) {print 10*$2+$3; exit}}'`
668 if [ -z "$v" -o "$v" -lt 14 ]; then
669 echo 'Error: docker version too old. Containers build skipped.'
673 echo 'Error: docker not enabled or not properly configured for non-root access.'
674 echo 'Check the docker service is enabled and running. You can allow non-root access'
675 echo 'as follows: edit /etc/sysconfig/docker and add OPTIONS="-G gid" where gid is a'
676 echo 'group name that you are a member of. Then restart the docker service.'
680 [ -f $tmp/failed
] && build_failure Packaging docker images
, docker configuration
683 ($MAKE -C build
/containers pack_pcp
2>&1 ||
touch $tmp/failed
) 2>&1 |
tee -a $LOGDIR/pcp
685 ($MAKE -C build
/containers pack_pcp
2>&1 ||
touch $tmp/failed
) >>$LOGDIR/pcp
2>&1
688 [ -f $tmp/failed
] && build_failure Packaging docker containers via pack_pcp
691 # real build starts here
696 # short-circuit for performing builds with dpkg-buildpackage
697 $dodeb && debian_build
701 # check for requested web application sources we're packaging
704 # shift into the clean packaging build tree from here onward
709 # short-circuit for performing rpm-only builds with rpmbuild
710 # (skips over the default_build stage as rpmbuild does that).
715 default_build
# perform a complete build in-situ
716 packaging_pcp
# create all known package formats
720 # --with-docker, currently only for RPM platforms with docker
728 grep '^Wrote:' $LOGDIR/pcp |
sed -e 's/\.\.\/\.\.\///'