4949#include <dirent.h>
5050#endif
5151
52+ #include <getopt.h>
53+
5254#include "avrdude.h"
5355#include "libavrdude.h"
5456#include "config.h"
@@ -229,6 +231,52 @@ const char *pgmid; // Programmer -c string
229231
230232static char usr_config [PATH_MAX ]; // Per-user config file
231233
234+
235+ static
236+ const avr_buildinfo avrdude_buildinfo = {
237+ "avrdude" , AVRDUDE_FULL_VERSION ,
238+ {
239+ {"buildsystem" , AVRDUDE_BUILDSYSTEM },
240+ {NULL , NULL },
241+ }
242+ };
243+
244+
245+ static void print_buildinfo (const avr_buildinfo * const buildinfo )
246+ {
247+ msg_info (" * %s %s\n" ,
248+ buildinfo -> name , buildinfo -> version );
249+
250+ for (unsigned int i = 0 ; buildinfo -> items [i ].key ; ++ i ) {
251+ if (buildinfo -> items [i ].value ) {
252+ msg_info (" %3u. %s: %s\n" ,
253+ i + 1 ,
254+ buildinfo -> items [i ].key ,
255+ buildinfo -> items [i ].value );
256+ }
257+ }
258+ }
259+
260+
261+ static void print_version_message (void )
262+ {
263+ msg_info ("avrdude %s\n" , AVRDUDE_FULL_VERSION );
264+ msg_info ("Copyright (C) ...2024...\n" );
265+ msg_info ("License GPL...\n" );
266+ msg_info ("This is free software...\n" );
267+
268+ const avr_buildinfo * const all_buildinfos [] = {
269+ & avrdude_buildinfo ,
270+ & libavrdude_buildinfo ,
271+ NULL ,
272+ };
273+
274+ for (unsigned int i = 0 ; all_buildinfos [i ]; ++ i ) {
275+ print_buildinfo (all_buildinfos [i ]);
276+ }
277+ }
278+
279+
232280// Usage message
233281static void usage (void ) {
234282 char * home = getenv ("HOME" );
@@ -273,6 +321,7 @@ static void usage(void) {
273321 " -q Quell progress output; -q -q for less\n"
274322 " -l, --logfile logfile Use logfile rather than stderr for diagnostics\n"
275323 " -?, --help Display this usage\n"
324+ " --version Display build and version information\n"
276325 "\navrdude version %s, https://github.com/avrdudes/avrdude\n" ,
277326 progname , strlen (cfg ) < 24 ? "config file " : "" , cfg , AVRDUDE_FULL_VERSION );
278327
@@ -817,6 +866,7 @@ int main(int argc, char *argv[]) {
817866#endif
818867
819868 // Process command line arguments
869+ #define LONGOPT_VERSION 0x2342
820870 struct option longopts [] = {
821871 {"help" , no_argument , NULL , '?' },
822872 {"baud" , required_argument , NULL , 'b' },
@@ -838,6 +888,7 @@ int main(int argc, char *argv[]) {
838888 {"memory" , required_argument , NULL , 'U' },
839889 {"verbose" , no_argument , NULL , 'v' },
840890 {"noverify" , no_argument , NULL , 'V' },
891+ {"version" , no_argument , NULL , LONGOPT_VERSION },
841892 {NULL , 0 , NULL , 0 }
842893 };
843894 while ((ch = getopt_long (argc , argv ,
@@ -988,6 +1039,11 @@ int main(int argc, char *argv[]) {
9881039 exit (0 );
9891040 break ;
9901041
1042+ case LONGOPT_VERSION :
1043+ print_version_message ();
1044+ exit (0 );
1045+ break ;
1046+
9911047 default :
9921048 pmsg_error ("invalid option -%c\n\n" , ch );
9931049 usage ();
0 commit comments