1 # Copyright (C) 1996-2023 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
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.
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.
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/>.
19 # Makefile for name service switch.
31 # This is the trivial part which goes into libc itself.
33 $(addsuffix -lookup,$(databases)) \
47 nss_parse_line_result \
70 ifeq ($(have-thread-library),yes)
71 CFLAGS-fgetgrent.c += -fexceptions
72 CFLAGS-fgetgrent_r.c += -fexceptions $(libio-mtsafe)
73 CFLAGS-getgrent.c += -fexceptions
74 CFLAGS-getgrent_r.c += -fexceptions
75 CFLAGS-getgrgid.c += -fexceptions
76 CFLAGS-getgrgid_r.c += -fexceptions
77 CFLAGS-getgrnam.c += -fexceptions
78 CFLAGS-getgrnam_r.c += -fexceptions
79 CFLAGS-initgroups.c += -fexceptions
80 CFLAGS-putgrent.c += -fexceptions $(libio-mtsafe)
96 ifeq ($(have-thread-library),yes)
97 CFLAGS-getsgent_r.c += -fexceptions
98 CFLAGS-getsgent.c += -fexceptions
99 CFLAGS-fgetsgent.c += -fexceptions
100 CFLAGS-fgetsgent_r.c += -fexceptions $(libio-mtsafe)
101 CFLAGS-putsgent.c += -fexceptions $(libio-mtsafe)
102 CFLAGS-getsgnam.c += -fexceptions
103 CFLAGS-getsgnam_r.c += -fexceptions
106 # These are the databases that go through nss dispatch.
107 # Caution: if you add a database here, you must add its real name
108 # in databases.def, too.
123 ifneq (,$(filter sunrpc,$(subdirs)))
129 CPPFLAGS-getent.c = -DHAVE_SUNRPC=$(have-sunrpc)
131 others := getent makedb
132 install-bin := getent makedb
133 makedb-modules = xmalloc hash-string
134 others-extras = $(makedb-modules)
135 extra-objs += $(makedb-modules:=.o)
137 tests-static = tst-field
138 tests-internal = tst-field
165 tst-nss-db-endgrent \
166 tst-nss-db-endpwent \
167 tst-nss-files-hosts-long \
168 tst-nss-files-hosts-v4mapped \
169 tst-nss-gai-actions \
170 tst-nss-gai-hv2-canonname \
176 ifeq (yes,$(build-shared))
177 # Tests which need libdl
178 tests += tst-nss-files-hosts-erange
179 tests += tst-nss-files-hosts-multi
180 tests += tst-nss-files-hosts-getent
181 tests += tst-nss-files-alias-leak
182 tests += tst-nss-files-alias-truncated
183 # tst_fgetgrent currently only works with shared libraries
184 test-srcs := tst_fgetgrent
185 ifeq ($(run-built-tests),yes)
186 tests-special += $(objpfx)tst_fgetgrent.out
187 $(objpfx)tst_fgetgrent.out: tst_fgetgrent.sh $(objpfx)tst_fgetgrent
188 $(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \
193 # If we have a thread library then we can test cancellation against
194 # some routines like getpwuid_r.
195 ifeq (yes,$(have-thread-library))
196 tests += tst-cancel-getpwuid_r
199 # Specify rules for the nss_* modules. We have some services.
200 services := files db compat
202 extra-libs = $(services:%=libnss_%)
203 # These libraries will be built in the `others' pass rather than
204 # the `lib' pass, because they depend on libc.so being built already.
205 extra-libs-others = $(extra-libs)
207 # The sources are found in the appropriate subdir.
208 subdir-dirs = $(services:%=nss_%)
209 vpath %.c $(subdir-dirs) ../locale/programs ../intl
213 $(addprefix files-, $(filter-out key, $(databases))) \
218 # Build only an empty shared libnss_files.
219 libnss_files-inhibit-o = $(filter-out .os,$(object-suffixes))
221 # Pretend that libnss_files.so is a linker script, so that the symbolic link
223 install-lib-ldscripts = libnss_files.so
224 $(inst_libdir)/libnss_files.so:
226 libnss_db-dbs := $(addprefix db-,\
227 $(filter-out hosts network key alias,\
230 libnss_db-routines := $(libnss_db-dbs) db-open db-init hash-string
231 generated += $(filter-out db-alias.c db-netgrp.c, \
232 $(addsuffix .c,$(libnss_db-dbs)))
234 libnss_compat-routines := $(addprefix compat-,grp pwd spwd initgroups) \
237 install-others += $(inst_vardbdir)/Makefile
239 # Build static module into libc if requested
240 libnss_db-inhibit-o = $(filter-out .os,$(object-suffixes))
241 libnss_compat-inhibit-o = $(filter-out .os,$(object-suffixes))
242 ifeq ($(build-static-nss),yes)
243 tests-static += tst-nss-static
245 extra-test-objs += nss_test1.os nss_test2.os nss_test_errno.os \
246 nss_test_gai_hv2_canonname.os
248 ifeq ($(run-built-tests),yes)
250 tests-special += $(objpfx)mtrace-tst-nss-gai-hv2-canonname.out
254 generated += mtrace-tst-nss-gai-hv2-canonname.out \
255 tst-nss-gai-hv2-canonname.mtrace
259 ifeq (yes,$(have-selinux))
260 LDLIBS-makedb := -lselinux
263 libnss-libc = $(common-objpfx)linkobj/libc.so
264 # Target-specific variable setting to link objects using deprecated
265 # RPC interfaces with the version of libc.so that makes them available
267 $(services:%=$(objpfx)libnss_%.so): libc-for-link = $(libnss-libc)
269 $(libnss_db-dbs:%=$(objpfx)%.c): $(objpfx)db-%.c: nss_files/files-%.c
271 (echo '#define EXTERN_PARSER';\
272 echo '#define GENERIC "../nss_db/db-XXX.c"';\
273 echo '#include "$<"') > $@.new
277 $(objpfx)makedb: $(makedb-modules:%=$(objpfx)%.o)
279 $(inst_vardbdir)/Makefile: db-Makefile $(+force)
282 libnss_test1.so-no-z-defs = 1
283 libnss_test2.so-no-z-defs = 1
285 rtld-tests-LDFLAGS += -Wl,--dynamic-list=nss_test.ver
287 libof-nss_test1 = extramodules
288 libof-nss_test2 = extramodules
289 libof-nss_test_errno = extramodules
290 libof-nss_test_gai_hv2_canonname = extramodules
291 $(objpfx)/libnss_test1.so: $(objpfx)nss_test1.os $(link-libc-deps)
293 $(objpfx)/libnss_test2.so: $(objpfx)nss_test2.os $(link-libc-deps)
295 $(objpfx)/libnss_test_errno.so: $(objpfx)nss_test_errno.os $(link-libc-deps)
297 $(objpfx)/libnss_test_gai_hv2_canonname.so: \
298 $(objpfx)nss_test_gai_hv2_canonname.os $(link-libc-deps)
300 $(objpfx)nss_test2.os : nss_test1.c
301 # Use the nss_files suffix for these objects as well.
302 $(objpfx)/libnss_test1.so$(libnss_files.so-version): $(objpfx)/libnss_test1.so
304 $(objpfx)/libnss_test2.so$(libnss_files.so-version): $(objpfx)/libnss_test2.so
306 $(objpfx)/libnss_test_errno.so$(libnss_files.so-version): \
307 $(objpfx)/libnss_test_errno.so
309 $(objpfx)/libnss_test_gai_hv2_canonname.so$(libnss_files.so-version): \
310 $(objpfx)/libnss_test_gai_hv2_canonname.so
312 $(patsubst %,$(objpfx)%.out,$(tests) $(tests-container)) : \
313 $(objpfx)/libnss_test1.so$(libnss_files.so-version) \
314 $(objpfx)/libnss_test2.so$(libnss_files.so-version) \
315 $(objpfx)/libnss_test_errno.so$(libnss_files.so-version) \
316 $(objpfx)/libnss_test_gai_hv2_canonname.so$(libnss_files.so-version)
318 ifeq (yes,$(have-thread-library))
319 $(objpfx)tst-cancel-getpwuid_r: $(shared-thread-library)
322 $(objpfx)tst-nss-files-alias-leak.out: $(objpfx)/libnss_files.so
323 $(objpfx)tst-nss-files-alias-truncated.out: $(objpfx)/libnss_files.so
325 tst-nss-gai-hv2-canonname-ENV = \
326 MALLOC_TRACE=$(objpfx)tst-nss-gai-hv2-canonname.mtrace \
327 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
328 $(objpfx)mtrace-tst-nss-gai-hv2-canonname.out: \
329 $(objpfx)tst-nss-gai-hv2-canonname.out
330 { test -r $(objpfx)tst-nss-gai-hv2-canonname.mtrace \
331 || ( echo "tst-nss-gai-hv2-canonname.mtrace does not exist"; exit 77; ) \
332 && $(common-objpfx)malloc/mtrace \
333 $(objpfx)tst-nss-gai-hv2-canonname.mtrace; } > $@; \
336 # Disable DT_RUNPATH on NSS tests so that the glibc internal NSS
337 # functions can load testing NSS modules via DT_RPATH.
338 LDFLAGS-tst-nss-test1 = -Wl,--disable-new-dtags
339 LDFLAGS-tst-nss-test2 = -Wl,--disable-new-dtags
340 LDFLAGS-tst-nss-test3 = -Wl,--disable-new-dtags
341 LDFLAGS-tst-nss-test4 = -Wl,--disable-new-dtags
342 LDFLAGS-tst-nss-test5 = -Wl,--disable-new-dtags
343 LDFLAGS-tst-nss-test_errno = -Wl,--disable-new-dtags
344 LDFLAGS-tst-nss-test_gai_hv2_canonname = -Wl,--disable-new-dtags