7f1c6fab320ff0babb5838ea4505153d33f3a90d
[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 can build tinc using either the native [Windows SDK][sdk-ms] (which comes with Visual Studio),
39 or with the Unix-like [msys2 environment][sdk-msys2]. Install either one of them, plus
40 the latest version of [meson][meson-release].
41
42 If you prefer the native SDK, you might want to work on tinc (or build it) under Visual Studio.
43 To do so, follow [these instructions][meson-vs].
44
45 By default, tinc produces a static Windows build, so you don't need to install anything
46 in order to _run_ the compiled binaries.
47
48 [sdk-ms]: https://visualstudio.com/
49 [sdk-msys2]: https://msys2.org/
50 [meson-release]: https://github.com/mesonbuild/meson/releases
51 [meson-vs]: https://mesonbuild.com/Using-with-Visual-Studio.html
52
53 # Building from source
54
55 ## Native
56
57 ### Setup
58
59 Tinc's functionality can vary greatly depending on how you configure it.
60 Have a look at the available options in [`meson_options.txt`](meson_options.txt), or run:
61
62     $ meson configure
63
64 First you need to create a build directory. If you want the default experience, run:
65
66     $ meson setup builddir
67
68 or with configuration options (your shell can probably autocomplete them on `Tab`, try it):
69
70     $ meson setup builddir -Dprefix=/usr/local -Dbuildtype=release
71
72 (For autotools users: this is a rough equivalent of `autoreconf -fsi && ./configure --prefix=/usr/local --with-foobar`).
73
74 This creates a build directory (named `builddir`) with build type set to `release`
75 (which enables compiler optimizations) and path prefix set to `/usr/local`.
76
77 Pass any additional options in the same way. Typically, this is not needed: tinc will
78 autodetect available libraries and adjust its functionality accordingly.
79
80 If you'd like to reconfigure the project after running `setup`, you can either remove
81 the build directory and start anew, or use:
82
83     $ meson configure builddir -Dlzo=disabled -Dlz4=enabled
84
85 ### Compile
86
87 You then need to build the project:
88
89     $ meson compile -C builddir
90
91 (For autotools users: this is an equivalent of `make -j$(nproc)`).
92
93 ### Test
94
95 You might want to run the test suite to ensure tinc is working correctly:
96
97     $ meson test -C builddir
98
99 (For autotools users: this is an equivalent of `make -j$(nproc) test`).
100
101 ### Install
102
103 To install tinc to your system, run:
104
105     $ meson install -C builddir
106
107 (For autotools users: this is an equivalent of `make install`).
108
109 Please be aware that this is not the best method of installing software
110 because it will not be tracked by your operating system's package manager. You
111 should use packages provided by your operating system, or build your own
112 (this is a large and complicated topic which is out of the scope of this document).
113
114 ### Uninstall
115
116 To uninstall tinc, run:
117
118     # ninja -C builddir uninstall
119
120 (For autotools users: this is an equivalent of `make uninstall`).
121
122 ## Cross-compilation
123
124 ### Linux to Linux
125
126 Cross-compilation is easy to do on Debian or its derivatives.
127 Set `$HOST` to your target architecture and install the cross-compilation toolchain and `-dev` versions of all libraries you'd like to link:
128
129     $ HOST=armhf
130     $ dpkg --add-architecture $HOST
131     $ apt update
132     $ apt install -y crossbuild-essential-$HOST zlib1g-dev:$HOST …
133
134 If you'd like to run tests on emulated hardware, install `qemu-user`:
135
136     $ apt install -y qemu-user
137     $ update-binfmts --enable
138
139 Set two environment variables: the C compiler, and pkg-config, and then proceed as usual:
140
141     $ export CC=arm-linux-gnueabihf-gcc
142     $ export PKG_CONFIG=arm-linux-gnueabihf-pkg-config
143     $ meson setup build --cross-file /dev/null
144
145 or put the names into a [cross file][cross] and pass it to meson:
146
147     $ cat >cross-armhf <<EOF
148     [binaries]
149     c = 'arm-linux-gnueabihf-gcc'
150     pkgconfig = 'arm-linux-gnueabihf-pkg-config'
151     EOF
152
153     $ meson setup build --cross-file cross-armhf
154
155 [cross]: https://mesonbuild.com/Cross-compilation.html
156
157 ### Linux to Windows
158
159 Install cross-compilation toolchain:
160
161     $ apt install -y mingw-w64 mingw-w64-tools
162
163 tinc will use its own vendored libraries, so you don't need to install or build anything manually.
164
165 Prepare the [cross file][cross] to let meson know you're building binaries for a different operating system.
166 Take a look at the [file](.ci/cross/windows/amd64) used by CI for an example, or refer to examples provided
167 by the meson project: [x86][mingw32], [x86_64][mingw64].
168
169 Then build as usual. Because Windows binaries are built with static linkage by default,
170 you might want to enable link-time optimization. It is much slower than building without LTO,
171 but produces binaries that are 80%+ smaller:
172
173     $ meson setup build -Dbuildtype=release -Db_lto=true --cross-file cross-windows
174     $ ninja -C build
175
176 [mingw64]: https://github.com/mesonbuild/meson/blob/master/cross/linux-mingw-w64-64bit.txt
177 [mingw32]: https://github.com/mesonbuild/meson/blob/master/cross/linux-mingw-w64-32bit.txt
178
179 ### Linux to Android
180
181 First you need to install [Android NDK][ndk].
182
183 [ndk]: https://developer.android.com/studio/projects/install-ndk
184
185 Prepare a [cross file][cross]. Here's a working example for reference:
186
187 ```ini
188 [host_machine]
189 system     = 'android'
190 cpu_family = 'arm'
191 cpu        = 'aarch64'
192 endian     = 'little'
193
194 [binaries]
195 c = 'aarch64-linux-android24-clang'
196 ```
197
198 Then build as usual:
199
200     $ export ANDROID_NDK_ROOT=/tmp/ndk/android-ndk-r24
201     $ export PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
202     $ meson setup android-aarch64 -Dcrypto=nolegacy --cross-file android
203     $ ninja -C android-aarch64
204
205 ### macOS to iOS
206
207 The same instructions should work for iOS.
208 Refer to this [cross file][ios] for an example.
209
210 [ios]: https://github.com/mesonbuild/meson/blob/master/cross/iphone.txt