Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build information to libavrdude and avrdude and display it #1698

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
108 changes: 108 additions & 0 deletions src/buildinfo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include <libavrdude.h>

#include <ac_cfg.h>


const avr_buildinfo libavrdude_buildinfo = {
"libavrdude", AVRDUDE_FULL_VERSION,
{
{"buildsystem", AVRDUDE_BUILDSYSTEM},

{"libelf",
#ifdef HAVE_LIBELF
"yes"
#else
NULL
#endif
},

{"libusb",
#ifdef HAVE_LIBUSB
"yes"
#else
NULL
#endif
},

{"libusb_1_0",
#ifdef HAVE_LIBUSB_1_0
"yes"
#else
NULL
#endif
},

{"libhidapi",
#ifdef HAVE_LIBHIDAPI
"yes"
#else
NULL
#endif
},

{"libhid",
#ifdef HAVE_LIBHID
"yes"
#else
NULL
#endif
},

{"libftdi",
#ifdef HAVE_LIBFTDI
"yes"
#else
NULL
#endif
},

{"libftdi1",
#ifdef HAVE_LIBFTDI1
"yes"
#else
NULL
#endif
},

{"libreadline",
#ifdef HAVE_LIBREADLINE
"yes"
#else
NULL
#endif
},

{"libserialport",
#ifdef HAVE_LIBSERIALPORT
"yes"
#else
NULL
#endif
},

{"parport",
#ifdef HAVE_PARPORT
"yes"
#else
NULL
#endif
},

{"linuxgpio",
#ifdef HAVE_LINUXGPIO
"yes"
#else
NULL
#endif
},

{"linuxspi",
#ifdef HAVE_LINUXSPI
"yes"
#else
NULL
#endif
},
{NULL, NULL},
},
};
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
15 changes: 15 additions & 0 deletions src/libavrdude.h
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,21 @@ extern "C" {
int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p);
int avr_reset_cache(const PROGRAMMER *pgm, const AVRPART *p);


typedef struct avr_buildinfo_item {
const char *const key;
const char *const value;
} avr_buildinfo_item;

typedef struct avr_buildinfo {
const char *const name;
const char *const version;
avr_buildinfo_item items[];
} avr_buildinfo;

extern const avr_buildinfo libavrdude_buildinfo;


#ifdef __cplusplus
}
#endif
Expand Down
63 changes: 61 additions & 2 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,50 @@ const char *pgmid; // Programmer -c string

static char usr_config[PATH_MAX]; // Per-user config file


static
const avr_buildinfo avrdude_buildinfo = {
"avrdude", AVRDUDE_FULL_VERSION,
{
{"buildsystem", AVRDUDE_BUILDSYSTEM},
{NULL, NULL},
}
};


static void print_buildinfo(const avr_buildinfo *const buildinfo)
{
msg_info(" * %s %s\n",
buildinfo->name, buildinfo->version);

for (unsigned int i=0; buildinfo->items[i].key; ++i) {
if (buildinfo->items[i].value) {
msg_info(" %3u. %s: %s\n", i,
buildinfo->items[i].key, buildinfo->items[i].value);
}
}
}


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");

const avr_buildinfo *const all_buildinfos[] = {
&avrdude_buildinfo,
&libavrdude_buildinfo,
NULL,
};

for (unsigned int i=0; all_buildinfos[i]; ++i) {
print_buildinfo(all_buildinfos[i]);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a good reason to use printf instead of msg_info here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a quick hack proof of concept, and I have not familiarized myself with the message API yet, so... No :-)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, take your time. For reference, here are all of them:

avrdude/src/avrdude.h

Lines 64 to 96 in 5c1649d

// Shortcuts
#define msg_ext_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, 0, MSG_EXT_ERROR, __VA_ARGS__)
#define msg_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, 0, MSG_ERROR, __VA_ARGS__)
#define msg_warning(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, 0, MSG_WARNING, __VA_ARGS__)
#define msg_info(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, 0, MSG_INFO, __VA_ARGS__)
#define msg_notice(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, 0, MSG_NOTICE, __VA_ARGS__)
#define msg_notice2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, 0, MSG_NOTICE2, __VA_ARGS__)
#define msg_debug(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, 0, MSG_DEBUG, __VA_ARGS__)
#define msg_trace(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, 0, MSG_TRACE, __VA_ARGS__)
#define msg_trace2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, 0, MSG_TRACE2, __VA_ARGS__)
#define pmsg_ext_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FUNCTION|MSG2_FILELINE|MSG2_TYPE|MSG2_FLUSH, MSG_EXT_ERROR, __VA_ARGS__)
#define pmsg_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FUNCTION|MSG2_FILELINE|MSG2_TYPE|MSG2_FLUSH, MSG_ERROR, __VA_ARGS__)
#define pmsg_warning(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FUNCTION|MSG2_FILELINE|MSG2_TYPE|MSG2_FLUSH, MSG_WARNING, __VA_ARGS__)
#define pmsg_info(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_INFO, __VA_ARGS__)
#define pmsg_notice(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_NOTICE, __VA_ARGS__)
#define pmsg_notice2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_NOTICE2, __VA_ARGS__)
#define pmsg_debug(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_DEBUG, __VA_ARGS__)
#define pmsg_trace(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_TRACE, __VA_ARGS__)
#define pmsg_trace2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_PROGNAME|MSG2_FLUSH, MSG_TRACE2, __VA_ARGS__)
#define imsg_ext_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT1|MSG2_FLUSH, MSG_EXT_ERROR, __VA_ARGS__)
#define imsg_error(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT1|MSG2_FLUSH, MSG_ERROR, __VA_ARGS__)
#define imsg_warning(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT1|MSG2_FLUSH, MSG_WARNING, __VA_ARGS__)
#define imsg_info(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH, MSG_INFO, __VA_ARGS__)
#define imsg_notice(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH, MSG_NOTICE, __VA_ARGS__)
#define imsg_notice2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH, MSG_NOTICE2, __VA_ARGS__)
#define imsg_debug(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH, MSG_DEBUG, __VA_ARGS__)
#define imsg_trace(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH, MSG_TRACE, __VA_ARGS__)
#define imsg_trace2(...) avrdude_message2(stderr, __LINE__, __FILE__, __func__, MSG2_INDENT2|MSG2_FLUSH, MSG_TRACE2, __VA_ARGS__)
#define term_out(...) avrdude_message2(stdout, __LINE__, __FILE__, __func__, MSG2_FLUSH, MSG_INFO, __VA_ARGS__)
#define fmsg_out(fp, ...) avrdude_message2(fp, __LINE__, __FILE__, __func__, MSG2_FLUSH, MSG_INFO, __VA_ARGS__)

  • There are msg_* macros that just print whatever you insert.
  • There are pmsg_* that prints avrdude: and then whatever you insert
  • There are imsg_* that indents so that text printed on the screen will align with p_msg

And suffixes:

  • There are _info which prints what you insert regardless of mode
  • There are notice that will print with one or more -v's
  • There are notice2 that will print with two or more -v's
  • And more 🙂



// Usage message
static void usage(void) {
char *home = getenv("HOME");
Expand Down Expand Up @@ -269,7 +315,8 @@ 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"
" -? Display this usage\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,7 +861,14 @@ int main(int argc, char *argv[]) {
#endif

// Process command line arguments
while((ch = getopt(argc, argv, "?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrtT:U:vVx:")) != -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: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 @@ -960,6 +1014,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
Loading