Debian Codegraph @

src/basic/build.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <stdio.h>
4
5 #include "alloc-util.h"
6 #include "ansi-color.h"
7 #include "build.h"
8 #include "extract-word.h"
9 #include "log.h"
10 #include "string-util.h"
11 #include "version.h"
12
13 const char* const systemd_features =
14
15 /* PAM and MAC frameworks */
16
17 #if HAVE_PAM
18 "+PAM"
19 #else
20 "-PAM"
21 #endif
22
23 #if HAVE_AUDIT
24 " +AUDIT"
25 #else
26 " -AUDIT"
27 #endif
28
29 #if HAVE_SELINUX
30 " +SELINUX"
31 #else
32 " -SELINUX"
33 #endif
34
35 #if HAVE_APPARMOR
36 " +APPARMOR"
37 #else
38 " -APPARMOR"
39 #endif
40
41 #if ENABLE_IMA
42 " +IMA"
43 #else
44 " -IMA"
45 #endif
46
47 #if ENABLE_IPE
48 " +IPE"
49 #else
50 " -IPE"
51 #endif
52
53 #if ENABLE_SMACK
54 " +SMACK"
55 #else
56 " -SMACK"
57 #endif
58
59 #if HAVE_SECCOMP
60 " +SECCOMP"
61 #else
62 " -SECCOMP"
63 #endif
64
65 /* cryptographic libraries */
66
67 #if HAVE_GCRYPT
68 " +GCRYPT"
69 #else
70 " -GCRYPT"
71 #endif
72
73 #if HAVE_GNUTLS
74 " +GNUTLS"
75 #else
76 " -GNUTLS"
77 #endif
78
79 #if HAVE_OPENSSL
80 " +OPENSSL"
81 #else
82 " -OPENSSL"
83 #endif
84
85 /* all other libraries, sorted alphabetically */
86
87 #if HAVE_ACL
88 " +ACL"
89 #else
90 " -ACL"
91 #endif
92
93 #if HAVE_BLKID
94 " +BLKID"
95 #else
96 " -BLKID"
97 #endif
98
99 #if HAVE_LIBCURL
100 " +CURL"
101 #else
102 " -CURL"
103 #endif
104
105 #if HAVE_ELFUTILS
106 " +ELFUTILS"
107 #else
108 " -ELFUTILS"
109 #endif
110
111 #if HAVE_LIBFIDO2
112 " +FIDO2"
113 #else
114 " -FIDO2"
115 #endif
116
117 #if HAVE_LIBIDN2
118 " +IDN2"
119 #else
120 " -IDN2"
121 #endif
122
123 #if HAVE_KMOD
124 " +KMOD"
125 #else
126 " -KMOD"
127 #endif
128
129 #if HAVE_LIBCRYPTSETUP
130 " +LIBCRYPTSETUP"
131 #else
132 " -LIBCRYPTSETUP"
133 #endif
134
135 #if HAVE_LIBCRYPTSETUP_PLUGINS
136 " +LIBCRYPTSETUP_PLUGINS"
137 #else
138 " -LIBCRYPTSETUP_PLUGINS"
139 #endif
140
141 #if HAVE_LIBFDISK
142 " +LIBFDISK"
143 #else
144 " -LIBFDISK"
145 #endif
146
147 #if HAVE_PCRE2
148 " +PCRE2"
149 #else
150 " -PCRE2"
151 #endif
152
153 #if HAVE_PWQUALITY
154 " +PWQUALITY"
155 #else
156 " -PWQUALITY"
157 #endif
158
159 #if HAVE_P11KIT
160 " +P11KIT"
161 #else
162 " -P11KIT"
163 #endif
164
165 #if HAVE_QRENCODE
166 " +QRENCODE"
167 #else
168 " -QRENCODE"
169 #endif
170
171 #if HAVE_TPM2
172 " +TPM2"
173 #else
174 " -TPM2"
175 #endif
176
177 /* compressors */
178
179 #if HAVE_BZIP2
180 " +BZIP2"
181 #else
182 " -BZIP2"
183 #endif
184
185 #if HAVE_LZ4
186 " +LZ4"
187 #else
188 " -LZ4"
189 #endif
190
191 #if HAVE_XZ
192 " +XZ"
193 #else
194 " -XZ"
195 #endif
196
197 #if HAVE_ZLIB
198 " +ZLIB"
199 #else
200 " -ZLIB"
201 #endif
202
203 #if HAVE_ZSTD
204 " +ZSTD"
205 #else
206 " -ZSTD"
207 #endif
208
209 /* other stuff that doesn't fit above */
210
211 #if BPF_FRAMEWORK
212 " +BPF_FRAMEWORK"
213 #else
214 " -BPF_FRAMEWORK"
215 #endif
216
217 #if HAVE_VMLINUX_H
218 " +BTF"
219 #else
220 " -BTF"
221 #endif
222
223 #if HAVE_XKBCOMMON
224 " +XKBCOMMON"
225 #else
226 " -XKBCOMMON"
227 #endif
228
229 #if ENABLE_UTMP
230 " +UTMP"
231 #else
232 " -UTMP"
233 #endif
234
235 #if HAVE_LIBARCHIVE
236 " +LIBARCHIVE"
237 #else
238 " -LIBARCHIVE"
239 #endif
240
241 ;
242
243 static char* systemd_features_with_color(void) {
244 const char *p = systemd_features;
245 _cleanup_free_ char *ret = NULL;
246 int r;
247
248 for (;;) {
249 _cleanup_free_ char *word = NULL;
250 char *q;
251
252 r = extract_first_word(&p, &word, NULL, 0);
253 if (r < 0) {
254 log_warning_errno(r, "Cannot split features string, ignoring: %m");
255 return NULL;
256 }
257 if (r == 0)
258 return TAKE_PTR(ret);
259
260 if (ret && !strextend(&ret, " ")) {
261 log_oom_warning();
262 return NULL;
263 }
264
265 if (word[0] == '+')
266 q = strextend(&ret, ANSI_HIGHLIGHT_GREEN, CHAR_TO_STR(word[0]), ANSI_GREEN, word+1, ANSI_NORMAL);
267 else if (word[0] == '-')
268 q = strextend(&ret, ANSI_HIGHLIGHT_RED, CHAR_TO_STR(word[0]), ANSI_RED, word+1, ANSI_NORMAL);
269 else
270 q = strextend(&ret, word);
271 if (!q) {
272 log_oom_warning();
273 return NULL;
274 }
275 }
276 }
277
278 int version(void) {
279 _cleanup_free_ char *b = NULL;
280
281 if (colors_enabled())
282 b = systemd_features_with_color();
283
284 printf("%ssystemd %i%s (" GIT_VERSION ")\n%s\n",
285 ansi_highlight(), PROJECT_VERSION, ansi_normal(),
286 b ?: systemd_features);
287 return 0;
288 }