Enable compiling libx52 with weak symbol binding

This change allows exporting libx52_vendor_command as a weak symbol,
thereby allowing it to be overridden by a test runner to validate that
the library is indeed behaving as per the spec.

Because this is something that may not be necessarily desirable on a
production environment, add a configure time flag to disable building
with weak symbols. This will also disable any tests that may rely on
libx52_vendor_command being a weak function.
pull/22/head
nirenjan 2020-06-06 16:24:31 -07:00
parent 01e815fc3b
commit 95bc71859b
2 changed files with 25 additions and 1 deletions

View File

@ -64,6 +64,16 @@ AM_COND_IF([HAVE_DOXYGEN],
# Configuration headers
AC_CONFIG_HEADERS([config.h])
# Weak symbol support
# By default, libx52 is compiled with weak symbols, allowing certain functions
# to be overridden by the application, if necessary. However, you can get away
# with disabling the weak symbols, which will also disable some of the checks.
AC_ARG_ENABLE([weak_symbols],
AS_HELP_STRING([--disable-weak-symbols],
[Disable weak symbols during compilation]))
AM_CONDITIONAL([USE_WEAK_SYMBOLS], [test "x$enable_weak_symbols" != "xno"])
AM_COND_IF([USE_WEAK_SYMBOLS], [AX_SYS_WEAK_ALIAS])
AC_CONFIG_FILES([ po/Makefile.in
Makefile
lib/Makefile

View File

@ -66,7 +66,15 @@ int _x52_translate_libusb_error(enum libusb_error errcode)
};
}
int libx52_vendor_command(libx52_device *x52, uint16_t index, uint16_t value)
#if defined HAVE_SYS_WEAK_ALIAS
#if defined HAVE_SYS_WEAK_ALIAS_PRAGMA
#pragma weak libx52_vendor_command = _x52_vendor_command
#endif
int _x52_vendor_command
#else
int libx52_vendor_command
#endif
(libx52_device *x52, uint16_t index, uint16_t value)
{
int j;
int rc = 0;
@ -91,6 +99,12 @@ int libx52_vendor_command(libx52_device *x52, uint16_t index, uint16_t value)
return _x52_translate_libusb_error(rc);
}
#if defined HAVE_SYS_WEAK_ALIAS
#if defined HAVE_SYS_WEAK_ALIAS_ATTRIBUTE
int libx52_vendor_command(libx52_device *x52, uint16_t index, uint16_t value)
__attribute__((weak, alias("_x52_vendor_command")));
#endif
#endif
static int _x52_write_line(libx52_device *x52, uint8_t line_index)
{