Change usage (--version) output to note when ASM isn't really being used.
[rsync.git] / usage.c
1 /*
2  * Some usage & version related functions.
3  *
4  * Copyright (C) 2002-2020 Wayne Davison
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, visit the http://fsf.org website.
18  */
19
20 #include "rsync.h"
21 #include "version.h"
22 #include "latest-year.h"
23 #include "git-version.h"
24 #include "default-cvsignore.h"
25
26 extern struct name_num_obj valid_checksums;
27 extern struct name_num_obj valid_compressions;
28
29 static char *istring(const char *fmt, int val)
30 {
31         char *str;
32         if (asprintf(&str, fmt, val) < 0)
33                 out_of_memory("istring");
34         return str;
35 }
36
37 static void print_info_flags(enum logcode f)
38 {
39         STRUCT_STAT *dumstat;
40         char line_buf[75];
41         int line_len, j;
42         char *info_flags[] = {
43
44         "*Capabilities",
45
46                 istring("%d-bit files", (int)(sizeof (OFF_T) * 8)),
47                 istring("%d-bit inums", (int)(sizeof dumstat->st_ino * 8)), /* Don't check ino_t! */
48                 istring("%d-bit timestamps", (int)(sizeof (time_t) * 8)),
49                 istring("%d-bit long ints", (int)(sizeof (int64) * 8)),
50
51 #ifndef HAVE_SOCKETPAIR
52                 "no "
53 #endif
54                         "socketpairs",
55
56 #ifndef SUPPORT_LINKS
57                 "no "
58 #endif
59                         "symlinks",
60
61 #ifndef CAN_SET_SYMLINK_TIMES
62                 "no "
63 #endif
64                         "symtimes",
65
66 #ifndef SUPPORT_HARD_LINKS
67                 "no "
68 #endif
69                         "hardlinks",
70
71 #ifndef CAN_HARDLINK_SPECIAL
72                 "no "
73 #endif
74                         "hardlink-specials",
75
76 #ifndef CAN_HARDLINK_SYMLINK
77                 "no "
78 #endif
79                         "hardlink-symlinks",
80
81 #ifndef INET6
82                 "no "
83 #endif
84                         "IPv6",
85
86 #ifndef SUPPORT_ATIMES
87                 "no "
88 #endif
89                         "atimes",
90
91                 "batchfiles",
92
93 #ifndef HAVE_FTRUNCATE
94                 "no "
95 #endif
96                         "inplace",
97
98 #ifndef HAVE_FTRUNCATE
99                 "no "
100 #endif
101                         "append",
102
103 #ifndef SUPPORT_ACLS
104                 "no "
105 #endif
106                         "ACLs",
107
108 #ifndef SUPPORT_XATTRS
109                 "no "
110 #endif
111                         "xattrs",
112
113 #ifdef RSYNC_USE_PROTECTED_ARGS
114                 "default "
115 #else
116                 "optional "
117 #endif
118                         "protect-args",
119
120 #ifndef ICONV_OPTION
121                 "no "
122 #endif
123                         "iconv",
124
125 #ifndef SUPPORT_PREALLOCATION
126                 "no "
127 #endif
128                         "prealloc",
129
130 #ifndef HAVE_MKTIME
131                 "no "
132 #endif
133                         "stop-at",
134
135 #ifndef SUPPORT_CRTIMES
136                 "no "
137 #endif
138                         "crtimes",
139
140         "*Optimizations",
141
142 #ifndef HAVE_SIMD
143                 "no "
144 #endif
145                         "SIMD",
146
147 #if !defined HAVE_ASM || defined USE_OPENSSL
148                 "no "
149 #endif
150                         "asm",
151
152 #ifndef USE_OPENSSL
153                 "no "
154 #endif
155                         "openssl-crypto",
156
157                 NULL
158         };
159
160         for (line_len = 0, j = 0; ; j++) {
161                 char *str = info_flags[j], *next_nfo = str ? info_flags[j+1] : NULL;
162                 int str_len = str && *str != '*' ? strlen(str) : 1000;
163                 int need_comma = next_nfo && *next_nfo != '*' ? 1 : 0;
164                 if (line_len && line_len + 1 + str_len + need_comma >= (int)sizeof line_buf) {
165                         rprintf(f, "   %s\n", line_buf);
166                         line_len = 0;
167                 }
168                 if (!str)
169                         break;
170                 if (*str == '*') {
171                         rprintf(f, "%s:\n", str+1);
172                         continue;
173                 }
174                 line_len += snprintf(line_buf+line_len, sizeof line_buf - line_len, " %s%s", str, need_comma ? "," : "");
175         }
176 }
177
178 void print_rsync_version(enum logcode f)
179 {
180         char tmpbuf[256], *subprotocol = "";
181
182 #if SUBPROTOCOL_VERSION != 0
183         subprotocol = istring(".PR%d", SUBPROTOCOL_VERSION);
184 #endif
185         rprintf(f, "%s  version %s  protocol version %d%s\n",
186                 RSYNC_NAME, rsync_version(), PROTOCOL_VERSION, subprotocol);
187
188         rprintf(f, "Copyright (C) 1996-" LATEST_YEAR " by Andrew Tridgell, Wayne Davison, and others.\n");
189         rprintf(f, "Web site: https://rsync.samba.org/\n");
190
191         print_info_flags(f);
192
193         rprintf(f, "Checksum list:\n");
194         get_default_nno_list(&valid_checksums, tmpbuf, sizeof tmpbuf, '(');
195         rprintf(f, "    %s\n", tmpbuf);
196
197         rprintf(f, "Compress list:\n");
198         get_default_nno_list(&valid_compressions, tmpbuf, sizeof tmpbuf, '(');
199         rprintf(f, "    %s\n", tmpbuf);
200
201 #ifdef MAINTAINER_MODE
202         rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
203 #endif
204
205 #if SIZEOF_INT64 < 8
206         rprintf(f, "WARNING: no 64-bit integers on this platform!\n");
207 #endif
208         if (sizeof (int64) != SIZEOF_INT64) {
209                 rprintf(f,
210                         "WARNING: size mismatch in SIZEOF_INT64 define (%d != %d)\n",
211                         (int) SIZEOF_INT64, (int) sizeof (int64));
212         }
213
214         rprintf(f,"\n");
215         rprintf(f,"rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you\n");
216         rprintf(f,"are welcome to redistribute it under certain conditions.  See the GNU\n");
217         rprintf(f,"General Public Licence for details.\n");
218 }
219
220 void usage(enum logcode F)
221 {
222   print_rsync_version(F);
223
224   rprintf(F,"\n");
225   rprintf(F,"rsync is a file transfer program capable of efficient remote update\n");
226   rprintf(F,"via a fast differencing algorithm.\n");
227
228   rprintf(F,"\n");
229   rprintf(F,"Usage: rsync [OPTION]... SRC [SRC]... DEST\n");
230   rprintf(F,"  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\n");
231   rprintf(F,"  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n");
232   rprintf(F,"  or   rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST\n");
233   rprintf(F,"  or   rsync [OPTION]... [USER@]HOST:SRC [DEST]\n");
234   rprintf(F,"  or   rsync [OPTION]... [USER@]HOST::SRC [DEST]\n");
235   rprintf(F,"  or   rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n");
236   rprintf(F,"The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect\n");
237   rprintf(F,"to an rsync daemon, and require SRC or DEST to start with a module name.\n");
238   rprintf(F,"\n");
239   rprintf(F,"Options\n");
240 #include "help-rsync.h"
241   rprintf(F,"\n");
242   rprintf(F,"Use \"rsync --daemon --help\" to see the daemon-mode command-line options.\n");
243   rprintf(F,"Please see the rsync(1) and rsyncd.conf(5) man pages for full documentation.\n");
244   rprintf(F,"See https://rsync.samba.org/ for updates, bug reports, and answers\n");
245 }
246
247 void daemon_usage(enum logcode F)
248 {
249   print_rsync_version(F);
250
251   rprintf(F,"\n");
252   rprintf(F,"Usage: rsync --daemon [OPTION]...\n");
253 #include "help-rsyncd.h"
254   rprintf(F,"\n");
255   rprintf(F,"If you were not trying to invoke rsync as a daemon, avoid using any of the\n");
256   rprintf(F,"daemon-specific rsync options.  See also the rsyncd.conf(5) man page.\n");
257 }
258
259 const char *rsync_version(void)
260 {
261 #ifdef RSYNC_GITVER
262         return RSYNC_GITVER;
263 #else
264         return RSYNC_VERSION;
265 #endif
266 }
267
268 const char *default_cvsignore(void)
269 {
270         return DEFAULT_CVSIGNORE;
271 }