diff --git a/CMakeLists.txt b/CMakeLists.txt index 071f50b27..23a100be3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ include(FindPackageMessage) include(GNUInstallDirs) set(CONFIG_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}") +set(AVRDUDE_BUILDSYSTEM "cmake") set(AVRDUDE_FULL_VERSION ${CMAKE_PROJECT_VERSION}) # ===================================== diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9c1b9149f..997107cb3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -160,6 +160,7 @@ add_library(libavrdude avrpart.c bitbang.c bitbang.h + buildinfo.c buspirate.c buspirate.h butterfly.c diff --git a/src/Makefile.am b/src/Makefile.am index 1f063c9d3..60af16212 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -107,6 +107,7 @@ libavrdude_a_SOURCES = \ avrpart.c \ bitbang.c \ bitbang.h \ + buildinfo.c \ buspirate.c \ buspirate.h \ butterfly.c \ diff --git a/src/buildinfo.c b/src/buildinfo.c new file mode 100644 index 000000000..b00b16578 --- /dev/null +++ b/src/buildinfo.c @@ -0,0 +1,51 @@ +#include + +#include "ac_cfg.h" + +static +const char *const libavrdude_buildinfo[] = { + AVRDUDE_FULL_VERSION, + "buildsystem: " AVRDUDE_BUILDSYSTEM, +#ifdef HAVE_LIBELF + "libelf", +#endif +#ifdef HAVE_LIBUSB + "libusb", +#endif +#ifdef HAVE_LIBUSB_1_0 + "libusb_1_0", +#endif +#ifdef HAVE_LIBHIDAPI + "libhidapi", +#endif +#ifdef HAVE_LIBHID + "libhid", +#endif +#ifdef HAVE_LIBFTDI + "libftdi", +#endif +#ifdef HAVE_LIBFTDI1 + "libftdi1", +#endif +#ifdef HAVE_LIBREADLINE + "libreadline", +#endif +#ifdef HAVE_LIBSERIALPORT + "libserialport", +#endif +#ifdef HAVE_PARPORT + "parport", +#endif +#ifdef HAVE_LINUXGPIO + "linuxgpio", +#endif +#ifdef HAVE_LINUXSPI + "linuxspi", +#endif + NULL +}; + +const char *const *avr_get_buildinfo(void) +{ + return libavrdude_buildinfo; +} diff --git a/src/cmake_config.h.in b/src/cmake_config.h.in index b8e9c2504..321ecbbcb 100644 --- a/src/cmake_config.h.in +++ b/src/cmake_config.h.in @@ -21,6 +21,7 @@ #endif #define AVRDUDE_FULL_VERSION "@AVRDUDE_FULL_VERSION@" +#define AVRDUDE_BUILDSYSTEM "@AVRDUDE_BUILDSYSTEM@" /* Options */ diff --git a/src/configure.ac b/src/configure.ac index 4b6809279..39a724cba 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -88,6 +88,9 @@ AC_DEFINE_UNQUOTED([AVRDUDE_FULL_VERSION], ["$AVRDUDE_FULL_VERSION"], [The full avrdude version as displayed in -? and avrdude.conf]) AC_SUBST([AVRDUDE_FULL_VERSION]) +AC_DEFINE_UNQUOTED([AVRDUDE_BUILDSYSTEM], ["autotools"], + [The buildsystem used to build avrdude]) + # Checks for programs. AC_PROG_CC diff --git a/src/libavrdude.h b/src/libavrdude.h index 1675b7668..42c9d90de 100644 --- a/src/libavrdude.h +++ b/src/libavrdude.h @@ -1184,6 +1184,8 @@ int avr_page_erase_cached(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p); int avr_reset_cache(const PROGRAMMER *pgm, const AVRPART *p); +const char *const *avr_get_buildinfo(void); + #ifdef __cplusplus } #endif diff --git a/src/main.c b/src/main.c index 7debe44b2..f3fe20ab4 100644 --- a/src/main.c +++ b/src/main.c @@ -46,6 +46,8 @@ #include #include +#include + #include "avrdude.h" #include "libavrdude.h" #include "config.h" @@ -218,6 +220,39 @@ const char *pgmid; // Programmer -c string static char usr_config[PATH_MAX]; // Per-user config file + +static +const char *const avrdude_buildinfo[] = { + AVRDUDE_FULL_VERSION, + "buildsystem: " AVRDUDE_BUILDSYSTEM, + NULL +}; + + +static void print_buildinfos(const char *const *buildinfo) +{ + for (unsigned int i=1; buildinfo[i]; ++i) { + printf("%3u. %s\n", i, buildinfo[i]); + } +} + + +static void print_version_message(void) +{ + printf("avrdude (...) %s\n", AVRDUDE_FULL_VERSION); + printf("Copyright (C) ...\n"); + printf("License GPL...\n"); + printf("This is free software...\n"); + + printf("avrdude %s\n", avrdude_buildinfo[0]); + print_buildinfos(avrdude_buildinfo); + + const char *const *libavrdude_buildinfo = avr_get_buildinfo(); + printf("libavrdude %s\n", libavrdude_buildinfo[0]); + print_buildinfos(libavrdude_buildinfo); +} + + /* * usage message */ @@ -264,6 +299,7 @@ static void usage(void) " -v Verbose output; -v -v for more\n" " -q Quell progress output; -q -q for less\n" " -l logfile Use logfile rather than stderr for diagnostics\n" + " --version Display build and version information\n" " -? Display this usage\n" "\navrdude version %s, https://github.com/avrdudes/avrdude\n", progname, strlen(cfg) < 24? "config file ": "", cfg, version); @@ -771,7 +807,15 @@ int main(int argc, char * argv []) /* * process command line arguments */ - while ((ch = getopt(argc,argv,"?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrstT:U:uvVx:yY:")) != -1) { +#define LONGOPT_VERSION 0x2342 + struct option longopts[] = { + {"help", no_argument, NULL, '?'}, + {"version", no_argument, NULL, LONGOPT_VERSION}, + {NULL, 0, NULL, 0} + }; + while ((ch = getopt_long(argc, argv, + "?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrstT:U:uvVwx:yY:", + longopts, NULL)) != -1) { switch (ch) { case 'b': /* override default programmer baud rate */ @@ -931,6 +975,11 @@ int main(int argc, char * argv []) exit(0); break; + case LONGOPT_VERSION: /* version and build information */ + print_version_message(); + exit(0); + break; + default: pmsg_error("invalid option -%c\n\n", ch); usage();