Skip to content

Commit f09ff55

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 * 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.
1 parent 100098d commit f09ff55

File tree

8 files changed

+110
-1
lines changed

8 files changed

+110
-1
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
@@ -169,6 +169,7 @@ add_library(libavrdude
169169
avrpart.c
170170
bitbang.c
171171
bitbang.h
172+
buildinfo.c
172173
buspirate.c
173174
buspirate.h
174175
butterfly.c

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ libavrdude_a_SOURCES = \
107107
avrpart.c \
108108
bitbang.c \
109109
bitbang.h \
110+
buildinfo.c \
110111
buspirate.c \
111112
buspirate.h \
112113
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
@@ -89,6 +89,9 @@ AC_DEFINE_UNQUOTED([AVRDUDE_FULL_VERSION], ["$AVRDUDE_FULL_VERSION"],
8989
[The full avrdude version as displayed in -? and avrdude.conf])
9090
AC_SUBST([AVRDUDE_FULL_VERSION])
9191

92+
AC_DEFINE_UNQUOTED([AVRDUDE_BUILDSYSTEM], ["autotools"],
93+
[The buildsystem used to build avrdude])
94+
9295

9396
# Checks for programs.
9497
AC_PROG_CC

src/libavrdude.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,8 @@ int avr_page_erase_cached(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM
11841184
int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p);
11851185
int avr_reset_cache(const PROGRAMMER *pgm, const AVRPART *p);
11861186

1187+
const char *const *avr_get_buildinfo(void);
1188+
11871189
#ifdef __cplusplus
11881190
}
11891191
#endif

src/main.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#include <sys/stat.h>
4848
#include <sys/time.h>
4949

50+
#include <getopt.h>
51+
5052
#include "avrdude.h"
5153
#include "libavrdude.h"
5254
#include "config.h"
@@ -210,6 +212,39 @@ const char *pgmid; // Programmer -c string
210212

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

215+
216+
static
217+
const char *const avrdude_buildinfo[] = {
218+
AVRDUDE_FULL_VERSION,
219+
"buildsystem: " AVRDUDE_BUILDSYSTEM,
220+
NULL
221+
};
222+
223+
224+
static void print_buildinfos(const char *const *buildinfo)
225+
{
226+
for (unsigned int i=1; buildinfo[i]; ++i) {
227+
msg_info("%3u. %s\n", i, buildinfo[i]);
228+
}
229+
}
230+
231+
232+
static void print_version_message(void)
233+
{
234+
msg_info("avrdude (...) %s\n", AVRDUDE_FULL_VERSION);
235+
msg_info("Copyright (C) ...2024...\n");
236+
msg_info("License GPL...\n");
237+
msg_info("This is free software...\n");
238+
239+
msg_info("avrdude %s\n", avrdude_buildinfo[0]);
240+
print_buildinfos(avrdude_buildinfo);
241+
242+
const char *const *libavrdude_buildinfo = avr_get_buildinfo();
243+
msg_info("libavrdude %s\n", libavrdude_buildinfo[0]);
244+
print_buildinfos(libavrdude_buildinfo);
245+
}
246+
247+
213248
/*
214249
* usage message
215250
*/
@@ -256,6 +291,7 @@ static void usage(void)
256291
" -v Verbose output; -v -v for more\n"
257292
" -q Quell progress output; -q -q for less\n"
258293
" -l logfile Use logfile rather than stderr for diagnostics\n"
294+
" --version Display build and version information\n"
259295
" -? Display this usage\n"
260296
"\navrdude version %s, https://github.com/avrdudes/avrdude\n",
261297
progname, strlen(cfg) < 24? "config file ": "", cfg, AVRDUDE_FULL_VERSION);
@@ -771,7 +807,15 @@ int main(int argc, char * argv [])
771807
/*
772808
* process command line arguments
773809
*/
774-
while ((ch = getopt(argc,argv,"?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrstT:U:uvVx:yY:")) != -1) {
810+
#define LONGOPT_VERSION 0x2342
811+
struct option longopts[] = {
812+
{"help", no_argument, NULL, '?'},
813+
{"version", no_argument, NULL, LONGOPT_VERSION},
814+
{NULL, 0, NULL, 0}
815+
};
816+
while ((ch = getopt_long(argc, argv,
817+
"?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrstT:U:uvVwx:yY:",
818+
longopts, NULL)) != -1) {
775819

776820
switch (ch) {
777821
case 'b': /* override default programmer baud rate */
@@ -931,6 +975,11 @@ int main(int argc, char * argv [])
931975
exit(0);
932976
break;
933977

978+
case LONGOPT_VERSION: /* version and build information */
979+
print_version_message();
980+
exit(0);
981+
break;
982+
934983
default:
935984
pmsg_error("invalid option -%c\n\n", ch);
936985
usage();

0 commit comments

Comments
 (0)