Skip to content

Commit 5545e13

Browse files
committed
Merge #584: configure: Use CFLAGS_FOR_BUILD when checking native compiler
a34bcaa Actually pass CFLAGS_FOR_BUILD and LDFLAGS_FOR_BUILD to linker (Tim Ruffing) 2d5f4ce configure: Use CFLAGS_FOR_BUILD when checking native compiler (Tim Ruffing) Pull request description: 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). 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. Tree-SHA512: 31a92a5516cf2f9801c918edfba0059aa4f8549b0c1de94fc166b5e92ad1868a480c48cdc5ff62679ba20e26f4a0e2948c71fd2b3e80766673d2bf7512da3875
2 parents 20c5869 + a34bcaa commit 5545e13

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

Makefile.am

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,14 @@ 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)
158157
gen_%.o: src/gen_%.c
159158
$(CC_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
160159

161160
$(gen_context_BIN): $(gen_context_OBJECTS)
162-
$(CC_FOR_BUILD) $^ -o $@
161+
$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@
163162

164163
$(libsecp256k1_la_OBJECTS): src/ecmult_static_context.h
165164
$(tests_OBJECTS): src/ecmult_static_context.h

configure.ac

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,27 +162,54 @@ else
162162
fi
163163

164164
if test x"$use_ecmult_static_precomputation" != x"no"; then
165+
# Temporarily switch to an environment for the native compiler
165166
save_cross_compiling=$cross_compiling
166167
cross_compiling=no
167-
TEMP_CC="$CC"
168+
SAVE_CC="$CC"
168169
CC="$CC_FOR_BUILD"
169-
AC_MSG_CHECKING([native compiler: ${CC_FOR_BUILD}])
170+
SAVE_CFLAGS="$CFLAGS"
171+
CFLAGS="$CFLAGS_FOR_BUILD"
172+
SAVE_CPPFLAGS="$CPPFLAGS"
173+
CPPFLAGS="$CPPFLAGS_FOR_BUILD"
174+
SAVE_LDFLAGS="$LDFLAGS"
175+
LDFLAGS="$LDFLAGS_FOR_BUILD"
176+
177+
warn_CFLAGS_FOR_BUILD="-Wall -Wextra -Wno-unused-function"
178+
saved_CFLAGS="$CFLAGS"
179+
CFLAGS="$CFLAGS $warn_CFLAGS_FOR_BUILD"
180+
AC_MSG_CHECKING([if native ${CC_FOR_BUILD} supports ${warn_CFLAGS_FOR_BUILD}])
181+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
182+
[ AC_MSG_RESULT([yes]) ],
183+
[ AC_MSG_RESULT([no])
184+
CFLAGS="$saved_CFLAGS"
185+
])
186+
187+
AC_MSG_CHECKING([for working native compiler: ${CC_FOR_BUILD}])
170188
AC_RUN_IFELSE(
171-
[AC_LANG_PROGRAM([], [return 0])],
189+
[AC_LANG_PROGRAM([], [])],
172190
[working_native_cc=yes],
173191
[working_native_cc=no],[dnl])
174-
CC="$TEMP_CC"
192+
193+
CFLAGS_FOR_BUILD="$CFLAGS"
194+
195+
# Restore the environment
175196
cross_compiling=$save_cross_compiling
197+
CC="$SAVE_CC"
198+
CFLAGS="$SAVE_CFLAGS"
199+
CPPFLAGS="$SAVE_CPPFLAGS"
200+
LDFLAGS="$SAVE_LDFLAGS"
176201

177202
if test x"$working_native_cc" = x"no"; then
203+
AC_MSG_RESULT([no])
178204
set_precomp=no
205+
m4_define([please_set_for_build], [Please set CC_FOR_BUILD, CFLAGS_FOR_BUILD, CPPFLAGS_FOR_BUILD, and/or LDFLAGS_FOR_BUILD.])
179206
if test x"$use_ecmult_static_precomputation" = x"yes"; then
180-
AC_MSG_ERROR([${CC_FOR_BUILD} does not produce working binaries. Please set CC_FOR_BUILD])
207+
AC_MSG_ERROR([native compiler ${CC_FOR_BUILD} does not produce working binaries. please_set_for_build])
181208
else
182-
AC_MSG_RESULT([${CC_FOR_BUILD} does not produce working binaries. Please set CC_FOR_BUILD])
209+
AC_MSG_WARN([Disabling statically generated ecmult table because the native compiler ${CC_FOR_BUILD} does not produce working binaries. please_set_for_build])
183210
fi
184211
else
185-
AC_MSG_RESULT([ok])
212+
AC_MSG_RESULT([yes])
186213
set_precomp=yes
187214
fi
188215
else

0 commit comments

Comments
 (0)