Skip to content

Commit 0916bdb

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 CLI tool * Add a long "--version" argument which shows a long version message. This buildinfo contains the name and version of the software component, and then a key-value-list for each buildinfo item.
1 parent b47c687 commit 0916bdb

File tree

8 files changed

+187
-0
lines changed

8 files changed

+187
-0
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}${EXTRA_VERSION_SUFFIX}")
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: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#include <libavrdude.h>
2+
3+
#include <ac_cfg.h>
4+
5+
6+
const avr_buildinfo libavrdude_buildinfo = {
7+
"libavrdude", AVRDUDE_FULL_VERSION,
8+
{
9+
{"buildsystem", AVRDUDE_BUILDSYSTEM},
10+
11+
{"libelf",
12+
#ifdef HAVE_LIBELF
13+
"yes"
14+
#else
15+
NULL
16+
#endif
17+
},
18+
19+
{"libusb",
20+
#ifdef HAVE_LIBUSB
21+
"yes"
22+
#else
23+
NULL
24+
#endif
25+
},
26+
27+
{"libusb_1_0",
28+
#ifdef HAVE_LIBUSB_1_0
29+
"yes"
30+
#else
31+
NULL
32+
#endif
33+
},
34+
35+
{"libhidapi",
36+
#ifdef HAVE_LIBHIDAPI
37+
"yes"
38+
#else
39+
NULL
40+
#endif
41+
},
42+
43+
{"libhid",
44+
#ifdef HAVE_LIBHID
45+
"yes"
46+
#else
47+
NULL
48+
#endif
49+
},
50+
51+
{"libftdi",
52+
#ifdef HAVE_LIBFTDI
53+
"yes"
54+
#else
55+
NULL
56+
#endif
57+
},
58+
59+
{"libftdi1",
60+
#ifdef HAVE_LIBFTDI1
61+
"yes"
62+
#else
63+
NULL
64+
#endif
65+
},
66+
67+
{"libreadline",
68+
#ifdef HAVE_LIBREADLINE
69+
"yes"
70+
#else
71+
NULL
72+
#endif
73+
},
74+
75+
{"libserialport",
76+
#ifdef HAVE_LIBSERIALPORT
77+
"yes"
78+
#else
79+
NULL
80+
#endif
81+
},
82+
83+
{"parport",
84+
#ifdef HAVE_PARPORT
85+
"yes"
86+
#else
87+
NULL
88+
#endif
89+
},
90+
91+
{"linuxgpio",
92+
#ifdef HAVE_LINUXGPIO
93+
"yes"
94+
#else
95+
NULL
96+
#endif
97+
},
98+
99+
{"linuxspi",
100+
#ifdef HAVE_LINUXSPI
101+
"yes"
102+
#else
103+
NULL
104+
#endif
105+
},
106+
107+
{NULL, NULL},
108+
},
109+
};

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
@@ -93,6 +93,9 @@ AC_DEFINE_UNQUOTED([AVRDUDE_FULL_VERSION], ["$AVRDUDE_FULL_VERSION"],
9393
[The full avrdude version as displayed in -? and avrdude.conf])
9494
AC_SUBST([AVRDUDE_FULL_VERSION])
9595

96+
AC_DEFINE_UNQUOTED([AVRDUDE_BUILDSYSTEM], ["autotools"],
97+
[The buildsystem used to build avrdude])
98+
9699

97100
# Define libavrdude libtool version from cmake libavrdude information
98101
dnl

src/libavrdude.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,21 @@ 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+
1206+
typedef struct avr_buildinfo_item {
1207+
const char *const key;
1208+
const char *const value;
1209+
} avr_buildinfo_item;
1210+
1211+
typedef struct avr_buildinfo {
1212+
const char *const name;
1213+
const char *const version;
1214+
avr_buildinfo_item items[];
1215+
} avr_buildinfo;
1216+
1217+
extern const avr_buildinfo libavrdude_buildinfo;
1218+
1219+
12051220
#ifdef __cplusplus
12061221
}
12071222
#endif

src/main.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
#include <dirent.h>
5050
#endif
5151

52+
#include <getopt.h>
53+
5254
#include "avrdude.h"
5355
#include "libavrdude.h"
5456
#include "config.h"
@@ -229,6 +231,52 @@ const char *pgmid; // Programmer -c string
229231

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

234+
235+
static
236+
const avr_buildinfo avrdude_buildinfo = {
237+
"avrdude", AVRDUDE_FULL_VERSION,
238+
{
239+
{"buildsystem", AVRDUDE_BUILDSYSTEM},
240+
{NULL, NULL},
241+
}
242+
};
243+
244+
245+
static void print_buildinfo(const avr_buildinfo *const buildinfo)
246+
{
247+
msg_info(" * %s %s\n",
248+
buildinfo->name, buildinfo->version);
249+
250+
for (unsigned int i=0; buildinfo->items[i].key; ++i) {
251+
if (buildinfo->items[i].value) {
252+
msg_info(" %3u. %s: %s\n",
253+
i+1,
254+
buildinfo->items[i].key,
255+
buildinfo->items[i].value);
256+
}
257+
}
258+
}
259+
260+
261+
static void print_version_message(void)
262+
{
263+
msg_info("avrdude %s\n", AVRDUDE_FULL_VERSION);
264+
msg_info("Copyright (C) ...2024...\n");
265+
msg_info("License GPL...\n");
266+
msg_info("This is free software...\n");
267+
268+
const avr_buildinfo *const all_buildinfos[] = {
269+
&avrdude_buildinfo,
270+
&libavrdude_buildinfo,
271+
NULL,
272+
};
273+
274+
for (unsigned int i=0; all_buildinfos[i]; ++i) {
275+
print_buildinfo(all_buildinfos[i]);
276+
}
277+
}
278+
279+
232280
// Usage message
233281
static void usage(void) {
234282
char *home = getenv("HOME");
@@ -273,6 +321,7 @@ static void usage(void) {
273321
" -q Quell progress output; -q -q for less\n"
274322
" -l, --logfile logfile Use logfile rather than stderr for diagnostics\n"
275323
" -?, --help Display this usage\n"
324+
" --version Display build and version information\n"
276325
"\navrdude version %s, https://github.com/avrdudes/avrdude\n",
277326
progname, strlen(cfg) < 24? "config file ": "", cfg, AVRDUDE_FULL_VERSION);
278327

@@ -817,6 +866,7 @@ int main(int argc, char *argv[]) {
817866
#endif
818867

819868
// Process command line arguments
869+
#define LONGOPT_VERSION 0x2342
820870
struct option longopts[] = {
821871
{"help", no_argument, NULL, '?'},
822872
{"baud", required_argument, NULL, 'b'},
@@ -838,6 +888,7 @@ int main(int argc, char *argv[]) {
838888
{"memory", required_argument, NULL, 'U'},
839889
{"verbose", no_argument, NULL, 'v'},
840890
{"noverify", no_argument, NULL, 'V'},
891+
{"version", no_argument, NULL, LONGOPT_VERSION},
841892
{NULL, 0, NULL, 0}
842893
};
843894
while((ch = getopt_long(argc, argv,
@@ -988,6 +1039,11 @@ int main(int argc, char *argv[]) {
9881039
exit(0);
9891040
break;
9901041

1042+
case LONGOPT_VERSION:
1043+
print_version_message();
1044+
exit(0);
1045+
break;
1046+
9911047
default:
9921048
pmsg_error("invalid option -%c\n\n", ch);
9931049
usage();

0 commit comments

Comments
 (0)