Changeset 3874


Ignore:
Timestamp:
Oct 25, 2018 7:50:51 AM (11 months ago)
Author:
stefan
Message:

add macro AC_COIN_NAMEMANGLING to check for namemangling of header-less library

  • similar to AC_COIN_F77_WRAPPERS, but without the use of any Fortran macros
  • thus, this doesn't assume that the lib we check is actually a Fortran lib
  • therefore, AC_COIN_NAMEMANGLING is placed in coin.m4 and not coin_fortran.m4
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/coin.m4

    r3873 r3874  
    324324    CXX="$am_aux_dir/compile $CXX"
    325325  fi
     326])
     327
     328###########################################################################
     329#                   COIN_NAMEMANGLING                                     #
     330###########################################################################
     331
     332# COIN_NAMEMANGLING (lib,func,lflags)
     333# -------------------------------------------------------------------------
     334# Determine C/C++ name mangling to allow linking with header-less libraries.
     335#  lib ($1) a library we're attempting to link to
     336#  func ($2) a function within that library
     337#  lflags ($3) flags to link to library, defaults to -l$1 if not given
     338#
     339# Defines the C macros $1_FUNC and $1_FUNC_ (in uppercase) to be used for
     340# declaring functions from library $1.
     341
     342# Ideally, the function name will contain an embedded underscore but the
     343# macro doesn't require that because typical COIN-OR use cases (BLAS, LAPACK)
     344# don't have any names with embedded underscores. The default is `no extra
     345# underscore' (because this is tested first and will succeed if the name
     346# has no embedded underscore).
     347
     348# The possibilities amount to
     349# { lower / upper case } X (no) trailing underscore X (no) extra underscore
     350# where the extra underscore is applied to name with an embedded underscore.
     351
     352
     353# -------------------------------------------------------------------------
     354
     355AC_DEFUN([AC_COIN_NAMEMANGLING],
     356[
     357  AC_CACHE_CHECK(
     358    [$1 name mangling scheme],
     359    [m4_tolower(ac_cv_$1_namemangling)],
     360    [ac_save_LIBS=$LIBS
     361     a4_ifblank([$3], [LIBS="-l$1"], [LIBS="$3"])
     362     for ac_case in "lower case" "upper case" ; do
     363       for ac_trail in "underscore" "no underscore" ; do
     364         for ac_extra in "no extra underscore" "extra underscore" ; do
     365           m4_tolower(ac_cv_$1_namemangling)="${ac_case}, ${ac_trail}, ${ac_extra}"
     366           # AC_MSG_NOTICE([Attempting link for m4_tolower(ac_cv_$1_namemangling)])
     367           case $ac_case in
     368             "lower case")
     369               ac_name=m4_tolower($2)
     370               ;;
     371             "upper case")
     372               ac_name=m4_toupper($2)
     373               ;;
     374           esac
     375           if test "$ac_trail" = underscore ; then
     376             ac_name=${ac_name}_
     377           fi
     378           # AC_MSG_CHECKING([$2 -> $ac_name])
     379           AC_LINK_IFELSE(
     380             [AC_LANG_PROGRAM(
     381                [#ifdef __cplusplus
     382                  extern "C"
     383                 #endif
     384                 void $ac_name();],
     385                [$ac_name()])],
     386             [ac_result=success],
     387             [ac_result=failure])
     388           # AC_MSG_RESULT([$result])
     389           if test $ac_result = success ; then
     390             break 3
     391           fi
     392         done
     393       done
     394     done
     395     if test "$ac_result" = "failure" ; then
     396       m4_tolower(ac_cv_$1_namemangling)=unknown
     397     fi
     398     LIBS=$ac_save_LIBS])
     399
     400  # setup the m4_toupper($1)_FUNC and m4_toupper($1)_FUNC_ macros
     401  AH_TEMPLATE(m4_toupper($1_FUNC), [Define to a macro mangling the given C identifier (in lower and upper case).])
     402  AH_TEMPLATE(m4_toupper($1_FUNC_), [As m4_toupper(_AC_$1_FUNC), but for C identifiers containing underscores.])
     403  case "$ac_cv_f77_mangling" in
     404   "lower case, no underscore, no extra underscore")
     405      AC_DEFINE(m4_toupper($1_FUNC)[(name,NAME)],  [name])
     406      AC_DEFINE(m4_toupper($1_FUNC_)[(name,NAME)], [name]) ;;
     407   "lower case, no underscore, extra underscore")
     408      AC_DEFINE(m4_toupper($1_FUNC)[(name,NAME)],  [name])
     409      AC_DEFINE(m4_toupper($1_FUNC_)[(name,NAME)], [name [##] _]) ;;
     410   "lower case, underscore, no extra underscore")
     411      AC_DEFINE(m4_toupper($1_FUNC)[(name,NAME)],  [name [##] _])
     412      AC_DEFINE(m4_toupper($1_FUNC_)[(name,NAME)], [name [##] _]) ;;
     413   "lower case, underscore, extra underscore")
     414      AC_DEFINE(m4_toupper($1_FUNC)[(name,NAME)],  [name [##] _])
     415      AC_DEFINE(m4_toupper($1_FUNC_)[(name,NAME)], [name [##] __]) ;;
     416   "upper case, no underscore, no extra underscore")
     417      AC_DEFINE(m4_toupper($1_FUNC)[(name,NAME)],  [NAME])
     418      AC_DEFINE(m4_toupper($1_FUNC_)[(name,NAME)], [NAME]) ;;
     419   "upper case, no underscore, extra underscore")
     420      AC_DEFINE(m4_toupper($1_FUNC)[(name,NAME)],  [NAME])
     421      AC_DEFINE(m4_toupper($1_FUNC_)[(name,NAME)], [NAME [##] _]) ;;
     422   "upper case, underscore, no extra underscore")
     423      AC_DEFINE(m4_toupper($1_FUNC)[(name,NAME)],  [NAME [##] _])
     424      AC_DEFINE(m4_toupper($1_FUNC_)[(name,NAME)], [NAME [##] _]) ;;
     425   "upper case, underscore, extra underscore")
     426      AC_DEFINE(m4_toupper($1_FUNC)[(name,NAME)],  [NAME [##] _])
     427      AC_DEFINE(m4_toupper($1_FUNC_)[(name,NAME)], [NAME [##] __]) ;;
     428   "unknown")
     429      AC_MSG_WARN([Unable to determine correct name mangling scheme for $2 in $1]) ;;
     430   *)
     431      AC_MSG_WARN([unknown name-mangling scheme])
     432      ;;
     433  esac
     434  # AC_MSG_NOTICE([Done COIN_NAMEMANGLING])
    326435])
    327436
Note: See TracChangeset for help on using the changeset viewer.