From 8eb6a70c5ef74759b1be6fa6fab39f0525b8c3cd Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Thu, 17 Jan 2013 14:52:35 +0100 Subject: [PATCH] Replace build script with a smart wrapper If a user simply types `make` it will run in parallel by default, which is what we want to do in most cases. --- CMakeLists.txt | 6 ++++++ GNUmakefile | 30 ++++++++++++++++++++++++++++++ build | 2 -- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 GNUmakefile delete mode 100755 build diff --git a/CMakeLists.txt b/CMakeLists.txt index e98f267a..4e473b35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -295,3 +295,9 @@ add_custom_target (distclean COMMENT Removing CMake-generated files VERBATIM ) + +# smart wrapper that auto-parallelizes builds +file (COPY + GNUmakefile + DESTINATION ${PROJECT_BINARY_DIR} + ) diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 00000000..80754828 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,30 @@ +# GNUmakefile is processed before Makefile, which is why we arrive here +# first; when we call the other makefile, then we must specify its real +# name with the -f parameter + +# figure out the number of processors from the system, add one and round +# to nearest integer. this is the maximum number of processes we want running +# at the same time (one for each core and one stuck on I/O) +PROCS:=$(shell echo "("$$(grep -P -c '^processor\t:' /proc/cpuinfo)+1")"/1 | bc) + +# use these utilities if they are available +IONICE:=$(shell test -x "$$(which ionice)" && echo ionice -c2 -n7) +NICE:=$(shell test -x "$$(which nice)" && echo nice) + +# ignore that there may be files with these names, we are going to call +# the other make regardless +.PHONY: __everything $(MAKECMDGOALS) + +# outsource the processing to the real makefile, running in parallel and +# in a nice environment so that it doesn't hog our workstation. if there +# is nothing else happening on the box, then it will run just as fast +__everything: + @$(IONICE) $(NICE) $(MAKE) -f Makefile -j $(PROCS) $(MAKECMDGOALS) + +# automatically generate all the goals we are asked to make and delegate +# processing of them to the real makefile through the dependency (since +# everything depends on the same thing, then we only call the other make +# once). the dummy command is just there to make sure that make doesn't +# show the "Nothing to do for `foo'" message after processing +$(MAKECMDGOALS): __everything + @true diff --git a/build b/build deleted file mode 100755 index f4b077cd..00000000 --- a/build +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec ionice -c2 -n7 nice make -j $(echo "("$(grep -P -c '^processor\t:' /proc/cpuinfo)+1")"/1 | bc) "$@"