1 # Copyright (C) 1996-2020 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.
27 # This is the trivial part which goes into libc itself.
28 routines = nsswitch getnssent getnssent_r digits_dots \
29 valid_field valid_list_field rewrite_field \
30 $(addsuffix -lookup,$(databases)) \
31 compat-lookup nss_hash nss_files_fopen
33 # These are the databases that go through nss dispatch.
34 # Caution: if you add a database here, you must add its real name
35 # in databases.def, too.
36 databases = proto service hosts network grp pwd ethers \
37 spwd netgrp alias sgrp
39 ifneq (,$(filter sunrpc,$(subdirs)))
45 CPPFLAGS-getent.c = -DHAVE_SUNRPC=$(have-sunrpc)
47 others := getent makedb
48 install-bin := getent makedb
49 makedb-modules = xmalloc hash-string
50 others-extras = $(makedb-modules)
51 extra-objs += $(makedb-modules:=.o)
53 tests-static = tst-field
54 tests-internal = tst-field
55 tests = test-netdb test-digits-dots tst-nss-getpwent bug17079 \
64 tst-nss-files-hosts-long \
68 # Tests which need libdl
69 ifeq (yes,$(build-shared))
70 tests += tst-nss-files-hosts-erange
71 tests += tst-nss-files-hosts-multi
72 tests += tst-nss-files-hosts-getent
73 tests += tst-nss-files-alias-leak
74 tests += tst-nss-files-alias-truncated
77 # If we have a thread library then we can test cancellation against
78 # some routines like getpwuid_r.
79 ifeq (yes,$(have-thread-library))
80 tests += tst-cancel-getpwuid_r
83 # Specify rules for the nss_* modules. We have some services.
84 services := files db compat
86 extra-libs = $(services:%=libnss_%)
87 # These libraries will be built in the `others' pass rather than
88 # the `lib' pass, because they depend on libc.so being built already.
89 extra-libs-others = $(extra-libs)
91 # The sources are found in the appropriate subdir.
92 subdir-dirs = $(services:%=nss_%)
93 vpath %.c $(subdir-dirs) ../locale/programs ../intl
96 libnss_files-routines := $(addprefix files-, \
97 $(filter-out key, $(databases))) \
98 files-initgroups files-init
100 libnss_db-dbs := $(addprefix db-,\
101 $(filter-out hosts network key alias,\
104 libnss_db-routines := $(libnss_db-dbs) db-open db-init hash-string
105 generated += $(filter-out db-alias.c db-netgrp.c, \
106 $(addsuffix .c,$(libnss_db-dbs)))
108 libnss_compat-routines := $(addprefix compat-,grp pwd spwd initgroups) \
111 install-others += $(inst_vardbdir)/Makefile
113 # Build static module into libc if requested
114 libnss_files-inhibit-o = $(filter-out .os,$(object-suffixes))
115 libnss_db-inhibit-o = $(filter-out .os,$(object-suffixes))
116 libnss_compat-inhibit-o = $(filter-out .os,$(object-suffixes))
117 ifeq ($(build-static-nss),yes)
118 routines += $(libnss_files-routines)
119 static-only-routines += $(libnss_files-routines)
120 tests-static += tst-nss-static
122 extra-test-objs += nss_test1.os nss_test2.os
126 ifeq (yes,$(have-selinux))
127 LDLIBS-makedb := -lselinux
130 libnss-libc = $(common-objpfx)linkobj/libc.so
131 # Target-specific variable setting to link objects using deprecated
132 # RPC interfaces with the version of libc.so that makes them available
134 $(services:%=$(objpfx)libnss_%.so): libc-for-link = $(libnss-libc)
136 $(objpfx)libnss_db.so: $(objpfx)libnss_files.so
138 $(libnss_db-dbs:%=$(objpfx)%.c): $(objpfx)db-%.c: nss_files/files-%.c
140 (echo '#define EXTERN_PARSER';\
141 echo '#define GENERIC "../nss_db/db-XXX.c"';\
142 echo '#include "$<"') > $@.new
146 $(objpfx)makedb: $(makedb-modules:%=$(objpfx)%.o)
148 $(inst_vardbdir)/Makefile: db-Makefile $(+force)
151 libnss_test1.so-no-z-defs = 1
152 libnss_test2.so-no-z-defs = 1
154 rtld-tests-LDFLAGS += -Wl,--dynamic-list=nss_test.ver
156 libof-nss_test1 = extramodules
157 libof-nss_test2 = extramodules
158 $(objpfx)/libnss_test1.so: $(objpfx)nss_test1.os $(link-libc-deps)
160 $(objpfx)/libnss_test2.so: $(objpfx)nss_test2.os $(link-libc-deps)
162 $(objpfx)nss_test2.os : nss_test1.c
163 ifdef libnss_test1.so-version
164 $(objpfx)/libnss_test1.so$(libnss_test1.so-version): $(objpfx)/libnss_test1.so
167 ifdef libnss_test2.so-version
168 $(objpfx)/libnss_test2.so$(libnss_test2.so-version): $(objpfx)/libnss_test2.so
171 $(patsubst %,$(objpfx)%.out,$(tests) $(tests-container)) : \
172 $(objpfx)/libnss_test1.so$(libnss_test1.so-version) \
173 $(objpfx)/libnss_test2.so$(libnss_test2.so-version)
175 ifeq (yes,$(have-thread-library))
176 $(objpfx)tst-cancel-getpwuid_r: $(shared-thread-library)
179 $(objpfx)tst-nss-files-hosts-erange: $(libdl)
180 $(objpfx)tst-nss-files-hosts-multi: $(libdl)
181 $(objpfx)tst-nss-files-hosts-getent: $(libdl)
182 $(objpfx)tst-nss-files-alias-leak: $(libdl)
183 $(objpfx)tst-nss-files-alias-leak.out: $(objpfx)/libnss_files.so
184 $(objpfx)tst-nss-files-alias-truncated: $(libdl)
185 $(objpfx)tst-nss-files-alias-truncated.out: $(objpfx)/libnss_files.so