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_tinystdio = [
36  'asprintf.c',
37  'atomic_load.c',
38  'atold_engine.c',
39  'bufio.c',
40  'clearerr.c',
41  'dtox_engine.c',
42  'ecvt.c',
43  'ecvtf.c',
44  'ecvtf_r.c',
45  'ecvtl.c',
46  'ecvtl_r.c',
47  'ecvt_r.c',
48  'fclose.c',
49  'fcvt.c',
50  'fcvtf.c',
51  'fcvtf_r.c',
52  'fcvtl.c',
53  'fcvtl_r.c',
54  'fcvt_r.c',
55  'fdevopen.c',
56  'feof.c',
57  'ferror.c',
58  'fflush.c',
59  'fgetc.c',
60  'fgetpos.c',
61  'fgets.c',
62  'fgetwc.c',
63  'fgetws.c',
64  'fileno.c',
65  'filestrget.c',
66  'filestrputalloc.c',
67  'filestrput.c',
68  'filewstrget.c',
69  'flockfile.c',
70  'fmemopen.c',
71  'fprintf.c',
72  'fputc.c',
73  'fputs.c',
74  'fputwc.c',
75  'fputws.c',
76  'fread.c',
77  'fscanf.c',
78  'fseek.c',
79  'fseeko.c',
80  'fsetpos.c',
81  'ftell.c',
82  'ftello.c',
83  'ftox_engine.c',
84  'ftrylockfile.c',
85  'funlockfile.c',
86  'funopen.c',
87  'fwide.c',
88  'fwprintf.c',
89  'fwrite.c',
90  'fwscanf.c',
91  'gcvt.c',
92  'gcvtf.c',
93  'gcvtl.c',
94  'getchar.c',
95  'getdelim.c',
96  'getline.c',
97  'gets.c',
98  'getwchar.c',
99  'ldtoa_engine.c',
100  'ldtox_engine.c',
101  'matchcaseprefix.c',
102  'mktemp.c',
103  'perror.c',
104  'printf.c',
105  'putchar.c',
106  'puts.c',
107  'putwchar.c',
108  'remove.c',
109  'rewind.c',
110  'scanf.c',
111  'setbuf.c',
112  'setbuffer.c',
113  'setlinebuf.c',
114  'setvbuf.c',
115  'sflags.c',
116  'snprintf.c',
117  'snprintfd.c',
118  'snprintff.c',
119  'sprintf.c',
120  'sprintfd.c',
121  'sprintff.c',
122  'sscanf.c',
123  'strfromd.c',
124  'strfromf.c',
125  'strfroml.c',
126  'strtod.c',
127  'strtod_l.c',
128  'strtof.c',
129  'strtof_l.c',
130  'strtoimax.c',
131  'strtol.c',
132  'strtold.c',
133  'strtold_l.c',
134  'strtol_l.c',
135  'strtoll.c',
136  'strtoll_l.c',
137  'strtoul.c',
138  'strtoul_l.c',
139  'strtoull.c',
140  'strtoull_l.c',
141  'strtoumax.c',
142  'swprintf.c',
143  'swscanf.c',
144  'tmpfile.c',
145  'tmpnam.c',
146  'ungetc.c',
147  'ungetwc.c',
148  'vasprintf.c',
149  'vffprintf.c',
150  'vffscanf.c',
151  'vfiprintf.c',
152  'vfiscanf.c',
153  'vflprintf.c',
154  'vflscanf.c',
155  'vfmprintf.c',
156  'vfmscanf.c',
157  'vfprintf.c',
158  'vfscanf.c',
159  'vfwprintf.c',
160  'vfwscanf.c',
161  'vprintf.c',
162  'vscanf.c',
163  'vsnprintf.c',
164  'vsprintf.c',
165  'vsscanf.c',
166  'vswprintf.c',
167  'vswscanf.c',
168  'vwprintf.c',
169  'vwscanf.c',
170  'wprintf.c',
171  'wscanf.c',
172  'sprintf_s.c',
173]
174
175# exact float/string conversion code
176srcs_dtoa_ryu = [
177  'atod_ryu.c',
178  'atof_ryu.c',
179  'dtoa_ryu.c',
180  'ftoa_ryu.c',
181  'ryu_divpow2.c',
182  'ryu_log10.c',
183  'ryu_log2pow5.c',
184  'ryu_pow5bits.c',
185  'ryu_table.c',
186  'ryu_umul128.c',
187]
188
189# smaller float/string conversion code
190srcs_dtoa_float = [
191  'atod_engine.c',
192  'atof_engine.c',
193  'dtoa_engine.c',
194  'ftoa_engine.c',
195]
196
197if io_float_exact
198  srcs_tinystdio += srcs_dtoa_ryu
199else
200  srcs_tinystdio += srcs_dtoa_float
201endif
202
203# atomic support for ungetc
204srcs_tinystdio_atomic = [
205  'compare_exchange.c',
206  'exchange.c',
207]
208
209if atomic_ungetc
210  srcs_tinystdio += srcs_tinystdio_atomic
211endif
212
213# code using POSIX APIs
214srcs_tinystdio_posix = [
215  'fdopen.c',
216  'fopen.c',
217  'freopen.c',
218]
219
220if posix_io
221  srcs_tinystdio += srcs_tinystdio_posix
222endif
223
224# stdin/stdout/stderr using POSIX APIs
225srcs_tinystdio_posix_console = [
226  'posixiob_stdin.c',
227  'posixiob_stdout.c',
228  'posixiob_stderr.c',
229]
230
231if posix_console
232  srcs_tinystdio += srcs_tinystdio_posix_console
233endif
234
235inc_headers = ['stdio.h', 'stdio-bufio.h']
236install_headers(inc_headers,
237		install_dir: include_dir
238	       )
239
240srcs_tinystdio_use = []
241foreach file : srcs_tinystdio
242  s_file = fs.replace_suffix(file, '.S')
243  if file in srcs_machine
244    message('libc/tinystdio/' + file + ': machine overrides generic')
245  elif s_file in srcs_machine
246    message('libc/tinystdio/' + s_file + ': machine overrides generic')
247  else
248    srcs_tinystdio_use += file
249  endif
250endforeach
251
252src_tinystdio = files(srcs_tinystdio_use)
253
254if enable_cdefs_tests
255  foreach header : inc_headers
256    test_name = 'check-cdef-' + header
257    test(test_name,
258         validate_cdefs,
259         args: [meson.current_source_dir() / header] + cc.cmd_array() + c_args + inc_args,
260         suite: 'headers')
261  endforeach
262endif
263