Skip to content

Commit 2d5f4ce

Browse files
configure: Use CFLAGS_FOR_BUILD when checking native compiler
This fixes a bug where configure would fail or disable static ecmult tables because it wrongly checks the native compiler using the target CFLAGS (instead of the native CFLAGS_FOR_BUILD), and similar for CPPFLAGS and LDFLAGS. Moreover, this commit adds tests to figure out whether the native compiler supports the warning flags passed during the build, and it contains a few minor improvements to the code that checks the native compiler.
1 parent e34ceb3 commit 2d5f4ce

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ endif
151151

152152
if USE_ECMULT_STATIC_PRECOMPUTATION
153153
CPPFLAGS_FOR_BUILD +=-I$(top_srcdir)
154-
CFLAGS_FOR_BUILD += -Wall -Wextra -Wno-unused-function
155154

156155
gen_context_OBJECTS = gen_context.o
157156
gen_context_BIN = gen_context$(BUILD_EXEEXT)

configure.ac

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,27 +168,54 @@ else
168168
fi
169169

170170
if test x"$use_ecmult_static_precomputation" != x"no"; then
171+
# Temporarily switch to an environment for the native compiler
171172
save_cross_compiling=$cross_compiling
172173
cross_compiling=no
173-
TEMP_CC="$CC"
174+
SAVE_CC="$CC"
174175
CC="$CC_FOR_BUILD"
175-
AC_MSG_CHECKING([native compiler: ${CC_FOR_BUILD}])
176+
SAVE_CFLAGS="$CFLAGS"
177+
CFLAGS="$CFLAGS_FOR_BUILD"
178+
SAVE_CPPFLAGS="$CPPFLAGS"
179+
CPPFLAGS="$CPPFLAGS_FOR_BUILD"
180+
SAVE_LDFLAGS="$LDFLAGS"
181+
LDFLAGS="$LDFLAGS_FOR_BUILD"
182+
183+
warn_CFLAGS_FOR_BUILD="-Wall -Wextra -Wno-unused-function"
184+
saved_CFLAGS="$CFLAGS"
185+
CFLAGS="$CFLAGS $warn_CFLAGS_FOR_BUILD"
186+
AC_MSG_CHECKING([if native ${CC_FOR_BUILD} supports ${warn_CFLAGS_FOR_BUILD}])
187+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
188+
[ AC_MSG_RESULT([yes]) ],
189+
[ AC_MSG_RESULT([no])
190+
CFLAGS="$saved_CFLAGS"
191+
])
192+
193+
AC_MSG_CHECKING([for working native compiler: ${CC_FOR_BUILD}])
176194
AC_RUN_IFELSE(
177-
[AC_LANG_PROGRAM([], [return 0])],
195+
[AC_LANG_PROGRAM([], [])],
178196
[working_native_cc=yes],
179197
[working_native_cc=no],[dnl])
180-
CC="$TEMP_CC"
198+
199+
CFLAGS_FOR_BUILD="$CFLAGS"
200+
201+
# Restore the environment
181202
cross_compiling=$save_cross_compiling
203+
CC="$SAVE_CC"
204+
CFLAGS="$SAVE_CFLAGS"
205+
CPPFLAGS="$SAVE_CPPFLAGS"
206+
LDFLAGS="$SAVE_LDFLAGS"
182207

183208
if test x"$working_native_cc" = x"no"; then
209+
AC_MSG_RESULT([no])
184210
set_precomp=no
211+
m4_define([please_set_for_build], [Please set CC_FOR_BUILD, CFLAGS_FOR_BUILD, CPPFLAGS_FOR_BUILD, and/or LDFLAGS_FOR_BUILD.])
185212
if test x"$use_ecmult_static_precomputation" = x"yes"; then
186-
AC_MSG_ERROR([${CC_FOR_BUILD} does not produce working binaries. Please set CC_FOR_BUILD])
213+
AC_MSG_ERROR([native compiler ${CC_FOR_BUILD} does not produce working binaries. please_set_for_build])
187214
else
188-
AC_MSG_RESULT([${CC_FOR_BUILD} does not produce working binaries. Please set CC_FOR_BUILD])
215+
AC_MSG_WARN([Disabling statically generated ecmult table because the native compiler ${CC_FOR_BUILD} does not produce working binaries. please_set_for_build])
189216
fi
190217
else
191-
AC_MSG_RESULT([ok])
218+
AC_MSG_RESULT([yes])
192219
set_precomp=yes
193220
fi
194221
else

0 commit comments

Comments
 (0)