|
48 | 48 | #include <dirent.h> |
49 | 49 | #endif |
50 | 50 |
|
| 51 | +#include <getopt.h> |
| 52 | + |
51 | 53 | #include "avrdude.h" |
52 | 54 | #include "libavrdude.h" |
53 | 55 | #include "config.h" |
@@ -228,6 +230,39 @@ const char *pgmid; // Programmer -c string |
228 | 230 |
|
229 | 231 | static char usr_config[PATH_MAX]; // Per-user config file |
230 | 232 |
|
| 233 | + |
| 234 | +static |
| 235 | +const char *const avrdude_buildinfo[] = { |
| 236 | + AVRDUDE_FULL_VERSION, |
| 237 | + "buildsystem: " AVRDUDE_BUILDSYSTEM, |
| 238 | + NULL |
| 239 | +}; |
| 240 | + |
| 241 | + |
| 242 | +static void print_buildinfos(const char *const *buildinfo) |
| 243 | +{ |
| 244 | + for (unsigned int i=1; buildinfo[i]; ++i) { |
| 245 | + msg_info("%3u. %s\n", i, buildinfo[i]); |
| 246 | + } |
| 247 | +} |
| 248 | + |
| 249 | + |
| 250 | +static void print_version_message(void) |
| 251 | +{ |
| 252 | + msg_info("avrdude (...) %s\n", AVRDUDE_FULL_VERSION); |
| 253 | + msg_info("Copyright (C) ...2024...\n"); |
| 254 | + msg_info("License GPL...\n"); |
| 255 | + msg_info("This is free software...\n"); |
| 256 | + |
| 257 | + msg_info("avrdude %s\n", avrdude_buildinfo[0]); |
| 258 | + print_buildinfos(avrdude_buildinfo); |
| 259 | + |
| 260 | + const char *const *libavrdude_buildinfo = avr_get_buildinfo(); |
| 261 | + msg_info("libavrdude %s\n", libavrdude_buildinfo[0]); |
| 262 | + print_buildinfos(libavrdude_buildinfo); |
| 263 | +} |
| 264 | + |
| 265 | + |
231 | 266 | // Usage message |
232 | 267 | static void usage(void) { |
233 | 268 | char *home = getenv("HOME"); |
@@ -269,6 +304,7 @@ static void usage(void) { |
269 | 304 | " -v Verbose output; -v -v for more\n" |
270 | 305 | " -q Quell progress output; -q -q for less\n" |
271 | 306 | " -l logfile Use logfile rather than stderr for diagnostics\n" |
| 307 | + " --version Display build and version information\n" |
272 | 308 | " -? | --help Display this usage\n" |
273 | 309 | "\navrdude version %s, https://github.com/avrdudes/avrdude\n", |
274 | 310 | progname, strlen(cfg) < 24? "config file ": "", cfg, AVRDUDE_FULL_VERSION); |
@@ -814,12 +850,14 @@ int main(int argc, char *argv[]) { |
814 | 850 | #endif |
815 | 851 |
|
816 | 852 | // Process command line arguments |
| 853 | +#define LONGOPT_VERSION 0x2342 |
817 | 854 | struct option longopts[] = { |
818 | | - {"help", no_argument, NULL, '?'}, |
819 | | - {NULL, 0, NULL, 0} |
| 855 | + {"help", no_argument, NULL, '?'}, |
| 856 | + {"version", no_argument, NULL, LONGOPT_VERSION}, |
| 857 | + {NULL, 0, NULL, 0} |
820 | 858 | }; |
821 | | - while((ch = getopt(argc, argv, "?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrtT:U:vVx:", |
822 | | - longopts, NULL)) != -1) { |
| 859 | + while((ch = getopt_long(argc, argv, "?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrtT:U:vVx:", |
| 860 | + longopts, NULL)) != -1) { |
823 | 861 | switch(ch) { |
824 | 862 | case 'b': // Override default programmer baud rate |
825 | 863 | baudrate = str_int(optarg, STR_INT32, &errstr); |
@@ -965,6 +1003,11 @@ int main(int argc, char *argv[]) { |
965 | 1003 | exit(0); |
966 | 1004 | break; |
967 | 1005 |
|
| 1006 | + case LONGOPT_VERSION: |
| 1007 | + print_version_message(); |
| 1008 | + exit(0); |
| 1009 | + break; |
| 1010 | + |
968 | 1011 | default: |
969 | 1012 | pmsg_error("invalid option -%c\n\n", ch); |
970 | 1013 | usage(); |
|
0 commit comments