configure: test if -lm is available on host compiler

Fixes host binaries compilation on platforms without math lib.

Fixes clang host compilation, which replaces `-lm` with `m.lib` that
does not exist:
LINK : fatal error LNK1181: cannot open input file 'm.lib'
clang: error: linker command failed with exit code 1181 (use -v to see invocation)

Fixes MSVC (cl) host warning:
cl : Command line warning D9002 : ignoring unknown option '-lm'

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
This commit is contained in:
Kacper Michajłow
2026-03-31 18:30:52 +02:00
parent 43be5cccd8
commit 740dc9e027

38
configure vendored
View File

@@ -1081,6 +1081,10 @@ hostcc_o(){
eval printf '%s\\n' $HOSTCC_O
}
hostld_o(){
eval printf '%s\\n' $HOSTLD_O
}
glslc_o(){
eval printf '%s\\n' $GLSLC_O
}
@@ -1835,6 +1839,16 @@ test_host_cc(){
test_cmd $host_cc $host_cflags "$@" $HOSTCC_C $(hostcc_o $TMPO) $TMPC
}
test_host_ld(){
log test_host_ld "$@"
flags=$(filter_out '-l*|*.so' $@)
libs=$(filter '-l*|*.so' $@)
test_host_cc $($host_cflags_filter $flags) || return
flags=$($host_ldflags_filter $flags)
libs=$($host_ldflags_filter $libs)
test_cmd $host_ld $host_ldflags $flags $(hostld_o $TMPE) $TMPO $libs $host_extralibs
}
test_host_cpp(){
log test_host_cpp "$@"
cat > $TMPC
@@ -1899,6 +1913,27 @@ check_host_cpp_condition(){
test_host_cpp_condition "$@" && enable $name
}
check_host_lib(){
log check_host_lib "$@"
headers="$1"
funcs="$2"
shift 2
{
for hdr in $headers; do
print_include $hdr
done
echo "#include <stdint.h>"
for func in $funcs; do
echo "long check_$func(void) { return (long) $func; }"
done
echo "int main(void) { int ret = 0;"
for func in $funcs; do
echo " ret |= ((intptr_t)check_$func) & 0xFFFF;"
done
echo "return ret; }"
} | test_host_ld "$@" && append host_extralibs "$@"
}
cp_if_changed(){
cmp -s "$1" "$2" && { test "$quiet" != "yes" && echo "$2 is unchanged"; } && return
mkdir -p "$(dirname $2)"
@@ -4470,7 +4505,7 @@ GLSLC_O='-o $@'
NVCC_C='-c'
NVCC_O='-o $@'
host_extralibs='-lm'
host_extralibs=
host_cflags_filter=echo
host_ldflags_filter=echo
@@ -7223,6 +7258,7 @@ enabled zlib_gzip && enabled gzip || disable resource_compression
check_lib libdl dlfcn.h "dlopen dlsym" || check_lib libdl dlfcn.h "dlopen dlsym" -ldl
check_lib libm math.h sin -lm
check_host_lib math.h sin -lm
atan2f_args=2
copysign_args=2