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

  * Switch from getopt() to getopt_long() (available on GNU, BSD, and
    the existing msvc/getopt.[ch] already implement getopt_long() on
    Windows)

  * Add a long "--version" argument which shows a long version message.
  • Loading branch information
ndim committed Aug 6, 2024
1 parent f06b436 commit ae419f5
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 1 deletion.
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 @@ -170,6 +170,7 @@ add_library(libavrdude
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 @@ -104,6 +104,7 @@ libavrdude_a_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 @@ -84,6 +84,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
Expand Down
2 changes: 2 additions & 0 deletions src/libavrdude.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 50 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#include <sys/stat.h>
#include <sys/time.h>

#include <getopt.h>

#include "avrdude.h"
#include "libavrdude.h"
#include "config.h"
Expand Down Expand Up @@ -216,6 +218,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
*/
Expand Down Expand Up @@ -262,6 +297,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, AVRDUDE_FULL_VERSION);
Expand Down Expand Up @@ -770,7 +806,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:uvVx:yY",
longopts, NULL)) != -1) {

switch (ch) {
case 'b': /* override default programmer baud rate */
Expand Down Expand Up @@ -927,6 +971,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();
Expand Down

0 comments on commit ae419f5

Please sign in to comment.