1# Copyright (C) 1991-2021 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#	Sub-makefile for string portion of library.
20#
21subdir	:= string
22
23include ../Makeconfig
24
25headers		:= string.h bits/string_fortified.h			\
26		   strings.h bits/strings_fortified.h			\
27		   byteswap.h bits/byteswap.h				\
28		   endian.h bits/endian.h bits/endianness.h		\
29		   bits/uintn-identity.h				\
30		   memory.h argz.h envz.h
31
32routines	:= strcat strchr strcmp strcoll strcpy strcspn		\
33		   strverscmp strdup strndup				\
34		   strerror _strerror strlen strnlen			\
35		   strncat strncmp strncpy				\
36		   strrchr strpbrk strsignal strspn strstr strtok	\
37		   strtok_r strxfrm memchr memcmp memcmpeq memmove memset	\
38		   mempcpy bcopy bzero ffs ffsll stpcpy stpncpy		\
39		   strcasecmp strncase strcasecmp_l strncase_l		\
40		   memccpy memcpy wordcopy strsep strcasestr		\
41		   swab strfry memfrob memmem rawmemchr strchrnul	\
42		   $(addprefix argz-,append count create ctsep next	\
43				     delete extract insert stringify	\
44				     addsep replace)			\
45		   envz basename					\
46		   strcoll_l strxfrm_l string-inlines memrchr		\
47		   xpg-strerror strerror_l explicit_bzero		\
48		   sigdescr_np sigabbrev_np strerrorname_np		\
49		   strerrordesc_np
50
51strop-tests	:= memchr memcmp memcpy memcpy-large memcmpeq memmove mempcpy 	\
52		   memset memccpy stpcpy stpncpy strcat strchr strcmp strcpy	\
53		   strcspn strlen strncmp strncpy strpbrk strrchr strspn memmem	\
54		   strstr strcasestr strnlen strcasecmp strncasecmp	\
55		   strncat rawmemchr strchrnul bcopy bzero memrchr	\
56		   explicit_bzero
57tests		:= tester inl-tester noinl-tester testcopy test-ffs	\
58		   tst-strlen stratcliff tst-svc tst-inlcall		\
59		   bug-strncat1 bug-strspn1 bug-strpbrk1 tst-bswap	\
60		   tst-strtok tst-strxfrm bug-strcoll1 tst-strfry	\
61		   bug-strtok1 $(addprefix test-,$(strop-tests))	\
62		   bug-envz1 tst-strxfrm2 tst-endian tst-svc2		\
63		   tst-strtok_r bug-strcoll2 tst-cmp tst-xbzero-opt	\
64		   test-endian-types test-endian-file-scope		\
65		   test-endian-sign-conversion tst-memmove-overflow	\
66		   test-sig_np
67
68# Both tests require the .mo translation files generated by msgfmt.
69tests-translation := tst-strsignal					\
70		     tst-strerror
71
72tests-container   += $(tests-translation)
73ifeq ($(MSGFMT),:)
74tests-unsupported += $(tests-translation)
75endif
76
77# This test allocates a lot of memory and can run for a long time.
78xtests = tst-strcoll-overflow
79
80# This test needs libdl.
81ifeq (yes,$(build-shared))
82tests += test-strerror-errno
83endif
84
85ifeq ($(run-built-tests),yes)
86tests-special += $(objpfx)tst-svc-cmp.out
87endif
88
89include ../Rules
90
91CFLAGS-inl-tester.c += -fno-builtin
92CFLAGS-noinl-tester.c += -fno-builtin
93CFLAGS-tst-strlen.c += -fno-builtin
94CFLAGS-stratcliff.c += -fno-builtin
95CFLAGS-test-ffs.c += -fno-builtin
96CFLAGS-tst-inlcall.c += -fno-builtin
97CFLAGS-tst-xbzero-opt.c += -O3
98CFLAGS-test-endian-sign-conversion.c += -Werror -Wsign-conversion
99# BZ 21006: Resolve all functions but at least explicit_bzero at startup.
100# Otherwise the test fails on s390x as the memcpy in prepare_test_buffer is
101# done by loading r4 / r5 with the test_pattern and using store multiple
102# instruction to store r4 / r5 to buf.  If explicit_bzero would be resolved in
103# setup_explicit_clear, r4 / r5 would be stored to stack by _dl_runtime_resolve
104# and the call to memmem in count_test_patterns will find a hit of the
105# test_pattern on the stack.
106LDFLAGS-tst-xbzero-opt = -z now
107
108# Called during TLS initialization.
109CFLAGS-memcpy.c += $(no-stack-protector)
110CFLAGS-wordcopy.c += $(no-stack-protector)
111
112ifeq ($(run-built-tests),yes)
113$(objpfx)tst-svc-cmp.out: tst-svc.expect $(objpfx)tst-svc.out
114	cmp $^ > $@; \
115	$(evaluate-test)
116
117LOCALES := de_DE.UTF-8 en_US.ISO-8859-1 en_US.UTF-8 \
118           tr_TR.ISO-8859-9 tr_TR.UTF-8 cs_CZ.UTF-8 \
119	   da_DK.ISO-8859-1 en_GB.UTF-8 pt_BR.UTF-8
120include ../gen-locales.mk
121
122$(objpfx)test-strcasecmp.out: $(gen-locales)
123$(objpfx)test-strncasecmp.out: $(gen-locales)
124$(objpfx)tst-strxfrm.out: $(gen-locales)
125$(objpfx)tst-strxfrm2.out: $(gen-locales)
126# bug-strcoll2 needs cs_CZ.UTF-8 and da_DK.ISO-8859-1.
127$(objpfx)bug-strcoll2.out: $(gen-locales)
128$(objpfx)tst-strcoll-overflow.out: $(gen-locales)
129$(objpfx)tst-strsignal.out: $(gen-locales)
130$(objpfx)tst-strerror.out: $(gen-locales)
131
132endif
133