diff --git a/ChangeLog b/ChangeLog index cbf37de4..64d1d601 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18735,3 +18735,7 @@ 2019-06-04 Fred Gleason * Fixed a bug in rdimport(1) that caused a segfault when processing an ID3 tag with a field that contained a null value. +2019-06-05 Fred Gleason + * Added a 'AX_COUNT_CPUS()' autoconf macro. + * Modified the 'make rpm' target to use one less than the total + available CPU cores. diff --git a/acinclude.m4 b/acinclude.m4 index 1787290c..f2346242 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1,34 +1,31 @@ -dnl acinclude.m4 -dnl -dnl Local Autoconf macro definitions for LibRHpi -dnl -dnl (C) Copyright 2006,2016 Fred Gleason -dnl -dnl BNV_HAVE_QT Macro Copyright (C) 2001, 2002, 2003, 2005, 2006 -dnl Bastiaan Veelo -dnl -dnl This program is free software; you can redistribute it and/or modify -dnl it under the terms of the GNU General Public License version 2 as -dnl published by the Free Software Foundation. -dnl -dnl This program is distributed in the hope that it will be useful, -dnl but WITHOUT ANY WARRANTY; without even the implied warranty of -dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -dnl GNU General Public License for more details. -dnl -dnl You should have received a copy of the GNU General Public -dnl License along with this program; if not, write to the Free Software -dnl Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -dnl +# acinclude.m4 +# +# Local Autoconf macro definitions +# +# (C) Copyright 2006-2019 Fred Gleason +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# 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. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# -dnl AR_GCC_TARGET() -dnl -dnl Get gcc(1)'s idea of the target architecture, distribution and os. -dnl The following variables are set: -dnl $ar_gcc_arch = Target Architecture (i586, XF86_64, etc) -dnl $ar_gcc_distro = Target Distribution (suse, slackware, etc) -dnl $ar_gcc_os = Target Operating System (linux, solaris, etc) -dnl +# AR_GCC_TARGET() +# +# Get gcc(1)'s idea of the target architecture, distribution and os. +# The following variables are set: +# $ar_gcc_arch = Target Architecture (i586, XF86_64, etc) +# $ar_gcc_distro = Target Distribution (suse, slackware, etc) +# $ar_gcc_os = Target Operating System (linux, solaris, etc) +# AC_DEFUN([AR_GCC_TARGET],[AC_REQUIRE([AC_PROG_CC])] [ AC_MSG_CHECKING(target architecture) @@ -39,16 +36,16 @@ AC_DEFUN([AR_GCC_TARGET],[AC_REQUIRE([AC_PROG_CC])] ] ) -dnl AR_GET_DISTRO() -dnl -dnl Try to determine the name and version of the distribution running -dnl on the host machine, based on entries in '/etc/'. -dnl The following variables are set: -dnl $ar_distro_name = Distribution Name (SuSE, Debian, etc) -dnl $ar_distro_version = Distribution Version (10.3, 3.1, etc) -dnl $ar_distro_major = Distribution Version Major Number (10, 3, etc) -dnl $ar_distro_minor = Distribution Version Minor Number (3, 1, etc) -dnl +# AR_GET_DISTRO() +# +# Try to determine the name and version of the distribution running +# on the host machine, based on entries in '/etc/'. +# The following variables are set: +# $ar_distro_name = Distribution Name (SuSE, Debian, etc) +# $ar_distro_version = Distribution Version (10.3, 3.1, etc) +# $ar_distro_major = Distribution Version Major Number (10, 3, etc) +# $ar_distro_minor = Distribution Version Minor Number (3, 1, etc) +# AC_DEFUN([AR_GET_DISTRO],[] [ AC_MSG_CHECKING(distribution) @@ -59,3 +56,105 @@ AC_DEFUN([AR_GET_DISTRO],[] AC_MSG_RESULT([$ar_distro_name $ar_distro_version]) ] ) + +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_count_cpus.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_COUNT_CPUS([ACTION-IF-DETECTED],[ACTION-IF-NOT-DETECTED]) +# +# DESCRIPTION +# +# Attempt to count the number of logical processor cores (including +# virtual and HT cores) currently available to use on the machine and +# place detected value in CPU_COUNT variable. +# +# On successful detection, ACTION-IF-DETECTED is executed if present. If +# the detection fails, then ACTION-IF-NOT-DETECTED is triggered. The +# default ACTION-IF-NOT-DETECTED is to set CPU_COUNT to 1. +# +# LICENSE +# +# Copyright (c) 2014,2016 Karlson2k (Evgeny Grin) +# Copyright (c) 2012 Brian Aker +# Copyright (c) 2008 Michael Paul Bailey +# Copyright (c) 2008 Christophe Tournayre +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +##serial 22 + + AC_DEFUN([AX_COUNT_CPUS],[dnl + AC_REQUIRE([AC_CANONICAL_HOST])dnl + AC_REQUIRE([AC_PROG_EGREP])dnl + AC_MSG_CHECKING([the number of available CPUs]) + CPU_COUNT="0" + + # Try generic methods + + # 'getconf' is POSIX utility, but '_NPROCESSORS_ONLN' and + # 'NPROCESSORS_ONLN' are platform-specific + command -v getconf >/dev/null 2>&1 && \ + CPU_COUNT=`getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null` || CPU_COUNT="0" + AS_IF([[test "$CPU_COUNT" -gt "0" 2>/dev/null || ! command -v nproc >/dev/null 2>&1]],[[: # empty]],[dnl + # 'nproc' is part of GNU Coreutils and is widely available + CPU_COUNT=`OMP_NUM_THREADS='' nproc 2>/dev/null` || CPU_COUNT=`nproc 2>/dev/null` || CPU_COUNT="0" + ])dnl + + AS_IF([[test "$CPU_COUNT" -gt "0" 2>/dev/null]],[[: # empty]],[dnl + # Try platform-specific preferred methods + AS_CASE([[$host_os]],dnl + [[*linux*]],[[CPU_COUNT=`lscpu -p 2>/dev/null | $EGREP -e '^@<:@0-9@:>@+,' -c` || CPU_COUNT="0"]],dnl + [[*darwin*]],[[CPU_COUNT=`sysctl -n hw.logicalcpu 2>/dev/null` || CPU_COUNT="0"]],dnl + [[freebsd*]],[[command -v sysctl >/dev/null 2>&1 && CPU_COUNT=`sysctl -n kern.smp.cpus 2>/dev/null` || CPU_COUNT="0"]],dnl + [[netbsd*]], [[command -v sysctl >/dev/null 2>&1 && CPU_COUNT=`sysctl -n hw.ncpuonline 2>/dev/null` || CPU_COUNT="0"]],dnl + [[solaris*]],[[command -v psrinfo >/dev/null 2>&1 && CPU_COUNT=`psrinfo 2>/dev/null | $EGREP -e '^@<:@0-9@:>@.*on-line' -c 2>/dev/null` || CPU_COUNT="0"]],dnl + [[mingw*]],[[CPU_COUNT=`ls -qpU1 /proc/registry/HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/CentralProcessor/ 2>/dev/null | $EGREP -e '^@<:@0-9@:>@+/' -c` || CPU_COUNT="0"]],dnl + [[msys*]],[[CPU_COUNT=`ls -qpU1 /proc/registry/HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/CentralProcessor/ 2>/dev/null | $EGREP -e '^@<:@0-9@:>@+/' -c` || CPU_COUNT="0"]],dnl + [[cygwin*]],[[CPU_COUNT=`ls -qpU1 /proc/registry/HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/CentralProcessor/ 2>/dev/null | $EGREP -e '^@<:@0-9@:>@+/' -c` || CPU_COUNT="0"]]dnl + )dnl + ])dnl + + AS_IF([[test "$CPU_COUNT" -gt "0" 2>/dev/null || ! command -v sysctl >/dev/null 2>&1]],[[: # empty]],[dnl + # Try less preferred generic method + # 'hw.ncpu' exist on many platforms, but not on GNU/Linux + CPU_COUNT=`sysctl -n hw.ncpu 2>/dev/null` || CPU_COUNT="0" + ])dnl + + AS_IF([[test "$CPU_COUNT" -gt "0" 2>/dev/null]],[[: # empty]],[dnl + # Try platform-specific fallback methods + # They can be less accurate and slower then preferred methods + AS_CASE([[$host_os]],dnl + [[*linux*]],[[CPU_COUNT=`$EGREP -e '^processor' -c /proc/cpuinfo 2>/dev/null` || CPU_COUNT="0"]],dnl + [[*darwin*]],[[CPU_COUNT=`system_profiler SPHardwareDataType 2>/dev/null | $EGREP -i -e 'number of cores:'|cut -d : -f 2 -s|tr -d ' '` || CPU_COUNT="0"]],dnl + [[freebsd*]],[[CPU_COUNT=`dmesg 2>/dev/null| $EGREP -e '^cpu@<:@0-9@:>@+: '|sort -u|$EGREP -e '^' -c` || CPU_COUNT="0"]],dnl + [[netbsd*]], [[CPU_COUNT=`command -v cpuctl >/dev/null 2>&1 && cpuctl list 2>/dev/null| $EGREP -e '^@<:@0-9@:>@+ .* online ' -c` || \ + CPU_COUNT=`dmesg 2>/dev/null| $EGREP -e '^cpu@<:@0-9@:>@+ at'|sort -u|$EGREP -e '^' -c` || CPU_COUNT="0"]],dnl + [[solaris*]],[[command -v kstat >/dev/null 2>&1 && CPU_COUNT=`kstat -m cpu_info -s state -p 2>/dev/null | $EGREP -c -e 'on-line'` || \ + CPU_COUNT=`kstat -m cpu_info 2>/dev/null | $EGREP -c -e 'module: cpu_info'` || CPU_COUNT="0"]],dnl + [[mingw*]],[AS_IF([[CPU_COUNT=`reg query 'HKLM\\Hardware\\Description\\System\\CentralProcessor' 2>/dev/null | $EGREP -e '\\\\@<:@0-9@:>@+$' -c`]],dnl + [[: # empty]],[[test "$NUMBER_OF_PROCESSORS" -gt "0" 2>/dev/null && CPU_COUNT="$NUMBER_OF_PROCESSORS"]])],dnl + [[msys*]],[[test "$NUMBER_OF_PROCESSORS" -gt "0" 2>/dev/null && CPU_COUNT="$NUMBER_OF_PROCESSORS"]],dnl + [[cygwin*]],[[test "$NUMBER_OF_PROCESSORS" -gt "0" 2>/dev/null && CPU_COUNT="$NUMBER_OF_PROCESSORS"]]dnl + )dnl + ])dnl + + AS_IF([[test "x$CPU_COUNT" != "x0" && test "$CPU_COUNT" -gt 0 2>/dev/null]],[dnl + AC_MSG_RESULT([[$CPU_COUNT]]) + m4_ifvaln([$1],[$1],)dnl + ],[dnl + m4_ifval([$2],[dnl + AS_UNSET([[CPU_COUNT]]) + AC_MSG_RESULT([[unable to detect]]) + $2 + ], [dnl + CPU_COUNT="1" + AC_MSG_RESULT([[unable to detect (assuming 1)]]) + ])dnl + ])dnl + ])dnl diff --git a/configure.ac b/configure.ac index 30135985..26a04ed7 100644 --- a/configure.ac +++ b/configure.ac @@ -137,6 +137,20 @@ else AC_SUBST(RD_LIB_PATH,lib) fi +# +# Determine number of available CPU cores for building packages +# +AX_COUNT_CPUS([],[]) +if test $CPU_COUNT -lt 2 ; then + AC_SUBST(CPUS_AVAIL,1) +else + if test $CPU_COUNT -gt 16 ; then + AC_SUBST(CPUS_AVAIL,16) + else + AC_SUBST(CPUS_AVAIL,$(($CPU_COUNT-1))) + fi +fi + # # Determine Distro # diff --git a/rivendell.spec.in b/rivendell.spec.in index 79af74ce..8a8340bb 100644 --- a/rivendell.spec.in +++ b/rivendell.spec.in @@ -111,7 +111,7 @@ associated with. %build export PYTHON=/usr/bin/python3.6 %configure --libexecdir=@libexecdir@ --sysconfdir=@sysconfdir@ @RDXPORTDEBUG@ -make -j 10 +make -j @CPUS_AVAIL@ %install