Update docs with instructions on building with meson
[tinc] / INSTALL.md
1 # Dependencies
2
3 Before you can start compiling tinc from a fresh git clone, you have
4 to install the very latest versions of the following packages:
5
6 - `meson`
7 - `ninja`
8 - `pkgconf` or `pkg-config`
9 - `GCC` or `Clang` (any version with C11 support, although older versions might work)
10 - `OpenSSL`\* (1.1.0+) or `LibreSSL` or `libgcrypt` (not needed if legacy protocol is disabled)
11
12 Plus a few optional dependencies. Support for them will be enabled if they're present:
13
14 - `ncurses` or `PDCurses`
15 - `readline`
16 - `zlib`\*
17 - `LZO`\*
18 - `LZ4`\*
19
20 If packages marked by `*` are not available, tinc will fall back to its own vendored copies.
21 This behavior can be disabled by setting the appropriate meson option to `disabled`.
22
23 To build `info` documentation you'll also need these packages:
24
25 - `texinfo` or `makeinfo`
26
27 You might also need some additional command-line utilities to be able to run the integration test suite:
28
29 - `diffutils`
30 - `procps`
31 - `socat`
32 - `netcat`
33
34 Please consult your operating system's documentation for more details.
35
36 ## Windows
37
38 You will need to install [msys2][msys2] to build tinc under Windows.
39
40 [msys2]: https://msys2.org/
41
42 By default, tinc produces a static Windows build, so you don't need to install anything
43 in order to _run_ the compiled binaries.
44
45 # Building
46
47 ## Native
48
49 Have a look at the available configuration options in `meson_options.txt`, or run:
50
51     $ meson configure
52
53 The project can be built as any other meson project:
54
55     $ meson setup build -Dprefix=/usr/local -Dbuildtype=release
56
57 This creates a build directory (named `build`) with build type set to `release`
58 (which enables compiler optimizations) and path prefix set to `/usr/local`.
59
60 Pass any additional options in the same way. Typically, this is not needed: tinc will
61 autodetect available libraries and adjust its functionality accordingly.
62
63 If you'd like to reconfigure the project after running `setup`, you can either remove
64 the build directory and start anew, or use:
65
66     $ meson configure build -Dlzo=disabled -Dlz4=enabled
67
68 You then need to build the project:
69
70     $ ninja -C build
71
72 You might want to run the test suite to ensure tinc is working correctly:
73
74     $ ninja -C build test
75
76 To install tinc to your system, run:
77
78     # ninja -C build install
79
80 Please be aware that this is not the best method of installing software
81 because it will not be tracked by your operating system's package manager. You
82 should use packages provided by your operating system, or build your own
83 (this is a large and complicated topic which is out of the scope of this document).
84
85 To uninstall tinc, run:
86
87     # ninja -C build uninstall
88
89 ## Cross-compilation
90
91 ### Linux to Linux
92
93 Cross-compilation is easy to do on Debian or its derivatives.
94 Set `$HOST` to your target architecture and install the cross-compilation toolchain and `-dev` versions of all libraries you'd like to link:
95
96     $ HOST=armhf
97     $ dpkg --add-architecture $HOST
98     $ apt update
99     $ apt install -y crossbuild-essential-$HOST zlib1g-dev:$HOST …
100
101 If you'd like to run tests on emulated hardware, install `qemu-user`:
102
103     $ apt install -y qemu-user
104     $ update-binfmts --enable
105
106 Set two environment variables: the C compiler, and pkg-config, and then proceed as usual:
107
108     $ export CC=arm-linux-gnueabihf-gcc
109     $ export PKG_CONFIG=arm-linux-gnueabihf-pkg-config
110     $ meson setup build --cross-file /dev/null
111
112 or put the names into a [cross file][cross] and pass it to meson:
113
114     $ cat >cross-armhf <<EOF
115     [binaries]
116     c = 'arm-linux-gnueabihf-gcc'
117     pkgconfig = 'arm-linux-gnueabihf-pkg-config'
118     EOF
119
120     $ meson setup build --cross-file cross-armhf
121
122 [cross]: https://mesonbuild.com/Cross-compilation.html
123
124 ### Linux to Windows
125
126 Install cross-compilation toolchain:
127
128     $ apt install -y mingw-w64 mingw-w64-tools
129
130 tinc will use its own vendored libraries, so you don't need to install or build anything manually.
131
132 Prepare the [cross file][cross] to let meson know you're building binaries for a different opearting system.
133 Take a look at the [file](.ci/cross/windows/amd64) used by CI for an example, or refer to examples provided
134 by the meson project: [x86][mingw32], [x86_64][mingw64].
135
136 Then build as usual. Because Windows binaries are built with static linkage by default,
137 you might want to enable link-time optimization. It is much slower than building without LTO,
138 but produces binaries that are 80%+ smaller:
139
140     $ meson setup build -Dbuildtype=release -Db_lto=true --cross-file cross-windows
141     $ ninja -C build
142
143 [mingw64]: https://github.com/mesonbuild/meson/blob/master/cross/linux-mingw-w64-64bit.txt
144 [mingw32]: https://github.com/mesonbuild/meson/blob/master/cross/linux-mingw-w64-32bit.txt
145
146 ### Linux to Android
147
148 First you need to install [Android NDK][ndk].
149
150 [ndk]: https://developer.android.com/studio/projects/install-ndk
151
152 Prepare a [cross file][cross]. Here's a working example for reference:
153
154 ```ini
155 [host_machine]
156 system     = 'android'
157 cpu_family = 'arm'
158 cpu        = 'aarch64'
159 endian     = 'little'
160
161 [binaries]
162 c = 'aarch64-linux-android24-clang'
163 ```
164
165 Then build as usual:
166
167     $ export ANDROID_NDK_ROOT=/tmp/ndk/android-ndk-r24
168     $ export PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
169     $ meson setup android-aarch64 -Dcrypto=nolegacy --cross-file android
170     $ ninja -C android-aarch64
171
172 ### macOS to iOS
173
174 The same instructions should work for iOS.
175 Refer to this [cross file][ios] for an example.
176
177 [ios]: https://github.com/mesonbuild/meson/blob/master/cross/iphone.txt