Changeset 3875


Ignore:
Timestamp:
Oct 27, 2018 9:14:46 AM (11 months ago)
Author:
stefan
Message:

add macros to check for various name mangling schemes in link check; add new macro to check for lapack

  • added AC_COIN_TRY_LINK to check whether a function exists in a library, thereby trying different name mangling scheme and recording the successful one
  • added AC_COIN_DEFINENAMEMANGLING to define XYZ_FUNC/XYZ_FUNC_ macros depending on given name mangling scheme
  • add AC_COIN_CHK_LAPACK to check for Lapack and define COIN_LAPACK_FUNC(_) according to found name mangling scheme
  • do all this without requiring or assuming Fortran
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/coin.m4

    r3874 r3875  
    324324    CXX="$am_aux_dir/compile $CXX"
    325325  fi
     326])
     327
     328###########################################################################
     329#                   COIN_DEFINENAMEMANGLING                               #
     330###########################################################################
     331
     332# COIN_DEFINENAMEMANGLING (name,namemangling)
     333# -------------------------------------------------------------------------
     334# Determine C/C++ name mangling to allow linking with header-less libraries.
     335#  name ($1) an identifier to prefix C macro names
     336#  namemangling ($2) the name mangling scheme as determined by COIN_NAMEMANGLING
     337#                    or COIN_TRY_LINK
     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# -------------------------------------------------------------------------
     343
     344AC_DEFUN([AC_COIN_DEFINENAMEMANGLING],
     345[
     346  AH_TEMPLATE($1_FUNC, [Define to a macro mangling the given C identifier (in lower and upper case).])
     347  AH_TEMPLATE($1_FUNC_, [As $1_FUNC, but for C identifiers containing underscores.])
     348  case "$2" in
     349   "lower case, no underscore, no extra underscore")
     350      AC_DEFINE($1_FUNC[(name,NAME)],  [name])
     351      AC_DEFINE($1_FUNC_[(name,NAME)], [name]) ;;
     352   "lower case, no underscore, extra underscore")
     353      AC_DEFINE($1_FUNC[(name,NAME)],  [name])
     354      AC_DEFINE($1_FUNC_[(name,NAME)], [name [##] _]) ;;
     355   "lower case, underscore, no extra underscore")
     356      AC_DEFINE($1_FUNC[(name,NAME)],  [name [##] _])
     357      AC_DEFINE($1_FUNC_[(name,NAME)], [name [##] _]) ;;
     358   "lower case, underscore, extra underscore")
     359      AC_DEFINE($1_FUNC[(name,NAME)],  [name [##] _])
     360      AC_DEFINE($1_FUNC_[(name,NAME)], [name [##] __]) ;;
     361   "upper case, no underscore, no extra underscore")
     362      AC_DEFINE($1_FUNC[(name,NAME)],  [NAME])
     363      AC_DEFINE($1_FUNC_[(name,NAME)], [NAME]) ;;
     364   "upper case, no underscore, extra underscore")
     365      AC_DEFINE($1_FUNC[(name,NAME)],  [NAME])
     366      AC_DEFINE($1_FUNC_[(name,NAME)], [NAME [##] _]) ;;
     367   "upper case, underscore, no extra underscore")
     368      AC_DEFINE($1_FUNC[(name,NAME)],  [NAME [##] _])
     369      AC_DEFINE($1_FUNC_[(name,NAME)], [NAME [##] _]) ;;
     370   "upper case, underscore, extra underscore")
     371      AC_DEFINE($1_FUNC[(name,NAME)],  [NAME [##] _])
     372      AC_DEFINE($1_FUNC_[(name,NAME)], [NAME [##] __]) ;;
     373   *)
     374      AC_MSG_WARN([Unsupported or unknown name-mangling scheme: $2])
     375      ;;
     376  esac
    326377])
    327378
     
    399450
    400451  # 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
     452  AC_COIN_DEFINENAMEMANGLING([m4_toupper($1)],[$m4_tolower(ac_cv_$1_namemangling)])
     453
    434454  # AC_MSG_NOTICE([Done COIN_NAMEMANGLING])
    435455])
    436456
     457
     458###########################################################################
     459#                            COIN_TRY_LINK                                #
     460###########################################################################
     461
     462# This is a helper macro for checking if a library can be linked based on
     463# a function name only.
     464#   COIN_TRY_LINK(func,lflags,pcfiles,action-if-success,action-if-failed)
     465#  func ($1) the name of the function to try to link
     466#  lflags ($2) linker flags to use
     467#  pcfiles ($3) pc files to query for additional linker flags
     468#  action-if-success ($4) commands to execute if any linking was successful
     469#  action-if-failed ($5) commands to execute if no linking was successful
     470#
     471# The macro tries different name mangling schemes and expands into
     472# action-if-success for the first one that succeeds.
     473# It sets variable func_namemangling according to the found name mangling
     474# scheme, which can be used as input for COIN_DEFINENAMEMANGLING.
     475
     476AC_DEFUN([AC_COIN_TRY_LINK],
     477[
     478  # setup LIBS by adding $2 and those from $3
     479  ac_save_LIBS="$LIBS"
     480  m4_ifnblank([$2], [LIBS="$2 $LIBS"])
     481  m4_ifnblank([$3],
     482    [AC_REQUIRE([AC_COIN_HAS_PKGCONFIG])
     483     temp_LFLAGS=`PKG_CONFIG_PATH="$COIN_PKG_CONFIG_PATH" $PKG_CONFIG --libs $3`
     484     LIBS="$temp_LFLAGS $LIBS"
     485    ])
     486
     487  $1_namemangling=unknown
     488
     489  # TODO shouldn't we make use of ac_extra somewhere below?
     490  for ac_extra in "no extra underscore" "extra underscore" ; do
     491    for ac_case in "lower case" "upper case" ; do
     492      for ac_trail in "underscore" "no underscore" ; do
     493        #AC_MSG_NOTICE([Attempting link for ${ac_case}, ${ac_trail}, ${ac_extra}])
     494        case $ac_case in
     495          "lower case")
     496            ac_name=m4_tolower($1)
     497            ;;
     498          "upper case")
     499            ac_name=m4_toupper($1)
     500            ;;
     501        esac
     502        if test "$ac_trail" = underscore ; then
     503          ac_name=${ac_name}_
     504        fi
     505        AC_MSG_CHECKING([for function $ac_name in $LIBS])
     506        AC_LINK_IFELSE(
     507          [AC_LANG_PROGRAM(
     508            [#ifdef __cplusplus
     509             extern "C"
     510             #endif
     511             void $ac_name();],
     512            [$ac_name()])],
     513          [$1_namemangling="${ac_case}, ${ac_trail}, ${ac_extra}"
     514           ac_result=success],
     515          [ac_result=failure])
     516        AC_MSG_RESULT([$ac_result])
     517        if test $ac_result = success ; then
     518          break 3
     519        fi
     520      done
     521    done
     522  done
     523  LIBS=$ac_save_LIBS
     524
     525  if test $ac_result = success ; then
     526    m4_ifblank([$4],[:],[$4])
     527    m4_ifnblank([$5],[else $5])
     528  fi
     529])
    437530
    438531###########################################################################
     
    644737# COIN_DEF_PRIM_ARGS([prim],[base],[lflags],[cflags],[dflags],[build])
    645738
    646 # This is a utility macro to handle the standard arguments that COIN
     739# This is a utility macro to handle the standard arguments that COIN-OR
    647740# configuration files supply for a component (package or library):
    648741#   --with-prim: use primitive (yes / no / special)
     
    15711664]) # AC_COIN_CHK_GNU_READLINE
    15721665
     1666
     1667###########################################################################
     1668#                       COIN_CHK_LAPACK                                   #
     1669###########################################################################
     1670
     1671# COIN_CHK_LAPACK([client packages])
     1672
     1673# This macro checks for a LAPACK library and adds the information necessary to
     1674# use it to the _LFLAGS, _CFLAGS, and _PCFILES variables of the client packages
     1675# passed as a space-separated list in parameter $1. These correspond to
     1676# Libs.private, Cflags.private, and Requires.private, respectively, in a .pc
     1677# file.
     1678
     1679# The algorithm first invokes FIND_PRIM_PKG. The parameters --with-lapack,
     1680# --with-lapack-lflags, and --with-lapack-cflags are interpreted there. If
     1681# nothing is found, default locations are checked.
     1682# A link check is used to determine whether default locations work and to
     1683# determine the name mangling scheme of the Lapack library.
     1684
     1685AC_DEFUN([AC_COIN_CHK_LAPACK],
     1686[
     1687# Make sure the necessary variables exist for each client package.
     1688  m4_foreach_w([myvar],[$1],
     1689    [AC_SUBST(m4_toupper(myvar)_LIBS)
     1690     AC_SUBST(m4_toupper(myvar)_CFLAGS)
     1691     AC_SUBST(m4_toupper(myvar)_PCFILES)
     1692    ])
     1693
     1694# Set up command line arguments with DEF_PRIM_ARGS and give FIND_PRIM_PKG
     1695# a chance, just in case lapack.pc exists. The result (coin_has_lapack)
     1696# will be one of yes (either the user specified something or pkgconfig
     1697# found something), no (user specified nothing and pkgconfig found nothing)
     1698# or skipping (user said do not use). We'll also have variables lapack_lflags,
     1699# lapack_cflags, lapack_data, and lapack_pcfiles.
     1700
     1701  AC_COIN_DEF_PRIM_ARGS([lapack],yes,yes,yes,no)
     1702  AC_COIN_FIND_PRIM_PKG([lapack])
     1703
     1704# If FIND_PRIM_PKG found something, then we'll do a link check to figure
     1705# out whether it is working and what the name mangling scheme is.
     1706# This sets dsyev_namemangling
     1707  if test "$coin_has_lapack" = yes ; then
     1708    AC_COIN_TRY_LINK([dsyev],[$lapack_lflags],[$lapack_pcfiles],,
     1709      [AC_MSG_ERROR([Could not find dsyev in Lapack])])
     1710  fi
     1711
     1712# If FIND_PRIM_PKG didn't find anything, try a few guesses. First, try some
     1713# specialised checks based on the host system type. If none of them are
     1714# applicable, or the applicable one fails, try the generic -llapack.
     1715# TODO check for Lapack in Blas
     1716  if test "$coin_has_lapack" = no ; then
     1717    case $build in
     1718      *-sgi-*)
     1719        AC_COIN_TRY_LINK([dsyev],[-lcomplib.sgimath],[],[
     1720          coin_has_lapack=yes
     1721          lapack_lflags=-lcomplib.sgimath])
     1722        ;;
     1723
     1724      *-*-solaris*)
     1725        # See comments in COIN_CHK_PKG_BLAS.
     1726        AC_COIN_TRY_LINK([dsyev],[-lsunperf],[],[
     1727          coin_has_lapack=yes
     1728          lapack_lflags=-lsunperf])
     1729        ;;
     1730    esac
     1731  fi
     1732  if test "$coin_has_lapack" = no ; then
     1733    AC_COIN_TRY_LINK([dsyev],[-llapack],[],[
     1734      coin_has_lapack=yes
     1735      lapack_lflags=-llapack])
     1736  fi
     1737
     1738# Time to set some variables. Create an automake conditional COIN_HAS_LAPACK.
     1739  AM_CONDITIONAL(m4_toupper(COIN_HAS_LAPACK),[test $coin_has_lapack = yes])
     1740
     1741# If we've located the package, define preprocessor symbol COIN_HAS_LAPACK
     1742# and COIN_LAPACK_FUNC[_] and augment the necessary variables for the client packages.
     1743  if test $coin_has_lapack = yes ; then
     1744    AC_DEFINE(m4_toupper(COIN_HAS_LAPACK),[1],
     1745      [Define to 1 if the LAPACK package is available])
     1746    AC_COIN_DEFINENAMEMANGLING([COIN_LAPACK], ${dsyev_namemangling})
     1747    m4_foreach_w([myvar],[$1],
     1748      [m4_toupper(myvar)_PCFILES="$lapack_pcfiles $m4_toupper(myvar)_PCFILES"
     1749       m4_toupper(myvar)_LFLAGS="$lapack_lflags $m4_toupper(myvar)_LFLAGS"
     1750       m4_toupper(myvar)_CFLAGS="$lapack_cflags $m4_toupper(myvar)_CFLAGS"
     1751      ])
     1752  fi
     1753]) # AC_COIN_CHK_LAPACK
     1754
    15731755###########################################################################
    15741756#                           COIN_DOXYGEN                                  #
  • trunk/coin_fortran.m4

    r3862 r3875  
    465465# on the command line or obtained via a .pc file by adding `nolinkcheck' as $2.
    466466
    467 AC_DEFUN([AC_COIN_CHK_LAPACK],
     467AC_DEFUN([AC_COIN_CHK_LAPACK_OLD],
    468468[
    469469  AC_REQUIRE([AC_COIN_PROG_F77])
Note: See TracChangeset for help on using the changeset viewer.