|
46 | 46 | #include <sys/stat.h> |
47 | 47 | #include <sys/time.h> |
48 | 48 |
|
| 49 | +#include <getopt.h> |
| 50 | + |
49 | 51 | #include "avrdude.h" |
50 | 52 | #include "libavrdude.h" |
51 | 53 | #include "config.h" |
@@ -218,6 +220,39 @@ const char *pgmid; // Programmer -c string |
218 | 220 |
|
219 | 221 | static char usr_config[PATH_MAX]; // Per-user config file |
220 | 222 |
|
| 223 | + |
| 224 | +static |
| 225 | +const char *const avrdude_buildinfo[] = { |
| 226 | + AVRDUDE_FULL_VERSION, |
| 227 | + "buildsystem: " AVRDUDE_BUILDSYSTEM, |
| 228 | + NULL |
| 229 | +}; |
| 230 | + |
| 231 | + |
| 232 | +static void print_buildinfos(const char *const *buildinfo) |
| 233 | +{ |
| 234 | + for (unsigned int i=1; buildinfo[i]; ++i) { |
| 235 | + printf("%3u. %s\n", i, buildinfo[i]); |
| 236 | + } |
| 237 | +} |
| 238 | + |
| 239 | + |
| 240 | +static void print_version_message(void) |
| 241 | +{ |
| 242 | + printf("avrdude (...) %s\n", AVRDUDE_FULL_VERSION); |
| 243 | + printf("Copyright (C) ...\n"); |
| 244 | + printf("License GPL...\n"); |
| 245 | + printf("This is free software...\n"); |
| 246 | + |
| 247 | + printf("avrdude %s\n", avrdude_buildinfo[0]); |
| 248 | + print_buildinfos(avrdude_buildinfo); |
| 249 | + |
| 250 | + const char *const *libavrdude_buildinfo = avr_get_buildinfo(); |
| 251 | + printf("libavrdude %s\n", libavrdude_buildinfo[0]); |
| 252 | + print_buildinfos(libavrdude_buildinfo); |
| 253 | +} |
| 254 | + |
| 255 | + |
221 | 256 | /* |
222 | 257 | * usage message |
223 | 258 | */ |
@@ -264,6 +299,7 @@ static void usage(void) |
264 | 299 | " -v Verbose output; -v -v for more\n" |
265 | 300 | " -q Quell progress output; -q -q for less\n" |
266 | 301 | " -l logfile Use logfile rather than stderr for diagnostics\n" |
| 302 | + " --version Display build and version information\n" |
267 | 303 | " -? Display this usage\n" |
268 | 304 | "\navrdude version %s, https://github.com/avrdudes/avrdude\n", |
269 | 305 | progname, strlen(cfg) < 24? "config file ": "", cfg, version); |
@@ -771,7 +807,15 @@ int main(int argc, char * argv []) |
771 | 807 | /* |
772 | 808 | * process command line arguments |
773 | 809 | */ |
774 | | - while ((ch = getopt(argc,argv,"?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrstT:U:uvVx:yY:")) != -1) { |
| 810 | +#define LONGOPT_VERSION 0x2342 |
| 811 | + struct option longopts[] = { |
| 812 | + {"help", no_argument, NULL, '?'}, |
| 813 | + {"version", no_argument, NULL, LONGOPT_VERSION}, |
| 814 | + {NULL, 0, NULL, 0} |
| 815 | + }; |
| 816 | + while ((ch = getopt_long(argc, argv, |
| 817 | + "?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrstT:U:uvVwx:yY:", |
| 818 | + longopts, NULL)) != -1) { |
775 | 819 |
|
776 | 820 | switch (ch) { |
777 | 821 | case 'b': /* override default programmer baud rate */ |
@@ -931,6 +975,11 @@ int main(int argc, char * argv []) |
931 | 975 | exit(0); |
932 | 976 | break; |
933 | 977 |
|
| 978 | + case LONGOPT_VERSION: /* version and build information */ |
| 979 | + print_version_message(); |
| 980 | + exit(0); |
| 981 | + break; |
| 982 | + |
934 | 983 | default: |
935 | 984 | pmsg_error("invalid option -%c\n\n", ch); |
936 | 985 | usage(); |
|
0 commit comments