Remove 'grp' and merge into 'nss' and 'posix'
[platform/upstream/glibc.git] / stdlib / Makefile
1 # Copyright (C) 1991-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 stdlib routines
20 #
21 subdir  := stdlib
22
23 include ../Makeconfig
24
25 headers := \
26   alloca.h \
27   bits/errno.h \
28   bits/indirect-return.h \
29   bits/monetary-ldbl.h \
30   bits/stdint-intn.h \
31   bits/stdint-uintn.h \
32   bits/stdlib-bsearch.h \
33   bits/stdlib-float.h \
34   bits/stdlib-ldbl.h \
35   bits/stdlib.h \
36   bits/time64.h \
37   bits/timesize.h \
38   bits/types/error_t.h \
39   bits/wordsize.h \
40   errno.h \
41   fmtmsg.h \
42   inttypes.h \
43   monetary.h \
44   stdint.h \
45   stdlib.h \
46   sys/errno.h \
47   sys/random.h \
48   sys/ucontext.h \
49   ucontext.h \
50   # headers
51
52 routines := \
53   a64l \
54   abort \
55   abs \
56   arc4random \
57   arc4random_uniform \
58   at_quick_exit \
59   atof \
60   atoi \
61   atol\
62   atoll \
63   bsearch \
64   canonicalize \
65   cxa_at_quick_exit \
66   cxa_atexit \
67   cxa_finalize \
68   cxa_thread_atexit_impl \
69   div \
70   drand48 \
71   drand48-iter \
72   drand48_r \
73   erand48 \
74   erand48_r \
75   exit \
76   fmtmsg \
77   getcontext \
78   getentropy \
79   getenv \
80   getrandom \
81   getsubopt \
82   jrand48 \
83   jrand48_r \
84   l64a \
85   labs \
86   lcong48 \
87   lcong48_r \
88   ldiv \
89   llabs \
90   lldiv \
91   lrand48 \
92   lrand48_r \
93   makecontext \
94   mblen \
95   mbstowcs \
96   mbtowc \
97   mrand48 \
98   mrand48_r \
99   msort \
100   nrand48 \
101   nrand48_r \
102   old_atexit  \
103   on_exit atexit \
104   putenv \
105   qsort \
106   quick_exit \
107   rand \
108   rand_r \
109   random \
110   random_r \
111   rpmatch \
112   secure-getenv \
113   seed48 \
114   seed48_r \
115   setcontext \
116   setenv \
117   srand48 \
118   srand48_r \
119   strfmon \
120   strfmon_l \
121   strfromd \
122   strfromf \
123   strfroml \
124   strtod \
125   strtod_l \
126   strtod_nan \
127   strtof \
128   strtof_l \
129   strtof_nan \
130   strtol \
131   strtol_l \
132   strtold \
133   strtold_l \
134   strtold_nan \
135   strtoll \
136   strtoll_l \
137   strtoul \
138   strtoul_l \
139   strtoull \
140   strtoull_l \
141   swapcontext \
142   system \
143   wcstombs \
144   wctomb  \
145   xpg_basename \
146   # routines
147
148 # Exclude fortified routines from being built with _FORTIFY_SOURCE
149 routines_no_fortify += \
150   mbstowcs \
151   wcstombs \
152   wctomb \
153   # routines_no_fortify
154
155 aux = \
156   grouping \
157   groupingwc \
158   tens_in_limb \
159   # aux
160
161 # These routines will be omitted from the libc shared object.
162 # Instead the static object files will be included in a special archive
163 # linked against when the shared library will be used.
164 static-only-routines = \
165   at_quick_exit \
166   atexit \
167   # static-only-routines
168
169 test-srcs := \
170   tst-fmtmsg \
171   #test-srcs
172
173 tests := \
174   bug-fmtmsg1 \
175   bug-getcontext \
176   bug-strtod \
177   bug-strtod2 \
178   test-a64l \
179   test-at_quick_exit-race \
180   test-atexit-race \
181   test-atexit-recursive \
182   test-bz22786 \
183   test-canon \
184   test-canon2 \
185   test-cxa_atexit-race \
186   test-cxa_atexit-race2 \
187   test-dlclose-exit-race \
188   test-on_exit-race \
189   testdiv \
190   testmb \
191   testmb2 \
192   testrand \
193   testsort \
194   tst-abs \
195   tst-arc4random-fork \
196   tst-arc4random-stats \
197   tst-arc4random-thread \
198   tst-at_quick_exit \
199   tst-atexit \
200   tst-atof1 \
201   tst-atof2 \
202   tst-bsearch \
203   tst-bz20544 \
204   tst-canon-bz26341 \
205   tst-cxa_atexit \
206   tst-environ \
207   tst-getrandom \
208   tst-labs \
209   tst-limits \
210   tst-llabs \
211   tst-makecontext \
212   tst-makecontext-align \
213   tst-makecontext2 \
214   tst-makecontext3 \
215   tst-on_exit \
216   tst-qsort \
217   tst-qsort2 \
218   tst-quick_exit \
219   tst-rand48 \
220   tst-rand48-2 \
221   tst-random \
222   tst-random2 \
223   tst-realpath \
224   tst-realpath-toolong \
225   tst-secure-getenv \
226   tst-setcontext \
227   tst-setcontext2 \
228   tst-setcontext3 \
229   tst-setcontext4 \
230   tst-setcontext5 \
231   tst-setcontext6 \
232   tst-setcontext7 \
233   tst-setcontext8 \
234   tst-setcontext9 \
235   tst-strfmon_l \
236   tst-strfrom \
237   tst-strfrom-locale \
238   tst-strtod \
239   tst-strtod-nan-locale \
240   tst-strtod-nan-sign \
241   tst-strtod-overflow \
242   tst-strtod-round \
243   tst-strtod-underflow \
244   tst-strtod2 \
245   tst-strtod5 \
246   tst-strtod6 \
247   tst-strtol \
248   tst-strtol-binary-c11 \
249   tst-strtol-binary-c2x \
250   tst-strtol-binary-gnu11 \
251   tst-strtol-binary-gnu2x \
252   tst-strtol-locale \
253   tst-strtoll \
254   tst-swapcontext1 \
255   tst-thread-quick_exit \
256   tst-tininess \
257   tst-unsetenv1 \
258   tst-width \
259   tst-width-stdint \
260   tst-xpg-basename \
261   # tests
262
263 tests-internal := \
264   tst-strtod1i \
265   tst-strtod3 \
266   tst-strtod4 \
267   tst-strtod5i \
268   tst-tls-atexit \
269   tst-tls-atexit-nodelete \
270   # tests-internal
271
272 tests-static := \
273   tst-secure-getenv \
274   # tests-static
275
276 tests-container := \
277   tst-system \
278   #tests-container
279
280 ifeq ($(build-hardcoded-path-in-tests),yes)
281 tests += \
282   tst-empty-env \
283   # tests
284 endif
285
286 LDLIBS-test-atexit-race = $(shared-thread-library)
287 LDLIBS-test-at_quick_exit-race = $(shared-thread-library)
288 LDLIBS-test-cxa_atexit-race = $(shared-thread-library)
289 LDLIBS-test-cxa_atexit-race2 = $(shared-thread-library)
290 LDLIBS-test-on_exit-race = $(shared-thread-library)
291 LDLIBS-tst-canon-bz26341 = $(shared-thread-library)
292 LDLIBS-tst-arc4random-fork = $(shared-thread-library)
293 LDLIBS-tst-arc4random-thread = $(shared-thread-library)
294 LDLIBS-tst-system = $(shared-thread-library)
295
296 LDLIBS-test-dlclose-exit-race = $(shared-thread-library)
297 LDFLAGS-test-dlclose-exit-race = $(LDFLAGS-rdynamic)
298 LDLIBS-test-dlclose-exit-race-helper.so = $(libsupport) $(shared-thread-library)
299
300 CFLAGS-tst-abs.c += -fno-builtin
301 CFLAGS-tst-labs.c += -fno-builtin
302 CFLAGS-tst-llabs.c += -fno-builtin
303
304 ifeq ($(have-cxx-thread_local),yes)
305 CFLAGS-tst-quick_exit.o = -std=c++11
306 LDLIBS-tst-quick_exit = -lstdc++
307 CFLAGS-tst-thread-quick_exit.o = -std=c++11
308 LDLIBS-tst-thread-quick_exit = -lstdc++
309 $(objpfx)tst-thread-quick_exit: $(shared-thread-library)
310 else
311 tests-unsupported += \
312   tst-quick_exit \
313   tst-thread-quick_exit \
314   # tests-unsupported
315 endif
316
317 modules-names = \
318   test-dlclose-exit-race-helper \
319   tst-tls-atexit-lib \
320   # modules-names
321 extra-test-objs += $(addsuffix .os, $(modules-names))
322
323 ifeq ($(build-shared),yes)
324 tests += \
325   tst-putenv \
326   # tests
327 endif
328
329 # Several mpn functions from GNU MP are used by the strtod function.
330 mpn-routines := \
331   add_n \
332   addmul_1 \
333   cmp \
334   divmod_1 \
335   divrem \
336   inlines \
337   lshift \
338   mod_1 \
339   mul \
340   mul_1 \
341   mul_n \
342   rshift \
343   sub_n \
344   submul_1 \
345   udiv_qrnnd \
346   # mpn-routines
347 mpn-headers = \
348   asm-syntax.h \
349   gmp-impl.h \
350   gmp-mparam.h \
351   gmp.h \
352   longlong.h \
353   # mpn-headers
354
355 routines := \
356   $(strip $(routines) $(mpn-routines)) \
357   dbl2mpn \
358   ldbl2mpn \
359   mpn2dbl \
360   mpn2flt \
361   mpn2ldbl \
362   # routines
363 aux += \
364   fpioconst \
365   mp_clz_tab \
366   # aux
367
368 tests-extras += \
369   tst-putenvmod \
370   # tests-extras
371
372 extra-test-objs += \
373   tst-putenvmod.os \
374   # extra-test-objs
375
376 generated += \
377   isomac \
378   isomac.out \
379   tst-putenvmod.so \
380   # generated
381
382 CFLAGS-bsearch.c += $(uses-callbacks)
383 CFLAGS-msort.c += $(uses-callbacks)
384 CFLAGS-qsort.c += $(uses-callbacks)
385 CFLAGS-system.c += -fexceptions
386 CFLAGS-system.os = -fomit-frame-pointer
387 CFLAGS-fmtmsg.c += -fexceptions
388
389 CFLAGS-strfmon.c += $(libio-mtsafe)
390 CFLAGS-strfmon_l.c += $(libio-mtsafe)
391
392 # The strfrom class of functions call __printf_fp in order to convert the
393 # floating-point value to characters.  This requires the value of IO_MTSAFE_IO.
394 CFLAGS-strfromd.c += $(libio-mtsafe)
395 CFLAGS-strfromf.c += $(libio-mtsafe)
396 CFLAGS-strfroml.c += $(libio-mtsafe)
397
398 CFLAGS-strtol.c += $(config-cflags-wno-ignored-attributes)
399 CFLAGS-strtoul.c += $(config-cflags-wno-ignored-attributes)
400 CFLAGS-strtoll.c += $(config-cflags-wno-ignored-attributes)
401 CFLAGS-strtoull.c += $(config-cflags-wno-ignored-attributes)
402 CFLAGS-strtof.c += $(config-cflags-wno-ignored-attributes)
403 CFLAGS-strtof_l.c += $(config-cflags-wno-ignored-attributes)
404 CFLAGS-strtod.c += $(config-cflags-wno-ignored-attributes)
405 CFLAGS-strtod_l.c += $(config-cflags-wno-ignored-attributes)
406 CFLAGS-strtold.c += $(config-cflags-wno-ignored-attributes)
407 CFLAGS-strtold_l.c += $(config-cflags-wno-ignored-attributes)
408 CFLAGS-secure-getenv.c += $(config-cflags-wno-ignored-attributes)
409
410 CFLAGS-tst-bsearch.c += $(stack-align-test-flags)
411 CFLAGS-tst-qsort.c += $(stack-align-test-flags)
412 CFLAGS-tst-makecontext.c += -funwind-tables
413 CFLAGS-tst-makecontext2.c += $(stack-align-test-flags)
414
415 CFLAGS-testmb.c += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Werror
416
417 # Some versions of GCC supported for building glibc do not support -std=c2x
418 # or -std=gnu2x, so the tests for those versions use -std=c11 and -std=gnu11
419 # and then _ISOC2X_SOURCE is defined in the test as needed.
420 CFLAGS-tst-strtol-binary-c11.c += -std=c11
421 CFLAGS-tst-strtol-binary-c2x.c += -std=c11
422 CFLAGS-tst-strtol-binary-gnu11.c += -std=gnu11
423 CFLAGS-tst-strtol-binary-gnu2x.c += -std=gnu11
424
425
426 # Run a test on the header files we use.
427 tests-special += $(objpfx)isomac.out
428
429 ifeq ($(run-built-tests),yes)
430 tests-special += $(objpfx)tst-fmtmsg.out
431 endif
432
433 include ../Rules
434
435 ifeq ($(run-built-tests),yes)
436 LOCALES := \
437   cs_CZ.UTF-8 \
438   de_DE.UTF-8 \
439   el_GR.UTF-8 \
440   en_US.ISO-8859-1 \
441   hi_IN.UTF-8 \
442   hr_HR.UTF-8 \
443   tg_TJ.UTF-8 \
444   tr_TR.ISO-8859-9 \
445   tr_TR.UTF-8 \
446   # LOCALES
447 include ../gen-locales.mk
448
449 $(objpfx)bug-strtod2.out: $(gen-locales)
450 $(objpfx)testmb2.out: $(gen-locales)
451 $(objpfx)tst-strtod.out: $(gen-locales)
452 $(objpfx)tst-strtod1i.out: $(gen-locales)
453 $(objpfx)tst-strtod3.out: $(gen-locales)
454 $(objpfx)tst-strtod4.out: $(gen-locales)
455 $(objpfx)tst-strtod5.out: $(gen-locales)
456 $(objpfx)tst-strtod5i.out: $(gen-locales)
457 $(objpfx)tst-strtol-locale.out: $(gen-locales)
458 $(objpfx)tst-strtod-nan-locale.out: $(gen-locales)
459 $(objpfx)tst-strfmon_l.out: $(gen-locales)
460 $(objpfx)tst-strfrom.out: $(gen-locales)
461 $(objpfx)tst-strfrom-locale.out: $(gen-locales)
462 $(objpfx)test-dlclose-exit-race.out: $(objpfx)test-dlclose-exit-race-helper.so
463 endif
464
465 # Testdir has to be named stdlib and needs to be writable
466 test-canon-ARGS = --test-dir=${common-objpfx}stdlib
467
468 bug-fmtmsg1-ENV = SEV_LEVEL=foo,11,newsev
469
470 $(objpfx)isomac.out: $(objpfx)isomac
471         $(dir $<)$(notdir $<) '$(CC)'  \
472         '-I../include $(+sysdep-includes) $(sysincludes) -I..' > $@; \
473         $(evaluate-test)
474
475 isomac-CFLAGS = -O
476 $(objpfx)isomac: isomac.c
477         $(native-compile)
478
479 $(objpfx)tst-fmtmsg.out: tst-fmtmsg.sh $(objpfx)tst-fmtmsg
480         $(SHELL) $< $(common-objpfx) '$(test-program-prefix-before-env)' \
481                  '$(run-program-env)' '$(test-program-prefix-after-env)' \
482                  $(common-objpfx)stdlib/; \
483         $(evaluate-test)
484
485 $(objpfx)tst-putenv: $(objpfx)tst-putenvmod.so
486 LDFLAGS-tst-putenv = -Wl,--no-as-needed
487
488 $(objpfx)tst-putenvmod.so: $(objpfx)tst-putenvmod.os $(link-libc-deps)
489         $(build-module)
490 libof-tst-putenvmod = extramodules
491
492 $(objpfx)bug-getcontext: $(libm)
493 $(objpfx)bug-strtod2: $(libm)
494 $(objpfx)tst-strtod-round: $(libm)
495 $(objpfx)tst-tininess: $(libm)
496 $(objpfx)tst-strtod-underflow: $(libm)
497 $(objpfx)tst-strtod6: $(libm)
498 $(objpfx)tst-strtod-nan-locale: $(libm)
499 $(objpfx)tst-strtod-nan-sign: $(libm)
500
501 tst-tls-atexit-lib.so-no-z-defs = yes
502 test-dlclose-exit-race-helper.so-no-z-defs = yes
503
504 $(objpfx)tst-tls-atexit: $(shared-thread-library)
505 $(objpfx)tst-tls-atexit.out: $(objpfx)tst-tls-atexit-lib.so
506
507 $(objpfx)tst-tls-atexit-nodelete: $(shared-thread-library)
508 $(objpfx)tst-tls-atexit-nodelete.out: $(objpfx)tst-tls-atexit-lib.so
509
510 $(objpfx)tst-setcontext3.out: tst-setcontext3.sh $(objpfx)tst-setcontext3
511         $(SHELL) $< $(common-objpfx) '$(test-program-prefix-before-env)' \
512                  '$(run-program-env)' '$(test-program-prefix-after-env)' \
513                  $(common-objpfx)stdlib/; \
514         $(evaluate-test)