[vlc-devel] [PATCH v2] configure: Detect bswap* functions

Rémi Denis-Courmont remi at remlab.net
Mon Mar 5 12:26:40 CET 2018


Le 27 février 2018 06:24:03 GMT+02:00, Kamil Rytarowski <n54 at gmx.com> a écrit :
>Attempt to detect bswap16, bswap32 and bswap64 on a target OS.
>
>Use a generic approach with AC_LINK_IFELSE() and AC_LANG_PROGRAM()
>to detect these functions, because their symbols can be mangled in
>libc.
>
>This is required for the NetBSD case:
> - bswap16's symbol in the libc is renamed to __bswap16,
> - bswap32's symbol renamed to __bswap32,
> - bswap64's symbol not renamed and kept as bswap64.
>
>This revision corrects build failure on NetBSD.
>---
> configure.ac         | 37 +++++++++++++++++++++++++++++++++++++
> include/vlc_common.h |  6 ++++++
> 2 files changed, 43 insertions(+)
>
>diff --git a/configure.ac b/configure.ac
>index 4184012912..0007dc8e2a 100644
>--- a/configure.ac
>+++ b/configure.ac
>@@ -847,6 +847,43 @@ AC_CHECK_HEADERS([features.h getopt.h linux/dccp.h
>linux/magic.h mntent.h sys/ev
> dnl  MacOS
> AC_CHECK_HEADERS([xlocale.h])
> 
>+dnl  byte swap
>+AC_MSG_CHECKING([bswap16])
>+AC_LINK_IFELSE([AC_LANG_PROGRAM([[
>+#include <sys/types.h>
>+#include <stdint.h>]], [
>+uint16_t A = bswap16(1);
>+])], [
>+  AC_MSG_RESULT([yes])
>+  AC_DEFINE([HAVE_BSWAP16], [1], [Define to 1 if you have the
>`bswap16` function.])
>+], [
>+  AC_MSG_RESULT([no])
>+])
>+
>+AC_MSG_CHECKING([bswap32])
>+AC_LINK_IFELSE([AC_LANG_PROGRAM([[
>+#include <sys/types.h>
>+#include <stdint.h>]], [
>+uint32_t A = bswap32(1);
>+])], [
>+  AC_MSG_RESULT([yes])
>+  AC_DEFINE([HAVE_BSWAP32], [1], [Define to 1 if you have the
>`bswap32` function.])
>+], [
>+  AC_MSG_RESULT([no])
>+])
>+
>+AC_MSG_CHECKING([bswap64])
>+AC_LINK_IFELSE([AC_LANG_PROGRAM([[
>+#include <sys/types.h>
>+#include <stdint.h>]], [
>+uint64_t A = bswap64(1);
>+])], [
>+  AC_MSG_RESULT([yes])
>+  AC_DEFINE([HAVE_BSWAP64], [1], [Define to 1 if you have the
>`bswap64` function.])
>+], [
>+  AC_MSG_RESULT([no])
>+])
>+
>dnl LP64 and LLP64 architectures had better define ssize_t by
>themselves...
>AH_TEMPLATE(ssize_t, [Define to `int' if <stddef.h> does not define.])
>dnl ` (fix VIM syntax highlight
> AC_CHECK_TYPE(ssize_t,, [
>diff --git a/include/vlc_common.h b/include/vlc_common.h
>index bab06bcf41..96646d29ce 100644
>--- a/include/vlc_common.h
>+++ b/include/vlc_common.h
>@@ -752,13 +752,16 @@ VLC_USED static inline int vlc_popcount(unsigned
>long long x)
> }
> #endif
> 
>+#ifndef HAVE_BSWAP16
> /** Byte swap (16 bits) */
> VLC_USED
> static inline uint16_t (bswap16)(uint16_t x)
> {
>     return (x << 8) | (x >> 8);
> }
>+#endif
> 
>+#ifndef HAVE_BSWAP32
> /** Byte swap (32 bits) */
> VLC_USED
> static inline uint32_t (bswap32)(uint32_t x)
>@@ -772,7 +775,9 @@ static inline uint32_t (bswap32)(uint32_t x)
>          | ((x & 0xFF000000) >> 24);
> #endif
> }
>+#endif
> 
>+#ifndef HAVE_BSWAP64
> /** Byte swap (64 bits) */
> VLC_USED
> static inline uint64_t (bswap64)(uint64_t x)
>@@ -800,6 +805,7 @@ static inline uint64_t (bswap64)(uint64_t x)
> #endif
> }
> /** @} */
>+#endif
> 
> /**
>  * \defgroup overflow Overflowing arithmetic
>-- 
>2.16.1
>
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel

Does this not break the test suite? Public headers cannot depend on config.h.
-- 
Remi Denis-Courmont


More information about the vlc-devel mailing list