samba4-0006-build-unify-and-fix-endian-tests.patch 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. From ee4e06b7223fb2925bc887c89216a66029d44862 Mon Sep 17 00:00:00 2001
  2. From: Gustavo Zacarias <gustavo@zacarias.com.ar>
  3. Date: Tue, 1 Apr 2014 06:41:47 -0300
  4. Subject: [PATCH 2/5] build: unify and fix endian tests
  5. Unify the endian tests out of lib/ccan/wscript into wafsamba since
  6. they're almost cross-compile friendly.
  7. While at it fix them to be so by moving the preprocessor directives out
  8. of main scope since that will fail.
  9. And keep the WORDS_BIGENDIAN, HAVE_LITTLE_ENDIAN and HAVE_BIG_ENDIAN
  10. defines separate because of different codebases.
  11. Status: Upstream.
  12. Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
  13. ---
  14. buildtools/wafsamba/wscript | 65 ++++++++++++++++++++++++++++++++++++++++++---
  15. lib/ccan/wscript | 55 --------------------------------------
  16. 2 files changed, 62 insertions(+), 58 deletions(-)
  17. diff --git a/buildtools/wafsamba/wscript b/buildtools/wafsamba/wscript
  18. index 7984227..1a2cfe6 100755
  19. --- a/buildtools/wafsamba/wscript
  20. +++ b/buildtools/wafsamba/wscript
  21. @@ -390,9 +390,68 @@ def configure(conf):
  22. else:
  23. conf.define('SHLIBEXT', "so", quote=True)
  24. - conf.CHECK_CODE('long one = 1; return ((char *)(&one))[0]',
  25. - execute=True,
  26. - define='WORDS_BIGENDIAN')
  27. + # First try a header check for cross-compile friendlyness
  28. + conf.CHECK_CODE(code = """#ifdef __BYTE_ORDER
  29. + #define B __BYTE_ORDER
  30. + #elif defined(BYTE_ORDER)
  31. + #define B BYTE_ORDER
  32. + #endif
  33. +
  34. + #ifdef __LITTLE_ENDIAN
  35. + #define LITTLE __LITTLE_ENDIAN
  36. + #elif defined(LITTLE_ENDIAN)
  37. + #define LITTLE LITTLE_ENDIAN
  38. + #endif
  39. +
  40. + #if !defined(LITTLE) || !defined(B) || LITTLE != B
  41. + #error Not little endian.
  42. + #endif
  43. + int main(void) { return 0; }""",
  44. + addmain=False,
  45. + headers="endian.h sys/endian.h",
  46. + define="HAVE_LITTLE_ENDIAN")
  47. + conf.CHECK_CODE(code = """#ifdef __BYTE_ORDER
  48. + #define B __BYTE_ORDER
  49. + #elif defined(BYTE_ORDER)
  50. + #define B BYTE_ORDER
  51. + #endif
  52. +
  53. + #ifdef __BIG_ENDIAN
  54. + #define BIG __BIG_ENDIAN
  55. + #elif defined(BIG_ENDIAN)
  56. + #define BIG BIG_ENDIAN
  57. + #endif
  58. +
  59. + #if !defined(BIG) || !defined(B) || BIG != B
  60. + #error Not big endian.
  61. + #endif
  62. + int main(void) { return 0; }""",
  63. + addmain=False,
  64. + headers="endian.h sys/endian.h",
  65. + define="HAVE_BIG_ENDIAN")
  66. +
  67. + if not conf.CONFIG_SET("HAVE_BIG_ENDIAN") and not conf.CONFIG_SET("HAVE_LITTLE_ENDIAN"):
  68. + # That didn't work! Do runtime test.
  69. + conf.CHECK_CODE("""union { int i; char c[sizeof(int)]; } u;
  70. + u.i = 0x01020304;
  71. + return u.c[0] == 0x04 && u.c[1] == 0x03 && u.c[2] == 0x02 && u.c[3] == 0x01 ? 0 : 1;""",
  72. + addmain=True, execute=True,
  73. + define='HAVE_LITTLE_ENDIAN',
  74. + msg="Checking for HAVE_LITTLE_ENDIAN - runtime")
  75. + conf.CHECK_CODE("""union { int i; char c[sizeof(int)]; } u;
  76. + u.i = 0x01020304;
  77. + return u.c[0] == 0x01 && u.c[1] == 0x02 && u.c[2] == 0x03 && u.c[3] == 0x04 ? 0 : 1;""",
  78. + addmain=True, execute=True,
  79. + define='HAVE_BIG_ENDIAN',
  80. + msg="Checking for HAVE_BIG_ENDIAN - runtime")
  81. +
  82. + # Extra sanity check.
  83. + if conf.CONFIG_SET("HAVE_BIG_ENDIAN") == conf.CONFIG_SET("HAVE_LITTLE_ENDIAN"):
  84. + Logs.error("Failed endian determination. The PDP-11 is back?")
  85. + sys.exit(1)
  86. + else:
  87. + if conf.CONFIG_SET("HAVE_BIG_ENDIAN"):
  88. + conf.DEFINE('WORDS_BIGENDIAN', 1)
  89. # check if signal() takes a void function
  90. if conf.CHECK_CODE('return *(signal (0, 0)) (0) == 1',
  91. diff --git a/lib/ccan/wscript b/lib/ccan/wscript
  92. index 1c5f337..0e540db 100644
  93. --- a/lib/ccan/wscript
  94. +++ b/lib/ccan/wscript
  95. @@ -25,61 +25,6 @@ def configure(conf):
  96. conf.CHECK_CODE('int __attribute__((used)) func(int x) { return x; }',
  97. addmain=False, link=False, cflags=conf.env['WERROR_CFLAGS'],
  98. define='HAVE_ATTRIBUTE_USED')
  99. - # We try to use headers for a compile-time test.
  100. - conf.CHECK_CODE(code = """#ifdef __BYTE_ORDER
  101. - #define B __BYTE_ORDER
  102. - #elif defined(BYTE_ORDER)
  103. - #define B BYTE_ORDER
  104. - #endif
  105. -
  106. - #ifdef __LITTLE_ENDIAN
  107. - #define LITTLE __LITTLE_ENDIAN
  108. - #elif defined(LITTLE_ENDIAN)
  109. - #define LITTLE LITTLE_ENDIAN
  110. - #endif
  111. -
  112. - #if !defined(LITTLE) || !defined(B) || LITTLE != B
  113. - #error Not little endian.
  114. - #endif""",
  115. - headers="endian.h sys/endian.h",
  116. - define="HAVE_LITTLE_ENDIAN")
  117. - conf.CHECK_CODE(code = """#ifdef __BYTE_ORDER
  118. - #define B __BYTE_ORDER
  119. - #elif defined(BYTE_ORDER)
  120. - #define B BYTE_ORDER
  121. - #endif
  122. -
  123. - #ifdef __BIG_ENDIAN
  124. - #define BIG __BIG_ENDIAN
  125. - #elif defined(BIG_ENDIAN)
  126. - #define BIG BIG_ENDIAN
  127. - #endif
  128. -
  129. - #if !defined(BIG) || !defined(B) || BIG != B
  130. - #error Not big endian.
  131. - #endif""",
  132. - headers="endian.h sys/endian.h",
  133. - define="HAVE_BIG_ENDIAN")
  134. -
  135. - if not conf.CONFIG_SET("HAVE_BIG_ENDIAN") and not conf.CONFIG_SET("HAVE_LITTLE_ENDIAN"):
  136. - # That didn't work! Do runtime test.
  137. - conf.CHECK_CODE("""union { int i; char c[sizeof(int)]; } u;
  138. - u.i = 0x01020304;
  139. - return u.c[0] == 0x04 && u.c[1] == 0x03 && u.c[2] == 0x02 && u.c[3] == 0x01 ? 0 : 1;""",
  140. - addmain=True, execute=True,
  141. - define='HAVE_LITTLE_ENDIAN',
  142. - msg="Checking for HAVE_LITTLE_ENDIAN - runtime")
  143. - conf.CHECK_CODE("""union { int i; char c[sizeof(int)]; } u;
  144. - u.i = 0x01020304;
  145. - return u.c[0] == 0x01 && u.c[1] == 0x02 && u.c[2] == 0x03 && u.c[3] == 0x04 ? 0 : 1;""",
  146. - addmain=True, execute=True,
  147. - define='HAVE_BIG_ENDIAN',
  148. - msg="Checking for HAVE_BIG_ENDIAN - runtime")
  149. -
  150. - # Extra sanity check.
  151. - if conf.CONFIG_SET("HAVE_BIG_ENDIAN") == conf.CONFIG_SET("HAVE_LITTLE_ENDIAN"):
  152. - Logs.error("Failed endian determination. The PDP-11 is back?")
  153. - sys.exit(1)
  154. conf.CHECK_CODE('return __builtin_choose_expr(1, 0, "garbage");',
  155. link=True,
  156. --
  157. 1.8.3.2