Merge lp:~widelands-dev/widelands/number_of_cpus_as_option into lp:widelands

Proposed by GunChleoc on 2018-11-08
Status: Merged
Merged at revision: 8914
Proposed branch: lp:~widelands-dev/widelands/number_of_cpus_as_option
Merge into: lp:widelands
Diff against target: 136 lines (+76/-31)
1 file modified
compile.sh (+76/-31)
To merge this branch: bzr merge lp:~widelands-dev/widelands/number_of_cpus_as_option
Reviewer Review Type Date Requested Status
Toni Förster 2018-11-08 Approve on 2018-11-08
Review via email: mp+358492@code.launchpad.net

Commit message

Add option to compile script to let users pick how many processor cores to compile/link with.

Description of the change

Needs testing with Mac - the Darwin detaction option was producing an error message on Linux, so I changed the syntax.

To post a comment you must log in.
8910. By GunChleoc on 2018-11-08

Fix indentation

Toni Förster (stonerl) wrote :

Does work on macOS. Just one nitpick -> see inline

review: Approve
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4190. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/452672051.
Appveyor build 3986. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_number_of_cpus_as_option-3986.

8911. By GunChleoc on 2018-11-09

Tweaked the helptext.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'compile.sh'
2--- compile.sh 2018-11-08 08:47:48 +0000
3+++ compile.sh 2018-11-09 06:44:23 +0000
4@@ -40,10 +40,15 @@
5 echo " "
6 echo "-a or --no-asan If in debug mode, switch off the AddressSanitizer."
7 echo " Release builds are created without AddressSanitizer"
8- echo " per default."
9+ echo " by default."
10 echo " "
11 echo "Compiler options:"
12 echo " "
13+ echo "-j <number> or --cores <number>"
14+ echo " Set the number of processor cores to use for"
15+ echo " compiling and linking. Default is to leave 1 core"
16+ echo " free."
17+ echo " "
18 echo "-r or --release Create a release build. If this is not set,"
19 echo " a debug build will be created."
20 echo " "
21@@ -77,33 +82,77 @@
22 BUILD_TYPE="Debug"
23 USE_ASAN="ON"
24 COMPILER="default"
25-while [ "$1" != "" ]; do
26- if [ "$1" = "--no-website" -o "$1" = "-w" ]; then
27- BUILD_WEBSITE="OFF"
28- elif [ "$1" = "--release" -o "$1" = "-r" ]; then
29- BUILD_TYPE="Release"
30- USE_ASAN="OFF"
31- elif [ "$1" = "--no-translations" -o "$1" = "-t" ]; then
32- BUILD_TRANSLATIONS="OFF"
33- elif [ "$1" = "--no-asan" -o "$1" = "-a" ]; then
34- USE_ASAN="OFF"
35- elif [ "$1" = "--gcc" ]; then
36- if [ -f /usr/bin/gcc -a /usr/bin/g++ ]; then
37- export CC=/usr/bin/gcc
38- export CXX=/usr/bin/g++
39- fi
40- elif [ "$1" = "--clang" ]; then
41- if [ -f /usr/bin/clang -a /usr/bin/clang++ ]; then
42- export CC=/usr/bin/clang
43- export CXX=/usr/bin/clang++
44- fi
45- elif [ "$1" = "--help" -o "$1" = "-h" ]; then
46- print_help
47- exit 0
48- fi
49- shift
50+
51+if [ "$(uname)" = "Darwin" ]; then
52+ CORES="$(expr $(sysctl -n hw.ncpu) - 1)"
53+else
54+ CORES="$(nproc --ignore=1)"
55+fi
56+
57+for opt in "$@"
58+do
59+ case $opt in
60+ -a|--no-asan)
61+ USE_ASAN="OFF"
62+ shift
63+ ;;
64+ -h|--help)
65+ print_help
66+ exit 0
67+ shift
68+ ;;
69+ -j|--cores)
70+ MAXCORES=$((CORES + 1))
71+ if [ "$2" ]; then
72+ if [ "$MAXCORES" -ge "$2" ]; then
73+ CORES="$2"
74+ else
75+ echo "Maximum number of supported cores is $MAXCORES."
76+ CORES="$MAXCORES"
77+ fi
78+ else
79+ echo "Call -j/--cores with a number, e.g. '-j $MAXCORES'"
80+ exit 1
81+ fi
82+ shift # past argument
83+ shift # past value
84+ ;;
85+ -r|--release)
86+ BUILD_TYPE="Release"
87+ USE_ASAN="OFF"
88+ shift
89+ ;;
90+ -t|--no-translations)
91+ BUILD_TRANSLATIONS="OFF"
92+ shift
93+ ;;
94+ -w|--no-website)
95+ BUILD_WEBSITE="OFF"
96+ shift
97+ ;;
98+ --gcc)
99+ if [ -f /usr/bin/gcc -a /usr/bin/g++ ]; then
100+ export CC=/usr/bin/gcc
101+ export CXX=/usr/bin/g++
102+ fi
103+ shift
104+ ;;
105+ --clang)
106+ if [ -f /usr/bin/clang -a /usr/bin/clang++ ]; then
107+ export CC=/usr/bin/clang
108+ export CXX=/usr/bin/clang++
109+ fi
110+ shift
111+ ;;
112+ *)
113+ # unknown option
114+ ;;
115+ esac
116 done
117
118+echo "Using ${CORES} core(s)."
119+echo ""
120+
121 if [ $BUILD_WEBSITE = "ON" ]; then
122 echo "A complete build will be created."
123 echo "You can use -w or --no-website to omit building and"
124@@ -199,11 +248,7 @@
125 cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOPTION_BUILD_WEBSITE_TOOLS=$BUILD_WEBSITE -DOPTION_BUILD_TRANSLATIONS=$BUILD_TRANSLATIONS -DOPTION_ASAN=$USE_ASAN
126 fi
127
128- if [ $(uname) == "Darwin" ]; then
129- $buildtool -j "$(expr $(sysctl -n hw.ncpu) - 1)"
130- else
131- $buildtool -j "$(nproc --ignore=1)"
132- fi
133+ $buildtool -j $CORES
134
135 return 0
136 }