0005-auto-unix-make-sys_nerr-guessing-cross-friendly.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. From 08617a8d29ee22831175697555558fec8f52772c Mon Sep 17 00:00:00 2001
  2. From: Samuel Martin <s.martin49@gmail.com>
  3. Date: Sun, 1 Jun 2014 16:05:04 +0200
  4. Subject: [PATCH] auto/unix: make sys_nerr guessing cross-friendly
  5. This patch replaces the default sys_nerr runtest with a test done at
  6. buildtime.
  7. The idea behind this buildtime test is finding the value of the ERR_MAX
  8. macro if defined, or the EHWPOISON (which is currently the last errno)
  9. otherwise.
  10. Signed-off-by: Samuel Martin <s.martin49@gmail.com>
  11. Refresh for 1.8.0.
  12. Signed-off-by: Danomi Manchego <danomimanchego123@gmail.com>
  13. ---
  14. auto/os/sys_nerr | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  15. auto/unix | 10 ++++++++
  16. 2 files changed, 88 insertions(+)
  17. create mode 100644 auto/os/sys_nerr
  18. diff --git a/auto/os/sys_nerr b/auto/os/sys_nerr
  19. new file mode 100644
  20. index 0000000..8970f5f
  21. --- /dev/null
  22. +++ b/auto/os/sys_nerr
  23. @@ -0,0 +1,78 @@
  24. +
  25. +# Copyright (C) Samuel Martin <s.martin49@gmail.com>
  26. +
  27. +
  28. +echo $ngx_n "checking for sys_nerr value...$ngx_c"
  29. +
  30. +# sys_nerr guessing is done using a (very) poor (but working)
  31. +# heuristics, by checking for the value of ERR_MAX if defined, or
  32. +# EHWPOISON otherwise.
  33. +
  34. +cat << END >> $NGX_AUTOCONF_ERR
  35. +
  36. +----------------------------------------
  37. +checking for sys_nerr value
  38. +
  39. +END
  40. +
  41. +ngx_sys_nerr=
  42. +
  43. +cat << _EOF > $NGX_AUTOTEST.c
  44. +
  45. +#include <stdio.h>
  46. +#include <errno.h>
  47. +
  48. +static char sys_nerr_test[ERR_MAX];
  49. +int main(void)
  50. +{
  51. + return 0;
  52. +}
  53. +
  54. +_EOF
  55. +
  56. +if $CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
  57. + $NGX_AUTOTEST.c -o $NGX_AUTOTEST \
  58. + $NGX_LD_OPT $ngx_feature_libs >/dev/null 2>&1 ; then
  59. + _ngx_max_err_macro=ERR_MAX
  60. +else
  61. + # the +2 has been empirically found!
  62. + _ngx_max_err_macro="EHWPOISON + 2"
  63. +fi
  64. +
  65. +cat << _EOF > $NGX_AUTOTEST.c
  66. +
  67. +#include <stdio.h>
  68. +#include <errno.h>
  69. +
  70. +static char sys_nerr_test[(TEST_ERR_MAX == $_ngx_max_err_macro) ? 1 : -1];
  71. +int main(void)
  72. +{
  73. + return 0;
  74. +}
  75. +
  76. +_EOF
  77. +
  78. +
  79. +ngx_sys_nerr=`for i in $(seq 0 2000) ; do \
  80. + $CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
  81. + -DTEST_ERR_MAX="$i" \
  82. + $NGX_AUTOTEST.c -o $NGX_AUTOTEST \
  83. + $NGX_LD_OPT $ngx_feature_libs >/dev/null 2>&1 || continue ;\
  84. + echo $i ; break ; done`
  85. +
  86. +rm -rf $NGX_AUTOTEST*
  87. +
  88. +if test -z $ngx_sys_nerr ; then
  89. + ngx_size=0
  90. + ngx_sys_nerr=0
  91. +fi
  92. +
  93. +cat << END >> $NGX_AUTO_CONFIG_H
  94. +
  95. +#ifndef $ngx_feature_name
  96. +#define $ngx_feature_name $ngx_sys_nerr
  97. +#endif
  98. +
  99. +END
  100. +
  101. +echo " $ngx_sys_nerr"
  102. diff --git a/auto/unix b/auto/unix
  103. index 7dbf9d1..00a7370 100755
  104. --- a/auto/unix
  105. +++ b/auto/unix
  106. @@ -708,6 +708,10 @@ ngx_feature_incs='#include <errno.h>
  107. #include <stdio.h>'
  108. ngx_feature_path=
  109. ngx_feature_libs=
  110. +
  111. +if false ; then
  112. +# Disabled because only valid for native build.
  113. +
  114. ngx_feature_test='printf("%d", sys_nerr);'
  115. . auto/feature
  116. @@ -756,6 +760,12 @@ if [ $ngx_found = no ]; then
  117. . auto/feature
  118. fi
  119. +else
  120. + # Cross-compilation support
  121. + . auto/os/sys_nerr
  122. +
  123. +fi
  124. +
  125. ngx_feature="localtime_r()"
  126. ngx_feature_name="NGX_HAVE_LOCALTIME_R"
  127. --
  128. 1.9.1