1From e1dcd27e816520bdabc69511d90c4a2ebc242831 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Fri, 6 Jan 2023 18:51:34 -0800
4Subject: [PATCH] configure: Fix compoiler detection logic for
5 cross-compilation
6
7We can not run binaries during cross compile, so poke at compiler to
8figure out if it is clang or gcc, for OE we do not have other compilers
9in opensource world if there are we can extend this logic
10
11Upstream-Status: Inappropriate [OE-Specific]
12
13Signed-off-by: Khem Raj <raj.khem@gmail.com>
14---
15 configure | 56 ++++++++++++++++---------------------------------------
16 1 file changed, 16 insertions(+), 40 deletions(-)
17
18--- a/configure
19+++ b/configure
20@@ -661,48 +661,24 @@ if test "$PROFILE"; then
21 fi
22
23 printf "Finding suitable compiler........"
24-if test ! -x "${CC}"; then
25-	CC=`pathsearch "${CC:-cc}"`
26-	if test -z "$CC" -o ! -x "$CC"; then
27-		CC=`pathsearch "${CC:-gcc}"`
28-	fi
29+if test -z "$CC"; then
30+  if test ! -x "${CC}"; then
31+	  CC=`pathsearch "${CC:-cc}"`
32+	  if test -z "$CC" -o ! -x "$CC"; then
33+		  CC=`pathsearch "${CC:-gcc}"`
34+	  fi
35+  fi
36+  assert "$CC" "not found"
37+fi
38+if `$CC --version | grep gcc > /dev/null 2>&1`; then
39+  COMPILER=gcc
40+elif `$CC --version | grep clang > /dev/null 2>&1`; then
41+  COMPILER=clang
42+else
43+  COMPILER="not-found"
44 fi
45-assert "$CC" "not found"
46-
47-cat << EOF > .1.c
48-#include <stdio.h>
49-int main(void) {
50-#if defined(_WIN32)
51-#if defined(__MINGW64__)
52-	puts("mingw64");
53-	return (0);
54-#elif defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION >= 3)
55-	puts("mingw32");
56-	return (0);
57-#else
58-	return (1);
59-#endif /* __MINGW32__ && __MINGW32_MAJOR_VERSION >= 3 */
60-#elif defined(__clang__) && (__clang_major__ >= 3)
61-	puts("clang");
62-	return (0);
63-#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5110)
64-	puts("suncc");
65-	return (0);
66-#elif defined(__GNUC__) && (__GNUC__ >= 4)
67-	puts("gcc");
68-	return (0);
69-#else
70-	return (1);
71-#endif
72-}
73-EOF
74-
75-$CC -o .1 .1.c
76-COMPILER=`./.1 2> /dev/null`
77-r=$?
78-rm -f .1.c .1
79
80-if test "$r" -ne 0; then
81+if test "$COMPILER" = "not-found"; then
82 	assert "" "update compiler"
83 else
84 	echo "success [$CC]"
85