Blame m4/search_function.m4

Packit 6baad5
dnl Copyright (c) 2008 Diego Pettenò <flameeyes@gmail.com>
Packit 6baad5
dnl
Packit 6baad5
dnl This program is free software; you can redistribute it and/or modify
Packit 6baad5
dnl it under the terms of the GNU General Public License as published by
Packit 6baad5
dnl the Free Software Foundation; either version 2, or (at your option)
Packit 6baad5
dnl any later version.
Packit 6baad5
dnl
Packit 6baad5
dnl This program is distributed in the hope that it will be useful,
Packit 6baad5
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6baad5
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 6baad5
dnl GNU General Public License for more details.
Packit 6baad5
dnl
Packit 6baad5
dnl You should have received a copy of the GNU General Public License
Packit 6baad5
dnl along with this program; if not, write to the Free Software
Packit 6baad5
dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit 6baad5
dnl 02110-1301, USA.
Packit 6baad5
dnl
Packit 6baad5
dnl As a special exception, the copyright owners of the
Packit 6baad5
dnl macro gives unlimited permission to copy, distribute and modify the
Packit 6baad5
dnl configure scripts that are the output of Autoconf when processing the
Packit 6baad5
dnl Macro. You need not follow the terms of the GNU General Public
Packit 6baad5
dnl License when using or distributing such scripts, even though portions
Packit 6baad5
dnl of the text of the Macro appear in them. The GNU General Public
Packit 6baad5
dnl License (GPL) does govern all other use of the material that
Packit 6baad5
dnl constitutes the Autoconf Macro.
Packit 6baad5
dnl 
Packit 6baad5
dnl This special exception to the GPL applies to versions of the
Packit 6baad5
dnl Autoconf Macro released by this project. When you make and
Packit 6baad5
dnl distribute a modified version of the Autoconf Macro, you may extend
Packit 6baad5
dnl this special exception to the GPL to apply to your modified version as
Packit 6baad5
dnl well.
Packit 6baad5
Packit 6baad5
dnl ACF_SEARCH_FUNCTION([function name],
Packit 6baad5
dnl                     [m4 list of libraries],
Packit 6baad5
dnl                     [action if found],
Packit 6baad5
dnl                     [action if not found],
Packit 6baad5
dnl                     [test source])
Packit 6baad5
dnl
Packit 6baad5
dnl Improved modified version of AC_SEARCH_LIBS, with some
Packit 6baad5
dnl differences:
Packit 6baad5
dnl  - it accepts an m4 list for libraries to allow compound libraries
Packit 6baad5
dnl    instead of using the other-libraries parameter;
Packit 6baad5
dnl  - action if not found is only invoked when the function is not
Packit 6baad5
dnl    found at all;
Packit 6baad5
dnl  - an optional parameter allows for custom source code for testing
Packit 6baad5
dnl    (allowing to search for functions that are actually aliased).
Packit 6baad5
AC_DEFUN([ACF_SEARCH_FUNCTION], [
Packit 6baad5
  m4_pushdef([search_sourcecode], [
Packit 6baad5
    m4_default([$5], [
Packit 6baad5
      AC_LANG_CALL([], [$1])
Packit 6baad5
    ])
Packit 6baad5
  ])
Packit 6baad5
  m4_pushdef([cache_variable], AS_TR_SH([acf_cv_library_$1]))
Packit 6baad5
Packit 6baad5
  m4_pushdef([action_if_found],
Packit 6baad5
    m4_default([$3], [LIBS="$LIBS $]cache_variable["]))
Packit 6baad5
  m4_pushdef([action_if_not_found], m4_default([$4], [:]))
Packit 6baad5
Packit 6baad5
  AC_CACHE_CHECK([for library containing $1],
Packit 6baad5
    cache_variable,
Packit 6baad5
    [while true; do
Packit 6baad5
       m4_foreach([library], [, $2], [
Packit 6baad5
         save_libs=$LIBS
Packit 6baad5
	 LIBS="$LIBS library"
Packit 6baad5
         AC_LINK_IFELSE(search_sourcecode,
Packit 6baad5
           cache_variable=" library")
Packit 6baad5
         LIBS=$save_libs
Packit 6baad5
	 AS_IF(test -n "$cache_variable", [break])
Packit 6baad5
       ])
Packit 6baad5
       break
Packit 6baad5
     done
Packit 6baad5
    ])
Packit 6baad5
Packit 6baad5
  m4_popdef([search_sourcecode])
Packit 6baad5
Packit 6baad5
  AS_IF(test -n "$cache_variable",
Packit 6baad5
    m4_n([action_if_found]),
Packit 6baad5
    m4_n([action_if_not_found])
Packit 6baad5
    )
Packit 6baad5
Packit 6baad5
  m4_popdef([cache_variable])
Packit 6baad5
])