Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build information to libavrdude and avrdude and display it #1698

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ include(FetchContent)
include(FindPackageMessage)
include(GNUInstallDirs)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/build-helpers")
include(buildinfo)

set(CONFIG_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}")
set(AVRDUDE_BUILDSYSTEM "cmake")
set(AVRDUDE_FULL_VERSION "${CMAKE_PROJECT_VERSION}${EXTRA_VERSION_SUFFIX}")

# =====================================
Expand Down Expand Up @@ -364,8 +368,8 @@ endif()
# Configuration
# =====================================

message(STATUS "Configuration summary:")
message(STATUS "----------------------")
message(STATUS "Configuration details:")
message(STATUS "---------------------")

if (DEBUG_CMAKE)
message(STATUS "CMAKE_HOST_SYSTEM: ${CMAKE_HOST_SYSTEM}")
Expand Down Expand Up @@ -401,27 +405,27 @@ if (DEBUG_CMAKE)
endif()

if(HAVE_LIBELF)
message(STATUS "DO HAVE libelf")
buildinfo_item("libelf" "DO HAVE")
else()
message(STATUS "DON'T HAVE libelf")
buildinfo_item("libelf" "DON'T HAVE")
endif()

if(HAVE_LIBUSB)
message(STATUS "DO HAVE libusb")
buildinfo_item("libusb" "DO HAVE")
else()
message(STATUS "DON'T HAVE libusb")
buildinfo_item("libusb" "DON'T HAVE")
endif()

if(HAVE_LIBUSB_1_0)
message(STATUS "DO HAVE libusb_1_0")
buildinfo_item("libusb_1_0" "DO HAVE")
else()
message(STATUS "DON'T HAVE libusb_1_0")
buildinfo_item("libusb_1_0" "DON'T HAVE")
endif()

if(HAVE_LIBHIDAPI)
message(STATUS "DO HAVE libhidapi")
buildinfo_item("libhidapi" "DO HAVE")
else()
message(STATUS "DON'T HAVE libhidapi")
buildinfo_item("libhidapi" "DON'T HAVE")
endif()

if(HAVE_LIBFTDI)
Expand Down Expand Up @@ -480,9 +484,9 @@ else()
endif()

if(HAVE_LINUXSPI)
message(STATUS "ENABLED linuxspi")
buildinfo_item("linuxspi" "ENABLED")
else()
message(STATUS "DISABLED linuxspi")
buildinfo_item("linuxspi" "DISABLED")
endif()

if(HAVE_SWIG)
Expand All @@ -492,3 +496,6 @@ else()
endif()

message(STATUS "----------------------")

# print the output collected by earlier calls to buildinfo_item()
buildinfo_output()
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ set(SOURCES
avrpart.c
bitbang.c
bitbang.h
buildinfo.c
buspirate.c
buspirate.h
butterfly.c
Expand Down
3 changes: 3 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ EXTRA_DIST = \

BUILT_SOURCES =
CLEANFILES =
DISTCLEANFILES =

built_sources =
built_sources += config_gram.c
Expand All @@ -42,6 +43,7 @@ built_sources += lexer.c
BUILT_SOURCES += $(built_sources)
CLEANFILES += $(built_sources)

include build-helpers/buildinfo.mk
include build-helpers/versioninfo.mk

#SUBDIRS = doc
Expand Down Expand Up @@ -106,6 +108,7 @@ libavrdude_la_SOURCES = \
avr_opcodes.c \
bitbang.c \
bitbang.h \
buildinfo.c \
buspirate.c \
buspirate.h \
butterfly.c \
Expand Down
44 changes: 44 additions & 0 deletions src/build-helpers/buildinfo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function(buildinfo_setup)
message(STATUS "BEGIN buildinfo_setup")
string(CONCAT BUILDINFO_INCLUDE_TOP
" /* buildinfo-include.c - DO NOT MODIFY THIS FILE! */\n"
" /* This include file buildinfo-include.c is AUTOGENERATED by configure. */\n"
" /* This file is meant to be \#include'ed, but is not a header file. */\n"
)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/src/buildinfo-include.c"
"${BUILDINFO_INCLUDE_TOP}")
string(CONCAT BUILDINFO_SUMMARY_TOP
"\n"
"\n"
"Configuration summary:\n"
"----------------------\n"
"\n"
)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/buildinfo-summary.txt"
"${BUILDINFO_SUMMARY_TOP}")
message(STATUS "END buildinfo_setup")
endfunction()

function(buildinfo_item KEY VAL)
cmake_parse_arguments(arg "" "" "" ${ARGN})
# message(STATUS "BEGIN buildinfo_item")
# message(STATUS " K,V: ${KEY}, ${VAL}")
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/src/buildinfo-include.c"
" {\"AUTO-BUILDINFO ${KEY}\", \"${VAL}\"},\n")
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/buildinfo-summary.txt"
" * ${KEY}: ${VAL}\n")
# message(STATUS "END buildinfo_item")
endfunction()

function(buildinfo_output)
message(STATUS "BEGIN buildinfo_output")
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/src/buildinfo-include.c"
" /* end of buildinfo-include.c */\n")
#file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/buildinfo-summary.txt"
# "\nThe End.\n")
file(READ "${CMAKE_CURRENT_BINARY_DIR}/buildinfo-summary.txt" msg)
message(STATUS ${msg})
message(STATUS "END buildinfo_output")
endfunction()

buildinfo_setup()
70 changes: 70 additions & 0 deletions src/build-helpers/buildinfo.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# buildinfo.m4 - print build info at build time and at runtime -*- Autoconf -*-
# serial 2
dnl | Increment the above serial number every time you edit this file.
dnl | When it finds multiple m4 files with the same name,
dnl | aclocal will use the one with the highest serial.
dnl
dnl
dnl ========================================================================
dnl BUILDINFO_SETUP()
dnl ========================================================================
dnl
m4_pattern_forbid([^BUILDINFO_SETUP])dnl
dnl
AC_DEFUN([BUILDINFO_SETUP], [dnl
dnl AC_MSG_NOTICE([BEGIN ][[$0]])
cat>buildinfo-summary.txt<<EOF

Configuration summary:
----------------------

EOF
cat>buildinfo-include.c<<EOF
/* buildinfo-include.c - DO NOT MODIFY THIS FILE! */
/* This include file buildinfo-include.c is AUTOGENERATED by configure. */
/* This file is meant to be \#include'ed, but is not a header file. */
EOF
dnl AC_MSG_NOTICE([END ][[$0]])
])dnl
dnl
dnl
dnl ========================================================================
dnl BUILDINFO_ITEM([key], [value])
dnl ========================================================================
dnl
m4_pattern_forbid([^BUILDINFO_ITEM])dnl
dnl
AC_DEFUN([BUILDINFO_ITEM], [dnl
dnl AC_MSG_NOTICE([BEGIN ][[$0]])
AC_REQUIRE([BUILDINFO_SETUP])
printf " * %-15s %s\n" "$1:" "$2" >> buildinfo-summary.txt
printf " {\"AUTO-BUILDINFO %s\", \"%s\"},\n" "$1" "$2" >> buildinfo-include.c
dnl AC_MSG_NOTICE([END ][[$0]])
])dnl
dnl
dnl
dnl ========================================================================
dnl BUILDINFO_OUTPUT()
dnl ========================================================================
dnl
m4_pattern_forbid([^BUILDINFO_OUTPUT])dnl
dnl
AC_DEFUN([BUILDINFO_OUTPUT], [dnl
dnl AC_MSG_NOTICE([BEGIN ][[$0]])
AC_REQUIRE([BUILDINFO_SETUP])
cat>>buildinfo-summary.txt<<EOF

EOF
cat>>buildinfo-include.c<<EOF
/* end of buildinfo-include.c */
EOF
dnl AC_MSG_NOTICE([END ][[$0]])

cat buildinfo-summary.txt
])dnl
dnl
dnl ####################################################################
dnl
dnl Local Variables:
dnl mode: autoconf
dnl End:
1 change: 1 addition & 0 deletions src/build-helpers/buildinfo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FIXME: Write this file.
5 changes: 5 additions & 0 deletions src/build-helpers/buildinfo.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
EXTRA_DIST += build-helpers/buildinfo.m4
EXTRA_DIST += build-helpers/buildinfo.md

DISTCLEANFILES += buildinfo-include.c
DISTCLEANFILES += buildinfo-summary.txt
111 changes: 111 additions & 0 deletions src/buildinfo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include <libavrdude.h>

#include <ac_cfg.h>


const avr_buildinfo libavrdude_buildinfo = {
"libavrdude", AVRDUDE_FULL_VERSION,
{
{"buildsystem", AVRDUDE_BUILDSYSTEM},

#include <buildinfo-include.c>

{"libelf",
#ifdef HAVE_LIBELF
"yes"
#else
NULL
#endif
},

{"libusb",
#ifdef HAVE_LIBUSB
"yes"
#else
NULL
#endif
},

{"libusb_1_0",
#ifdef HAVE_LIBUSB_1_0
"yes"
#else
NULL
#endif
},

{"libhidapi",
#ifdef HAVE_LIBHIDAPI
"yes"
#else
NULL
#endif
},

{"libhid",
#ifdef HAVE_LIBHID
"yes"
#else
NULL
#endif
},

{"libftdi",
#ifdef HAVE_LIBFTDI
"yes"
#else
NULL
#endif
},

{"libftdi1",
#ifdef HAVE_LIBFTDI1
"yes"
#else
NULL
#endif
},

{"libreadline",
#ifdef HAVE_LIBREADLINE
"yes"
#else
NULL
#endif
},

{"libserialport",
#ifdef HAVE_LIBSERIALPORT
"yes"
#else
NULL
#endif
},

{"parport",
#ifdef HAVE_PARPORT
"yes"
#else
NULL
#endif
},

{"linuxgpio",
#ifdef HAVE_LINUXGPIO
"yes"
#else
NULL
#endif
},

{"linuxspi",
#ifdef HAVE_LINUXSPI
"yes"
#else
NULL
#endif
},

{NULL, NULL},
},
};
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
Loading
Loading