baf7d9d0ab35cbeb43a7be6abaabf90d703f3c5b
[platform/upstream/glibc.git] / nss / Makefile
1 # Copyright (C) 1996-2023 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 #       Makefile for name service switch.
20 #
21 subdir  := nss
22
23 include ../Makeconfig
24
25 headers := \
26   grp.h \
27   nss.h \
28   # headers
29
30 # This is the trivial part which goes into libc itself.
31 routines = \
32   $(addsuffix -lookup,$(databases)) \
33   compat-lookup \
34   digits_dots \
35   getnssent \
36   getnssent_r \
37   nss_action \
38   nss_action_parse \
39   nss_database \
40   nss_fgetent_r \
41   nss_files_data \
42   nss_files_fopen \
43   nss_files_functions \
44   nss_hash \
45   nss_module \
46   nss_parse_line_result \
47   nss_readline \
48   nsswitch \
49   rewrite_field \
50   valid_field \
51   valid_list_field \
52   # routines
53
54 # grp routines:
55 routines += \
56   fgetgrent \
57   fgetgrent_r \
58   getgrent \
59   getgrent_r \
60   getgrgid \
61   getgrgid_r \
62   getgrnam \
63   getgrnam_r \
64   grp-merge \
65   initgroups \
66   putgrent \
67   # routines
68
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)
80 endif
81
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.
85 databases = \
86   alias \
87   ethers \
88   grp \
89   hosts \
90   netgrp \
91   network \
92   proto \
93   pwd \
94   service \
95   sgrp \
96   spwd \
97   # databases
98
99 ifneq (,$(filter sunrpc,$(subdirs)))
100 databases               += key rpc
101 have-sunrpc             := 1
102 else
103 have-sunrpc             := 0
104 endif
105 CPPFLAGS-getent.c       = -DHAVE_SUNRPC=$(have-sunrpc)
106
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)
112
113 tests-static            = tst-field
114 tests-internal          = tst-field
115
116 tests := \
117   bug17079 \
118   test-digits-dots \
119   test-netdb \
120   testgrp \
121   tst-nss-getpwent \
122   tst-nss-hash \
123   tst-nss-test1 \
124   tst-nss-test2 \
125   tst-nss-test4 \
126   tst-nss-test5 \
127   tst-nss-test_errno \
128   tst-putgrent \
129   # tests
130
131 xtests = bug-erange
132
133 tests-container := \
134   tst-initgroups1 \
135   tst-initgroups2 \
136   tst-nss-compat1 \
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 \
143   tst-nss-test3 \
144   tst-reload1 \
145   tst-reload2 \
146   # tests-container
147
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)'; \
161         $(evaluate-test)
162 endif
163 endif
164
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
169 endif
170
171 # Specify rules for the nss_* modules.  We have some services.
172 services                := files db compat
173
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)
178
179 # The sources are found in the appropriate subdir.
180 subdir-dirs = $(services:%=nss_%)
181 vpath %.c $(subdir-dirs) ../locale/programs ../intl
182
183
184 routines += \
185   $(addprefix files-, $(filter-out key, $(databases))) \
186   files-init \
187   files-initgroups \
188   # routines
189
190 # Build only an empty shared libnss_files.
191 libnss_files-inhibit-o = $(filter-out .os,$(object-suffixes))
192
193 # Pretend that libnss_files.so is a linker script, so that the symbolic link
194 # is not installed.
195 install-lib-ldscripts = libnss_files.so
196 $(inst_libdir)/libnss_files.so:
197
198 libnss_db-dbs           := $(addprefix db-,\
199                                        $(filter-out hosts network key alias,\
200                                                     $(databases))) \
201                            db-initgroups
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)))
205
206 libnss_compat-routines  := $(addprefix compat-,grp pwd spwd initgroups) \
207                            nisdomain
208
209 install-others          += $(inst_vardbdir)/Makefile
210
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
216 endif
217 extra-test-objs         += nss_test1.os nss_test2.os nss_test_errno.os \
218                            nss_test_gai_hv2_canonname.os
219
220 ifeq ($(run-built-tests),yes)
221 ifneq (no,$(PERL))
222 tests-special += $(objpfx)mtrace-tst-nss-gai-hv2-canonname.out
223 endif
224 endif
225
226 generated += mtrace-tst-nss-gai-hv2-canonname.out \
227                 tst-nss-gai-hv2-canonname.mtrace
228
229 include ../Rules
230
231 ifeq (yes,$(have-selinux))
232 LDLIBS-makedb           := -lselinux
233 endif
234
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
238 # for new links:
239 $(services:%=$(objpfx)libnss_%.so): libc-for-link = $(libnss-libc)
240
241 $(libnss_db-dbs:%=$(objpfx)%.c): $(objpfx)db-%.c: nss_files/files-%.c
242         @rm -f $@.new
243         (echo '#define EXTERN_PARSER';\
244          echo '#define GENERIC "../nss_db/db-XXX.c"';\
245          echo '#include "$<"') > $@.new
246         mv -f $@.new $@
247
248
249 $(objpfx)makedb: $(makedb-modules:%=$(objpfx)%.o)
250
251 $(inst_vardbdir)/Makefile: db-Makefile $(+force)
252         $(do-install)
253
254 libnss_test1.so-no-z-defs = 1
255 libnss_test2.so-no-z-defs = 1
256
257 rtld-tests-LDFLAGS += -Wl,--dynamic-list=nss_test.ver
258
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)
264         $(build-module)
265 $(objpfx)/libnss_test2.so: $(objpfx)nss_test2.os $(link-libc-deps)
266         $(build-module)
267 $(objpfx)/libnss_test_errno.so: $(objpfx)nss_test_errno.os $(link-libc-deps)
268         $(build-module)
269 $(objpfx)/libnss_test_gai_hv2_canonname.so: \
270   $(objpfx)nss_test_gai_hv2_canonname.os $(link-libc-deps)
271         $(build-module)
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
275         $(make-link)
276 $(objpfx)/libnss_test2.so$(libnss_files.so-version): $(objpfx)/libnss_test2.so
277         $(make-link)
278 $(objpfx)/libnss_test_errno.so$(libnss_files.so-version): \
279   $(objpfx)/libnss_test_errno.so
280         $(make-link)
281 $(objpfx)/libnss_test_gai_hv2_canonname.so$(libnss_files.so-version): \
282   $(objpfx)/libnss_test_gai_hv2_canonname.so
283         $(make-link)
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)
289
290 ifeq (yes,$(have-thread-library))
291 $(objpfx)tst-cancel-getpwuid_r: $(shared-thread-library)
292 endif
293
294 $(objpfx)tst-nss-files-alias-leak.out: $(objpfx)/libnss_files.so
295 $(objpfx)tst-nss-files-alias-truncated.out: $(objpfx)/libnss_files.so
296
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; } > $@; \
306         $(evaluate-test)
307
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