Skip to content

Commit

Permalink
XXX add basic buildinfo ideas
Browse files Browse the repository at this point in the history
Add basic buildinfo ideas, quick and dirty and not tested comprehensively:

  * Define build information for libavrdude and the avrdude tool

  * Add a long "--version" argument which shows a long version message.

XXX Just add the output to "avrdude -v" header?
  • Loading branch information
ndim committed Aug 24, 2024
1 parent 9873a32 commit 424ae72
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 4 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

# =====================================
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ set(SOURCES
avrpart.c
bitbang.c
bitbang.h
buildinfo.c
buspirate.c
buspirate.h
butterfly.c
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ libavrdude_la_SOURCES = \
avr_opcodes.c \
bitbang.c \
bitbang.h \
buildinfo.c \
buspirate.c \
buspirate.h \
butterfly.c \
Expand Down
51 changes: 51 additions & 0 deletions src/buildinfo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <libavrdude.h>

#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;
}
1 change: 1 addition & 0 deletions src/cmake_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#endif

#define AVRDUDE_FULL_VERSION "@AVRDUDE_FULL_VERSION@"
#define AVRDUDE_BUILDSYSTEM "@AVRDUDE_BUILDSYSTEM@"

/* Options */

Expand Down
3 changes: 3 additions & 0 deletions src/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,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])


# Define libavrdude libtool version from cmake libavrdude information
dnl
Expand Down
2 changes: 2 additions & 0 deletions src/libavrdude.h
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,8 @@ extern "C" {
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
Expand Down
51 changes: 47 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include <dirent.h>
#endif

#include <getopt.h>

#include "avrdude.h"
#include "libavrdude.h"
#include "config.h"
Expand Down Expand Up @@ -228,6 +230,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) {
msg_info("%3u. %s\n", i, buildinfo[i]);
}
}


static void print_version_message(void)
{
msg_info("avrdude (...) %s\n", AVRDUDE_FULL_VERSION);
msg_info("Copyright (C) ...2024...\n");
msg_info("License GPL...\n");
msg_info("This is free software...\n");

msg_info("avrdude %s\n", avrdude_buildinfo[0]);
print_buildinfos(avrdude_buildinfo);

const char *const *libavrdude_buildinfo = avr_get_buildinfo();
msg_info("libavrdude %s\n", libavrdude_buildinfo[0]);
print_buildinfos(libavrdude_buildinfo);
}


// Usage message
static void usage(void) {
char *home = getenv("HOME");
Expand Down Expand Up @@ -269,6 +304,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"
" -? | --help Display this usage\n"
"\navrdude version %s, https://github.com/avrdudes/avrdude\n",
progname, strlen(cfg) < 24? "config file ": "", cfg, AVRDUDE_FULL_VERSION);
Expand Down Expand Up @@ -814,12 +850,14 @@ int main(int argc, char *argv[]) {
#endif

// Process command line arguments
#define LONGOPT_VERSION 0x2342
struct option longopts[] = {
{"help", no_argument, NULL, '?'},
{NULL, 0, NULL, 0}
{"help", no_argument, NULL, '?'},
{"version", no_argument, NULL, LONGOPT_VERSION},
{NULL, 0, NULL, 0}
};
while((ch = getopt(argc, argv, "?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrtT:U:vVx:",
longopts, NULL)) != -1) {
while((ch = getopt_long(argc, argv, "?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrtT:U:vVx:",
longopts, NULL)) != -1) {
switch(ch) {
case 'b': // Override default programmer baud rate
baudrate = str_int(optarg, STR_INT32, &errstr);
Expand Down Expand Up @@ -965,6 +1003,11 @@ int main(int argc, char *argv[]) {
exit(0);
break;

case LONGOPT_VERSION:
print_version_message();
exit(0);
break;

default:
pmsg_error("invalid option -%c\n\n", ch);
usage();
Expand Down

0 comments on commit 424ae72

Please sign in to comment.