Skip to content

Commit 424ae72

Browse files
committed
XXX add basic buildinfo ideas
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?
1 parent 9873a32 commit 424ae72

File tree

8 files changed

+107
-4
lines changed

8 files changed

+107
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ include(FindPackageMessage)
4949
include(GNUInstallDirs)
5050

5151
set(CONFIG_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}")
52+
set(AVRDUDE_BUILDSYSTEM "cmake")
5253
set(AVRDUDE_FULL_VERSION ${CMAKE_PROJECT_VERSION})
5354

5455
# =====================================

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ set(SOURCES
179179
avrpart.c
180180
bitbang.c
181181
bitbang.h
182+
buildinfo.c
182183
buspirate.c
183184
buspirate.h
184185
butterfly.c

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ libavrdude_la_SOURCES = \
106106
avr_opcodes.c \
107107
bitbang.c \
108108
bitbang.h \
109+
buildinfo.c \
109110
buspirate.c \
110111
buspirate.h \
111112
butterfly.c \

src/buildinfo.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <libavrdude.h>
2+
3+
#include <ac_cfg.h>
4+
5+
static
6+
const char *const libavrdude_buildinfo[] = {
7+
AVRDUDE_FULL_VERSION,
8+
"buildsystem: " AVRDUDE_BUILDSYSTEM,
9+
#ifdef HAVE_LIBELF
10+
"libelf",
11+
#endif
12+
#ifdef HAVE_LIBUSB
13+
"libusb",
14+
#endif
15+
#ifdef HAVE_LIBUSB_1_0
16+
"libusb_1_0",
17+
#endif
18+
#ifdef HAVE_LIBHIDAPI
19+
"libhidapi",
20+
#endif
21+
#ifdef HAVE_LIBHID
22+
"libhid",
23+
#endif
24+
#ifdef HAVE_LIBFTDI
25+
"libftdi",
26+
#endif
27+
#ifdef HAVE_LIBFTDI1
28+
"libftdi1",
29+
#endif
30+
#ifdef HAVE_LIBREADLINE
31+
"libreadline",
32+
#endif
33+
#ifdef HAVE_LIBSERIALPORT
34+
"libserialport",
35+
#endif
36+
#ifdef HAVE_PARPORT
37+
"parport",
38+
#endif
39+
#ifdef HAVE_LINUXGPIO
40+
"linuxgpio",
41+
#endif
42+
#ifdef HAVE_LINUXSPI
43+
"linuxspi",
44+
#endif
45+
NULL
46+
};
47+
48+
const char *const *avr_get_buildinfo(void)
49+
{
50+
return libavrdude_buildinfo;
51+
}

src/cmake_config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#endif
2222

2323
#define AVRDUDE_FULL_VERSION "@AVRDUDE_FULL_VERSION@"
24+
#define AVRDUDE_BUILDSYSTEM "@AVRDUDE_BUILDSYSTEM@"
2425

2526
/* Options */
2627

src/configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ AC_DEFINE_UNQUOTED([AVRDUDE_FULL_VERSION], ["$AVRDUDE_FULL_VERSION"],
9191
[The full avrdude version as displayed in -? and avrdude.conf])
9292
AC_SUBST([AVRDUDE_FULL_VERSION])
9393

94+
AC_DEFINE_UNQUOTED([AVRDUDE_BUILDSYSTEM], ["autotools"],
95+
[The buildsystem used to build avrdude])
96+
9497

9598
# Define libavrdude libtool version from cmake libavrdude information
9699
dnl

src/libavrdude.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,8 @@ extern "C" {
12021202
int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p);
12031203
int avr_reset_cache(const PROGRAMMER *pgm, const AVRPART *p);
12041204

1205+
const char *const *avr_get_buildinfo(void);
1206+
12051207
#ifdef __cplusplus
12061208
}
12071209
#endif

src/main.c

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#include <dirent.h>
4949
#endif
5050

51+
#include <getopt.h>
52+
5153
#include "avrdude.h"
5254
#include "libavrdude.h"
5355
#include "config.h"
@@ -228,6 +230,39 @@ const char *pgmid; // Programmer -c string
228230

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

233+
234+
static
235+
const char *const avrdude_buildinfo[] = {
236+
AVRDUDE_FULL_VERSION,
237+
"buildsystem: " AVRDUDE_BUILDSYSTEM,
238+
NULL
239+
};
240+
241+
242+
static void print_buildinfos(const char *const *buildinfo)
243+
{
244+
for (unsigned int i=1; buildinfo[i]; ++i) {
245+
msg_info("%3u. %s\n", i, buildinfo[i]);
246+
}
247+
}
248+
249+
250+
static void print_version_message(void)
251+
{
252+
msg_info("avrdude (...) %s\n", AVRDUDE_FULL_VERSION);
253+
msg_info("Copyright (C) ...2024...\n");
254+
msg_info("License GPL...\n");
255+
msg_info("This is free software...\n");
256+
257+
msg_info("avrdude %s\n", avrdude_buildinfo[0]);
258+
print_buildinfos(avrdude_buildinfo);
259+
260+
const char *const *libavrdude_buildinfo = avr_get_buildinfo();
261+
msg_info("libavrdude %s\n", libavrdude_buildinfo[0]);
262+
print_buildinfos(libavrdude_buildinfo);
263+
}
264+
265+
231266
// Usage message
232267
static void usage(void) {
233268
char *home = getenv("HOME");
@@ -269,6 +304,7 @@ static void usage(void) {
269304
" -v Verbose output; -v -v for more\n"
270305
" -q Quell progress output; -q -q for less\n"
271306
" -l logfile Use logfile rather than stderr for diagnostics\n"
307+
" --version Display build and version information\n"
272308
" -? | --help Display this usage\n"
273309
"\navrdude version %s, https://github.com/avrdudes/avrdude\n",
274310
progname, strlen(cfg) < 24? "config file ": "", cfg, AVRDUDE_FULL_VERSION);
@@ -814,12 +850,14 @@ int main(int argc, char *argv[]) {
814850
#endif
815851

816852
// Process command line arguments
853+
#define LONGOPT_VERSION 0x2342
817854
struct option longopts[] = {
818-
{"help", no_argument, NULL, '?'},
819-
{NULL, 0, NULL, 0}
855+
{"help", no_argument, NULL, '?'},
856+
{"version", no_argument, NULL, LONGOPT_VERSION},
857+
{NULL, 0, NULL, 0}
820858
};
821-
while((ch = getopt(argc, argv, "?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrtT:U:vVx:",
822-
longopts, NULL)) != -1) {
859+
while((ch = getopt_long(argc, argv, "?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrtT:U:vVx:",
860+
longopts, NULL)) != -1) {
823861
switch(ch) {
824862
case 'b': // Override default programmer baud rate
825863
baudrate = str_int(optarg, STR_INT32, &errstr);
@@ -965,6 +1003,11 @@ int main(int argc, char *argv[]) {
9651003
exit(0);
9661004
break;
9671005

1006+
case LONGOPT_VERSION:
1007+
print_version_message();
1008+
exit(0);
1009+
break;
1010+
9681011
default:
9691012
pmsg_error("invalid option -%c\n\n", ch);
9701013
usage();

0 commit comments

Comments
 (0)