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