Debian Codegraph @

docs/hacking/compiling.rst

raw
1 Compiling Instructions
2 ======================
3
4 The methods for compiling Angband vary by platform and by build system. If
5 you get Angband working on a different platform or build system please let us
6 know so we can add to this file. Unless otherwise noted, all the commands
7 listed are to be run from top-level directory of the Angband source files.
8
9 .. contents:: Contents
10 :local:
11
12 macOS
13 -----
14
15 To build the new Cocoa front-end::
16
17 cd src
18 make -f Makefile.osx
19
20 That'll create a self-contained Mac application, Angband.app, in the directory
21 above src. You may use that application where it is or move it to wherever
22 is convenient for you.
23
24 By default, the current Makefile.osx builds an application that'll run natively
25 on x86_64 or arm64 machines. If only one of those architectures is of interest
26 to you or the version of Xcode you have doesn't support building both (a
27 typical error message in that case is something like ``/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:784:2: error: Unsupported architecture``),
28 you can change the architectures built by setting ARCHS on the command line of
29 make. To only build for x86_64, for instance, you would use::
30
31 cd src
32 make -f Makefile.osx clean
33 make -f Makefile.osx ARCHS=x86_64
34
35 (the clean step is to ensure that nothing from a previous build would cause
36 trouble; you'll typically need to do that if you've built it before and then
37 want to change the set of architectures to use). To build for multiple
38 architectures, use a list of architectures separated by whitespace, which
39 you'll have to quote. This is the equivalent to what Makefile.osx does by
40 default::
41
42 make -f Makefile.osx ARCHS="x86_64 arm64"
43
44 Debug build
45 ~~~~~~~~~~~
46
47 This will generate a debugging build like that described in the Linux section::
48
49 cd src
50 make -f Makefile.osx clean
51 make -f Makefile.osx OPT="-g -O1 -fno-omit-frame-pointer -fsanitize=undefined -fsanitize=address"
52
53 The clean step is there to clean out object files that were compiled with the
54 default options. The "-g" adds debugging symbols.
55 "-O1 -fno-omit-frame-pointer" dials back the optimization to get call stack
56 traces that are easier to interpret. For even clearer call stack traces, you
57 could add "-fno-optimize-sibling-calls" to the options or omit optimization
58 entirely by replacing "-O1 -fno-omit-frame-pointer" with "-O0".
59 "-fsanitize=address -fsanitize=undefined" enables the AddressSanitizer and
60 UndefinedBehaviorSanitizer tools.
61
62 To run the generated executable under Xcode's command-line debugger, lldb, do
63 this if you are already in the src directory from the compilation step::
64
65 cd ../Angband.app/Contents/MacOS
66 lldb ./angband
67
68 Test cases
69 ~~~~~~~~~~
70
71 To compile and run the unit tests, do this::
72
73 cd src
74 make -f Makefile.osx tests
75
76 If you want to rerun just one part, say monster/attack, of the unit tests,
77 that's most easily done by::
78
79 cd src/tests
80 monster/attack.exe
81
82 Previous versions put the test executables in src/tests/bin. With those
83 versions, the second line above would be::
84
85 bin/monster/attack
86
87 The reason for changing directories to src/tests is to match up with how the
88 tests were compiled: they expect Angband's configuration data to be in
89 ../../lib.
90
91 Statistics build
92 ~~~~~~~~~~~~~~~~
93
94 The Mac front end bypasses main.c and can not use the statistics front end.
95 It is possible to enable the debugging commands related to statistics (see
96 the descriptions for ``S``, ``D``, and ``P`` in :ref:`DebugDungeon`). To do so,
97 include "-DUSE_STATS" in the setting for OPT passed to make. The equivalent
98 of the standard build with those debugging commands enabled would be::
99
100 cd src
101 make -f Makefile.osx OPT="-DUSE_STATS -O2"
102
103 If you had already built everything without statistcs enabled, you would need to
104 run either "rm wiz-stats.o" or "make -f Makefile.osx clean" immediately after
105 running "cd src".
106
107 Linux / other UNIX
108 ------------------
109
110 Native builds
111 ~~~~~~~~~~~~~
112
113 Linux builds using autotools. There are several different front ends that you
114 can optionally build (GCU, SDL, SDL2, and X11) using arguments to configure
115 such as --enable-sdl, --disable-x11, etc. Each front end has different
116 dependencies (e.g. ncurses, SDL libraries, etc).
117
118 If your source files are from cloning the git repository, you'll first need
119 to run this to create the configure script::
120
121 ./autogen.sh
122
123 That is not necessary if your source files are from the source archive,
124 a .tar.gz file, for a release.
125
126 To build Angband to be run in-place, then run this::
127
128 ./configure --with-no-install [other options as needed]
129 make
130
131 That'll create an executable in the src directory. You can run it from the
132 same directory where you ran make with::
133
134 src/angband
135
136 To see what command line options are accepted, use::
137
138 src/angband -?
139
140 Note that some of Angband's makefiles (src/Makefile and src/tests/Makefile are
141 the primary offenders) assume features present in GNU make. If the default
142 make on your system is not GNU make, you'll likely have to replace instances
143 of make in the quoted commands with whatever will run GNU make. On OpenBSD,
144 for instance, that is gmake (which can be installed by running "pkg_add gmake").
145
146 On systems where there's several C compilers, ./configure may choose the
147 wrong one. One example of that is on OpenBSD 6.9 when building Angband with
148 SDL2: ./configure chooses gcc but the installed version of gcc can't handle
149 the SDL2 header files that are installed via pkg_add. To override ./configure's
150 default selection of the compiler, use::
151
152 env CC=the_good_compiler ./configure [the appropriate configure options]
153
154 Replace the_good_compiler in that command with the command for running the
155 compiler that you want. For OpenBSD 6.9 when compiling with SDL2, you'd
156 replace the_good_compiler with cc or clang.
157
158 To build Angband to be installed in some other location, run this::
159
160 ./configure --prefix /path/to [other options as needed]
161 make
162 make install
163
164 On some BSDs, you may need to copy install-sh into lib/ and various
165 subdirectories of lib/ in order to install correctly.
166
167 Compilation with CMake
168 ~~~~~~~~~~~~~~~~~~~~~~
169
170 The compilation process with CMake requires a version greater than 3,
171 by default the compilation process uses the X11 front end unless
172 one or more of the other graphical front ends are selected. The graphical front
173 ends are: GCU, SDL, SDL2 and X11. All of the following generate a
174 self-contained directory, build, that you can move elsewhere or rename. To
175 run the result, change directories to build (or whatever you renamed it to) and
176 run ./Angband .
177
178 To build Angband with the X11 front end::
179
180 mkdir build && cd build
181 cmake ..
182 make
183
184 If you want to build the X11 front end while building one of the other
185 graphical front ends, the option to pass to cmake is -DSUPPORT_X11_FRONTEND=ON .
186
187 To build Angband with the SDL front end::
188
189 mkdir build && cd build
190 cmake -DSUPPORT_SDL_FRONTEND=ON ..
191 make
192
193 To build Angband with the SDL2 front end::
194
195 mkdir build && cd build
196 cmake -DSUPPORT_SDL2_FRONTEND=ON ..
197 make
198
199 To build Angband with the GCU front end::
200
201 mkdir build && cd build
202 cmake -DSUPPORT_GCU_FRONTEND=ON ..
203 make
204
205 On OpenBSD (at least with OpenBSD 6.9), there's known issues with detecting
206 the software needed for the GCU front end. As a workaround, you could use
207 this instead::
208
209 mkdir build && cd build
210 mkdir -p ncursesw/include/ncursesw
211 ln -s /usr/include/ncurses.h ncursesw/include/ncursesw
212 mkdir -p ncursesw/lib
213 ln -s /usr/lib/libncursesw.so* ncursesw/lib
214 cmake -DCMAKE_PREFIX_PATH=`pwd`/ncursesw -DSUPPORT_GCU_FRONTEND=ON ..
215 make
216
217 You can build support for more than one of the graphical front ends by setting
218 all the desired SUPPORT_*_FRONTEND options when running cmake (the exception to
219 this are the SDL and SDL2 which can not be built at the same time). If you
220 want the executable to have support for sound, pass -DSUPPORT_SDL_SOUND=ON or
221 -DSUPPORT_SDL2_SOUND=ON to cmake (as with the SDL and SDL2 front ends, you
222 can't build support for both SDL and SDL2 sound; it is also not possible to
223 build the SDL front end with SDL2 sound or the SDL2 front end with SDL sound).
224
225 There are options to not build a self-contained installation and, instead,
226 organize the files for a typical Linux or Unix layout. One such option
227 installs the executable as setgid so the high score and save files can be
228 stored in a centralized location for multiple users. To enable that option,
229 pass -DSHARED_INSTALL=ON to cmake. To specify the group used for the setgid
230 executable, pass -DINSTALL_GROUP_ID=xxx to cmake where you replace xxx with
231 the name or number of the group to use. If you do not set the group, the games
232 group will be used. Another option creates a read-only installation with any
233 variable state, including the high score and save files, stored on a per-user
234 basis in the user's own directories. To enable that option, pass
235 -DREADONLY_INSTALL=ON to cmake. Turning on both SHARED_INSTALL and
236 READONLY_INSTALL is not supported and will cause cmake to exit with an error.
237 Turning either SHARED_INSTALL or READONLY_INSTALL when SUPPORT_WINDOWS_FRONTEND
238 is on is also not supported and will cause cmake to exit with an error. To
239 customize where the shared and read-only installations place files, pass
240 -DCMAKE_INSTALL_PREFIX=prefix to install all the files within the given prefix
241 (i.e. using -DCMAKE_INSTALL_PREFIX=/opt/Angband-4.2.3 would place all the files
242 within /opt/Angband-4.2.3 or its subdirectories). For finer-grained placement
243 of the files within the given prefix, you could also set CMAKE_INSTALL_BINDIR
244 (for the subdirectory of prefix where the executable will be placed; by
245 default that is bin), CMAKE_INSTALL_DATAROOTDIR (for the subdirectory of
246 prefix to hold read-only data not configured for the site; by default that is
247 share), CMAKE_INSTALL_SYSCONFDIR (for the subdrectory of prefix to hold data
248 configured for the site; by default that is etc), and
249 CMAKE_INSTALL_SHAREDSTATEDIR (for the subdirectory of prefix to hold writable
250 persistent state; by default that is com). Because paths to the data are
251 hardwired in the executable, setting the destination directory when running
252 make (i.e. by setting DESTDIR) is not supported and will not work in general:
253 set the destination when running cmake by setting the variables mentioned above.
254
255 Cross-building for Windows with Mingw
256 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
257
258 Many developers (as well as the auto-builder) build Angband for Windows using
259 Mingw on Linux. This requires that the necessary Mingw packages are all
260 installed.
261
262 This type of build now also uses autotools so the overall procedure is very
263 similar to that for a native build. The key difference is setting up to
264 cross-compile when running configure.
265
266 If your source files are from cloning the git repository, you'll first need
267 to run this to create the configure script::
268
269 ./autogen.sh
270
271 That is not necessary if your source files are from the source archive,
272 a .tar.gz file, for a release.
273
274 Then configure the cross-comilation and perform the compilation itself::
275
276 ./configure --enable-win --build=i686-pc-linux-gnu --host=i686-w64-mingw32
277 make install
278
279 You may need to change the --build and --host options there to match your
280 system. Mingw installs commands like 'i686-w64-mingw32-gcc'. The value of --host
281 should be that same command with the '-gcc' removed. Instead of i686 you may
282 see i686, amd64, etc. The value of --build should be the host you're building
283 on (see http://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.68/html_node/Specifying-Target-Triplets.html#Specifying%20Names for
284 gory details of how these triplets are arrived at). The 'make install' step
285 only works with very recent version. For older ones, use this instead of the
286 last step::
287
288 make
289 cp src/angband.exe .
290 cp src/win/dll/*.dll .
291
292 To run the result, you can use wine like this::
293
294 wine angband.exe
295
296 TODO: except for recent versions (after Angband 4.2.3) you likely need to
297 manually disable curses (add --disable-curses to the options passed to
298 configure), or the host curses installation will be found causing the build
299 process to fail when linking angband.exe (the error message will likely be
300 "cannot find -lncursesw" and "cannot find -ltinfo"). Most of the --with or
301 --enable options for configure are not appropriate when using --enable-win.
302 The ones that are okay are --with-private-dirs (on by default),
303 --with-gamedata-in-lib (has no effect), --enable-release,
304 and --enable-skip-old-int-typedefs.
305
306 Debug build
307 ~~~~~~~~~~~
308
309 **WARNING** this build is intended primarily for debugging purposes. It might have a somewhat slower performance, higher memory requirements and panic saves don't always work (in case of a crash there is a higher chance of losing progress).
310
311 When debugging crashes it can be very useful to get more information about *what exactly* went wrong. There are many tools that can detect common issues and provide useful information. Two such tools that are best used together are AddressSanitizer (ASan) and UndefinedBehaviorSanitizer (UBSan). To use them you'll need to enable them when compiling angband::
312
313 ./configure [options]
314 SANITIZE_FLAGS="-fsanitize=undefined -fsanitize=address" make
315
316 Note that compiling with this tools will require installing additional dependancies: libubsan libasan (names of the packages might be different in your distribution).
317
318 There is probably a way to get these tools to work on Windows. If you know how, please add the information to this file.
319
320 Test cases
321 ~~~~~~~~~~
322
323 To compile and run the unit tests if you used ./configure --with-no-install,
324 do this::
325
326 make tests
327
328 If you want to rerun just one part, say monster/attack, of the unit tests,
329 that's most easily done by directly running from the top-level directory::
330
331 src/tests/monster/attack.exe
332
333 Previous versions put the test executables in src/tests/bin. With those
334 versions, the line above would be::
335
336 src/tests/bin/monster/attack
337
338 There's a separate set of tests that use scripts to control a character in
339 the full game. To run those tests, you'll need to enable the test module
340 when running configure and then run the run-tests script in the top-level
341 directory::
342
343 ./configure --with-no-install --enable-test
344 make
345 ./run-tests
346
347 To compile and run the unit tests and run the run-tests script while using
348 CMake, do the following::
349
350 mkdir build && cd build
351 cmake -DSUPPORT_TEST_FRONTEND=ON ..
352 make alltests
353
354 If you only want the unit tests while using CMake, it's a little simpler::
355
356 mkdir build && cd build
357 cmake ..
358 make allunittests
359
360 Statistics build
361 ~~~~~~~~~~~~~~~~
362
363 If building directly for Linux/Unix using configure, you can get the statistics
364 front end and support for the debugging commands related to statistics (see
365 the descriptions for ``S``, ``D``, and ``P`` in :ref:`DebugDungeon`) by
366 including --enable-stats in the options to configure. For that to work, you'll
367 need to have sqlite3's headers and libraries installed (on Debian and Ubuntu,
368 the libsqlite3-dev package and its dependencies provides those). If using
369 CMake, pass -DSUPPORT_STATS_FRONTEND=ON to cmake to get the statistics front
370 end and support for the debugging commnands related to statistics; like builds
371 with configure that use --enable-stats, that requires sqlite3. With CMake, you
372 also have an the option to only include support for the debugging commands
373 related to statistics: pass -DSUPPORT_STATS_BACKEND=ON to cmake and either do
374 nothing for SUPPORT_STATS_FRONTEND or explicitly turn it off by passing
375 -DSUPPORT_STATS_FRONTEND=OFF to cmake.
376
377 When cross-compiling for Windows, the statistics front end is not useful
378 (the Windows front end bypasses main.c and can not use the statistics front
379 end). With configure, you could include support for debugging commands
380 related to statistics by setting CFLAGS to include -DUSE_STATS::
381
382 ./configure [your cross-compiling options] --enable-win CFLAGS=-DUSE_STATS
383
384 Windows
385 -------
386
387 Using MinGW
388 ~~~~~~~~~~~
389
390 This build now also uses autotools, so should be very similar to the Linux
391 build. Open the MinGW shell (MSYS) by running msys.bat.
392
393 If your source files are from cloning the git repository, you'll first need
394 to run this in the directory to create the configure script::
395
396 ./autogen.sh
397
398 That is not necessary if your source files are from the source archive,
399 a .tar.gz file, for a release.
400
401 Then run these commands::
402
403 ./configure --enable-win
404 make install
405
406 The last step only works with very recent versions. For older ones, use
407 "make" rather than "make install" and copy src/angband.exe,
408 src/win/dll/libpng12.dll, and src/win/dll/zlib1.dll to the top-level directory.
409
410 Using Cygwin (with MinGW)
411 ~~~~~~~~~~~~~~~~~~~~~~~~~
412
413 Use this option if you want to build a native Windows executable that
414 can run with or without Cygwin.
415
416 Use the Cygwin setup.exe to install the mingw-gcc-core package and any
417 dependencies suggested by the installer.
418
419 If your source files are from cloning the git repository, you'll first need
420 to run this in the directory to create the configure script::
421
422 ./autogen.sh
423
424 That is not necessary if your source files are from the source archive,
425 a .tar.gz file, for a release.
426
427 Then run these commands::
428
429 ./configure --enable-win --host=i686-pc-mingw32
430 make install
431
432 The last step only works with very recent versions. For older ones, use
433 "make" rather than "make install" and copy src/angband.exe,
434 src/win/dll/libpng12.dll, and src/win/zlib1.dll to the top-level directory.
435
436 If you want to build the Unix version of Angband that uses X11 or
437 Curses and run it under Cygwin, then follow the native build
438 instructions (./autogen.sh; ./configure; make; make install).
439
440 Using MSYS2 (with MinGW64)
441 ~~~~~~~~~~~~~~~~~~~~~~~~~~
442
443 Install the dependencies by::
444
445 pacman -S make mingw-w64-x86_64-toolchain mingw-w64-x86_64-ncurses
446
447 Additional dependencies for SDL2 client::
448
449 pacman -S mingw-w64-x86_64-SDL2 mingw-w64-x86_64-SDL2_image \
450 mingw-w64-x86_64-SDL2_ttf
451
452 Then run the following to compile with ncurses::
453
454 cd src
455 make -f Makefile.msys2
456
457 For SDL2, do::
458
459 cd src
460 make -f Makefile.msys2.sdl2
461
462 Very recent versions of Makefile.msys2.sdl2 allow use of SDL2 sound; to build
463 with that you'll need SDL2_mixer installed in addtion to the other SDL2
464 libraries mentioned above::
465
466 pacman -S mingw-w64-x86_64-SDL2_mixer
467
468 Then the executable with SDL2 sound support can be built with::
469
470 cd src
471 make -f Makefile.msys2.sdl2 SOUND=yes
472
473 Once built, go to the root of the source directory and start angband by::
474
475 ./angband.exe -uPLAYER
476
477 The ncurses client may not be able to start properly from msys2 shell, try::
478
479 start bash
480
481 and run::
482
483 export TERM=
484 ./angband.exe -uPLAYER
485
486 Using eclipse (Indigo) on Windows (with MinGW)
487 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
488
489 * For eclipse with EGit, select File | Import..., Git | Projects from Git, Next >
490 * Clone your/the upstream repo, or Add your existing cloned repo, Next >
491 * Select "Use the New Projects Wizard", Finish
492 * In the New Project Wizard, select C/C++ | Makefile Project with Existing Code, Next >
493 * Give the project a name (Angband),
494 * navigate to the repo you cloned in "Existing Code Location",
495 * Select "C", but not "C++"
496 * Choose "MinGW GCC" Toolchain, Finish
497 * Once the project is set up, r-click | Properties
498 * Go to C/C++ Build | Toolchain Editor, select "Gnu Make Builder" instead of "CDT Internal Builder"
499 * go to C/C++ Build, uncheck "Generate Makefiles automatically"
500
501 You still need to run ./autogen.sh, if your source files are from cloning the
502 git repository, and ./configure manually, outside eclipse (see above)
503
504 Using Visual Studio
505 ~~~~~~~~~~~~~~~~~~~
506
507 Blue Baron has detailed instructions for setting this up at:
508
509 src/win/angband_visual_studio_step_by_step.txt
510
511 Statistics build
512 ~~~~~~~~~~~~~~~~
513
514 The Windows front end bypasses main.c and can not use the statistics front end.
515 It is possible to enable the debugging commands related to statistics (see
516 the descriptions for ``S``, ``D``, and ``P`` in :ref:`DebugDungeon`). To do
517 so, set your compiler options so that the USE_STATS preprocessor macro is set.
518 When using mingw (either stand-alone or as part of Cygwin) and configure,
519 include CFLAGS=-DUSE_STATS in the options to configure to do that.
520
521 Nintendo DS / Nintendo 3DS
522 --------------------------
523
524 Builds for the Nintendo DS are made using devkitARM and libnds (or libctru for
525 the Nintendo 3DS respectively). All required dependencies can be installed by
526 selecting the appropriate package group while following the installation
527 instructions for devkitPro ( https://devkitpro.org/wiki/Getting_Started ).
528
529 The executable can then be built using::
530
531 cd src
532 make -f Makefile.nds
533
534 This will generate ``angband.nds`` in the current directory. For the Nintendo
535 3DS, replace the ``Makefile.nds`` part of the command with ``Makefile.3ds``,
536 and ``angband.3dsx`` will be generated instead.
537
538 Debugging
539 ~~~~~~~~~
540
541 Homebrew can be debugged using a gdbstub-enabled emulator, such as a Windows Dev+ build
542 of DeSmuMe (if you really dare to, note that it is very slow compared to real hardware)
543 for the Nintendo DS or Citra for the Nintendo 3DS. A Nintendo 3DS that has been modified
544 with custom firmware (such as Luma3DS) may also have the ability to debug homebrew on-device.
545
546 It is recommended to set/export ``NDS_DEBUG=1`` and to do a clean build when debugging,
547 as this disables some optimization and enables more debugging information.
548
549 Once the GDB server has been set up (and the host and port noted), the GDB client
550 can be loaded with the executable information::
551
552 /path/to/devkitARM/bin/arm-none-eabi-gdb angband.elf
553
554 The ``angband.elf`` file is a byproduct from the build process, and it has to match
555 the executable that is currently running in the emulator or on the device.
556 It is always named ``angband.elf`` for the Nintendo 3DS, and it's always either
557 ``angband.arm7.elf`` or ``angband.arm9.elf`` for the Nintendo DS, depending on
558 which processor should be debugged (as the main game runs on the ARM9 core exclusively,
559 this will almost always be the core that should be debugged).
560
561 Once the GDB command prompt is available, the following command can be used to
562 connect to the target device::
563
564 target remote <host>:<port>
565
566 Afterwards, the debugging target will pause automatically and it can be debugged as usual
567 using GDB.
568
569 Cross-building for DOS with DJGPP
570 ---------------------------------
571 These instructions were written using a Slackware64-15.0 host.
572
573 Install the following cross-compiler:
574 https://github.com/andrewwutw/build-djgpp
575
576 git clone https://github.com/andrewwutw/build-djgpp.git
577 cd build-djgpp
578 DJGPP_PREFIX=$HOME/local/cross-djgpp ./build-djgpp.sh 10.3.0
579
580 Then build angband using the cross-compiler:
581
582 cd angband/src
583 PATH=$PATH:$HOME/local/cross-djgpp/bin
584 make -f Makefile.ibm
585
586 Optionally build the documentation (requires Sphinx):
587
588 make -f Makefile.ibm docs
589
590 To create the angband.zip distribution
591
592 make -f Makefile.ibm dist
593
594 Documentation
595 -------------
596 To convert the documentation from restructured text to the desired output
597 format, you'll need Sphinx ( https://www.sphinx-doc.org/en/master/ )
598 and, unless you change the theme in the documentation configuration, the
599 sphinx-better-theme ( https://pypi.org/project/sphinx-better-theme/ ; which
600 can be installed via pip using::
601
602 pip install sphinx-better-theme
603
604 ).
605
606 With those utilities in place and sphinx-build in your path, you can perform
607 the conversion by running::
608
609 make html
610
611 in the docs subdirectory of the top-level directory in the source files.
612 That will generate a _build/html directory with the result of the conversion;
613 _build/html/index.html is the top-level help with links to everything else.
614
615 Other output formats besides HTML are possible. Run::
616
617 make
618
619 without any arguments in the docs subdirectory to see the formats that Sphinx
620 can generate.