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