1#
2# SPDX-License-Identifier: BSD-3-Clause
3#
4# Copyright © 2019 Keith Packard
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9#
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12#
13# 2. Redistributions in binary form must reproduce the above
14#    copyright notice, this list of conditions and the following
15#    disclaimer in the documentation and/or other materials provided
16#    with the distribution.
17#
18# 3. Neither the name of the copyright holder nor the names of its
19#    contributors may be used to endorse or promote products derived
20#    from this software without specific prior written permission.
21#
22# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33# OF THE POSSIBILITY OF SUCH DAMAGE.
34#
35srcs_string = [
36    'bcmp.c',
37    'bcopy.c',
38    'bzero.c',
39    'explicit_bzero.c',
40    'ffsl.c',
41    'ffsll.c',
42    'fls.c',
43    'flsl.c',
44    'flsll.c',
45    'gnu_basename.c',
46    'index.c',
47    'memccpy.c',
48    'memchr.c',
49    'memcmp.c',
50    'memcpy.c',
51    'memmem.c',
52    'memmove.c',
53    'mempcpy.c',
54    'memrchr.c',
55    'memset.c',
56    'rawmemchr.c',
57    'rindex.c',
58    'stpcpy.c',
59    'stpncpy.c',
60    'strcasecmp.c',
61    'strcasecmp_l.c',
62    'strcasestr.c',
63    'strcat.c',
64    'strchr.c',
65    'strchrnul.c',
66    'strcoll.c',
67    'strcoll_l.c',
68    'strcpy.c',
69    'strcspn.c',
70    'strdup.c',
71    'strerror.c',
72    'strerror_r.c',
73    'strlcat.c',
74    'strlcpy.c',
75    'strlen.c',
76    'strlwr.c',
77    'strncasecmp.c',
78    'strncasecmp_l.c',
79    'strncat.c',
80    'strncmp.c',
81    'strncpy.c',
82    'strndup.c',
83    'strnlen.c',
84    'strnstr.c',
85    'strpbrk.c',
86    'strrchr.c',
87    'strsep.c',
88    'strsignal.c',
89    'strspn.c',
90    'strstr.c',
91    'strtok.c',
92    'strtok_r.c',
93    'strupr.c',
94    'strverscmp.c',
95    'strxfrm.c',
96    'strxfrm_l.c',
97    'swab.c',
98    'timingsafe_bcmp.c',
99    'timingsafe_memcmp.c',
100    'wcpcpy.c',
101    'wcpncpy.c',
102    'wcscasecmp.c',
103    'wcscasecmp_l.c',
104    'wcscat.c',
105    'wcschr.c',
106    'wcscmp.c',
107    'wcscoll.c',
108    'wcscoll_l.c',
109    'wcscpy.c',
110    'wcscspn.c',
111    'wcsdup.c',
112    'wcslcat.c',
113    'wcslcpy.c',
114    'wcslen.c',
115    'wcsncasecmp.c',
116    'wcsncasecmp_l.c',
117    'wcsncat.c',
118    'wcsncmp.c',
119    'wcsncpy.c',
120    'wcsnlen.c',
121    'wcspbrk.c',
122    'wcsrchr.c',
123    'wcsspn.c',
124    'wcsstr.c',
125    'wcstok.c',
126    'wcswidth.c',
127    'wcsxfrm.c',
128    'wcsxfrm_l.c',
129    'wcwidth.c',
130    'wmemchr.c',
131    'wmemcmp.c',
132    'wmemcpy.c',
133    'wmemmove.c',
134    'wmempcpy.c',
135    'wmemset.c',
136    'xpg_strerror_r.c',
137    'memcpy_s.c',
138    'memmove_s.c',
139    'memset_s.c',
140    'strcat_s.c',
141    'strcpy_s.c',
142    'strerror_s.c',
143    'strerrorlen_s.c',
144    'strncat_s.c',
145    'strncpy_s.c',
146    'strnlen_s.c',
147]
148
149hdrs_string = [
150    'local.h',
151    'str-two-way.h',
152    'string_private.h',
153]
154
155srcs_strcmp = [
156  'strcmp.c'
157]
158
159srcs_string_use = []
160foreach file : srcs_string
161  s_file = fs.replace_suffix(file, '.S')
162  if file in srcs_machine
163    message('libc/string/' + file + ': machine overrides generic')
164  elif s_file in srcs_machine
165    message('libc/string/' + s_file + ': machine overrides generic')
166  else
167    srcs_string_use += file
168  endif
169endforeach
170
171srcs_strcmp_use = []
172foreach file : srcs_strcmp
173  s_file = fs.replace_suffix(file, '.S')
174  if file in srcs_machine
175    message('libc/string/' + file + ': machine overrides generic')
176  elif s_file in srcs_machine
177    message('libc/string/' + s_file + ': machine overrides generic')
178  else
179    srcs_strcmp_use += file
180  endif
181endforeach
182
183if fast_strcmp
184  cargs_strcmp = ['-O3']
185else
186  cargs_strcmp = []
187endif
188
189src_string = files(srcs_string_use)
190
191# Need a sub-library to pass custom cflags to strcmp
192
193if srcs_strcmp_use != []
194  foreach target : targets
195    value = get_variable('target_' + target)
196
197    set_variable('lib_string' + target,
198		 static_library('strcmp' + target,
199				srcs_strcmp_use,
200				pic: false,
201				c_args: value[1] + c_args + cargs_strcmp,
202				include_directories: inc))
203  endforeach
204endif
205