On Thu, Apr 3, 2025 at 9:19 PM Iain Sandoe <iains....@gmail.com> wrote: > > We should not assume that the target needs (or even has) libm. > > Tested on the usual suspects (x86_64, aarch64 linux, x86_64 darwin). > OK for trunk?
OK. > thanks > Iain. > > --- 8< --- > > Use the libtool config check and $(LIBM). > > libgcobol/ChangeLog: > > * Makefile.am: Use $(LIBM) to add the math lib when > it is needed. > * Makefile.in: Regenerate. > * configure: Regenerate. > * configure.ac: Check if the target wants libm. > > Signed-off-by: Iain Sandoe <i...@sandoe.co.uk> > --- > libgcobol/Makefile.am | 2 +- > libgcobol/Makefile.in | 3 +- > libgcobol/configure | 146 ++++++++++++++++++++++++++++++++++++++++- > libgcobol/configure.ac | 1 + > 4 files changed, 148 insertions(+), 4 deletions(-) > > diff --git a/libgcobol/Makefile.am b/libgcobol/Makefile.am > index cafb733dde1..45217421b1c 100644 > --- a/libgcobol/Makefile.am > +++ b/libgcobol/Makefile.am > @@ -48,7 +48,7 @@ libgcobol_la_LINK = $(LIBTOOL) --mode=link --tag=CXX $(CXX) > \ > -Wc,-shared-libgcc \ > -version-info $(LIBGCOBOL_VERSION) \ > -lstdc++ \ > - $(LTLDFLAGS) $(LTLIBICONV) > + $(LTLDFLAGS) $(LTLIBICONV) $(LIBM) > > WARN_CFLAGS = -W -Wall -Wwrite-strings > > diff --git a/libgcobol/Makefile.in b/libgcobol/Makefile.in > index c4a562a8058..0f0d9b687f1 100644 > --- a/libgcobol/Makefile.in > +++ b/libgcobol/Makefile.in > @@ -305,6 +305,7 @@ LD = @LD@ > LDFLAGS = @LDFLAGS@ > LIBGCOBOL_VERSION = @LIBGCOBOL_VERSION@ > LIBICONV = @LIBICONV@ > +LIBM = @LIBM@ > LIBOBJS = @LIBOBJS@ > LIBS = @LIBS@ > LIBTOOL = @LIBTOOL@ > @@ -428,7 +429,7 @@ libgcobol_la_LINK = $(LIBTOOL) --mode=link --tag=CXX > $(CXX) \ > -Wc,-shared-libgcc \ > -version-info $(LIBGCOBOL_VERSION) \ > -lstdc++ \ > - $(LTLDFLAGS) $(LTLIBICONV) > + $(LTLDFLAGS) $(LTLIBICONV) $(LIBM) > > WARN_CFLAGS = -W -Wall -Wwrite-strings > AM_CXXFLAGS = $(CXXFLAGS_FOR_TARGET) > diff --git a/libgcobol/configure b/libgcobol/configure > index e12b72e0817..e7b3b830890 100755 > --- a/libgcobol/configure > +++ b/libgcobol/configure > @@ -646,6 +646,7 @@ enable_static > enable_shared > ENABLE_DARWIN_AT_RPATH_FALSE > ENABLE_DARWIN_AT_RPATH_TRUE > +LIBM > CXXCPP > OTOOL64 > OTOOL > @@ -12908,7 +12909,7 @@ else > lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 > lt_status=$lt_dlunknown > cat > conftest.$ac_ext <<_LT_EOF > -#line 12911 "configure" > +#line 12912 "configure" > #include "confdefs.h" > > #if HAVE_DLFCN_H > @@ -13014,7 +13015,7 @@ else > lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 > lt_status=$lt_dlunknown > cat > conftest.$ac_ext <<_LT_EOF > -#line 13017 "configure" > +#line 13018 "configure" > #include "confdefs.h" > > #if HAVE_DLFCN_H > @@ -16348,6 +16349,147 @@ enable_dlopen=yes > > > > +LIBM= > +case $host in > +*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*) > + # These system don't have libm, or don't need it > + ;; > +*-ncr-sysv4.3*) > + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _mwvalidcheckl in > -lmw" >&5 > +$as_echo_n "checking for _mwvalidcheckl in -lmw... " >&6; } > +if ${ac_cv_lib_mw__mwvalidcheckl+:} false; then : > + $as_echo_n "(cached) " >&6 > +else > + ac_check_lib_save_LIBS=$LIBS > +LIBS="-lmw $LIBS" > +if test x$gcc_no_link = xyes; then > + as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." > "$LINENO" 5 > +fi > +cat confdefs.h - <<_ACEOF >conftest.$ac_ext > +/* end confdefs.h. */ > + > +/* Override any GCC internal prototype to avoid an error. > + Use char because int might match the return type of a GCC > + builtin and then its argument prototype would still apply. */ > +#ifdef __cplusplus > +extern "C" > +#endif > +char _mwvalidcheckl (); > +int > +main () > +{ > +return _mwvalidcheckl (); > + ; > + return 0; > +} > +_ACEOF > +if ac_fn_c_try_link "$LINENO"; then : > + ac_cv_lib_mw__mwvalidcheckl=yes > +else > + ac_cv_lib_mw__mwvalidcheckl=no > +fi > +rm -f core conftest.err conftest.$ac_objext \ > + conftest$ac_exeext conftest.$ac_ext > +LIBS=$ac_check_lib_save_LIBS > +fi > +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: > $ac_cv_lib_mw__mwvalidcheckl" >&5 > +$as_echo "$ac_cv_lib_mw__mwvalidcheckl" >&6; } > +if test "x$ac_cv_lib_mw__mwvalidcheckl" = xyes; then : > + LIBM="-lmw" > +fi > + > + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for cos in -lm" >&5 > +$as_echo_n "checking for cos in -lm... " >&6; } > +if ${ac_cv_lib_m_cos+:} false; then : > + $as_echo_n "(cached) " >&6 > +else > + ac_check_lib_save_LIBS=$LIBS > +LIBS="-lm $LIBS" > +if test x$gcc_no_link = xyes; then > + as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." > "$LINENO" 5 > +fi > +cat confdefs.h - <<_ACEOF >conftest.$ac_ext > +/* end confdefs.h. */ > + > +/* Override any GCC internal prototype to avoid an error. > + Use char because int might match the return type of a GCC > + builtin and then its argument prototype would still apply. */ > +#ifdef __cplusplus > +extern "C" > +#endif > +char cos (); > +int > +main () > +{ > +return cos (); > + ; > + return 0; > +} > +_ACEOF > +if ac_fn_c_try_link "$LINENO"; then : > + ac_cv_lib_m_cos=yes > +else > + ac_cv_lib_m_cos=no > +fi > +rm -f core conftest.err conftest.$ac_objext \ > + conftest$ac_exeext conftest.$ac_ext > +LIBS=$ac_check_lib_save_LIBS > +fi > +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_cos" >&5 > +$as_echo "$ac_cv_lib_m_cos" >&6; } > +if test "x$ac_cv_lib_m_cos" = xyes; then : > + LIBM="$LIBM -lm" > +fi > + > + ;; > +*) > + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for cos in -lm" >&5 > +$as_echo_n "checking for cos in -lm... " >&6; } > +if ${ac_cv_lib_m_cos+:} false; then : > + $as_echo_n "(cached) " >&6 > +else > + ac_check_lib_save_LIBS=$LIBS > +LIBS="-lm $LIBS" > +if test x$gcc_no_link = xyes; then > + as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." > "$LINENO" 5 > +fi > +cat confdefs.h - <<_ACEOF >conftest.$ac_ext > +/* end confdefs.h. */ > + > +/* Override any GCC internal prototype to avoid an error. > + Use char because int might match the return type of a GCC > + builtin and then its argument prototype would still apply. */ > +#ifdef __cplusplus > +extern "C" > +#endif > +char cos (); > +int > +main () > +{ > +return cos (); > + ; > + return 0; > +} > +_ACEOF > +if ac_fn_c_try_link "$LINENO"; then : > + ac_cv_lib_m_cos=yes > +else > + ac_cv_lib_m_cos=no > +fi > +rm -f core conftest.err conftest.$ac_objext \ > + conftest$ac_exeext conftest.$ac_ext > +LIBS=$ac_check_lib_save_LIBS > +fi > +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_cos" >&5 > +$as_echo "$ac_cv_lib_m_cos" >&6; } > +if test "x$ac_cv_lib_m_cos" = xyes; then : > + LIBM="-lm" > +fi > + > + ;; > +esac > + > + > > if test x$enable_darwin_at_rpath = xyes; then > ENABLE_DARWIN_AT_RPATH_TRUE= > diff --git a/libgcobol/configure.ac b/libgcobol/configure.ac > index 34c0235c56b..6b287a1ac70 100644 > --- a/libgcobol/configure.ac > +++ b/libgcobol/configure.ac > @@ -209,6 +209,7 @@ AM_PROG_LIBTOOL > LT_INIT > > AC_LIBTOOL_DLOPEN > +LT_LIB_M > > AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test x$enable_darwin_at_rpath = > xyes]) > > -- > 2.39.2 (Apple Git-143) >