~widelands-dev/widelands/trunk

5179 by Victor Pelt
.bzrignore shouldn't be in bzr
1
#!/bin/sh
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
2
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
3
print_help () {
4
    # Print help for our options
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
5
    echo "###########################################################"
6
    echo " "
7
    echo "  Because of the many different systems Widelands"
8
    echo "  might be compiled on, we unfortunally can not"
9
    echo "  provide a simple way to prepare your system for"
10
    echo "  compilation. To ensure your system is ready, best"
11
    echo "  check https://www.widelands.org/wiki/BuildingWidelands"
12
    echo " "
13
    echo "  You will often find helpful hands at our"
14
    echo "  * IRC Chat: https://www.widelands.org/webchat/"
15
    echo "  * Forums: https://www.widelands.org/forum/"
16
    echo "  * Mailinglist: https://www.widelands.org/wiki/MailLists/"
17
    echo " "
18
    echo "  Please post your bug reports and feature requests at:"
19
    echo "  https://github.com/widelands/widelands/issues"
20
    echo " "
21
    echo "###########################################################"
22
    echo " "
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
23
    echo "Per default, this script will create a full debug build."
24
    echo "Unless explicitly switched off, AddressSanitizer will"
25
    echo "be used as well with debug builds."
26
    echo " "
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
27
    echo "You can override the defaults locally by creating a file"
28
    echo "called '.compile_defaults' listing your desired command"
29
    echo "line options in a single line. Only the first line of the"
30
    echo "file is read, further lines can be used as comments."
31
    echo "The 'COMPILE_DEFAULTS' environment variable can be set to"
32
    echo "the name of a different file to use, or if set to a"
33
    echo "non-existent name, to use the built-in defaults."
34
    echo " "
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
35
    echo "The following options are available:"
36
    echo " "
8496.1.3 by GunChleoc
Merged trunk.
37
    echo "-h or --help          Print this help."
10036 by The Widelands Bunnybot
Build System Update (#5085)
38
    echo "-q or --quiet         Suppress most of compile.sh's output."
39
    echo "-v or --verbose       Make compile.sh's output verbose."
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
40
    echo "-n or --dry-run       Only print commands, do NOT run cmake nor compile"
41
    echo "                      anything."
8729.1.12 by Lucki
Catch FileError and restore some accidentally deleted lines
42
    echo " "
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
43
    echo "Omission options and their overrides:"
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
44
    echo " "
45
    echo "-w or --no-website    Omit building of website binaries."
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
46
    echo "+w or --with-website  Enable building of website binaries."
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
47
    echo " "
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
48
    echo "-s or --skip-tests    Skip linking and executing the tests."
49
    echo "+s or --do-tests      Link and execute the tests."
9148.2.1 by Notabilis
Adding compile.sh switch -s to skip building the tests.
50
    echo " "
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
51
    echo "-a or --no-asan       If in debug mode, switch off the AddressSanitizer."
52
    echo "                      Release builds are created without AddressSanitizer"
8908.1.3 by GunChleoc
Tweaked the helptext.
53
    echo "                      by default."
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
54
    echo "+a or --with-asan     If in release mode, switch on the AddressSanitizer."
55
    echo "                      Debug builds are created with AddressSanitizer by"
56
    echo "                      default."
57
    echo " "
10070 by The Widelands Bunnybot
Resolve thread sanitizer issues (#5114)
58
    echo "-m or --no-tsan       Switch off the ThreadSanitizer (default)."
59
    echo "+m or --with-tsan     Switch on the ThreadSanitizer."
60
    echo "                      Can only be used with --no-asan, because AddressSanitizer"
61
    echo "                      cannot be enabled at the same time."
62
    echo " "
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
63
    echo "-x or --without-xdg   Disable support for the XDG Base Directory Specification."
64
    echo "+x or --with-xdg      Enable support for the XDG Base Directory Specification."
8729.1.11 by Lucki
Support $XDG_CONFIG_HOME
65
    echo " "
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
66
    echo "Compiler options:"
67
    echo " "
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
68
    echo "-j <number> or --cores <number>"
69
    echo "                      Set the number of processor cores to use for"
8908.1.3 by GunChleoc
Tweaked the helptext.
70
    echo "                      compiling and linking. Default is to leave 1 core"
71
    echo "                      free."
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
72
    echo " "
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
73
    echo "-r or --release       Create a release build. If this is not set,"
74
    echo "                      a debug build will be created."
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
75
    echo "-d or --debug         Create a debug build. This is the default,"
76
    echo "                      unless overridden locally."
11080 by The Widelands Bunnybot
Visible option of RelWithDebInfo build type (CB #4903 / GH #6542)
77
    echo "-e or --rel-with-dbg  Create a release build with debugging symbols."
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
78
    echo " "
9392 by The Widelands Bunnybot
Add cross-compile-unit optimization with Linux GCC. (#3879)
79
    if which g++ >/dev/null; then # gcc specific
80
    echo "-c or --no-cross-opt  Do not use cross compile unit optimization,"
81
    echo "                      even if available."
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
82
    echo "+c or --with-cross-opt"
83
    echo "                      Use cross compile unit optimization if available."
9392 by The Widelands Bunnybot
Add cross-compile-unit optimization with Linux GCC. (#3879)
84
    echo " "
85
    fi
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
86
    echo "--gcc                 Try to build with GCC rather than the system default."
87
    echo "                      If you built with Clang before, you will have to clean"
88
    echo "                      your build directory before switching compilers."
89
    echo "                      Expects that the compiler is in '/usr/bin/'."
90
    echo " "
91
    echo "--clang               Try to build with Clang rather than the system default."
92
    echo "                      If you built with GCC before, you will have to clean"
93
    echo "                      your build directory before switching compilers."
94
    echo "                      Expects that the compiler is in '/usr/bin/'."
95
    echo " "
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
96
    echo "--default-compiler    Use the system default compiler."
97
    echo "                      If you built with a different compiler before, you will"
98
    echo "                      have to clean your build directory before switching"
99
    echo "                      compilers."
100
    echo " "
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
101
    echo "For the AddressSanitizer output to be useful, some systems (e.g. Ubuntu Linux)"
102
    echo "require that you set a symlink to the symbolizer. For example:"
103
    echo " "
104
    echo "    sudo ln -s /usr/bin/llvm-symbolizer-3.8 /usr/bin/llvm-symbolizer"
105
    echo " "
106
    echo "More info about AddressSanitizer at:"
107
    echo " "
9204 by The Widelands Bunnybot
Noordfrees: Launchpad mirror (#3766)\n\nMirrors all changes at widelands:master to lp:widelands (1d6b62c7619a182081e1c942ae533a95d6112044)
108
    echo "    https://clang.llvm.org/docs/AddressSanitizer.html"
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
109
    echo " "
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
110
    echo " "
111
    echo "CMake options:"
112
    echo " "
113
    echo "-D...                 Any option starting with -D will be passed to cmake"
114
    echo "                      unchanged before the above options."
115
    echo " "
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
116
    return
117
  }
118
8508.1.1 by Holger Rapp
Only include ASAN in debug builds by default.
119
## Options to control the build.
8075.1.2 by GunChleoc
Streamlined code for no website.
120
BUILD_WEBSITE="ON"
9148.2.1 by Notabilis
Adding compile.sh switch -s to skip building the tests.
121
BUILD_TESTS="ON"
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
122
BUILD_TYPE="Debug"
9392 by The Widelands Bunnybot
Add cross-compile-unit optimization with Linux GCC. (#3879)
123
USE_FLTO="yes"
10030 by The Widelands Bunnybot
Honour `--(no|with)-asan`-option regardless of ARGV-order (#5078)
124
USE_ASAN="default"
125
USE_ASAN_DEFAULT="ON"
10070 by The Widelands Bunnybot
Resolve thread sanitizer issues (#5114)
126
USE_TSAN="OFF"
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
127
COMPILER="default"
8729.1.24 by Lucki
Enable it by default
128
USE_XDG="ON"
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
129
EXTRA_OPTS=""
10036 by The Widelands Bunnybot
Build System Update (#5085)
130
# Option for this script itself
131
QUIET=0
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
132
RUN=""
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
133
134
if [ -z "$COMPILE_DEFAULTS" ]; then
135
  COMPILE_DEFAULTS=.compile_defaults
136
fi
137
138
# try to set default number of cores automatically
139
140
# nproc is a GNU tool, may not be available everywhere, but it is preferable,
141
# when it is available
142
if hash nproc 2>/dev/null ; then
143
  MAXCORES="$(nproc)"
144
else
145
  # try BSD / OS X
146
  if hash sysctl 2>/dev/null ; then
147
    MAXCORES="$(sysctl -n hw.ncpu)" 2>/dev/null
148
    # we will check result later
149
  fi
150
fi
151
152
# this has the marginally useful side-effect that MAXCORES can be set in the
153
# environment when neither method works...
154
if [ $MAXCORES -gt 0 ] 2>/dev/null ; then
155
  if [ $MAXCORES -gt 1 ]; then
156
    CORES=$((MAXCORES - 1))
157
  else
158
    CORES=1
159
  fi
160
else
161
  echo "Cannot determine number of available CPU cores. Only one core will be"
162
  echo "used by default. User provided -j will be trusted."
163
  echo " "
164
  MAXCORES=0
165
  CORES=1
166
fi
167
10036 by The Widelands Bunnybot
Build System Update (#5085)
168
OLD_CLI_ARGS="$@"
169
if [ -f "$COMPILE_DEFAULTS" -a -r "$COMPILE_DEFAULTS" ]; then
170
  read LOCAL_DEFAULTS <"$COMPILE_DEFAULTS"
171
  # We want $LOCAL_DEFAULTS to be split, so no "" for it
172
  set -- $LOCAL_DEFAULTS "$@"
173
fi
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
174
9949 by The Widelands Bunnybot
make `compile.sh` show help for invalid arguments (#4979)
175
while [ $# -gt 0 ]
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
176
do
9949 by The Widelands Bunnybot
make `compile.sh` show help for invalid arguments (#4979)
177
  case $1 in
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
178
    -a|--no-asan)
179
      USE_ASAN="OFF"
180
    shift
181
    ;;
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
182
    +a|--with-asan)
183
      USE_ASAN="ON"
184
    shift
185
    ;;
10070 by The Widelands Bunnybot
Resolve thread sanitizer issues (#5114)
186
    -m|--no-tsan)
187
      USE_TSAN="OFF"
188
    shift
189
    ;;
190
    +m|--with-tsan)
191
      USE_TSAN="ON"
192
    shift
193
    ;;
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
194
    -h|--help)
195
      print_help
196
      exit 0
197
    shift
198
    ;;
199
    -j|--cores)
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
200
      case $2 in
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
201
        *[!0-9]*|'')
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
202
          echo "Call -j/--cores with a number, e.g. '-j $MAXCORES'"
203
          exit 1
204
        ;;
205
      esac
206
      if [ "$2" -lt 1 ]; then
207
        echo "Invalid number of cores was specified: $2"
208
        exit 1
209
      fi
210
      if [ "$MAXCORES" -ge "$2" -o "$MAXCORES" -eq 0 ]; then
211
        CORES="$2"
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
212
      else
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
213
        echo "Cannot set number of cores to $2, because the maximum number"
214
        echo "of supported cores is $MAXCORES."
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
215
        exit 1
216
      fi
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
217
    shift 2 # past argument and value
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
218
    ;;
219
    -r|--release)
220
      BUILD_TYPE="Release"
10030 by The Widelands Bunnybot
Honour `--(no|with)-asan`-option regardless of ARGV-order (#5078)
221
      if [ "${USE_ASAN}" = "default" ]; then
222
        USE_ASAN="OFF"
223
      fi
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
224
    shift
225
    ;;
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
226
    -d|--debug)
227
      BUILD_TYPE="Debug"
10070 by The Widelands Bunnybot
Resolve thread sanitizer issues (#5114)
228
      if [ "${USE_ASAN}" = "default" ] && [ "${USE_TSAN}" = "OFF" ]; then
10030 by The Widelands Bunnybot
Honour `--(no|with)-asan`-option regardless of ARGV-order (#5078)
229
        USE_ASAN="ON"
230
      fi
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
231
    shift
232
    ;;
11080 by The Widelands Bunnybot
Visible option of RelWithDebInfo build type (CB #4903 / GH #6542)
233
    -e|--rel-with-dbg)
234
      BUILD_TYPE="RelWithDebInfo"
235
      if [ "${USE_ASAN}" = "default" ]; then
236
        USE_ASAN="OFF"
237
      fi
238
    shift
239
    ;;
9392 by The Widelands Bunnybot
Add cross-compile-unit optimization with Linux GCC. (#3879)
240
    -c|--no-cross-opt)
241
      USE_FLTO="no"
242
    shift
243
    ;;
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
244
    +c|--with-cross-opt)
245
      USE_FLTO="yes"
246
    shift
247
    ;;
9148.2.1 by Notabilis
Adding compile.sh switch -s to skip building the tests.
248
    -s|--skip-tests)
249
      BUILD_TESTS="OFF"
250
    shift
251
    ;;
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
252
    +s|--do-tests)
253
      BUILD_TESTS="ON"
254
    shift
255
    ;;
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
256
    -w|--no-website)
257
      BUILD_WEBSITE="OFF"
258
    shift
259
    ;;
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
260
    +w|--with-website)
261
      BUILD_WEBSITE="ON"
262
    shift
263
    ;;
10036 by The Widelands Bunnybot
Build System Update (#5085)
264
    -q|--quiet)
265
      QUIET=1
266
    shift
267
    ;;
268
    -v|--verbose)
269
      QUIET=0
270
    shift
271
    ;;
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
272
    -n|--dry-run)
273
      RUN=echo
274
    shift
275
    ;;
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
276
    --gcc)
10837 by The Widelands Bunnybot
fix error detected by shellcheck in compile.sh (GH #6268 / CB #4607)
277
      if [ -f /usr/bin/gcc -a -f /usr/bin/g++ ]; then
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
278
        COMPILER=gcc
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
279
        export CC=/usr/bin/gcc
280
        export CXX=/usr/bin/g++
281
      fi
282
    shift
283
    ;;
284
    --clang)
10837 by The Widelands Bunnybot
fix error detected by shellcheck in compile.sh (GH #6268 / CB #4607)
285
      if [ -f /usr/bin/clang -a -f /usr/bin/clang++ ]; then
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
286
        COMPILER=clang
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
287
        export CC=/usr/bin/clang
288
        export CXX=/usr/bin/clang++
289
      fi
290
    shift
291
    ;;
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
292
    --default-compiler)
293
      COMPILER=default
294
      unset CC
295
      unset CXX
296
    shift
297
    ;;
298
    -x|--without-xdg)
299
      USE_XDG="OFF"
300
    shift
301
    ;;
302
    +x|--with-xdg)
303
      USE_XDG="ON"
304
    shift
305
    ;;
306
    -D*)
307
      EXTRA_OPTS="$EXTRA_OPTS $1"
8729.1.10 by Lucki
Merge branch master
308
    shift
309
    ;;
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
310
    *)
9949 by The Widelands Bunnybot
make `compile.sh` show help for invalid arguments (#4979)
311
      # unknown option
312
      echo "Unknown option:" $1
313
      echo "Use -h or --help for list of available options"
314
      exit 1
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
315
    ;;
316
  esac
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
317
done
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
318
10030 by The Widelands Bunnybot
Honour `--(no|with)-asan`-option regardless of ARGV-order (#5078)
319
if [ "${USE_ASAN}" = "default" ]; then
10070 by The Widelands Bunnybot
Resolve thread sanitizer issues (#5114)
320
  if [ "${USE_TSAN}" = "ON" ]; then
321
    USE_ASAN="OFF"
322
  else
323
    USE_ASAN="${USE_ASAN_DEFAULT}"
324
  fi
325
fi
326
if [ "${USE_ASAN}" = "ON" ] && [ "${USE_TSAN}" = "ON" ]; then
327
  echo " "
328
  echo "Cannot compile with both Address and Thread Sanitizer enabled!"
329
  exit 1
10030 by The Widelands Bunnybot
Honour `--(no|with)-asan`-option regardless of ARGV-order (#5078)
330
fi
331
10036 by The Widelands Bunnybot
Build System Update (#5085)
332
if [ $QUIET -eq 0 ]; then
333
  echo " "
334
  echo "###########################################################"
335
  echo "#     Script to simplify the compilation of Widelands     #"
336
  echo "###########################################################"
337
  echo " "
338
339
  if [ -n "$LOCAL_DEFAULTS" ]; then
340
    echo "Using default compile options from '$COMPILE_DEFAULTS':"
341
    echo "   $LOCAL_DEFAULTS"
342
    echo " "
343
    echo "Command line options:"
344
    echo "   $OLD_CLI_ARGS"
345
    echo " "
346
  fi
347
fi
348
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
349
if [ -n "$RUN" ]; then
350
  if [ $QUIET -eq 0 ]; then
351
    echo " "
352
    echo "#################################################################"
353
    echo "#  Dry run: Nothing will be changed, commands will be printed.  #"
354
    echo "#################################################################"
355
    echo " "
356
  else
357
    echo "###  Dry run: Nothing will be changed, commands will be printed."
358
  fi
359
fi
360
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
361
## Get command and options to use in update.sh
362
COMMANDLINE="$0"
363
CMD_ADD () {
364
  COMMANDLINE="$COMMANDLINE $@"
365
}
366
10036 by The Widelands Bunnybot
Build System Update (#5085)
367
if [ $QUIET -ne 0 ]; then
368
369
  CMD_ADD "$LOCAL_DEFAULTS $OLD_CLI_ARGS"
370
371
else  # Start of verbose output section
372
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
373
if [ -n "$EXTRA_OPTS" ]; then
374
  echo "Extra CMake options used: $EXTRA_OPTS"
375
  echo " "
376
  CMD_ADD "$EXTRA_OPTS"
377
fi
378
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
379
echo "Using ${CORES} core(s)."
380
echo ""
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
381
CMD_ADD "--cores ${CORES}"
382
383
echo -n "Using compiler: "
384
if [ $COMPILER = default ]; then
385
  echo "system default"
386
  CMD_ADD "--default-compiler"
387
else
388
  echo "$COMPILER"
389
  CMD_ADD "--$COMPILER"
390
fi
391
echo " "
392
393
if [ $USE_FLTO = "yes" ]; then
394
  echo "Using cross compile unit optimization if available."
395
  CMD_ADD "--with-cross-opt"
396
else
397
  echo "Not using cross compile unit optimization."
398
  CMD_ADD "--no-cross-opt"
399
fi
400
echo " "
8908.1.1 by GunChleoc
Add option to compile script to let users pick how many processor cores to compile/link with.
401
8075.1.2 by GunChleoc
Streamlined code for no website.
402
if [ $BUILD_WEBSITE = "ON" ]; then
7851.1.30 by GunChleoc
Typo.
403
  echo "A complete build will be created."
8075.1.3 by GunChleoc
Added commandline switch for translations.
404
  echo "You can use -w or --no-website to omit building and"
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
405
  echo "linking website-related executables."
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
406
  CMD_ADD "--with-website"
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
407
else
408
  echo "Any website-related code will be OMITTED in the build."
409
  echo "Make sure that you have created and tested a full"
410
  echo "build before submitting code to the repository!"
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
411
  echo "You can use +w or --with-website to build and link"
412
  echo "website-related executables."
413
  CMD_ADD "--no-website"
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
414
fi
415
echo " "
9148.2.1 by Notabilis
Adding compile.sh switch -s to skip building the tests.
416
if [ $BUILD_TESTS = "ON" ]; then
417
  echo "Tests will be built."
418
  echo "You can use -s or --skip-tests to omit building them."
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
419
  CMD_ADD "--do-tests"
9148.2.1 by Notabilis
Adding compile.sh switch -s to skip building the tests.
420
else
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
421
  echo "Tests will not be built."
422
  echo "You can use +s or --do-tests to build them."
423
  CMD_ADD "--skip-tests"
8075.1.3 by GunChleoc
Added commandline switch for translations.
424
fi
425
echo " "
8110.5.3 by GunChleoc
clang-format.
426
echo "###########################################################"
427
echo " "
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
428
if [ $BUILD_TYPE = "Release" ]; then
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
429
  echo "Creating a Release build. Use -d to create a Debug build."
430
  CMD_ADD "--release"
11080 by The Widelands Bunnybot
Visible option of RelWithDebInfo build type (CB #4903 / GH #6542)
431
elif [ $BUILD_TYPE = "Debug" ]; then
8075.1.1 by GunChleoc
Added switch to compile.sh for release builds.
432
  echo "Creating a Debug build. Use -r to create a Release build."
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
433
  CMD_ADD "--debug"
11080 by The Widelands Bunnybot
Visible option of RelWithDebInfo build type (CB #4903 / GH #6542)
434
elif [ $BUILD_TYPE = "RelWithDebInfo" ]; then
435
  echo "Creating a RelWithDebInfo build."
436
  CMD_ADD "--rel-with-dbg"
8075.1.1 by GunChleoc
Added switch to compile.sh for release builds.
437
fi
438
echo " "
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
439
if [ $USE_ASAN = "ON" ]; then
440
  echo "Will build with AddressSanitizer."
9204 by The Widelands Bunnybot
Noordfrees: Launchpad mirror (#3766)\n\nMirrors all changes at widelands:master to lp:widelands (1d6b62c7619a182081e1c942ae533a95d6112044)
441
  echo "https://clang.llvm.org/docs/AddressSanitizer.html"
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
442
  echo "You can use -a or --no-asan to switch it off."
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
443
  CMD_ADD "--with-asan"
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
444
else
445
  echo "Will build without AddressSanitizer."
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
446
  echo "You can use +a or --with-asan to switch it on."
447
  CMD_ADD "--no-asan"
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
448
fi
10070 by The Widelands Bunnybot
Resolve thread sanitizer issues (#5114)
449
if [ $USE_TSAN = "ON" ]; then
450
  echo "Will build with ThreadSanitizer."
451
  echo "https://clang.llvm.org/docs/ThreadSanitizer.html"
452
  echo "You can use -m or --no-tsan to switch it off."
453
  CMD_ADD "--with-tsan"
454
else
455
  echo "Will build without ThreadSanitizer."
456
  echo "You can use +m or --with-tsan to switch it on."
457
  CMD_ADD "--no-tsan"
458
fi
8729.1.4 by Lucki
add xdg option to compile.sh
459
if [ $USE_XDG = "ON" ]; then
460
  echo " "
461
  echo "Basic XDG Base Directory Specification will be used on Linux"
462
  echo "if no existing \$HOME/.widelands folder is found."
463
  echo "The widelands user data can be found in \$XDG_DATA_HOME/widelands"
464
  echo "and defaults to \$HOME/.local/share/widelands."
8729.1.11 by Lucki
Support $XDG_CONFIG_HOME
465
  echo "The widelands user configuration can be found in \$XDG_CONFIG_HOME/widelands"
466
  echo "and defaults to \$HOME/.config/widelands."
8729.1.4 by Lucki
add xdg option to compile.sh
467
  echo "See https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html"
468
  echo "for more information."
469
  echo " "
9952 by The Widelands Bunnybot
`compile.sh` improvements (#4980)
470
  CMD_ADD "--with-xdg"
471
else
472
  CMD_ADD "--without-xdg"
8729.1.4 by Lucki
add xdg option to compile.sh
473
fi
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
474
echo " "
475
echo "###########################################################"
476
echo " "
477
echo "Call 'compile.sh -h' or 'compile.sh --help' for help."
478
echo ""
8075.1.1 by GunChleoc
Added switch to compile.sh for release builds.
479
echo "For instructions on how to adjust options and build with"
480
echo "CMake, please take a look at"
9204 by The Widelands Bunnybot
Noordfrees: Launchpad mirror (#3766)\n\nMirrors all changes at widelands:master to lp:widelands (1d6b62c7619a182081e1c942ae533a95d6112044)
481
echo "https://www.widelands.org/wiki/BuildingWidelands/."
8075.1.1 by GunChleoc
Added switch to compile.sh for release builds.
482
echo " "
483
echo "###########################################################"
484
echo " "
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
485
10036 by The Widelands Bunnybot
Build System Update (#5085)
486
fi  # End of verbose output section
487
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
488
######################################
7119.6.12 by Hans Joachim Desserud
Made a fallback solution if ninja is not available.
489
# Definition of some local variables #
490
######################################
7119.6.15 by Hans Joachim Desserud
Reorganize the buildtool check, leaving a gap for variation
491
buildtool="" #Use ninja by default, fall back to make if that is not available.
7119.6.12 by Hans Joachim Desserud
Made a fallback solution if ninja is not available.
492
######################################
493
494
495
######################################
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
496
#    Definition of some functions    #
497
######################################
498
  # Check basic stuff
499
  basic_check () {
500
    # Check whether the script is run in a widelands main directory
501
    if ! [ -f src/wlapplication.cc ] ; then
502
      echo "  This script must be run from the main directory of the widelands"
503
      echo "  source code."
504
      exit 1
505
    fi
506
    return 0
507
  }
508
7119.6.14 by Hans Joachim Desserud
Check whether ninja is available and set buildtool up front
509
  set_buildtool () {
10036 by The Widelands Bunnybot
Build System Update (#5085)
510
    GENERATOR=""
7119.6.19 by Hans Joachim Desserud
Catch alternative binary name for ninja
511
    #Defaults to ninja, but if that is not found, we use make instead
7119.6.16 by Hans Joachim Desserud
Make check whether ninja is installed work properly
512
    if [ `command -v ninja` ] ; then
7119.6.15 by Hans Joachim Desserud
Reorganize the buildtool check, leaving a gap for variation
513
      buildtool="ninja"
10036 by The Widelands Bunnybot
Build System Update (#5085)
514
      GENERATOR="-G Ninja"
7119.6.19 by Hans Joachim Desserud
Catch alternative binary name for ninja
515
    #On some systems (most notably Fedora), the binary is called ninja-build
516
    elif [ `command -v ninja-build` ] ; then
517
      buildtool="ninja-build"
10036 by The Widelands Bunnybot
Build System Update (#5085)
518
      GENERATOR="-G Ninja"
7119.6.22 by Hans Joachim Desserud
Case for systems refering to GNU make as gmake
519
    #... and some systems refer to GNU make as gmake
520
    elif [ `command -v gmake` ] ; then
521
      buildtool="gmake"
7119.6.15 by Hans Joachim Desserud
Reorganize the buildtool check, leaving a gap for variation
522
    else
7119.6.14 by Hans Joachim Desserud
Check whether ninja is available and set buildtool up front
523
      buildtool="make"
524
    fi
525
  }
526
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
527
  # Compile Widelands
528
  compile_widelands () {
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
529
    $RUN cmake $GENERATOR .. $EXTRA_OPTS                       \
530
               -DCMAKE_BUILD_TYPE=$BUILD_TYPE                  \
531
               -DOPTION_BUILD_WEBSITE_TOOLS=$BUILD_WEBSITE     \
532
               -DOPTION_BUILD_TESTS=$BUILD_TESTS               \
533
               -DOPTION_ASAN=$USE_ASAN                         \
534
               -DOPTION_TSAN=$USE_TSAN                         \
535
               -DUSE_XDG=$USE_XDG                              \
536
               -DUSE_FLTO_IF_AVAILABLE=${USE_FLTO}
7119.6.20 by Hans Joachim Desserud
Indentation
537
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
538
    $RUN $buildtool -j $CORES
8893.1.1 by franku
use more processor units by default in the compile script
539
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
540
    return 0
541
  }
542
543
  # Remove old and move newly compiled files
544
  move_built_files () {
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
545
    $RUN rm  -f ../VERSION || true
546
    $RUN rm  -f ../widelands || true
547
548
    $RUN rm  -f ../wl_map_object_info || true
549
    $RUN rm  -f ../wl_map_info || true
550
551
    $RUN cp VERSION ../VERSION
552
    $RUN mv src/widelands ../widelands
8319.1.1 by franku
move website executables to base dir
553
554
    if [ $BUILD_WEBSITE = "ON" ]; then
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
555
      $RUN mv ../build/src/website/wl_create_spritesheet ../wl_create_spritesheet
556
      $RUN mv ../build/src/website/wl_map_object_info ../wl_map_object_info
557
      $RUN mv ../build/src/website/wl_map_info ../wl_map_info
8319.1.1 by franku
move website executables to base dir
558
    fi
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
559
    return 0
560
  }
561
7119.6.1 by Hans Joachim Desserud
Always create update script
562
  create_update_script () {
9204 by The Widelands Bunnybot
Noordfrees: Launchpad mirror (#3766)\n\nMirrors all changes at widelands:master to lp:widelands (1d6b62c7619a182081e1c942ae533a95d6112044)
563
    # First check if this is an git checkout at all - only in that case,
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
564
    # creation of a script makes any sense.
9204 by The Widelands Bunnybot
Noordfrees: Launchpad mirror (#3766)\n\nMirrors all changes at widelands:master to lp:widelands (1d6b62c7619a182081e1c942ae533a95d6112044)
565
    if [ -n "$(git status -s)" ]; then
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
566
      echo "You don't appear to be using Git, or your working tree is not clean."
567
      echo "An update script will not be created."
10036 by The Widelands Bunnybot
Build System Update (#5085)
568
      if [ $QUIET -eq 0 ]; then
569
        git status
570
      fi
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
571
      return 0
6810.2.68 by GunChleoc
Some merging cleanup - needs testing:
572
    fi
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
573
      $RUN rm -f update.sh || true
574
      if [ -z "$RUN" ]; then
575
        cat > update.sh << END_SCRIPT
7119.6.26 by Hans Joachim Desserud
Create update script using cat. Not superhappy about breaking indentation that way though...
576
#!/bin/sh
577
echo "################################################"
578
echo "#            Widelands update script.          #"
579
echo "################################################"
580
echo " "
581
582
set -e
583
if ! [ -f src/wlapplication.cc ] ; then
584
  echo "  This script must be run from the main directory of the widelands"
585
  echo "  source code."
586
  exit 1
587
fi
588
9204 by The Widelands Bunnybot
Noordfrees: Launchpad mirror (#3766)\n\nMirrors all changes at widelands:master to lp:widelands (1d6b62c7619a182081e1c942ae533a95d6112044)
589
# Checkout current branch and pull latest master
590
git checkout
591
git pull https://github.com/widelands/widelands.git master
592
8937.2.1 by franku
use compile.sh if running update.sh
593
$COMMANDLINE
7119.6.26 by Hans Joachim Desserud
Create update script using cat. Not superhappy about breaking indentation that way though...
594
595
echo " "
596
echo "################################################"
597
echo "#      Widelands was updated successfully.     #"
598
echo "# You should be able to run it via ./widelands #"
599
echo "################################################"
600
END_SCRIPT
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
601
602
      else  # dry run
603
        echo 'cat > update.sh <<END_SCRIPT'
604
        echo "   # ..."
605
        echo "   $COMMANDLINE"
606
        echo "   # ..."
607
        echo "END_SCRIPT"
608
      fi
609
610
      $RUN chmod +x ./update.sh
611
      if [ $QUIET -eq 0 -a -z "$RUN" ]; then
10036 by The Widelands Bunnybot
Build System Update (#5085)
612
        echo "The update script has successfully been created."
613
      fi
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
614
  }
615
######################################
616
617
618
619
######################################
620
#    Here is the "main" function     #
621
######################################
5179 by Victor Pelt
.bzrignore shouldn't be in bzr
622
set -e
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
623
basic_check
7119.6.14 by Hans Joachim Desserud
Check whether ninja is available and set buildtool up front
624
set_buildtool
9204 by The Widelands Bunnybot
Noordfrees: Launchpad mirror (#3766)\n\nMirrors all changes at widelands:master to lp:widelands (1d6b62c7619a182081e1c942ae533a95d6112044)
625
626
# Dependency check doesn't work with ninja, so we do it manually here
627
if [ $BUILD_TYPE = "Debug" -a \( $buildtool = "ninja" -o $buildtool = "ninja-build" \) ]; then
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
628
  $RUN utils/build_deps.py
9204 by The Widelands Bunnybot
Noordfrees: Launchpad mirror (#3766)\n\nMirrors all changes at widelands:master to lp:widelands (1d6b62c7619a182081e1c942ae533a95d6112044)
629
fi
630
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
631
$RUN mkdir -p build
632
$RUN cd build
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
633
compile_widelands
634
move_built_files
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
635
$RUN cd ..
7119.6.1 by Hans Joachim Desserud
Always create update script
636
create_update_script
10036 by The Widelands Bunnybot
Build System Update (#5085)
637
638
if [ $QUIET -eq 0 ]; then  # Start of verbose output section
639
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
640
echo " "
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
641
echo "###########################################################"
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
642
if [ -z "$RUN" ]; then
643
  echo "# Congratulations! Widelands has been built successfully  #"
644
else
645
  echo "# Widelands would have been built                         #"
646
fi
8075.1.4 by GunChleoc
Print settings summary at end of script.
647
echo "# with the following settings:                            #"
648
echo "#                                                         #"
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
649
if [ $BUILD_TYPE = "Release" ]; then
8075.1.4 by GunChleoc
Print settings summary at end of script.
650
  echo "# - Release build                                         #"
11080 by The Widelands Bunnybot
Visible option of RelWithDebInfo build type (CB #4903 / GH #6542)
651
elif [ $BUILD_TYPE = "Debug" ]; then
8075.1.4 by GunChleoc
Print settings summary at end of script.
652
  echo "# - Debug build                                           #"
11080 by The Widelands Bunnybot
Visible option of RelWithDebInfo build type (CB #4903 / GH #6542)
653
elif [ $BUILD_TYPE = "RelWithDebInfo" ]; then
654
  echo "# - RelWithDebInfo build                                  #"
8075.1.4 by GunChleoc
Print settings summary at end of script.
655
fi
9148.2.1 by Notabilis
Adding compile.sh switch -s to skip building the tests.
656
if [ $BUILD_TESTS = "ON" ]; then
657
  echo "# - Tests                                                 #"
658
else
659
  echo "# - No tests                                              #"
660
fi
8075.1.4 by GunChleoc
Print settings summary at end of script.
661
8729.1.11 by Lucki
Support $XDG_CONFIG_HOME
662
if [ $USE_XDG = "ON" ]; then
663
  echo "# - With support for the XDG Base Directory Specification #"
664
else
665
  echo "# - Without support for the XDG Base Directory            #"
8729.1.16 by GunChleoc
Code review
666
  echo "#   Specification                                         #"
8729.1.11 by Lucki
Support $XDG_CONFIG_HOME
667
fi
8075.1.4 by GunChleoc
Print settings summary at end of script.
668
if [ $BUILD_WEBSITE = "ON" ]; then
669
  echo "# - Website-related executables                           #"
670
else
671
  echo "# - No website-related executables                        #"
672
fi
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
673
if [ -z "$RUN" ]; then
674
  echo "#                                                         #"
675
  echo "# You should now be able to run Widelands via             #"
676
  echo "# typing ./widelands + ENTER in your terminal             #"
677
  echo "#                                                         #"
678
  echo "# You can update Widelands via running ./update.sh        #"
679
  echo "# in the same directory that you ran this script in.      #"
680
fi
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
681
echo "###########################################################"
10036 by The Widelands Bunnybot
Build System Update (#5085)
682
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
683
elif [ -z "$RUN" ]; then
10036 by The Widelands Bunnybot
Build System Update (#5085)
684
  echo "Widelands has been built successfully."
10319 by The Widelands Bunnybot
`compile.sh` fix and tweaks (#5465)
685
else
686
  echo "###  Dry run of compile.sh has completed successfully."
10036 by The Widelands Bunnybot
Build System Update (#5085)
687
fi  # End of verbose output section
5477 by Nasenbaer
Move build_and_run.sh to compile.sh and rework it, to be much more intuitive for users.
688
######################################