1From 4bd8fe780ff2064f2d4e9c905d8a98dd0f9b6191 Mon Sep 17 00:00:00 2001
2From: Nevo Hed <nhed+buildroot@starry.com>
3Date: Mon, 30 Aug 2021 13:28:13 -0400
4Subject: [PATCH] Allow forcing of endianness for cross-compilation
5
6Upstream-status: Invalid (upstream doesn't support cross-compilation)
7See https://trac.nginx.org/nginx/ticket/2240
8
9Signed-off-by: Nevo Hed <nhed+buildroot@starry.com>
10---
11 auto/endianness | 61 ++++++++++++++++++++++++++++++++-----------------
12 auto/options    |  6 +++++
13 2 files changed, 46 insertions(+), 21 deletions(-)
14
15diff --git a/auto/endianness b/auto/endianness
16index 1b552b6b..4b2a3cd7 100644
17--- a/auto/endianness
18+++ b/auto/endianness
19@@ -26,25 +26,44 @@ int main(void) {
20
21 END
22
23-ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
24-          -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"
25-
26-eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"
27-
28-if [ -x $NGX_AUTOTEST ]; then
29-    if $NGX_AUTOTEST >/dev/null 2>&1; then
30-        echo " little endian"
31+case "${NGX_FORCE_ENDIANNESS}" in
32+    little)
33+        echo " little endian (forced)"
34         have=NGX_HAVE_LITTLE_ENDIAN . auto/have
35-    else
36-        echo " big endian"
37-    fi
38-
39-    rm -rf $NGX_AUTOTEST*
40-
41-else
42-    rm -rf $NGX_AUTOTEST*
43-
44-    echo
45-    echo "$0: error: cannot detect system byte ordering"
46-    exit 1
47-fi
48+    ;;
49+
50+    big)
51+        echo " big endian (forced)"
52+    ;;
53+
54+    "")
55+        ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
56+                  -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"
57+
58+        eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"
59+
60+        if [ -x $NGX_AUTOTEST ]; then
61+            if $NGX_AUTOTEST >/dev/null 2>&1; then
62+                echo " little endian"
63+                have=NGX_HAVE_LITTLE_ENDIAN . auto/have
64+            else
65+                echo " big endian"
66+            fi
67+
68+            rm -rf $NGX_AUTOTEST*
69+
70+        else
71+            rm -rf $NGX_AUTOTEST*
72+
73+            echo
74+            echo "$0: error: cannot detect system byte ordering"
75+            exit 1
76+        fi
77+    ;;
78+
79+    *)
80+        echo
81+        echo "$0: error: invalid \"--force-endianness=${NGX_FORCE_ENDIANNESS}\""
82+        exit 1
83+    ;;
84+esac
85diff --git a/auto/options b/auto/options
86index 80be906e..85a06456 100644
87--- a/auto/options
88+++ b/auto/options
89@@ -17,6 +17,8 @@ NGX_USER=
90 NGX_GROUP=
91 NGX_BUILD=
92
93+NGX_FORCE_ENDIANNESS=
94+
95 CC=${CC:-cc}
96 CPP=
97 NGX_OBJS=objs
98@@ -196,6 +198,8 @@ do
99         --user=*)                        NGX_USER="$value"          ;;
100         --group=*)                       NGX_GROUP="$value"         ;;
101
102+        --force-endianness=*)            NGX_FORCE_ENDIANNESS="$value" ;;
103+
104         --crossbuild=*)                  NGX_PLATFORM="$value"      ;;
105
106         --build=*)                       NGX_BUILD="$value"         ;;
107@@ -432,6 +436,8 @@ cat << END
108   --build=NAME                       set build name
109   --builddir=DIR                     set build directory
110
111+  --force-endianness=<big>|<little>  force endianness
112+
113   --with-select_module               enable select module
114   --without-select_module            disable select module
115   --with-poll_module                 enable poll module
116--
1172.31.1
118
119