• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1dnl
2dnl DNS Service Discovery (aka Bonjour) stuff for CUPS.
3dnl
4dnl Copyright © 2020-2024 by OpenPrinting.
5dnl Copyright © 2007-2019 by Apple Inc.
6dnl
7dnl Licensed under Apache License v2.0.  See the file "LICENSE" for more
8dnl information.
9dnl
10
11AC_ARG_WITH([dnssd], AS_HELP_STRING([--with-dnssd=...], [enable DNS Service Discovery support (avahi, mdnsresponder, no, yes)]))
12AS_IF([test x$with_dnssd = x], [
13    with_dnssd="yes"
14], [test "$with_dnssd" != avahi -a "$with_dnssd" != mdnsresponder -a "$with_dnssd" != no -a "$with_dnssd" != yes], [
15    AC_MSG_ERROR([Unsupported --with-dnssd value "$with_dnssd".])
16])
17AC_ARG_WITH([dnssd_libs], AS_HELP_STRING([--with-dnssd-libs], [set directory for DNS Service Discovery library]), [
18    LDFLAGS="-L$withval $LDFLAGS"
19    DSOFLAGS="-L$withval $DSOFLAGS"
20])
21AC_ARG_WITH([dnssd_includes], AS_HELP_STRING([--with-dnssd-includes], [set directory for DNS Service Discovery header files]), [
22    CFLAGS="-I$withval $CFLAGS"
23    CPPFLAGS="-I$withval $CPPFLAGS"
24])
25
26DNSSDLIBS=""
27DNSSD_BACKEND=""
28IPPFIND_BIN=""
29IPPFIND_MAN=""
30
31dnl First try using mDNSResponder...
32AS_IF([test $with_dnssd = yes -o $with_dnssd = mdnsresponder], [
33    AC_CHECK_HEADER([dns_sd.h], [
34	AS_CASE(["$host_os_name"], [darwin*], [
35	    # Darwin and macOS...
36	    with_dnssd="mdnsresponder"
37	    AC_DEFINE([HAVE_DNSSD], [1], [Have DNS-SD support?])
38	    AC_DEFINE([HAVE_MDNSRESPONDER], [1], [Have mDNSResponder library?])
39	    DNSSD_BACKEND="dnssd"
40	    IPPFIND_BIN="ippfind"
41	    IPPFIND_MAN="ippfind.1"
42	], [*], [
43	    # All others...
44	    AC_MSG_CHECKING([for current version of dns_sd library])
45	    SAVELIBS="$LIBS"
46	    LIBS="$LIBS -ldns_sd"
47	    AC_COMPILE_IFELSE([
48	        AC_LANG_PROGRAM([[#include <dns_sd.h>]], [[
49		    int constant = kDNSServiceFlagsShareConnection;
50		    unsigned char txtRecord[100];
51		    uint8_t valueLen;
52		    TXTRecordGetValuePtr(sizeof(txtRecord), txtRecord, "value", &valueLen);
53		]])
54	    ], [
55		AC_MSG_RESULT([yes])
56		with_dnssd="mdnsresponder"
57		AC_DEFINE([HAVE_DNSSD], [1], [Have DNS-SD support?])
58		AC_DEFINE([HAVE_MDNSRESPONDER], [1], [Have mDNSResponder library?])
59		DNSSDLIBS="-ldns_sd"
60		DNSSD_BACKEND="dnssd"
61		IPPFIND_BIN="ippfind"
62		IPPFIND_MAN="ippfind.1"
63		PKGCONFIG_LIBS_STATIC="$PKGCONFIG_LIBS_STATIC $DNSSDLIBS"
64	    ], [
65		AC_MSG_RESULT([no])
66		AS_IF([test $with_dnssd = mdnsresponder], [
67		    AC_MSG_ERROR([--with-dnssd=mdnsresponder specified but dns_sd library not present.])
68		])
69	    ])
70	    LIBS="$SAVELIBS"
71	])
72    ])
73])
74
75dnl Then try Avahi...
76AS_IF([test $with_dnssd = avahi -o $with_dnssd = yes], [
77    AS_IF([test "x$PKGCONFIG" = x], [
78	AS_IF([test $with_dnssd = avahi], [
79	    AC_MSG_ERROR([Avahi requires pkg-config.])
80	])
81    ], [
82	AC_MSG_CHECKING([for Avahi client])
83	AS_IF([$PKGCONFIG --exists avahi-client], [
84	    AC_MSG_RESULT([yes])
85	    CFLAGS="$CFLAGS `$PKGCONFIG --cflags avahi-client`"
86	    DNSSDLIBS="`$PKGCONFIG --libs avahi-client`"
87	    DNSSD_BACKEND="dnssd"
88	    IPPFIND_BIN="ippfind"
89	    IPPFIND_MAN="ippfind.1"
90		PKGCONFIG_REQUIRES="$PKGCONFIG_REQUIRES avahi-client"
91	    AC_DEFINE([HAVE_AVAHI], [1], [Have Avahi client library?])
92	    AC_DEFINE([HAVE_DNSSD], [1], [Have DNS-SD support?])
93	], [
94	    AC_MSG_RESULT([no])
95	    AS_IF([test $with_dnssd = avahi], [
96		AC_MSG_ERROR([--with-dnssd=avahi specified but Avahi client not present.])
97	    ])
98	])
99    ])
100])
101
102AC_SUBST([DNSSDLIBS])
103AC_SUBST([DNSSD_BACKEND])
104AC_SUBST([IPPFIND_BIN])
105AC_SUBST([IPPFIND_MAN])
106