summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2008-10-28 19:47:21 +0100
committerDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2008-10-28 19:49:26 +0100
commitc5da685240c4a9d85eae2ce34f4c1254c925c6f6 (patch)
tree7b4b401191e9c6fec10b18ed7352fd213084a4aa
parentcbfe5edc9ade74b56c7cbf4b0a49831325ae6e22 (diff)
Create an improved function search macro, and use it to look for res_query.
Instead of using AC_SEARCH_LIBS or AC_CHECK_LIB, create a new macro to search for function in different libraries; this is needed since the function name might just be a (preprocessor) macro for another symbol. The new macro is released under GPL2 (or later) + exception, and allows to provide a custom source code to use to test for the function.
-rw-r--r--configure.ac20
-rw-r--r--m4/search_function.m482
2 files changed, 88 insertions, 14 deletions
diff --git a/configure.ac b/configure.ac
index c8f8941..09e3518 100644
--- a/configure.ac
+++ b/configure.ac
@@ -78,20 +78,12 @@ AC_CHECK_FUNCS([memset select strndup setresuid setreuid strerror])
AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_LIB(socket, connect)
-AC_CHECK_FUNC(res_query, ,
- [AC_CHECK_LIB(resolv, res_query, [],
- [ save_libs="$LIBS"
- LIBS="-lresolv $LIBS"
- AC_MSG_CHECKING([for res_query in -lresolv (alternate version)])
- AC_LINK_IFELSE(
- [AC_LANG_PROGRAM([[#include <resolv.h>]], [[res_query(0,0,0,0,0)]])],
- [ AC_MSG_RESULT(yes) ],
- [ AC_MSG_RESULT(no)
- LIBS="$save_libs"
- AC_CHECK_LIB(bind, res_query,
- [], [ AC_MSG_ERROR(res_query not found) ] ) ] ) ] )
- ]
-)
+ACF_SEARCH_FUNCTION([res_query], [-lresolv, -lbind],
+ [], [AC_MSG_ERROR([res_query not found])],
+ [AC_LANG_PROGRAM([[
+ #include <resolv.h>
+ ]], [[res_query(0, 0, 0, 0, 0);]])
+ ])
ACX_PTHREAD
diff --git a/m4/search_function.m4 b/m4/search_function.m4
new file mode 100644
index 0000000..53bfcad
--- /dev/null
+++ b/m4/search_function.m4
@@ -0,0 +1,82 @@
+dnl Copyright (c) 2008 Diego Pettenò <flameeyes@gmail.com>
+dnl
+dnl This program is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2, or (at your option)
+dnl any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+dnl GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+dnl 02110-1301, USA.
+dnl
+dnl As a special exception, the copyright owners of the
+dnl macro gives unlimited permission to copy, distribute and modify the
+dnl configure scripts that are the output of Autoconf when processing the
+dnl Macro. You need not follow the terms of the GNU General Public
+dnl License when using or distributing such scripts, even though portions
+dnl of the text of the Macro appear in them. The GNU General Public
+dnl License (GPL) does govern all other use of the material that
+dnl constitutes the Autoconf Macro.
+dnl
+dnl This special exception to the GPL applies to versions of the
+dnl Autoconf Macro released by this project. When you make and
+dnl distribute a modified version of the Autoconf Macro, you may extend
+dnl this special exception to the GPL to apply to your modified version as
+dnl well.
+
+dnl ACF_SEARCH_FUNCTION([function name],
+dnl [m4 list of libraries],
+dnl [action if found],
+dnl [action if not found],
+dnl [test source])
+dnl
+dnl Improved modified version of AC_SEARCH_LIBS, with some
+dnl differences:
+dnl - it accepts an m4 list for libraries to allow compound libraries
+dnl instead of using the other-libraries parameter;
+dnl - action if not found is only invoked when the function is not
+dnl found at all;
+dnl - an optional parameter allows for custom source code for testing
+dnl (allowing to search for functions that are actually aliased).
+AC_DEFUN([ACF_SEARCH_FUNCTION], [
+ m4_pushdef([search_sourcecode], [
+ m4_default([$5], [
+ AC_LANG_CALL([], [$1])
+ ])
+ ])
+ m4_pushdef([cache_variable], AS_TR_SH([acf_cv_library_$1]))
+
+ m4_pushdef([action_if_found],
+ m4_default([$3], [LIBS="$LIBS $]cache_variable["]))
+ m4_pushdef([action_if_not_found], m4_default([$4], [:]))
+
+ AC_CACHE_CHECK([for library containing $1],
+ cache_variable,
+ [while true; do
+ m4_foreach([library], [, $2], [
+ save_libs=$LIBS
+ LIBS="$LIBS library"
+ AC_LINK_IFELSE(search_sourcecode,
+ cache_variable=" library")
+ LIBS=$save_libs
+ AS_IF(test -n "$cache_variable", [break])
+ ])
+ break
+ done
+ ])
+
+ m4_popdef([search_sourcecode])
+
+ AS_IF(test -n "$cache_variable",
+ m4_n([action_if_found]),
+ m4_n([action_if_not_found])
+ )
+
+ m4_popdef([cache_variable])
+])