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

MacOS - changes to the core code to allow DLite to compile on MacOS #1064

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
64 changes: 57 additions & 7 deletions src/utils/byteorder.h.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* .h file GENERATED FROM byterorder.h.in */

/* byteorder.h - cross-platform header for byte ordering
*
* Copyright (C) 2017 SINTEF Materials and Chemistry
Expand Down Expand Up @@ -60,10 +62,10 @@
#cmakedefine HAVE_BSWAP_64 /* Whether function bswap_64 exists */
#cmakedefine HAVE_BSWAP_128 /* Whether function bswap_128 exists */

#cmakedefine HAVE_BYTESWAP_USHORT /* Whether function _byteswap_ushort exists */
#cmakedefine HAVE_BYTESWAP_ULONG /* Whether function _byteswap_ulong exists */
#cmakedefine HAVE_BYTESWAP_UINT64 /* Whether function _byteswap_uint64 exists */
#cmakedefine HAVE_BYTESWAP_UINT128/* Whether function _byteswap_uint128 exists*/
#cmakedefine HAVE__BYTESWAP_USHORT /* Whether function _byteswap_ushort exists */
#cmakedefine HAVE__BYTESWAP_ULONG /* Whether function _byteswap_ulong exists */
#cmakedefine HAVE__BYTESWAP_UINT64 /* Whether function _byteswap_uint64 exists */
#cmakedefine HAVE__BYTESWAP_UINT128/* Whether function _byteswap_uint128 exists*/

#cmakedefine HAVE_HTOBE16 /* Whether function htobe16 exists */
#cmakedefine HAVE_HTOBE32 /* Whether function htobe32 exists */
Expand All @@ -74,11 +76,43 @@
#include "integers.h"

#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif
#if defined(__APPLE__) && defined(__MACH__)
#include <machine/endian.h>
#else
#include <endian.h>
#endif /* defined(__APPLE__) && defined(__MACH__) */
#endif /* ifdef HAVE_ENDIAN_H */

#ifdef HAVE_BYTESWAP_H
# include <byteswap.h>
#if defined(__APPLE__) && defined(__MACH__)
#include <libkern/OSByteOrder.h>
#ifdef HAVE_BSWAP_16
#define bswap_16(x) OSSwapInt16(x)
#endif
#ifdef HAVE_BSWAP_32
#define bswap_32(x) OSSwapInt32(x)
#endif
#ifdef HAVE_BSWAP_64
#define bswap_64(x) OSSwapInt64(x)
#endif
#ifdef HAVE_BSWAP_128
#define bswap_128(x) OSSwapInt128(x)
#endif
#ifdef HAVE_HTOBE16
#define htobe16(x) OSSwapHostToBigInt16(x)
#endif
#ifdef HAVE_HTOBE32
#define htobe32(x) OSSwapHostToBigInt32(x)
#endif
#ifdef HAVE_HTOBE64
#define htobe64(x) OSSwapHostToBigInt64(x)
#endif
#ifdef HAVE_HTOBE128
#define htobe128(x) OSSwapHostToBigInt128(x)
#endif
#else
#include <byteswap.h>
#endif /* defined(__APPLE__) && defined(__MACH__) */
#endif


Expand Down Expand Up @@ -161,6 +195,10 @@
# else
# error "Byte order not supported: " # BYTE_ORDER
# endif
#elif (defined(__APPLE__) && defined(__MACH__) && defined(HAVE_HTOBE16))
# define htole16(x) (uint16_t)(x)
# define be16toh(x) bswap_16(x)
# define le16toh(x) (uint16_t)(x)
#endif

#ifndef HAVE_HTOBE32
Expand All @@ -177,6 +215,10 @@
# else
# error "Byte order not supported: " # BYTE_ORDER
# endif
#elif (defined(__APPLE__) && defined(__MACH__) && defined(HAVE_HTOBE32))
# define htole32(x) (uint32_t)(x)
# define be32toh(x) bswap_32(x)
# define le32toh(x) (uint32_t)(x)
#endif

#ifndef HAVE_HTOBE64
Expand All @@ -193,6 +235,10 @@
# else
# error "Byte order not supported: " # BYTE_ORDER
# endif
#elif (defined(__APPLE__) && defined(__MACH__) && defined(HAVE_HTOBE64))
# define htole64(x) (uint64_t)(x)
# define be64toh(x) bswap_64(x)
# define le64toh(x) (uint64_t)(x)
#endif

#ifdef bswap128
Expand All @@ -210,6 +256,10 @@
# else
# error "Byte order not supported: " # BYTE_ORDER
# endif
# elif (defined(__APPLE__) && defined(__MACH__) && defined(HAVE_HTOBE128))
# define htole128(x) (uint128_t)(x)
# define be128toh(x) bswap_128(x)
# define le128toh(x) (uint128_t)(x)
# endif
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/utils/compat-src/getopt.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* Released under the MIT license
* https://github.com/takamin/win-c/blob/master/LICENSE
*/
#ifndef _GETOPT_H_
#define _GETOPT_H_

#ifdef __cplusplus
extern "C" {
Expand All @@ -16,6 +14,8 @@ extern "C" {
#ifdef HAVE_GETOPT
#include <getopt.h>
#else
#ifndef _GETOPT_H_
#define _GETOPT_H_

int getopt(int argc, char* const argv[],
const char* optstring);
Expand Down
25 changes: 14 additions & 11 deletions src/utils/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,23 @@
#cmakedefine HAVE_MBSTOWCS_S
#cmakedefine HAVE_WCSTOMBS_S

#cmakedefine HAVE_STRLCPY
#cmakedefine HAVE_STRLCAT

#cmakedefine HAVE_GETOPT
#cmakedefine HAVE_GETOPT_LONG

// #cmakedefine HAVE_SNPRINTF
// #cmakedefine HAVE__SNPRINTF
// #cmakedefine HAVE_VSNPRINTF
// #cmakedefine HAVE__VSNPRINTF
// #cmakedefine HAVE_VASPRINTF
// #cmakedefine HAVE__VASPRINTF
// #cmakedefine HAVE_ASPRINTF
// #cmakedefine HAVE__ASPRINTF
// #cmakedefine HAVE_LOCALECONV
// #cmakedefine HAVE_VA_COPY
// #cmakedefine HAVE___VA_COPY
#cmakedefine HAVE_SNPRINTF
#cmakedefine HAVE__SNPRINTF
#cmakedefine HAVE_VSNPRINTF
#cmakedefine HAVE__VSNPRINTF
#cmakedefine HAVE_VASPRINTF
#cmakedefine HAVE__VASPRINTF
#cmakedefine HAVE_ASPRINTF
#cmakedefine HAVE__ASPRINTF
#cmakedefine HAVE_LOCALECONV
#cmakedefine HAVE_VA_COPY
#cmakedefine HAVE___VA_COPY

#cmakedefine HAVE_MTX_INIT
#cmakedefine HAVE_MTX_LOCK
Expand Down
4 changes: 2 additions & 2 deletions src/utils/dsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@


/* Determine platform */
#if defined __APPLE__ && defined __MARCH__
#if defined __APPLE__ && defined __MACH__
# define DSL_PLATFORM DSL_Posix
# ifndef DSL_PREFIX
# define DSL_PREFIX ""
# define DSL_PREFIX "lib"
# endif
# ifndef DSL_EXT
# define DSL_EXT ".dylib"
Expand Down
2 changes: 1 addition & 1 deletion src/utils/fileinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <errno.h>
#include <stdio.h>

#if defined(__unix__)
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
# ifndef POSIX
# define POSIX
# endif
Expand Down
31 changes: 21 additions & 10 deletions src/utils/fileutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ static char *_platform_names[] = {"Native", "Unix", "Windows", "Apple", NULL};
*/
FUPlatform fu_native_platform(void)
{
#if defined POSIX
#if defined POSIX && !defined(__APPLE__)
return fuUnix;
#elif defined WINDOWS
return fuWindows;
#elif defined __APPLE__
#elif (defined __APPLE__ && defined __MACH__)
return fuApple;
#else
return fuUnknownPlatform;
Expand All @@ -91,6 +91,7 @@ int fu_supported_platform(FUPlatform platform)
switch (platform) {
case fuUnix:
case fuWindows:
case fuApple:
return 1;
default:
return 0;
Expand Down Expand Up @@ -127,8 +128,11 @@ const char *fu_dirsep(FUPlatform platform)
{
if (platform == fuNative) platform = fu_native_platform();
switch (platform) {
case fuUnix: return "/";
case fuWindows: return "\\";
case fuUnix:
case fuApple:
return "/";
case fuWindows:
return "\\";
default: return err(1, "unsupported platform: %d", platform), NULL;
}
}
Expand All @@ -140,8 +144,11 @@ const char *fu_pathsep(FUPlatform platform)
{
if (platform == fuNative) platform = fu_native_platform();
switch (platform) {
case fuUnix: return ":";
case fuWindows: return ";";
case fuUnix:
case fuApple:
return ":";
case fuWindows:
return ";";
default: return err(1, "unsupported platform: %d", platform), NULL;
}
}
Expand Down Expand Up @@ -590,6 +597,7 @@ char *fu_nativepath(const char *path, char *dest, size_t size,
{
switch (fu_native_platform()) {
case fuUnix:
case fuApple:
return fu_unixpath(path, dest, size, pathsep);
case fuWindows:
return fu_winpath(path, dest, size, pathsep);
Expand Down Expand Up @@ -811,7 +819,7 @@ FUPlatform fu_paths_set_platform(FUPaths *paths, FUPlatform platform)

for (i=0; i < paths->n; i++) {
const char *p = paths->paths[i];
if (platform == fuUnix)
if (platform == fuUnix || platform == fuApple)
paths->paths[i] = fu_unixpath(p, NULL, 0, ":");
else if (platform == fuWindows)
paths->paths[i] = fu_winpath(p, NULL, 0, ";");
Expand Down Expand Up @@ -942,7 +950,10 @@ int fu_paths_insertn(FUPaths *paths, const char *path, size_t len, int n)
if (!fu_supported_platform(platform))
FAIL1("unsupported platform: %d", platform);
switch (platform) {
case fuUnix: p = fu_unixpath(path, NULL, 0, paths->pathsep); break;
case fuUnix:
case fuApple:
p = fu_unixpath(path, NULL, 0, paths->pathsep);
break;
case fuWindows: p = fu_winpath(path, NULL, 0, paths->pathsep); break;
default: assert(0); // should never happen
}
Expand Down Expand Up @@ -1292,7 +1303,7 @@ FUIter *fu_pathsiter_init(const FUPaths *paths, const char *pattern)
}

/*
Help function for fu_paths_iter_nextfile(), which does not take `pattern`
Help function for fu_pathsiter_next(), which does not take `pattern`
into account.
*/
const char *_fu_pathsiter_next(FUIter *iter)
Expand Down Expand Up @@ -1394,7 +1405,7 @@ const char *fu_pathsiter_next(FUIter *iter)
}

/*
Deallocates iterator created with fu_paths_iter_init().
Deallocates iterator created with fu_pathsiter_init().
Returns non-zero on error.
*/
int fu_pathsiter_deinit(FUIter *iter)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/fileutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum {
};


#if defined __unix__ || (defined __APPLE__ && defined __MARCH__)
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
/* POSIX */
# ifndef POSIX
# define POSIX
Expand Down Expand Up @@ -65,7 +65,7 @@ typedef enum _FUPlatform {
fuNative=0, /*!< Platform we are compiling on */
fuUnix, /*!< Unix-like platforms; POSIX complient */
fuWindows, /*!< Windows */
fuApple, /*!< Apple - not yet supported... */
fuApple, /*!< Apple */
fuLastPlatform /*!< Must always be the last */
} FUPlatform;

Expand Down
Loading