diff --git a/SConstruct b/SConstruct index 67c7cdab..2f6fa89c 100755 --- a/SConstruct +++ b/SConstruct @@ -674,6 +674,39 @@ SConsEnvironment.InstallPerm = InstallPerm # Your extra checks here env = conf.Finish() +def get_cpu_count(): + # priority: environ('NUM_CPU'), else try to read actual cpu count, else fallback + fallback = 4 + + if 'NUM_CPU' in os.environ: + return int(os.environ.get('NUM_CPU')) + + # try multiprocessing.cpu_count() (Python 2.6+) + try: + import multiprocessing + return multiprocessing.cpu_count() + except (ImportError, NotImplementedError): + pass + + # try psutil.cpu_count() + try: + import psutil + return psutil.cpu_count() + except (ImportError, AttributeError): + pass + + # default value + return fallback + + +# set number of parallel jobs during build +# note: while not particularly intuitive or obvious from the documentation, +# SetOption() will *not* over-ride commandline option passed by `scons -j` +# or `scons --jobs=` +SetOption('num_jobs', get_cpu_count()) + +print "Running with --jobs=" + repr(GetOption('num_jobs')) + library = SConscript('lib/SConscript') programs = SConscript('src/SConscript', exports='library') env.Default(library) diff --git a/docs/install.rst b/docs/install.rst index 62846861..58951a65 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -152,9 +152,9 @@ build the software from the potentially unstable ``develop`` branch: $ git clone -b develop https://github.com/sahib/rmlint.git $ cd rmlint/ $ scons config # Look what features scons would compile - $ scons DEBUG=1 -j4 # Optional, build locally. + $ scons DEBUG=1 # Optional, build locally. # Install (and build if necessary). For releases you can omit DEBUG=1 - $ sudo scons DEBUG=1 -j4 --prefix=/usr install + $ sudo scons DEBUG=1 --prefix=/usr install Done! diff --git a/pkg/arch/PKGBUILD b/pkg/arch/PKGBUILD index 2a5b7c53..6cd27a9f 100644 --- a/pkg/arch/PKGBUILD +++ b/pkg/arch/PKGBUILD @@ -25,7 +25,7 @@ pkgver() { build() { cd "${srcdir}/${pkgname}" - scons -j4 DEBUG=1 --prefix=${pkgdir}/usr --actual-prefix=/usr + scons DEBUG=1 --prefix=${pkgdir}/usr --actual-prefix=/usr } package() { diff --git a/pkg/fedora/rmlint.spec b/pkg/fedora/rmlint.spec index 4fe739ce..36fa1a6d 100644 --- a/pkg/fedora/rmlint.spec +++ b/pkg/fedora/rmlint.spec @@ -16,13 +16,13 @@ especially an extremely fast tool to remove duplicates from your filesystem. %prep %autosetup -c rmlint-%{version} -%build scons config; scons -j4 --prefix=%{buildroot}/usr --actual-prefix=/usr --libdir=lib64 +%build scons config; scons --prefix=%{buildroot}/usr --actual-prefix=/usr --libdir=lib64 %install # Build rmlint, install it into BUILDROOT/-/, # but take care rmlint thinks it's installed to /usr (--actual_prefix) -scons install -j4 --prefix=%{buildroot}/usr --actual-prefix=/usr --libdir=lib64 +scons install --prefix=%{buildroot}/usr --actual-prefix=/usr --libdir=lib64 # Find all rmlint.mo files and put them in rmlint.lang %find_lang %{name}