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.
30 # This is the trivial part which goes into libc itself.
32 $(addsuffix -lookup,$(databases)) \
46 nss_parse_line_result \
69 ifeq ($(have-thread-library),yes)
70 CFLAGS-fgetgrent.c += -fexceptions
71 CFLAGS-fgetgrent_r.c += -fexceptions $(libio-mtsafe)
72 CFLAGS-getgrent.c += -fexceptions
73 CFLAGS-getgrent_r.c += -fexceptions
74 CFLAGS-getgrgid.c += -fexceptions
75 CFLAGS-getgrgid_r.c += -fexceptions
76 CFLAGS-getgrnam.c += -fexceptions
77 CFLAGS-getgrnam_r.c += -fexceptions
78 CFLAGS-initgroups.c += -fexceptions
79 CFLAGS-putgrent.c += -fexceptions $(libio-mtsafe)
82 # These are the databases that go through nss dispatch.
83 # Caution: if you add a database here, you must add its real name
84 # in databases.def, too.
99 ifneq (,$(filter sunrpc,$(subdirs)))
105 CPPFLAGS-getent.c = -DHAVE_SUNRPC=$(have-sunrpc)
107 others := getent makedb
108 install-bin := getent makedb
109 makedb-modules = xmalloc hash-string
110 others-extras = $(makedb-modules)
111 extra-objs += $(makedb-modules:=.o)
113 tests-static = tst-field
114 tests-internal = tst-field
137 tst-nss-db-endgrent \
138 tst-nss-db-endpwent \
139 tst-nss-files-hosts-long \
140 tst-nss-files-hosts-v4mapped \
141 tst-nss-gai-actions \
142 tst-nss-gai-hv2-canonname \
148 ifeq (yes,$(build-shared))
149 # Tests which need libdl
150 tests += tst-nss-files-hosts-erange
151 tests += tst-nss-files-hosts-multi
152 tests += tst-nss-files-hosts-getent
153 tests += tst-nss-files-alias-leak
154 tests += tst-nss-files-alias-truncated
155 # tst_fgetgrent currently only works with shared libraries
156 test-srcs := tst_fgetgrent
157 ifeq ($(run-built-tests),yes)
158 tests-special += $(objpfx)tst_fgetgrent.out
159 $(objpfx)tst_fgetgrent.out: tst_fgetgrent.sh $(objpfx)tst_fgetgrent
160 $(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \
165 # If we have a thread library then we can test cancellation against
166 # some routines like getpwuid_r.
167 ifeq (yes,$(have-thread-library))
168 tests += tst-cancel-getpwuid_r
171 # Specify rules for the nss_* modules. We have some services.
172 services := files db compat
174 extra-libs = $(services:%=libnss_%)
175 # These libraries will be built in the `others' pass rather than
176 # the `lib' pass, because they depend on libc.so being built already.
177 extra-libs-others = $(extra-libs)
179 # The sources are found in the appropriate subdir.
180 subdir-dirs = $(services:%=nss_%)
181 vpath %.c $(subdir-dirs) ../locale/programs ../intl
185 $(addprefix files-, $(filter-out key, $(databases))) \
190 # Build only an empty shared libnss_files.
191 libnss_files-inhibit-o = $(filter-out .os,$(object-suffixes))
193 # Pretend that libnss_files.so is a linker script, so that the symbolic link
195 install-lib-ldscripts = libnss_files.so
196 $(inst_libdir)/libnss_files.so:
198 libnss_db-dbs := $(addprefix db-,\
199 $(filter-out hosts network key alias,\
202 libnss_db-routines := $(libnss_db-dbs) db-open db-init hash-string
203 generated += $(filter-out db-alias.c db-netgrp.c, \
204 $(addsuffix .c,$(libnss_db-dbs)))
206 libnss_compat-routines := $(addprefix compat-,grp pwd spwd initgroups) \
209 install-others += $(inst_vardbdir)/Makefile
211 # Build static module into libc if requested
212 libnss_db-inhibit-o = $(filter-out .os,$(object-suffixes))
213 libnss_compat-inhibit-o = $(filter-out .os,$(object-suffixes))
214 ifeq ($(build-static-nss),yes)
215 tests-static += tst-nss-static
217 extra-test-objs += nss_test1.os nss_test2.os nss_test_errno.os \
218 nss_test_gai_hv2_canonname.os
220 ifeq ($(run-built-tests),yes)
222 tests-special += $(objpfx)mtrace-tst-nss-gai-hv2-canonname.out
226 generated += mtrace-tst-nss-gai-hv2-canonname.out \
227 tst-nss-gai-hv2-canonname.mtrace
231 ifeq (yes,$(have-selinux))
232 LDLIBS-makedb := -lselinux
235 libnss-libc = $(common-objpfx)linkobj/libc.so
236 # Target-specific variable setting to link objects using deprecated
237 # RPC interfaces with the version of libc.so that makes them available
239 $(services:%=$(objpfx)libnss_%.so): libc-for-link = $(libnss-libc)
241 $(libnss_db-dbs:%=$(objpfx)%.c): $(objpfx)db-%.c: nss_files/files-%.c
243 (echo '#define EXTERN_PARSER';\
244 echo '#define GENERIC "../nss_db/db-XXX.c"';\
245 echo '#include "$<"') > $@.new
249 $(objpfx)makedb: $(makedb-modules:%=$(objpfx)%.o)
251 $(inst_vardbdir)/Makefile: db-Makefile $(+force)
254 libnss_test1.so-no-z-defs = 1
255 libnss_test2.so-no-z-defs = 1
257 rtld-tests-LDFLAGS += -Wl,--dynamic-list=nss_test.ver
259 libof-nss_test1 = extramodules
260 libof-nss_test2 = extramodules
261 libof-nss_test_errno = extramodules
262 libof-nss_test_gai_hv2_canonname = extramodules
263 $(objpfx)/libnss_test1.so: $(objpfx)nss_test1.os $(link-libc-deps)
265 $(objpfx)/libnss_test2.so: $(objpfx)nss_test2.os $(link-libc-deps)
267 $(objpfx)/libnss_test_errno.so: $(objpfx)nss_test_errno.os $(link-libc-deps)
269 $(objpfx)/libnss_test_gai_hv2_canonname.so: \
270 $(objpfx)nss_test_gai_hv2_canonname.os $(link-libc-deps)
272 $(objpfx)nss_test2.os : nss_test1.c
273 # Use the nss_files suffix for these objects as well.
274 $(objpfx)/libnss_test1.so$(libnss_files.so-version): $(objpfx)/libnss_test1.so
276 $(objpfx)/libnss_test2.so$(libnss_files.so-version): $(objpfx)/libnss_test2.so
278 $(objpfx)/libnss_test_errno.so$(libnss_files.so-version): \
279 $(objpfx)/libnss_test_errno.so
281 $(objpfx)/libnss_test_gai_hv2_canonname.so$(libnss_files.so-version): \
282 $(objpfx)/libnss_test_gai_hv2_canonname.so
284 $(patsubst %,$(objpfx)%.out,$(tests) $(tests-container)) : \
285 $(objpfx)/libnss_test1.so$(libnss_files.so-version) \
286 $(objpfx)/libnss_test2.so$(libnss_files.so-version) \
287 $(objpfx)/libnss_test_errno.so$(libnss_files.so-version) \
288 $(objpfx)/libnss_test_gai_hv2_canonname.so$(libnss_files.so-version)
290 ifeq (yes,$(have-thread-library))
291 $(objpfx)tst-cancel-getpwuid_r: $(shared-thread-library)
294 $(objpfx)tst-nss-files-alias-leak.out: $(objpfx)/libnss_files.so
295 $(objpfx)tst-nss-files-alias-truncated.out: $(objpfx)/libnss_files.so
297 tst-nss-gai-hv2-canonname-ENV = \
298 MALLOC_TRACE=$(objpfx)tst-nss-gai-hv2-canonname.mtrace \
299 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
300 $(objpfx)mtrace-tst-nss-gai-hv2-canonname.out: \
301 $(objpfx)tst-nss-gai-hv2-canonname.out
302 { test -r $(objpfx)tst-nss-gai-hv2-canonname.mtrace \
303 || ( echo "tst-nss-gai-hv2-canonname.mtrace does not exist"; exit 77; ) \
304 && $(common-objpfx)malloc/mtrace \
305 $(objpfx)tst-nss-gai-hv2-canonname.mtrace; } > $@; \
308 # Disable DT_RUNPATH on NSS tests so that the glibc internal NSS
309 # functions can load testing NSS modules via DT_RPATH.
310 LDFLAGS-tst-nss-test1 = -Wl,--disable-new-dtags
311 LDFLAGS-tst-nss-test2 = -Wl,--disable-new-dtags
312 LDFLAGS-tst-nss-test3 = -Wl,--disable-new-dtags
313 LDFLAGS-tst-nss-test4 = -Wl,--disable-new-dtags
314 LDFLAGS-tst-nss-test5 = -Wl,--disable-new-dtags
315 LDFLAGS-tst-nss-test_errno = -Wl,--disable-new-dtags
316 LDFLAGS-tst-nss-test_gai_hv2_canonname = -Wl,--disable-new-dtags