From: Helmut Grohne <helmut@subdivi.de>
Subject: Work towards more cross-building support
Origin: vendor, https://bugs.debian.org/cgi-bin/bugreport.cgi?att=1;bug=980484;filename=cross.patch;msg=5
Forwarded: yes
# email sent to twu@gene.com on 2021-02-26
--- gmap-2020-12-17+ds.orig/config/builtin-popcount.m4
+++ gmap-2020-12-17+ds/config/builtin-popcount.m4
@@ -33,29 +33,41 @@
 # Test for __builtin functions with or without the -mpopcnt compiler flag
 CFLAGS="$CFLAGS_ORIG $POPCNT_CFLAGS"
 
-AC_MSG_CHECKING(for __builtin_popcount)
+AC_CHECK_DECL([__builtin_popcount],[
+AC_MSG_CHECKING(whether __builtin_popcount works)
 AC_RUN_IFELSE(
   [AC_LANG_PROGRAM([[]],
                    [[return (__builtin_popcount(0xffffffffu) == 32) ? 0 : 9;]])],
   [AC_MSG_RESULT(yes)
    AC_DEFINE([HAVE_BUILTIN_POPCOUNT],[1],[Define to 1 if __builtin_popcount works.])],
-  [AC_MSG_RESULT(no)])
+  [AC_MSG_RESULT(no)],
+  [AC_MSG_RESULT([cross, guessing yes])
+   AC_DEFINE([HAVE_BUILTIN_POPCOUNT],[1],[Define to 1 if __builtin_popcount works.])])
+],[])
 
-AC_MSG_CHECKING(for __builtin_clz)
+AC_CHECK_DECL([__builtin_clz],[
+AC_MSG_CHECKING(whether __builtin_clz works)
 AC_RUN_IFELSE(
   [AC_LANG_PROGRAM([[]],
                    [[return (__builtin_clz(0x1u) == 31) ? 0 : 9;]])],
   [AC_MSG_RESULT(yes)
    AC_DEFINE([HAVE_BUILTIN_CLZ],[1],[Define to 1 if __builtin_clz works.])],
-  [AC_MSG_RESULT(no)])
+  [AC_MSG_RESULT(no)],
+  [AC_MSG_RESULT([cross, guessing yes])
+   AC_DEFINE([HAVE_BUILTIN_CLZ],[1],[Define to 1 if __builtin_clz works.])])
+],[])
 
-AC_MSG_CHECKING(for __builtin_ctz)
+AC_CHECK_DECL([__builtin_ctz],[
+AC_MSG_CHECKING(whether __builtin_ctz works)
 AC_RUN_IFELSE(
   [AC_LANG_PROGRAM([[]],
                    [[return (__builtin_ctz(0x80000000u) == 31) ? 0 : 9;]])],
   [AC_MSG_RESULT(yes)
    AC_DEFINE([HAVE_BUILTIN_CTZ],[1],[Define to 1 if __builtin_ctz works.])],
-  [AC_MSG_RESULT(no)])
+  [AC_MSG_RESULT(no)],
+  [AC_MSG_RESULT([cross, guessing yes])
+   AC_DEFINE([HAVE_BUILTIN_CTZ],[1],[Define to 1 if __builtin_ctz works.])])
+])
 
 CFLAGS=$CFLAGS_ORIG
 
--- gmap-2020-12-17+ds.orig/config/asm-bsr.m4
+++ gmap-2020-12-17+ds/config/asm-bsr.m4
@@ -4,7 +4,7 @@
 AC_LANG(C)
 
 AC_MSG_CHECKING(for bsr instruction in assembly)
-AC_RUN_IFELSE(
+AC_LINK_IFELSE(
   [AC_LANG_PROGRAM([[ ]],
                    [[int msb; unsigned int x = rand(); asm("bsr %1,%0" : "=r"(msb) : "r"(x));]])],
   [AC_MSG_RESULT(yes)
--- gmap-2020-12-17+ds.orig/config/ax_cpuid_intel.m4
+++ gmap-2020-12-17+ds/config/ax_cpuid_intel.m4
@@ -1,6 +1,7 @@
 AC_DEFUN([AX_CPUID_INTEL],
 [AC_REQUIRE([AC_PROG_CC])
 AC_LANG_PUSH([C])
+AC_CHECK_HEADER([immintrin.h],[
 # Test for SSE2 support
   AC_MSG_CHECKING(for sse2 support)
   AC_RUN_IFELSE(
@@ -63,7 +64,7 @@
         [AC_MSG_RESULT(yes)
          ax_cv_cpu_has_avx512bw_ext=yes],
 	[AC_MSG_RESULT(no)])
-
+],[])
 AC_LANG_POP([C])
 ])
 
