1# Copyright (C) 1994-2021 Free Software Foundation, Inc.
2# This file is part of the GNU C Library.
3
4# The GNU C Library is free software; you can redistribute it and/or
5# modify it under the terms of the GNU Lesser General Public
6# License as published by the Free Software Foundation; either
7# version 2.1 of the License, or (at your option) any later version.
8
9# The GNU C Library is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12# Lesser General Public License for more details.
13
14# You should have received a copy of the GNU Lesser General Public
15# License along with the GNU C Library; if not, see
16# <https://www.gnu.org/licenses/>.
17
18#
19#	Sub-makefile for resolv portion of the library.
20#
21subdir	:= resolv
22
23include ../Makeconfig
24
25headers	:= resolv.h bits/types/res_state.h \
26	   netdb.h bits/netdb.h \
27	   arpa/nameser.h arpa/nameser_compat.h \
28	   sys/bitypes.h
29
30routines := \
31  dn_comp \
32  dn_expand \
33  dn_skipname \
34  dns-canon \
35  dns-host \
36  dns-network \
37  herror \
38  inet_addr \
39  inet_ntop \
40  inet_pton \
41  ns_makecanon \
42  ns_name_compress \
43  ns_name_ntop \
44  ns_name_pack \
45  ns_name_pton \
46  ns_name_skip \
47  ns_name_uncompress \
48  ns_name_unpack \
49  ns_samename \
50  nsap_addr \
51  nss_dns_functions \
52  res-close \
53  res-name-checking \
54  res-state \
55  res_context_hostalias \
56  res_enable_icmp \
57  res_get_nsaddr \
58  res_hconf \
59  res_init \
60  res_libc \
61  res_mkquery \
62  res_nameinquery \
63  res_queriesmatch \
64  res_query \
65  res_randomid \
66  res_send \
67  resolv_conf \
68  resolv_context \
69  # routines
70
71tests = tst-aton tst-leaks tst-inet_ntop
72tests-container = tst-leaks2
73
74tests-internal += tst-inet_aton_exact
75
76
77generate := mtrace-tst-leaks.out tst-leaks.mtrace tst-leaks2.mtrace
78
79extra-libs := libresolv libnss_dns
80ifeq ($(have-thread-library),yes)
81extra-libs += libanl
82routines += gai_sigqueue
83
84tests += \
85  tst-bug18665 \
86  tst-bug18665-tcp \
87  tst-ns_name \
88  tst-ns_name_compress \
89  tst-ns_name_pton \
90  tst-res_hconf_reorder \
91  tst-res_hnok \
92  tst-resolv-basic \
93  tst-resolv-binary \
94  tst-resolv-edns \
95  tst-resolv-network \
96  tst-resolv-nondecimal \
97  tst-resolv-res_init-multi \
98  tst-resolv-search \
99  tst-resolv-trailing \
100
101# This test calls __res_context_send directly, which is not exported
102# from libresolv.
103tests-internal += tst-resolv-txnid-collision
104tests-static += tst-resolv-txnid-collision
105
106# These tests need libdl.
107ifeq (yes,$(build-shared))
108tests += \
109  tst-resolv-ai_idn \
110  tst-resolv-ai_idn-latin1 \
111  tst-resolv-ai_idn-nolibidn2 \
112  tst-resolv-canonname \
113  tst-resolv-trustad \
114
115# Needs resolv_context.
116tests-internal += \
117  tst-resolv-res_init \
118  tst-resolv-res_init-thread \
119  tst-resolv-res_ninit \
120  tst-resolv-threads \
121
122# Used by tst-resolv-ai_idn-nolibidn2 to disable libidn2 (by not
123# providing any functions in libidn2.so.0).
124modules-names += tst-no-libidn2
125extra-test-objs += tst-no-libidn2.os
126LDFLAGS-tst-no-libidn2.so = -Wl,-soname,libidn2.so.0
127
128endif # $(build-shared)
129
130# This test accesses __inet_ntop_length, an internal libc function.
131tests-internal += tst-inet_pton
132
133# This test accesses the __p_secstodate compat symbol.
134ifeq ($(have-GLIBC_2.26)$(build-shared),yesyes)
135tests += tst-p_secstodate
136endif
137
138# This test sends millions of packets and is rather slow.
139xtests += tst-resolv-qtypes
140
141# This test has dropped packet tests and runs for a long time.
142xtests += tst-resolv-rotate
143endif
144extra-libs-others = $(extra-libs)
145libresolv-routines := \
146  base64 \
147  compat-gethnamaddr \
148  compat-hooks \
149  inet_net_ntop \
150  inet_net_pton \
151  inet_neta \
152  ns_date \
153  ns_name \
154  ns_netint \
155  ns_parse \
156  ns_print \
157  ns_samedomain \
158  ns_ttl \
159  res-putget \
160  res_data \
161  res_debug \
162  res_hostalias \
163  res_isourserver \
164  resolv-deprecated \
165  # libresolv-routines
166
167$(libanl-routines-var) += \
168  gai_cancel \
169  gai_error \
170  gai_misc \
171  gai_notify \
172  gai_suspend \
173  getaddrinfo_a \
174  # $(libanl-routines-var)
175
176libanl-routines += libanl-compat
177libanl-shared-only-routines += libanl-compat
178
179subdir-dirs = nss_dns
180vpath %.c nss_dns
181
182# Build only an empty shared libnss_dns.
183libnss_dns-inhibit-o = $(filter-out .os,$(object-suffixes))
184
185# Pretend that libnss_dns.so is a linker script, so that the symbolic link
186# is not installed.
187install-lib-ldscripts = libnss_dns.so
188$(inst_libdir)/libnss_dns.so:
189
190ifeq ($(run-built-tests),yes)
191ifneq (no,$(PERL))
192tests-special += $(objpfx)mtrace-tst-leaks.out $(objpfx)mtrace-tst-leaks2.out \
193		 $(objpfx)mtrace-tst-resolv-res_ninit.out
194endif
195endif
196
197generated += mtrace-tst-leaks.out tst-leaks.mtrace \
198	     mtrace-tst-leaks2.out tst-leaks2.mtrace \
199	     mtrace-tst-resolv-res_ninit.out tst-resolv-res_ninit.mtrace \
200
201include ../Rules
202
203LOCALES := en_US.UTF-8 en_US.ISO-8859-1
204include ../gen-locales.mk
205
206CFLAGS-res_hconf.c += -fexceptions
207
208# The DNS NSS modules needs the resolver.
209$(objpfx)libnss_dns.so: $(objpfx)libresolv.so
210
211# The asynchronous name lookup code needs the thread library.
212$(objpfx)libanl.so: $(shared-thread-library)
213
214$(objpfx)tst-res_hconf_reorder: $(shared-thread-library)
215tst-res_hconf_reorder-ENV = RESOLV_REORDER=on
216
217$(objpfx)tst-leaks: $(objpfx)libresolv.so
218tst-leaks-ENV = MALLOC_TRACE=$(objpfx)tst-leaks.mtrace \
219		LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
220$(objpfx)mtrace-tst-leaks.out: $(objpfx)tst-leaks.out
221	$(common-objpfx)malloc/mtrace $(objpfx)tst-leaks.mtrace > $@; \
222	$(evaluate-test)
223
224tst-leaks2-ENV = MALLOC_TRACE=$(objpfx)tst-leaks2.mtrace \
225		 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
226$(objpfx)mtrace-tst-leaks2.out: $(objpfx)tst-leaks2.out
227	{ test -r $(objpfx)tst-leaks2.mtrace \
228	|| ( echo "tst-leaks2.mtrace does not exist"; exit 77; ) \
229	&& $(common-objpfx)malloc/mtrace $(objpfx)tst-leaks2.mtrace; } > $@; \
230	$(evaluate-test)
231
232tst-resolv-res_ninit-ENV = MALLOC_TRACE=$(objpfx)tst-resolv-res_ninit.mtrace \
233			LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
234$(objpfx)mtrace-tst-resolv-res_ninit.out: $(objpfx)tst-resolv-res_ninit.out
235	$(common-objpfx)malloc/mtrace \
236	  $(objpfx)tst-resolv-res_ninit.mtrace > $@; \
237	  $(evaluate-test)
238
239$(objpfx)tst-bug18665-tcp: $(objpfx)libresolv.so $(shared-thread-library)
240$(objpfx)tst-bug18665: $(objpfx)libresolv.so $(shared-thread-library)
241$(objpfx)tst-resolv-ai_idn: $(objpfx)libresolv.so $(shared-thread-library)
242$(objpfx)tst-resolv-ai_idn-latin1: \
243  $(objpfx)libresolv.so $(shared-thread-library)
244$(objpfx)tst-resolv-ai_idn-nolibidn2: \
245  $(objpfx)libresolv.so $(shared-thread-library)
246$(objpfx)tst-resolv-ai_idn.out: $(gen-locales)
247$(objpfx)tst-resolv-ai_idn-latin1.out: $(gen-locales)
248$(objpfx)tst-resolv-ai_idn-nolibidn2.out: \
249  $(gen-locales) $(objpfx)tst-no-libidn2.so
250$(objpfx)tst-resolv-basic: $(objpfx)libresolv.so $(shared-thread-library)
251$(objpfx)tst-resolv-binary: $(objpfx)libresolv.so $(shared-thread-library)
252$(objpfx)tst-resolv-edns: $(objpfx)libresolv.so $(shared-thread-library)
253$(objpfx)tst-resolv-network: $(objpfx)libresolv.so $(shared-thread-library)
254$(objpfx)tst-resolv-res_init: $(objpfx)libresolv.so
255$(objpfx)tst-resolv-res_init-multi: $(objpfx)libresolv.so \
256  $(shared-thread-library)
257$(objpfx)tst-resolv-res_init-thread: $(objpfx)libresolv.so \
258  $(shared-thread-library)
259$(objpfx)tst-resolv-nondecimal: $(objpfx)libresolv.so $(shared-thread-library)
260$(objpfx)tst-resolv-qtypes: $(objpfx)libresolv.so $(shared-thread-library)
261$(objpfx)tst-resolv-rotate: $(objpfx)libresolv.so $(shared-thread-library)
262$(objpfx)tst-resolv-search: $(objpfx)libresolv.so $(shared-thread-library)
263$(objpfx)tst-resolv-trailing: $(objpfx)libresolv.so $(shared-thread-library)
264$(objpfx)tst-resolv-threads: $(objpfx)libresolv.so $(shared-thread-library)
265$(objpfx)tst-resolv-txnid-collision: $(objpfx)libresolv.a \
266  $(static-thread-library)
267$(objpfx)tst-resolv-canonname: $(objpfx)libresolv.so $(shared-thread-library)
268$(objpfx)tst-resolv-trustad: $(objpfx)libresolv.so $(shared-thread-library)
269
270$(objpfx)tst-ns_name: $(objpfx)libresolv.so
271$(objpfx)tst-ns_name.out: tst-ns_name.data
272$(objpfx)tst-ns_name_compress: $(objpfx)libresolv.so
273$(objpfx)tst-ns_name_pton: $(objpfx)libresolv.so
274$(objpfx)tst-res_hnok: $(objpfx)libresolv.so
275$(objpfx)tst-p_secstodate: $(objpfx)libresolv.so
276