Skip to content

Commit d1cf8b4

Browse files
authored
Merge pull request #66 from r-spatial/dewey-dev
Use configure script to detect endianness
2 parents d1ac929 + 11d6ccb commit d1cf8b4

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

configure

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS`
5252
CPPFLAGS=`${R_HOME}/bin/R CMD config CPPFLAGS`
5353

5454
# For debugging
55-
echo "Using PKG_CFLAGS=$PKG_CFLAGS"
55+
echo "Testing compiler using PKG_CFLAGS=$PKG_CFLAGS"
5656

5757
# Test configuration
5858
${CC} ${CPPFLAGS} ${PKG_CFLAGS} ${CFLAGS} -E ${PKG_TEST_FILE} >/dev/null 2>configure.log
@@ -100,7 +100,22 @@ fi
100100
fi #SONAME
101101
fi #AUTOBREW
102102

103+
# Define system endianness (compile-time endianness using system/compiler
104+
# defines isn't detected on Solaris)
105+
# based on endian detection from the feather package by @hadley
106+
R_ENDIAN=`${R_HOME}/bin/Rscript -e 'cat(.Platform$endian)'`
107+
# Trim off any warning messages that Rscript appends in front of the platform endianness
108+
R_ENDIAN=`expr "$R_ENDIAN" : '.*\(little\)$'`
109+
SYS_ENDIAN=""
110+
if [ "$R_ENDIAN" = "little" ]; then
111+
PKG_CFLAGS="$PKG_CFLAGS -DIS_LITTLE_ENDIAN"
112+
else
113+
PKG_CFLAGS="$PKG_CFLAGS -DIS_BIG_ENDIAN"
114+
fi
115+
103116
echo "Using PKG_LIBS=$PKG_LIBS"
117+
echo "Using PKG_CFLAGS=$PKG_CFLAGS"
118+
104119

105120
# Write to Makevars
106121
sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars

data-raw/update-s2.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ print_next <- function() {
8585
)
8686
cli::cat_bullet("Remove extra semi-colon at s2boolean_operation.h#376")
8787
cli::cat_bullet("Remove extra semi-colons because of FROMHOST_TYPE_MAP macro (utils/endian/endian.h#565)")
88+
cli::cat_bullet(
89+
"Check for definition of IS_LITTLE_ENDIAN and IS_BIG_ENDIAN to allow configure script ",
90+
"override (s2/base/port.h:273) without macro redefinition warnings"
91+
)
8892
cli::cat_bullet("Replace `abort()` with `cpp_compat_abort()`")
8993
cli::cat_bullet("Replace `cerr`/`cout` with `cpp_compat_cerr`/`cpp_compat_cout`")
9094
cli::cat_bullet("Replace `srandom()` with `cpp_compat_srandom()`")

inst/include/s2/base/port.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,15 @@ inline void sized_delete_array(void *ptr, size_t size) {
274274
// -----------------------------------------------------------------------------
275275

276276
// IS_LITTLE_ENDIAN, IS_BIG_ENDIAN
277+
278+
// Allow compiler -D defines to override detection here
279+
// which occasionally fails (e.g., on CRAN Solaris)
280+
#if defined(IS_LITTLE_ENDIAN)
281+
#undef IS_BIG_ENDIAN
282+
#elif defined(IS_BIG_ENDIAN)
283+
#undef IS_LITTLE_ENDIAN
284+
#else
285+
277286
#if defined __linux__ || defined OS_ANDROID || defined(__ANDROID__)
278287
// TODO(user): http://b/21460321; use one of OS_ANDROID or __ANDROID__.
279288
// _BIG_ENDIAN
@@ -318,6 +327,7 @@ inline void sized_delete_array(void *ptr, size_t size) {
318327

319328
#endif // __BYTE_ORDER
320329
#endif // _MSC_VER
330+
#endif // #if defined(IS_LITTLE_ENDIAN) ... #else
321331

322332
// byte swap functions (bswap_16, bswap_32, bswap_64).
323333

0 commit comments

Comments
 (0)