Remove 'gshadow' and merge into 'nss'
[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   gshadow.h \
28   nss.h \
29   # headers
30
31 # This is the trivial part which goes into libc itself.
32 routines = \
33   $(addsuffix -lookup,$(databases)) \
34   compat-lookup \
35   digits_dots \
36   getnssent \
37   getnssent_r \
38   nss_action \
39   nss_action_parse \
40   nss_database \
41   nss_fgetent_r \
42   nss_files_data \
43   nss_files_fopen \
44   nss_files_functions \
45   nss_hash \
46   nss_module \
47   nss_parse_line_result \
48   nss_readline \
49   nsswitch \
50   rewrite_field \
51   valid_field \
52   valid_list_field \
53   # routines
54
55 # grp routines:
56 routines += \
57   fgetgrent \
58   fgetgrent_r \
59   getgrent \
60   getgrent_r \
61   getgrgid \
62   getgrgid_r \
63   getgrnam \
64   getgrnam_r \
65   grp-merge \
66   initgroups \
67   putgrent \
68   # routines
69
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)
81 endif
82
83 # gshadow routines:
84 routines += \
85   fgetsgent \
86   fgetsgent_r \
87   getsgent \
88   getsgent_r \
89   getsgnam \
90   getsgnam_r \
91   putsgent \
92   sgetsgent \
93   sgetsgent_r \
94   # routines
95
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
104 endif
105
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.
109 databases = \
110   alias \
111   ethers \
112   grp \
113   hosts \
114   netgrp \
115   network \
116   proto \
117   pwd \
118   service \
119   sgrp \
120   spwd \
121   # databases
122
123 ifneq (,$(filter sunrpc,$(subdirs)))
124 databases               += key rpc
125 have-sunrpc             := 1
126 else
127 have-sunrpc             := 0
128 endif
129 CPPFLAGS-getent.c       = -DHAVE_SUNRPC=$(have-sunrpc)
130
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)
136
137 tests-static            = tst-field
138 tests-internal          = tst-field
139
140 tests := \
141   bug17079 \
142   test-digits-dots \
143   test-netdb \
144   testgrp \
145   tst-fgetsgent_r \
146   tst-gshadow \
147   tst-nss-getpwent \
148   tst-nss-hash \
149   tst-nss-test1 \
150   tst-nss-test2 \
151   tst-nss-test4 \
152   tst-nss-test5 \
153   tst-nss-test_errno \
154   tst-putgrent \
155   tst-putsgent \
156   tst-sgetsgent \
157   # tests
158
159 xtests = bug-erange
160
161 tests-container := \
162   tst-initgroups1 \
163   tst-initgroups2 \
164   tst-nss-compat1 \
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 \
171   tst-nss-test3 \
172   tst-reload1 \
173   tst-reload2 \
174   # tests-container
175
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)'; \
189         $(evaluate-test)
190 endif
191 endif
192
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
197 endif
198
199 # Specify rules for the nss_* modules.  We have some services.
200 services                := files db compat
201
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)
206
207 # The sources are found in the appropriate subdir.
208 subdir-dirs = $(services:%=nss_%)
209 vpath %.c $(subdir-dirs) ../locale/programs ../intl
210
211
212 routines += \
213   $(addprefix files-, $(filter-out key, $(databases))) \
214   files-init \
215   files-initgroups \
216   # routines
217
218 # Build only an empty shared libnss_files.
219 libnss_files-inhibit-o = $(filter-out .os,$(object-suffixes))
220
221 # Pretend that libnss_files.so is a linker script, so that the symbolic link
222 # is not installed.
223 install-lib-ldscripts = libnss_files.so
224 $(inst_libdir)/libnss_files.so:
225
226 libnss_db-dbs           := $(addprefix db-,\
227                                        $(filter-out hosts network key alias,\
228                                                     $(databases))) \
229                            db-initgroups
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)))
233
234 libnss_compat-routines  := $(addprefix compat-,grp pwd spwd initgroups) \
235                            nisdomain
236
237 install-others          += $(inst_vardbdir)/Makefile
238
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
244 endif
245 extra-test-objs         += nss_test1.os nss_test2.os nss_test_errno.os \
246                            nss_test_gai_hv2_canonname.os
247
248 ifeq ($(run-built-tests),yes)
249 ifneq (no,$(PERL))
250 tests-special += $(objpfx)mtrace-tst-nss-gai-hv2-canonname.out
251 endif
252 endif
253
254 generated += mtrace-tst-nss-gai-hv2-canonname.out \
255                 tst-nss-gai-hv2-canonname.mtrace
256
257 include ../Rules
258
259 ifeq (yes,$(have-selinux))
260 LDLIBS-makedb           := -lselinux
261 endif
262
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
266 # for new links:
267 $(services:%=$(objpfx)libnss_%.so): libc-for-link = $(libnss-libc)
268
269 $(libnss_db-dbs:%=$(objpfx)%.c): $(objpfx)db-%.c: nss_files/files-%.c
270         @rm -f $@.new
271         (echo '#define EXTERN_PARSER';\
272          echo '#define GENERIC "../nss_db/db-XXX.c"';\
273          echo '#include "$<"') > $@.new
274         mv -f $@.new $@
275
276
277 $(objpfx)makedb: $(makedb-modules:%=$(objpfx)%.o)
278
279 $(inst_vardbdir)/Makefile: db-Makefile $(+force)
280         $(do-install)
281
282 libnss_test1.so-no-z-defs = 1
283 libnss_test2.so-no-z-defs = 1
284
285 rtld-tests-LDFLAGS += -Wl,--dynamic-list=nss_test.ver
286
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)
292         $(build-module)
293 $(objpfx)/libnss_test2.so: $(objpfx)nss_test2.os $(link-libc-deps)
294         $(build-module)
295 $(objpfx)/libnss_test_errno.so: $(objpfx)nss_test_errno.os $(link-libc-deps)
296         $(build-module)
297 $(objpfx)/libnss_test_gai_hv2_canonname.so: \
298   $(objpfx)nss_test_gai_hv2_canonname.os $(link-libc-deps)
299         $(build-module)
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
303         $(make-link)
304 $(objpfx)/libnss_test2.so$(libnss_files.so-version): $(objpfx)/libnss_test2.so
305         $(make-link)
306 $(objpfx)/libnss_test_errno.so$(libnss_files.so-version): \
307   $(objpfx)/libnss_test_errno.so
308         $(make-link)
309 $(objpfx)/libnss_test_gai_hv2_canonname.so$(libnss_files.so-version): \
310   $(objpfx)/libnss_test_gai_hv2_canonname.so
311         $(make-link)
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)
317
318 ifeq (yes,$(have-thread-library))
319 $(objpfx)tst-cancel-getpwuid_r: $(shared-thread-library)
320 endif
321
322 $(objpfx)tst-nss-files-alias-leak.out: $(objpfx)/libnss_files.so
323 $(objpfx)tst-nss-files-alias-truncated.out: $(objpfx)/libnss_files.so
324
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; } > $@; \
334         $(evaluate-test)
335
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