|
47 | 47 | #include <sys/stat.h> |
48 | 48 | #include <sys/time.h> |
49 | 49 |
|
| 50 | +#include <getopt.h> |
| 51 | + |
50 | 52 | #include "avrdude.h" |
51 | 53 | #include "libavrdude.h" |
52 | 54 | #include "config.h" |
@@ -210,6 +212,39 @@ const char *pgmid; // Programmer -c string |
210 | 212 |
|
211 | 213 | static char usr_config[PATH_MAX]; // Per-user config file |
212 | 214 |
|
| 215 | + |
| 216 | +static |
| 217 | +const char *const avrdude_buildinfo[] = { |
| 218 | + AVRDUDE_FULL_VERSION, |
| 219 | + "buildsystem: " AVRDUDE_BUILDSYSTEM, |
| 220 | + NULL |
| 221 | +}; |
| 222 | + |
| 223 | + |
| 224 | +static void print_buildinfos(const char *const *buildinfo) |
| 225 | +{ |
| 226 | + for (unsigned int i=1; buildinfo[i]; ++i) { |
| 227 | + msg_info("%3u. %s\n", i, buildinfo[i]); |
| 228 | + } |
| 229 | +} |
| 230 | + |
| 231 | + |
| 232 | +static void print_version_message(void) |
| 233 | +{ |
| 234 | + msg_info("avrdude (...) %s\n", AVRDUDE_FULL_VERSION); |
| 235 | + msg_info("Copyright (C) ...2024...\n"); |
| 236 | + msg_info("License GPL...\n"); |
| 237 | + msg_info("This is free software...\n"); |
| 238 | + |
| 239 | + msg_info("avrdude %s\n", avrdude_buildinfo[0]); |
| 240 | + print_buildinfos(avrdude_buildinfo); |
| 241 | + |
| 242 | + const char *const *libavrdude_buildinfo = avr_get_buildinfo(); |
| 243 | + msg_info("libavrdude %s\n", libavrdude_buildinfo[0]); |
| 244 | + print_buildinfos(libavrdude_buildinfo); |
| 245 | +} |
| 246 | + |
| 247 | + |
213 | 248 | /* |
214 | 249 | * usage message |
215 | 250 | */ |
@@ -256,6 +291,7 @@ static void usage(void) |
256 | 291 | " -v Verbose output; -v -v for more\n" |
257 | 292 | " -q Quell progress output; -q -q for less\n" |
258 | 293 | " -l logfile Use logfile rather than stderr for diagnostics\n" |
| 294 | + " --version Display build and version information\n" |
259 | 295 | " -? Display this usage\n" |
260 | 296 | "\navrdude version %s, https://github.com/avrdudes/avrdude\n", |
261 | 297 | progname, strlen(cfg) < 24? "config file ": "", cfg, AVRDUDE_FULL_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