Source: gmap
Version: 2020-12-17+ds-2
Tags: patch upstream
User: [email protected]
Usertags: ftcbfs
gmap fails to cross build from source, because it uses AC_RUN_IFELSE a
lot. I wa able to reduce the impact somewhat with the attached patch:
* When checking for e.g. __builtin_popcount, still check that it works
on native builds, but during cross builds assume that it works when
the symbol is available.
* The bsr assembler instruction test doesn't gain anything from running
it. It can be demoted to a link test.
* Checks involving #include <immintrin.h> can be skipped when the
header is unavailable.
This still leaves a number of remaining AC_RUN_IFELSE and gmap will not
become cross buildable. Please consider applying my patch as an
incremental improvement nonetheless.
Helmut
--- 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])
])