Skip to content

Commit 71abc81

Browse files
author
Pavel Šimerda
committed
build: fix optional dependency handling
1 parent 1da9afc commit 71abc81

File tree

5 files changed

+64
-17
lines changed

5 files changed

+64
-17
lines changed

Diff for: Makefile.am

+19-9
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ include_HEADERS = \
3535
lib_LTLIBRARIES = \
3636
libnetresolve.la \
3737
libnetresolve-libc.la \
38-
libnetresolve-asyncns.la \
3938
libnss_netresolve.la
4039

4140
libnetresolve_la_SOURCES = \
@@ -55,7 +54,7 @@ libnetresolve_la_SOURCES = \
5554
lib/epoll.c \
5655
lib/select.c
5756
libnetresolve_la_LDFLAGS = \
58-
$(AM_LDFLAGS) -lldns \
57+
$(AM_LDFLAGS) $(LDNS_LIBS) \
5958
-export-symbols-regex '^netresolve_'
6059

6160
libnetresolve_libc_la_SOURCES = \
@@ -67,13 +66,17 @@ libnetresolve_libc_la_LDFLAGS = \
6766
libnetresolve_libc_la_LIBADD = \
6867
libnetresolve.la
6968

69+
if BUILD_FRONTEND_ASYNCNS
70+
lib_LTLIBRARIES += libnetresolve-asyncns.la
71+
7072
libnetresolve_asyncns_la_SOURCES = \
7173
compat/asyncns.c
7274
libnetresolve_asyncns_la_LDFLAGS = \
7375
$(AM_LDFLAGS) \
7476
--export-all-symbols
7577
libnetresolve_asyncns_la_LIBADD = \
7678
libnetresolve.la
79+
endif
7780

7881
libnss_netresolve_la_SOURCES = \
7982
compat/nsswitch.c
@@ -87,10 +90,12 @@ lib_LTLIBRARIES += \
8790
libnetresolve-backend-hosts.la \
8891
libnetresolve-backend-hostname.la \
8992
libnetresolve-backend-libc.la \
90-
libnetresolve-backend-asyncns.la \
9193
libnetresolve-backend-nss.la \
9294
libnetresolve-backend-exec.la
9395

96+
if BUILD_BACKEND_ASYNCNS
97+
lib_LTLIBRARIES += libnetresolve-backend-asyncns.la
98+
endif
9499
if BUILD_BACKEND_ARESDNS
95100
lib_LTLIBRARIES += libnetresolve-backend-aresdns.la
96101
endif
@@ -109,8 +114,6 @@ libnetresolve_backend_hosts_la_SOURCES = backends/hosts.c
109114
libnetresolve_backend_hostname_la_SOURCES = backends/hostname.c
110115
libnetresolve_backend_libc_la_SOURCES = backends/libc.c
111116
libnetresolve_backend_libc_la_LDFLAGS = $(AM_LDFLAGS) -lresolv
112-
libnetresolve_backend_asyncns_la_SOURCES = backends/asyncns.c
113-
libnetresolve_backend_asyncns_la_LDFLAGS = -lasyncns
114117
libnetresolve_backend_nss_la_SOURCES = backends/nss.c
115118
libnetresolve_backend_exec_la_SOURCES = backends/exec.c
116119

@@ -121,21 +124,25 @@ libnetresolve_backend_aresdns_la_CPPFLAGS = $(AM_CPPFLAGS) $(ARES_CFLAGS) -DUSE_
121124
endif
122125
if BUILD_BACKEND_UBDNS
123126
libnetresolve_backend_ubdns_la_SOURCES = backends/dns.c
124-
libnetresolve_backend_ubdns_la_LDFLAGS = $(AM_LDFLAGS) -lunbound
127+
libnetresolve_backend_ubdns_la_LDFLAGS = $(AM_LDFLAGS) $(UNBOUND_LIBS)
125128
libnetresolve_backend_ubdns_la_CPPFLAGS = $(AM_CPPFLAGS) -DUSE_UNBOUND=1
126129
endif
127130
if BUILD_BACKEND_AVAHI
128131
libnetresolve_backend_avahi_la_SOURCES = backends/avahi.c
129132
libnetresolve_backend_avahi_la_LDFLAGS = $(AM_LDFLAGS) $(AVAHI_LIBS)
130133
libnetresolve_backend_avahi_la_CPPFLAGS = $(AM_CPPFLAGS)
131134
endif
135+
if BUILD_BACKEND_ASYNCNS
136+
libnetresolve_backend_asyncns_la_SOURCES = backends/asyncns.c
137+
libnetresolve_backend_asyncns_la_LDFLAGS = $(ASYNCNS_LIBS)
138+
endif
132139

133140
bin_PROGRAMS = netresolve getaddrinfo getnameinfo gethostbyname gethostbyaddr res_query
134141
bin_SCRIPTS = tools/wrapresolve
135142

136143
netresolve_SOURCES = tools/netresolve.c
137144
netresolve_LDADD = libnetresolve.la
138-
netresolve_LDFLAGS = $(AM_LDFLAGS) -lldns
145+
netresolve_LDFLAGS = $(AM_LDFLAGS) $(LDNS_LIBS)
139146

140147
getaddrinfo_SOURCES = tools/getaddrinfo.c tools/compat.c
141148

@@ -146,7 +153,7 @@ gethostbyname_SOURCES = tools/gethostbyname.c tools/compat.c
146153
gethostbyaddr_SOURCES = tools/gethostbyaddr.c tools/compat.c
147154

148155
res_query_SOURCES = tools/res_query.c tools/compat.c
149-
res_query_LDFLAGS = $(AM_LDFLAGS) -lresolv -lldns
156+
res_query_LDFLAGS = $(AM_LDFLAGS) $(LDNS_LIBS) -lresolv
150157

151158
TESTS = \
152159
tests/test-netresolve.sh \
@@ -188,9 +195,12 @@ noinst_PROGRAMS = \
188195
test-gethostbyname \
189196
test-gethostbyname2 \
190197
test-gethostbyname_r \
191-
test-gethostbyname2_r \
198+
test-gethostbyname2_r
199+
if BUILD_FRONTEND_ASYNCNS
200+
noinst_PROGRAMS += \
192201
test-asyncns \
193202
test-asyncns-cancel
203+
endif
194204
if BUILD_ALL_TESTS
195205
TESTS += \
196206
test-libevent \

Diff for: configure.ac

+21-6
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,47 @@ if test "$use_ldns" != no; then
2424
AC_CHECK_LIB([ldns], [ldns_wire2pkt], [use_ldns=yes], [use_ldns=no])
2525
if test "$with_ldns" = yes -a "$with_ldns" = no; then AC_MSG_ERROR([Bulding with ldns requested but not available.]); fi
2626
fi
27-
AS_IF([test "$use_ldns"], AC_DEFINE(USE_LDNS, 1, [Use ldns library for DNS data operations (Default: yes).]))
27+
AS_IF([test "$use_ldns" = yes], AC_DEFINE(USE_LDNS, 1, [Use ldns library for DNS data operations (Default: yes).]))
28+
AS_IF([test "$use_ldns" = yes], AC_SUBST(LDNS_LIBS, -lldns))
2829

2930
AC_ARG_WITH(c-ares, AS_HELP_STRING([--with-c-ares|--without-c-ares], [Build c-ares backend (Default: yes)]), [build_aresdns="$with_c_ares"])
3031
if test "$build_aresdns" != no; then
3132
PKG_CHECK_MODULES([ARES], [libcares], [build_aresdns=yes], [build_aresdns=no])
3233
if test "$use_ldns" = no; then build_aresdns=no; fi
3334
if test "$with_c_ares" = yes -a "$build_aresdns" = no; then AC_MSG_ERROR([Support for c-ares requested but not available.]); fi
3435
fi
35-
AM_CONDITIONAL(BUILD_BACKEND_ARESDNS, [test $build_aresdns = "yes"])
36+
AM_CONDITIONAL(BUILD_BACKEND_ARESDNS, [test $build_aresdns = yes])
3637

3738
AC_ARG_WITH(unbound, AS_HELP_STRING([--with-unbound|--without-unbound], [Build libunbound backend (Default: yes)]), [build_ubdns="$with_unbound"])
3839
if test "$build_ubdns" != no; then
3940
AC_CHECK_LIB([unbound], [ub_ctx_create], [build_ubdns=yes], [build_ubdns=no])
4041
if test "$use_ldns" = no; then build_ubdns=no; fi
4142
if test "$with_unbound" = yes -a "$build_ubdns" = no; then AC_MSG_ERROR([Support for libunbound requested but not available.]); fi
4243
fi
43-
AM_CONDITIONAL(BUILD_BACKEND_UBDNS, [test $build_ubdns = "yes"])
44+
AM_CONDITIONAL(BUILD_BACKEND_UBDNS, [test "$build_ubdns" = yes])
45+
AS_IF([test "$build_ubdns" = yes], AC_SUBST(UNBOUND_LIBS, -lunbound))
4446

4547
AC_ARG_WITH(avahi, AS_HELP_STRING([--with-avahi|--without-avahi], [Build libavahi backend (Default: yes)]), [build_avahi="$with_avahi"])
4648
if test "$build_avahi" != no; then
4749
PKG_CHECK_MODULES([AVAHI], [avahi-client], [build_avahi=yes], [build_avahi=no])
4850
if test "$with_avahi" = yes -a "$build_avahi" = no; then AC_MSG_ERROR([Support for libavahi requested but not available.]); fi
4951
fi
50-
AM_CONDITIONAL(BUILD_BACKEND_AVAHI, [test $build_avahi = "yes"])
52+
AM_CONDITIONAL(BUILD_BACKEND_AVAHI, [test $build_avahi = yes])
53+
54+
AC_ARG_WITH(asyncns, AS_HELP_STRING([--with-asyncns|--without-asyncns], [Build libasyncns based backend (Default: yes)]), [build_asyncns="$with_asyncns"])
55+
if test "$build_asyncns" != no; then
56+
PKG_CHECK_MODULES([ASYNCNS], [libasyncns], [build_asyncns=yes], [build_asyncns=no])
57+
if test "$with_asyncns" = yes -a "$build_asyncns" = no; then AC_MSG_ERROR([Support for libasyncns requested but not available.]); fi
58+
fi
59+
AM_CONDITIONAL(BUILD_FRONTEND_ASYNCNS, [test $build_asyncns = yes])
60+
AM_CONDITIONAL(BUILD_BACKEND_ASYNCNS, [test $build_asyncns = yes])
5161

5262
AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-tests|--disable-tests], [Build tests using additional dependencies (Default: no)]))
53-
AS_IF([test "$enable_tests" = "yes"],
63+
AS_IF([test "$enable_tests" = yes],
5464
PKG_CHECK_MODULES([GLIB], [glib-2.0])
5565
AC_CHECK_LIB([event], [event_base_new], [EVENT_LIBS=-levent])
5666
AC_SUBST(EVENT_LIBS))
57-
AM_CONDITIONAL(BUILD_ALL_TESTS, [test "$enable_tests" = "yes"])
67+
AM_CONDITIONAL(BUILD_ALL_TESTS, [test "$enable_tests" = yes])
5868

5969
AC_CONFIG_HEADERS([config.h])
6070
AC_CONFIG_FILES([
@@ -78,11 +88,16 @@ Compiler:
7888
* cflags: ${CFLAGS}
7989
* ldflags: ${LDFLAGS}
8090
91+
Optional frontends:
92+
93+
* asyncns: $build_asyncns
94+
8195
Optional backends:
8296
8397
* aresdns: $build_aresdns
8498
* ubdns: $build_ubdns
8599
* avahi: $build_avahi
100+
* asyncns: $build_asyncns
86101
87102
Other dependencies:
88103

Diff for: include/netresolve-private.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <net/if.h>
3939
#include <arpa/inet.h>
4040
#include <sys/socket.h>
41+
#include <unistd.h>
4142
#include <assert.h>
4243

4344
#define debug_context(context, format, ...) debug( \

Diff for: tools/netresolve.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
*/
2424
#include <netresolve-private.h>
2525
#include <getopt.h>
26-
#include <ldns/ldns.h>
2726
#include <arpa/nameser.h>
2827
#include <netinet/ip_icmp.h>
2928
#include <linux/icmpv6.h>
3029

30+
#ifdef USE_LDNS
31+
#include <ldns/ldns.h>
32+
#endif
33+
3134
static int
3235
count_argv(char **argv)
3336
{
@@ -79,6 +82,7 @@ on_connect(netresolve_query_t context, int idx, int sock, void *user_data)
7982
static char *
8083
get_dns_string(netresolve_query_t query)
8184
{
85+
#ifdef USE_LDNS
8286
const uint8_t *answer;
8387
size_t length;
8488

@@ -98,6 +102,9 @@ get_dns_string(netresolve_query_t query)
98102

99103
ldns_pkt_free(pkt);
100104
return result;
105+
#else
106+
return NULL;
107+
#endif
101108
}
102109

103110
static const char *
@@ -288,10 +295,18 @@ main(int argc, char **argv)
288295
port_str = optarg;
289296
break;
290297
case 'C':
298+
#ifdef USE_LDNS
291299
cls = ldns_get_rr_class_by_name(optarg);
300+
#else
301+
cls = strtoll(optarg, NULL, 10);
302+
#endif
292303
break;
293304
case 'T':
305+
#ifdef USE_LDNS
294306
type = ldns_get_rr_type_by_name(optarg);
307+
#else
308+
type = strtoll(optarg, NULL, 10);
309+
#endif
295310
break;
296311
default:
297312
exit(EXIT_FAILURE);

Diff for: tools/res_query.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
#include <netdb.h>
2929
#include <arpa/nameser.h>
3030
#include <resolv.h>
31+
32+
#ifdef USE_LDNS
3133
#include <ldns/ldns.h>
34+
#endif
3235

3336
#include "compat.h"
3437

@@ -54,7 +57,6 @@ main(int argc, char **argv)
5457
int type = ns_t_a;
5558
uint8_t answer[SIZE];
5659
int length = 0;
57-
ldns_pkt *pkt;
5860

5961
while ((opt = getopt_long(argc, argv, opts, longopts, &idx)) != -1) {
6062
switch (opt) {
@@ -104,11 +106,15 @@ main(int argc, char **argv)
104106
printf("result:\n");
105107
printf(" length = %d\n", length);
106108

109+
#ifdef USE_LDNS
110+
ldns_pkt *pkt;
111+
107112
if (length > 0 && !ldns_wire2pkt(&pkt, answer, length)) {
108113
printf(" answer:\n%s\n", ldns_pkt2str(pkt));
109114

110115
ldns_pkt_free(pkt);
111116
}
117+
#endif
112118

113119
exit(EXIT_SUCCESS);
114120
}

0 commit comments

Comments
 (0)