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 "--version" argument which shows a long version message.
  • Loading branch information
ndim committed Feb 23, 2024
1 parent 5c61b9e commit 000b1e1
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 @@ -160,6 +160,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 @@ -107,6 +107,7 @@ libavrdude_a_SOURCES = \
avrpart.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 @@ -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
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 @@ -46,6 +46,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 @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 000b1e1

Please sign in to comment.