0001-configure-Fix-cross-compilation-errors.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. From 1146bf07624b5820b942b84b68e66f0d3dd25914 Mon Sep 17 00:00:00 2001
  2. From: Ola Jeppsson <ola.jeppsson@gmail.com>
  3. Date: Mon, 7 Oct 2019 18:07:30 -0400
  4. Subject: [PATCH] configure: Fix cross-compilation errors
  5. AC_RUN_IFELSE does not work when cross-compiling so we need to provide
  6. fallback methods for those cases.
  7. I tried to use constructs that work with Autoconf 2.52.
  8. Alas, I wasn't able to generate a working build system with that version.
  9. Autoconf 2.58 / Automake 1.7.9 is the earliest combo that I could get
  10. to work (with and without this patch).
  11. Perhaps it's time for a slight bump for the required version numbers?
  12. Cross-compiles sucessfully against:
  13. riscv64-unknown-linux-gnu
  14. Downloaded from upstream PR:
  15. https://github.com/memcached/memcached/pull/552
  16. Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
  17. ---
  18. configure.ac | 80 +++++++++++++++++++++++++++-------------------------
  19. 1 file changed, 41 insertions(+), 39 deletions(-)
  20. diff --git a/configure.ac b/configure.ac
  21. index fb78fc5..27dc939 100644
  22. --- a/configure.ac
  23. +++ b/configure.ac
  24. @@ -264,23 +264,42 @@ return sizeof(void*) == 8 ? 0 : 1;
  25. ],[
  26. CFLAGS="-m64 $org_cflags"
  27. ],[
  28. - AC_MSG_ERROR([Don't know how to build a 64-bit object.])
  29. + AC_MSG_ERROR([Don't know how to build a 64-bit object.])
  30. + ],[
  31. + dnl cross compile
  32. + AC_MSG_WARN([Assuming no extra CFLAGS are required for cross-compiling 64bit version.])
  33. ])
  34. fi
  35. dnl If data pointer is 64bit or not.
  36. -AC_RUN_IFELSE(
  37. - [AC_LANG_PROGRAM([], [dnl
  38. -return sizeof(void*) == 8 ? 0 : 1;
  39. - ])
  40. -],[
  41. - have_64bit_ptr=yes
  42. -],[
  43. +AC_CHECK_HEADERS([stdint.h])
  44. +AS_IF([test -z "$have_64bit_ptr"],
  45. + [AC_RUN_IFELSE(
  46. + [AC_LANG_PROGRAM([], [return sizeof(void*) == 8 ? 0 : 1;])],
  47. + [have_64bit_ptr=yes ],
  48. + [have_64bit_ptr=no],
  49. + [dnl cross compile (this test requires C99)
  50. + AS_IF([test "x$ac_cv_header_stdint_h" = xyes],
  51. + [AC_COMPILE_IFELSE(
  52. + [AC_LANG_PROGRAM([
  53. + #include <stdint.h>
  54. + #if UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFUL
  55. + /* 64 bit pointer */
  56. + #else
  57. + #error 32 bit pointer
  58. + #endif
  59. + ], [])],
  60. + [have_64bit_ptr=yes],
  61. + [have_64bit_ptr=no])],
  62. + [have_64bit_ptr=unknown])
  63. + ])
  64. ])
  65. -
  66. -if test $have_64bit_ptr = yes; then
  67. +AS_IF([test "$have_64bit_ptr" = "unknown" ],[
  68. + AC_MSG_ERROR([Cannot detect pointer size. Must pass have_64bit_ptr={yes,no} to configure.])
  69. +])
  70. +AS_IF([test "$have_64bit_ptr" = yes],[
  71. AC_DEFINE(HAVE_64BIT_PTR, 1, [data pointer is 64bit])
  72. -fi
  73. +])
  74. # Issue 213: Search for clock_gettime to help people linking
  75. # with a static version of libevent
  76. @@ -570,30 +589,10 @@ fi
  77. AC_C_SOCKLEN_T
  78. dnl Check if we're a little-endian or a big-endian system, needed by hash code
  79. -AC_DEFUN([AC_C_ENDIAN],
  80. -[AC_CACHE_CHECK(for endianness, ac_cv_c_endian,
  81. -[
  82. - AC_RUN_IFELSE(
  83. - [AC_LANG_PROGRAM([], [dnl
  84. - long val = 1;
  85. - char *c = (char *) &val;
  86. - exit(*c == 1);
  87. - ])
  88. - ],[
  89. - ac_cv_c_endian=big
  90. - ],[
  91. - ac_cv_c_endian=little
  92. - ])
  93. -])
  94. -if test $ac_cv_c_endian = big; then
  95. - AC_DEFINE(ENDIAN_BIG, 1, [machine is bigendian])
  96. -fi
  97. -if test $ac_cv_c_endian = little; then
  98. - AC_DEFINE(ENDIAN_LITTLE, 1, [machine is littleendian])
  99. -fi
  100. -])
  101. -
  102. -AC_C_ENDIAN
  103. +AC_C_BIGENDIAN(
  104. + [AC_DEFINE(ENDIAN_BIG, 1, [machine is bigendian])],
  105. + [AC_DEFINE(ENDIAN_LITTLE, 1, [machine is littleendian])],
  106. + [AC_MSG_ERROR([Cannot detect endianness. Must pass ac_cv_c_bigendian={yes,no} to configure.])])
  107. AC_DEFUN([AC_C_HTONLL],
  108. [
  109. @@ -670,12 +669,15 @@ AC_DEFUN([AC_C_ALIGNMENT],
  110. ],[
  111. ac_cv_c_alignment=need
  112. ],[
  113. - ac_cv_c_alignment=need
  114. + dnl cross compile
  115. + ac_cv_c_alignment=maybe
  116. ])
  117. ])
  118. -if test $ac_cv_c_alignment = need; then
  119. - AC_DEFINE(NEED_ALIGN, 1, [Machine need alignment])
  120. -fi
  121. +AS_IF([test $ac_cv_c_alignment = need],
  122. + [AC_DEFINE(NEED_ALIGN, 1, [Machine need alignment])])
  123. +AS_IF([test $ac_cv_c_alignment = maybe],
  124. + [AC_MSG_WARN([Assuming aligned access is required when cross-compiling])
  125. + AC_DEFINE(NEED_ALIGN, 1, [Machine need alignment])])
  126. ])
  127. AC_C_ALIGNMENT
  128. --
  129. 2.20.1