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