From b0119419b6edc287062e3a34a199a4315d860d28 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Tue, 14 Dec 2021 13:59:42 -0600 Subject: portability: take over apk_endian.h --- portability/apk_endian.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ portability/meson.build | 5 +++++ src/apk_endian.h | 33 ---------------------------- src/meson.build | 8 ++++++- 4 files changed, 69 insertions(+), 34 deletions(-) create mode 100644 portability/apk_endian.h delete mode 100644 src/apk_endian.h diff --git a/portability/apk_endian.h b/portability/apk_endian.h new file mode 100644 index 0000000..284b07b --- /dev/null +++ b/portability/apk_endian.h @@ -0,0 +1,57 @@ +/* apk_endian.h - Alpine Package Keeper (APK) + * + * Copyright (C) 2005-2008 Natanael Copa + * Copyright (C) 2008-2011 Timo Teräs + * Copyright (C) 2011 Rich Felker + * All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +#ifndef APK_ENDIAN_H +#define APK_ENDIAN_H + +static __inline uint16_t __bswap16(uint16_t __x) +{ + return (__x<<8) | (__x>>8); +} + +static __inline uint32_t __bswap32(uint32_t __x) +{ + return (__x>>24) | (__x>>8&0xff00) | (__x<<8&0xff0000) | (__x<<24); +} + +static __inline uint64_t __bswap64(uint64_t __x) +{ + return (__bswap32(__x)+0ULL)<<32 | __bswap32(__x>>32); +} + +#ifndef WORDS_BIGENDIAN +# define htobe16(x) __bswap16(x) +# define be16toh(x) __bswap16(x) +# define htobe32(x) __bswap32(x) +# define be32toh(x) __bswap32(x) +# define htobe64(x) __bswap64(x) +# define be64toh(x) __bswap64(x) +# define htole16(x) (uint16_t)(x) +# define le16toh(x) (uint16_t)(x) +# define htole32(x) (uint32_t)(x) +# define le32toh(x) (uint32_t)(x) +# define htole64(x) (uint64_t)(x) +# define le64toh(x) (uint64_t)(x) +#else +# define htobe16(x) (uint16_t)(x) +# define be16toh(x) (uint16_t)(x) +# define htobe32(x) (uint32_t)(x) +# define be32toh(x) (uint32_t)(x) +# define htobe64(x) (uint64_t)(x) +# define be64toh(x) (uint64_t)(x) +# define htole16(x) __bswap16(x) +# define le16toh(x) __bswap16(x) +# define htole32(x) __bswap32(x) +# define le32toh(x) __bswap32(x) +# define htole64(x) __bswap64(x) +# define le64toh(x) __bswap64(x) +#endif + +#endif diff --git a/portability/meson.build b/portability/meson.build index e3be65d..851dfca 100644 --- a/portability/meson.build +++ b/portability/meson.build @@ -1,6 +1,11 @@ cc = meson.get_compiler('c') +if host_machine.endian() == 'big' + add_project_arguments('-DWORDS_BIGENDIAN', language: 'c') +endif + + libportability_src = [] diff --git a/src/apk_endian.h b/src/apk_endian.h deleted file mode 100644 index d4ff516..0000000 --- a/src/apk_endian.h +++ /dev/null @@ -1,33 +0,0 @@ -/* apk_endian.h - Alpine Package Keeper (APK) - * - * Copyright (C) 2005-2008 Natanael Copa - * Copyright (C) 2008-2011 Timo Teräs - * All rights reserved. - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#ifndef APK_ENDIAN_H -#define APK_ENDIAN_H - -#ifdef __linux__ -# include -#endif - -#ifdef __APPLE__ -# include -# define htobe16(x) OSSwapHostToBigInt16(x) -# define htole16(x) OSSwapHostToLittleInt16(x) -# define be16toh(x) OSSwapBigToHostInt16(x) -# define le16toh(x) OSSwapLittleToHostInt16(x) -# define htobe32(x) OSSwapHostToBigInt32(x) -# define htole32(x) OSSwapHostToLittleInt32(x) -# define be32toh(x) OSSwapBigToHostInt32(x) -# define le32toh(x) OSSwapLittleToHostInt32(x) -# define htobe64(x) OSSwapHostToBigInt64(x) -# define htole64(x) OSSwapHostToLittleInt64(x) -# define be64toh(x) OSSwapBigToHostInt64(x) -# define le64toh(x) OSSwapLittleToHostInt64(x) -#endif - -#endif diff --git a/src/meson.build b/src/meson.build index ccfdbb0..da6bb9b 100644 --- a/src/meson.build +++ b/src/meson.build @@ -160,7 +160,12 @@ if(lua_dep.found()) libluaapk = library( 'luaapk', luaapk_src, - dependencies: [lua_dep, libapk_dep, shared_deps], + dependencies: [ + lua_dep, + libapk_dep, + shared_deps, + libportability_dep.partial_dependency(includes: true), + ], install: true, install_dir: lua_dep.get_pkgconfig_variable('libdir'), c_args: apk_cargs, @@ -175,6 +180,7 @@ apk_exe = executable( libapk_dep, shared_deps, libfetch_dep.partial_dependency(includes: true), + libportability_dep.partial_dependency(includes: true), ], c_args: apk_cargs, ) -- cgit v1.2.3-70-g09d2