1# Copyright (C) 1994-2022 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-noaaaa \
55  res-state \
56  res_context_hostalias \
57  res_enable_icmp \
58  res_get_nsaddr \
59  res_hconf \
60  res_init \
61  res_libc \
62  res_mkquery \
63  res_nameinquery \
64  res_queriesmatch \
65  res_query \
66  res_randomid \
67  res_send \
68  resolv_conf \
69  resolv_context \
70  # routines
71
72tests = tst-aton tst-leaks tst-inet_ntop
73tests-container = tst-leaks2
74
75tests-internal += tst-inet_aton_exact
76
77
78generate := mtrace-tst-leaks.out tst-leaks.mtrace tst-leaks2.mtrace
79
80extra-libs := libresolv libnss_dns
81ifeq ($(have-thread-library),yes)
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-noaaaa \
97  tst-resolv-nondecimal \
98  tst-resolv-res_init-multi \
99  tst-resolv-search \
100  tst-resolv-trailing \
101
102# This test calls __res_context_send directly, which is not exported
103# from libresolv.
104tests-internal += tst-resolv-txnid-collision
105tests-static += tst-resolv-txnid-collision
106
107# These tests need libdl.
108ifeq (yes,$(build-shared))
109tests += \
110  tst-resolv-ai_idn \
111  tst-resolv-ai_idn-latin1 \
112  tst-resolv-ai_idn-nolibidn2 \
113  tst-resolv-canonname \
114  tst-resolv-trustad \
115
116# Needs resolv_context.
117tests-internal += \
118  tst-resolv-res_init \
119  tst-resolv-res_init-thread \
120  tst-resolv-res_ninit \
121  tst-resolv-threads \
122
123# Used by tst-resolv-ai_idn-nolibidn2 to disable libidn2 (by not
124# providing any functions in libidn2.so.0).
125modules-names += tst-no-libidn2
126extra-test-objs += tst-no-libidn2.os
127LDFLAGS-tst-no-libidn2.so = -Wl,-soname,libidn2.so.0
128
129endif # $(build-shared)
130
131# This test accesses __inet_ntop_length, an internal libc function.
132tests-internal += tst-inet_pton
133
134# This test accesses the __p_secstodate compat symbol.
135ifeq ($(have-GLIBC_2.26)$(build-shared),yesyes)
136tests += tst-p_secstodate
137endif
138
139# This test sends millions of packets and is rather slow.
140xtests += tst-resolv-qtypes
141
142# This test has dropped packet tests and runs for a long time.
143xtests += tst-resolv-rotate
144endif # $(have-thread-library)
145
146extra-libs-others = $(extra-libs)
147libresolv-routines := \
148  base64 \
149  compat-gethnamaddr \
150  compat-hooks \
151  inet_net_ntop \
152  inet_net_pton \
153  inet_neta \
154  ns_date \
155  ns_name \
156  ns_netint \
157  ns_parse \
158  ns_print \
159  ns_samedomain \
160  ns_ttl \
161  res-putget \
162  res_data \
163  res_debug \
164  res_hostalias \
165  res_isourserver \
166  resolv-deprecated \
167  # libresolv-routines
168
169ifeq ($(have-GLIBC_2.34)$(have-thread-library),yesyes)
170# Empty compatibility library for old binaries.
171extra-libs += libanl
172libanl-routines += libanl-compat
173libanl-shared-only-routines += libanl-compat
174endif
175
176$(libanl-routines-var) += \
177  gai_cancel \
178  gai_error \
179  gai_misc \
180  gai_notify \
181  gai_suspend \
182  getaddrinfo_a \
183  # $(libanl-routines-var)
184
185# Pretend that libanl.so is a linker script, so that the symbolic link
186# is not installed.
187install-lib-ldscripts = libanl.so
188$(inst_libdir)/libanl.so:
189
190subdir-dirs = nss_dns
191vpath %.c nss_dns
192
193# Build only an empty shared libnss_dns.
194libnss_dns-inhibit-o = $(filter-out .os,$(object-suffixes))
195
196# Pretend that libnss_dns.so is a linker script, so that the symbolic link
197# is not installed.
198install-lib-ldscripts = libnss_dns.so
199$(inst_libdir)/libnss_dns.so:
200
201ifeq ($(run-built-tests),yes)
202ifneq (no,$(PERL))
203tests-special += $(objpfx)mtrace-tst-leaks.out $(objpfx)mtrace-tst-leaks2.out \
204		 $(objpfx)mtrace-tst-resolv-res_ninit.out
205endif
206endif
207
208generated += mtrace-tst-leaks.out tst-leaks.mtrace \
209	     mtrace-tst-leaks2.out tst-leaks2.mtrace \
210	     mtrace-tst-resolv-res_ninit.out tst-resolv-res_ninit.mtrace \
211
212include ../Rules
213
214LOCALES := en_US.UTF-8 en_US.ISO-8859-1
215include ../gen-locales.mk
216
217CFLAGS-res_hconf.c += -fexceptions
218
219# The DNS NSS modules needs the resolver.
220$(objpfx)libnss_dns.so: $(objpfx)libresolv.so
221
222# The asynchronous name lookup code needs the thread library.
223$(objpfx)libanl.so: $(shared-thread-library)
224
225$(objpfx)tst-res_hconf_reorder: $(shared-thread-library)
226tst-res_hconf_reorder-ENV = RESOLV_REORDER=on
227
228$(objpfx)tst-leaks: $(objpfx)libresolv.so
229tst-leaks-ENV = MALLOC_TRACE=$(objpfx)tst-leaks.mtrace \
230		LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
231$(objpfx)mtrace-tst-leaks.out: $(objpfx)tst-leaks.out
232	$(common-objpfx)malloc/mtrace $(objpfx)tst-leaks.mtrace > $@; \
233	$(evaluate-test)
234
235tst-leaks2-ENV = MALLOC_TRACE=$(objpfx)tst-leaks2.mtrace \
236		 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
237$(objpfx)mtrace-tst-leaks2.out: $(objpfx)tst-leaks2.out
238	{ test -r $(objpfx)tst-leaks2.mtrace \
239	|| ( echo "tst-leaks2.mtrace does not exist"; exit 77; ) \
240	&& $(common-objpfx)malloc/mtrace $(objpfx)tst-leaks2.mtrace; } > $@; \
241	$(evaluate-test)
242
243tst-resolv-res_ninit-ENV = MALLOC_TRACE=$(objpfx)tst-resolv-res_ninit.mtrace \
244			LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
245$(objpfx)mtrace-tst-resolv-res_ninit.out: $(objpfx)tst-resolv-res_ninit.out
246	$(common-objpfx)malloc/mtrace \
247	  $(objpfx)tst-resolv-res_ninit.mtrace > $@; \
248	  $(evaluate-test)
249
250$(objpfx)tst-bug18665-tcp: $(objpfx)libresolv.so $(shared-thread-library)
251$(objpfx)tst-bug18665: $(objpfx)libresolv.so $(shared-thread-library)
252$(objpfx)tst-resolv-ai_idn: $(objpfx)libresolv.so $(shared-thread-library)
253$(objpfx)tst-resolv-ai_idn-latin1: \
254  $(objpfx)libresolv.so $(shared-thread-library)
255$(objpfx)tst-resolv-ai_idn-nolibidn2: \
256  $(objpfx)libresolv.so $(shared-thread-library)
257$(objpfx)tst-resolv-ai_idn.out: $(gen-locales)
258$(objpfx)tst-resolv-ai_idn-latin1.out: $(gen-locales)
259$(objpfx)tst-resolv-ai_idn-nolibidn2.out: \
260  $(gen-locales) $(objpfx)tst-no-libidn2.so
261$(objpfx)tst-resolv-basic: $(objpfx)libresolv.so $(shared-thread-library)
262$(objpfx)tst-resolv-binary: $(objpfx)libresolv.so $(shared-thread-library)
263$(objpfx)tst-resolv-edns: $(objpfx)libresolv.so $(shared-thread-library)
264$(objpfx)tst-resolv-network: $(objpfx)libresolv.so $(shared-thread-library)
265$(objpfx)tst-resolv-res_init: $(objpfx)libresolv.so
266$(objpfx)tst-resolv-res_init-multi: $(objpfx)libresolv.so \
267  $(shared-thread-library)
268$(objpfx)tst-resolv-res_init-thread: $(objpfx)libresolv.so \
269  $(shared-thread-library)
270$(objpfx)tst-resolv-noaaaa: $(objpfx)libresolv.so $(shared-thread-library)
271$(objpfx)tst-resolv-nondecimal: $(objpfx)libresolv.so $(shared-thread-library)
272$(objpfx)tst-resolv-qtypes: $(objpfx)libresolv.so $(shared-thread-library)
273$(objpfx)tst-resolv-rotate: $(objpfx)libresolv.so $(shared-thread-library)
274$(objpfx)tst-resolv-search: $(objpfx)libresolv.so $(shared-thread-library)
275$(objpfx)tst-resolv-trailing: $(objpfx)libresolv.so $(shared-thread-library)
276$(objpfx)tst-resolv-threads: $(objpfx)libresolv.so $(shared-thread-library)
277$(objpfx)tst-resolv-txnid-collision: $(objpfx)libresolv.a \
278  $(static-thread-library)
279$(objpfx)tst-resolv-canonname: $(objpfx)libresolv.so $(shared-thread-library)
280$(objpfx)tst-resolv-trustad: $(objpfx)libresolv.so $(shared-thread-library)
281
282$(objpfx)tst-ns_name: $(objpfx)libresolv.so
283$(objpfx)tst-ns_name.out: tst-ns_name.data
284$(objpfx)tst-ns_name_compress: $(objpfx)libresolv.so
285$(objpfx)tst-ns_name_pton: $(objpfx)libresolv.so
286$(objpfx)tst-res_hnok: $(objpfx)libresolv.so
287$(objpfx)tst-p_secstodate: $(objpfx)libresolv.so
288