xref: /freebsd/sys/contrib/openzfs/config/user-libfetch.m4 (revision 02e9120893770924227138ba49df1edb3896112a)
1dnl #
2dnl # Check for a libfetch - either fetch(3) or libcurl.
3dnl #
4dnl # There are two configuration dimensions:
5dnl #   * fetch(3) vs libcurl
6dnl #   * static vs dynamic
7dnl #
8dnl # fetch(3) is only dynamic.
9dnl # We use sover 6, which first appeared in FreeBSD 8.0-RELEASE.
10dnl #
11dnl # libcurl development packages include curl-config(1) – we want:
12dnl #   * HTTPS support
13dnl #   * version at least 7.16 (October 2006), for sover 4
14dnl #   * to decide if it's static or not
15dnl #
16AC_DEFUN([ZFS_AC_CONFIG_USER_LIBFETCH], [
17	AC_MSG_CHECKING([for libfetch])
18	LIBFETCH_LIBS=
19	LIBFETCH_IS_FETCH=0
20	LIBFETCH_IS_LIBCURL=0
21	LIBFETCH_DYNAMIC=0
22	LIBFETCH_SONAME=
23	have_libfetch=
24
25	saved_libs="$LIBS"
26	LIBS="$LIBS -lfetch"
27	AC_LINK_IFELSE([AC_LANG_PROGRAM([[
28		#include <sys/param.h>
29		#include <stdio.h>
30		#include <fetch.h>
31	]], [fetchGetURL("", "");])], [
32		have_libfetch=1
33		LIBFETCH_IS_FETCH=1
34		LIBFETCH_DYNAMIC=1
35		LIBFETCH_SONAME="libfetch.so.6"
36		LIBFETCH_LIBS="-ldl"
37		AC_MSG_RESULT([fetch(3)])
38	], [])
39	LIBS="$saved_libs"
40
41	if test -z "$have_libfetch"; then
42		if curl-config --protocols 2>/dev/null | grep -q HTTPS &&
43		    test "$(printf "%u" "0x$(curl-config --vernum)")" -ge "$(printf "%u" "0x071000")"; then
44			have_libfetch=1
45			LIBFETCH_IS_LIBCURL=1
46			if test "$(curl-config --built-shared)" = "yes"; then
47				LIBFETCH_DYNAMIC=1
48				LIBFETCH_SONAME="libcurl.so.4"
49				LIBFETCH_LIBS="-ldl"
50				AC_MSG_RESULT([libcurl])
51			else
52				LIBFETCH_LIBS="$(curl-config --libs)"
53				AC_MSG_RESULT([libcurl (static)])
54			fi
55
56			CCFLAGS="$CCFLAGS $(curl-config --cflags)"
57		fi
58	fi
59
60	if test -z "$have_libfetch"; then
61		AC_MSG_RESULT([none])
62	fi
63
64	AC_SUBST([LIBFETCH_LIBS])
65	AC_SUBST([LIBFETCH_DYNAMIC])
66	AC_SUBST([LIBFETCH_SONAME])
67	AC_DEFINE_UNQUOTED([LIBFETCH_IS_FETCH], [$LIBFETCH_IS_FETCH], [libfetch is fetch(3)])
68	AC_DEFINE_UNQUOTED([LIBFETCH_IS_LIBCURL], [$LIBFETCH_IS_LIBCURL], [libfetch is libcurl])
69	AC_DEFINE_UNQUOTED([LIBFETCH_DYNAMIC], [$LIBFETCH_DYNAMIC], [whether the chosen libfetch is to be loaded at run-time])
70	AC_DEFINE_UNQUOTED([LIBFETCH_SONAME], ["$LIBFETCH_SONAME"], [soname of chosen libfetch])
71])
72