threads / patch / 16049

patchautoconf: Add link tests to each AC_CHECK_FUNC() test

Subject: [PATCH] autoconf: Add link tests to each AC_CHECK_FUNC() test

## tl;dr

4 messages between Oct 26, 2008 and Jun 9, 2009. Diffs are folded; open one to read it.

replies: 3people: 3as markdown or json

David M. Syzdek· Oct 26, 2008, 11:52 UTC · lore

Update configure.ac to test libraries for getaddrinfo, strcasestr, memmem, strlcpy, strtoumax, setenv, unsetenv, and mkdtemp. The default compilers on FreeBSD 4.9-SECURITY and FreeBSD 6.2-RELEASE-p4 do not generate warnings for missing prototypes unless `-Wall' is used. This behavior renders the results of AC_CHECK_FUNC() void on these platforms. The test AC_SEARCH_LIBS() verifies a function is valid by linking to symbol within the system libraries.

Signed-off-by: David M. Syzdek <david.syzdek@acsalaska.net>
---
 configure.ac |   57 ++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 40 insertions(+), 17 deletions(-)
Show changes to configure.ac +40 −17
diff --git a/configure.ac b/configure.ac
index 7c2856e..d3b8bc3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -293,9 +293,11 @@ AC_SUBST(NO_SOCKADDR_STORAGE)
 #
 # Define NO_IPV6 if you lack IPv6 support and getaddrinfo().
 AC_CHECK_TYPE([struct addrinfo],[
- AC_CHECK_FUNC([getaddrinfo],
-  [NO_IPV6=],
-  [NO_IPV6=YesPlease])
+ AC_CHECK_FUNC([getaddrinfo],[
+  AC_SEARCH_LIBS([getaddrinfo],,
+    [NO_IPV6=],
+    [NO_IPV6=YesPlease])
+ ],[NO_IPV6=YesPlease])
 ],[NO_IPV6=YesPlease],[
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -387,44 +389,65 @@ AC_SUBST(SNPRINTF_RETURNS_BOGUS)
 AC_MSG_NOTICE([CHECKS for library functions])
 #
 # Define NO_STRCASESTR if you don't have strcasestr.
-AC_CHECK_FUNC(strcasestr,
-[NO_STRCASESTR=],
+AC_CHECK_FUNC(strcasestr,[
+ AC_SEARCH_LIBS(strcasestr,,
+ [NO_STRCASESTR=],
+ [NO_STRCASESTR=YesPlease])
+],
 [NO_STRCASESTR=YesPlease])
 AC_SUBST(NO_STRCASESTR)
 #
 # Define NO_MEMMEM if you don't have memmem.
-AC_CHECK_FUNC(memmem,
-[NO_MEMMEM=],
+AC_CHECK_FUNC(memmem,[
+ AC_SEARCH_LIBS(memmem,,
+ [NO_MEMMEM=],
+ [NO_MEMMEM=YesPlease])
+],
 [NO_MEMMEM=YesPlease])
 AC_SUBST(NO_MEMMEM)
 #
 # Define NO_STRLCPY if you don't have strlcpy.
-AC_CHECK_FUNC(strlcpy,
-[NO_STRLCPY=],
+AC_CHECK_FUNC(strlcpy,[
+ AC_SEARCH_LIBS(strlcpy,,
+ [NO_STRLCPY=],
+ [NO_STRLCPY=YesPlease])
+],
 [NO_STRLCPY=YesPlease])
 AC_SUBST(NO_STRLCPY)
 #
 # Define NO_STRTOUMAX if you don't have strtoumax in the C library.
-AC_CHECK_FUNC(strtoumax,
-[NO_STRTOUMAX=],
+AC_CHECK_FUNC(strtoumax,[
+ AC_SEARCH_LIBS(strtoumax,,
+ [NO_STRTOUMAX=],
+ [NO_STRTOUMAX=YesPlease])
+],
 [NO_STRTOUMAX=YesPlease])
 AC_SUBST(NO_STRTOUMAX)
 #
 # Define NO_SETENV if you don't have setenv in the C library.
-AC_CHECK_FUNC(setenv,
-[NO_SETENV=],
+AC_CHECK_FUNC(setenv,[
+ AC_SEARCH_LIBS(setenv,,
+ [NO_SETENV=],
+ [NO_SETENV=YesPlease])
+],
 [NO_SETENV=YesPlease])
 AC_SUBST(NO_SETENV)
 #
 # Define NO_UNSETENV if you don't have unsetenv in the C library.
-AC_CHECK_FUNC(unsetenv,
-[NO_UNSETENV=],
+AC_CHECK_FUNC(unsetenv,[
+ AC_SEARCH_LIBS(unsetenv,,
+ [NO_UNSETENV=],
+ [NO_UNSETENV=YesPlease])
+],
 [NO_UNSETENV=YesPlease])
 AC_SUBST(NO_UNSETENV)
 #
 # Define NO_MKDTEMP if you don't have mkdtemp in the C library.
-AC_CHECK_FUNC(mkdtemp,
-[NO_MKDTEMP=],
+AC_CHECK_FUNC(mkdtemp,[
+ AC_SEARCH_LIBS(mkdtemp,,
+ [NO_MKDTEMP=],
+ [NO_MKDTEMP=YesPlease])
+],
 [NO_MKDTEMP=YesPlease])
 AC_SUBST(NO_MKDTEMP)
 #
-- 
1.6.0.2.GIT
Junio C Hamano· Nov 2, 2008, 08:04 UTC · re: David M. Syzdek · lore

Re: [PATCH] autoconf: Add link tests to each AC_CHECK_FUNC() test

"David M. Syzdek" <david.syzdek@acsalaska.net> writes:
Show 6 quoted lines
> Update configure.ac to test libraries for getaddrinfo, strcasestr, memmem,
> strlcpy, strtoumax, setenv, unsetenv, and mkdtemp.  The default compilers
> on FreeBSD 4.9-SECURITY and FreeBSD 6.2-RELEASE-p4 do not generate warnings
> for missing prototypes unless `-Wall' is used. This behavior renders the
> results of AC_CHECK_FUNC() void on these platforms. The test AC_SEARCH_LIBS()
> verifies a function is valid by linking to symbol within the system libraries.
Show 16 quoted lines
> diff --git a/configure.ac b/configure.ac
> index 7c2856e..d3b8bc3 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -293,9 +293,11 @@ AC_SUBST(NO_SOCKADDR_STORAGE)
>  #
>  # Define NO_IPV6 if you lack IPv6 support and getaddrinfo().
>  AC_CHECK_TYPE([struct addrinfo],[
> - AC_CHECK_FUNC([getaddrinfo],
> -  [NO_IPV6=],
> -  [NO_IPV6=YesPlease])
> + AC_CHECK_FUNC([getaddrinfo],[
> +  AC_SEARCH_LIBS([getaddrinfo],,
> +    [NO_IPV6=],
> +    [NO_IPV6=YesPlease])
> + ],[NO_IPV6=YesPlease])

It's been a looong time since I did any sizeable autoconf/m4 hacking, but the repetitititiveness of this patch loudly calls for a convenience macro of a higher order, perhaps something like:

        AC_DEFUN([GIT_CHECK_FUNC],[
         AC_CHECK_FUNC([$1],[
          AC_SEARCH_LIBS([$1},,
          [$2],[$3])],
          [$3])])
Then we can use it like:
	GIT_CHECK_FUNC([getaddrinfo],[NO_IPV6=],[NO_IPV6=YesPlease])
Hmm?

-- >8 -- [PATCH] autoconf: use AC_CHECK_FUNC() with AC_SEARCH_LIBS() test

Update configure.ac to test libraries for getaddrinfo, strcasestr, memmem, strlcpy, strtoumax, setenv, unsetenv, and mkdtemp. The default compilers on FreeBSD 4.9-SECURITY and FreeBSD 6.2-RELEASE-p4 do not generate warnings for missing prototypes unless `-Wall' is used. This behavior renders the results of AC_CHECK_FUNC() void on these platforms. The test AC_SEARCH_LIBS() verifies a function is valid by linking to symbol within the system libraries.

---
 configure.ac |   28 +++++++++++++++++++---------
 1 files changed, 19 insertions(+), 9 deletions(-)
Show changes to diff +19 −9
diff --git c/configure.ac w/configure.ac
index 27bab00..ef544e8 100644
--- c/configure.ac
+++ w/configure.ac
@@ -65,7 +65,17 @@ else \
 fi \
 ])# GIT_PARSE_WITH
 
-
+dnl
+dnl GIT_CHECK_FUNC(FUNCTION, IFTRUE, IFFALSE)
+dnl -----------------------------------------
+dnl Similar to AC_CHECK_FUNC, but on systems that do not generate
+dnl warnings for missing prototypes (e.g. FreeBSD when compiling without
+dnl -Wall), it does not work.  By looking for function definition in
+dnl libraries, this problem can be worked around.
+AC_DEFUN([GIT_CHECK_FUNC],[AC_CHECK_FUNC([$1],[
+  AC_SEARCH_LIBS([$1],,
+  [$2],[$3])
+],[$3])])
 ## Site configuration related to programs (before tests)
 ## --with-PACKAGE[=ARG] and --without-PACKAGE
 #
@@ -325,7 +335,7 @@ AC_SUBST(NO_SOCKADDR_STORAGE)
 #
 # Define NO_IPV6 if you lack IPv6 support and getaddrinfo().
 AC_CHECK_TYPE([struct addrinfo],[
- AC_CHECK_FUNC([getaddrinfo],
+ GIT_CHECK_FUNC([getaddrinfo],
   [NO_IPV6=],
   [NO_IPV6=YesPlease])
 ],[NO_IPV6=YesPlease],[
@@ -419,43 +429,43 @@ AC_SUBST(SNPRINTF_RETURNS_BOGUS)
 AC_MSG_NOTICE([CHECKS for library functions])
 #
 # Define NO_STRCASESTR if you don't have strcasestr.
-AC_CHECK_FUNC(strcasestr,
+GIT_CHECK_FUNC(strcasestr,
 [NO_STRCASESTR=],
 [NO_STRCASESTR=YesPlease])
 AC_SUBST(NO_STRCASESTR)
 #
 # Define NO_MEMMEM if you don't have memmem.
-AC_CHECK_FUNC(memmem,
+GIT_CHECK_FUNC(memmem,
 [NO_MEMMEM=],
 [NO_MEMMEM=YesPlease])
 AC_SUBST(NO_MEMMEM)
 #
 # Define NO_STRLCPY if you don't have strlcpy.
-AC_CHECK_FUNC(strlcpy,
+GIT_CHECK_FUNC(strlcpy,
 [NO_STRLCPY=],
 [NO_STRLCPY=YesPlease])
 AC_SUBST(NO_STRLCPY)
 #
 # Define NO_STRTOUMAX if you don't have strtoumax in the C library.
-AC_CHECK_FUNC(strtoumax,
+GIT_CHECK_FUNC(strtoumax,
 [NO_STRTOUMAX=],
 [NO_STRTOUMAX=YesPlease])
 AC_SUBST(NO_STRTOUMAX)
 #
 # Define NO_SETENV if you don't have setenv in the C library.
-AC_CHECK_FUNC(setenv,
+GIT_CHECK_FUNC(setenv,
 [NO_SETENV=],
 [NO_SETENV=YesPlease])
 AC_SUBST(NO_SETENV)
 #
 # Define NO_UNSETENV if you don't have unsetenv in the C library.
-AC_CHECK_FUNC(unsetenv,
+GIT_CHECK_FUNC(unsetenv,
 [NO_UNSETENV=],
 [NO_UNSETENV=YesPlease])
 AC_SUBST(NO_UNSETENV)
 #
 # Define NO_MKDTEMP if you don't have mkdtemp in the C library.
-AC_CHECK_FUNC(mkdtemp,
+GIT_CHECK_FUNC(mkdtemp,
 [NO_MKDTEMP=],
 [NO_MKDTEMP=YesPlease])
 AC_SUBST(NO_MKDTEMP)
Ralf Wildenhues· Jun 8, 2009, 21:24 UTC · re: Junio C Hamano · lore

Re: [PATCH] autoconf: Add link tests to each AC_CHECK_FUNC() test

Hello, and please forgive me for replying to a very old thread, <http://thread.gmane.org/gmane.comp.version-control.git/99159>. (BTW, is that frowned upon on this list?)

* Junio C Hamano wrote on Sun, Nov 02, 2008 at 09:04:21AM CET:
Show 7 quoted lines
> "David M. Syzdek" <david.syzdek@acsalaska.net> writes:
> > Update configure.ac to test libraries for getaddrinfo, strcasestr, memmem,
> > strlcpy, strtoumax, setenv, unsetenv, and mkdtemp.  The default compilers
> > on FreeBSD 4.9-SECURITY and FreeBSD 6.2-RELEASE-p4 do not generate warnings
> > for missing prototypes unless `-Wall' is used. This behavior renders the
> > results of AC_CHECK_FUNC() void on these platforms. The test AC_SEARCH_LIBS()
> > verifies a function is valid by linking to symbol within the system libraries.

This description does not make sense. AC_CHECK_FUNC does not take into account prototypes in the test; instead, it tries to link a program that requires the function symbol. In that matter, the patch that introduced

Show 13 quoted lines
> It's been a looong time since I did any sizeable autoconf/m4 hacking, but
> the repetitititiveness of this patch loudly calls for a convenience macro
> of a higher order, perhaps something like:
> 
>         AC_DEFUN([GIT_CHECK_FUNC],[
>          AC_CHECK_FUNC([$1],[
>           AC_SEARCH_LIBS([$1},,
>           [$2],[$3])],
>           [$3])])
> 
> Then we can use it like:
> 
> 	GIT_CHECK_FUNC([getaddrinfo],[NO_IPV6=],[NO_IPV6=YesPlease])

(which is 1689c5de8730ea334535337a341db3c7a21ad002) is not necessary. However, there might have been another reason altogether why David was seeing false configure test results on his system, and it would be interesting to know about them (both to possibly fix Autoconf, and the comment introducing GIT_CHECK_FUNC in configure.ac).

Otherwise, I'd propose reverting the commit.

Thanks for any feedback, Ralf

Junio C Hamano· Jun 9, 2009, 05:30 UTC · re: Ralf Wildenhues · lore

Re: [PATCH] autoconf: Add link tests to each AC_CHECK_FUNC() test

Ralf Wildenhues <Ralf.Wildenhues@gmx.de> writes:
> Hello, and please forgive me for replying to a very old thread,
> <http://thread.gmane.org/gmane.comp.version-control.git/99159>.
> (BTW, is that frowned upon on this list?)
Not at all.
Show 12 quoted lines
> * Junio C Hamano wrote on Sun, Nov 02, 2008 at 09:04:21AM CET:
>> "David M. Syzdek" <david.syzdek@acsalaska.net> writes:
>> > Update configure.ac to test libraries for getaddrinfo, strcasestr, memmem,
>> > strlcpy, strtoumax, setenv, unsetenv, and mkdtemp.  The default compilers
>> > on FreeBSD 4.9-SECURITY and FreeBSD 6.2-RELEASE-p4 do not generate warnings
>> > for missing prototypes unless `-Wall' is used. This behavior renders the
>> > results of AC_CHECK_FUNC() void on these platforms. The test AC_SEARCH_LIBS()
>> > verifies a function is valid by linking to symbol within the system libraries.
>
> This description does not make sense.  AC_CHECK_FUNC does not take into
> account prototypes in the test; instead, it tries to link a program that
> requires the function symbol.

Yeah, I just looked at output from AC_CHECK_FUNC(); it creates main() that calls the function being checked and tries to see if the program links.

And SEARCH_LIBS() won't catch missing prototypes either.
> However, there might have been another reason altogether why David was
> seeing false configure test results on his system, and it would be
> interesting to know about them (both to possibly fix Autoconf, and the
> comment introducing GIT_CHECK_FUNC in configure.ac).

Yeah, I am interested, too. The closest BSD variant I happen to have access to is FreeBSD 7.2, and reverting the commit there does not seem to have any ill effects, so I'd like to know what breakage the patch fixed (or covered up).

← back to recent threads