1# Copyright (C) 1991-2022 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#	Specific makefile for stdio-common.
20#
21subdir	:= stdio-common
22
23include ../Makeconfig
24
25headers	:= stdio_ext.h printf.h bits/printf-ldbl.h bits/stdio_lim.h
26
27routines := \
28  _itoa \
29  _itowa \
30  asprintf \
31  ctermid \
32  cuserid \
33  dprintf \
34  flockfile \
35  fprintf \
36  fscanf \
37  ftrylockfile \
38  funlockfile \
39  gentempfd \
40  getline \
41  getw \
42  iovfscanf \
43  isoc99_fscanf \
44  isoc99_scanf \
45  isoc99_sscanf \
46  isoc99_vfscanf \
47  isoc99_vscanf \
48  isoc99_vsscanf \
49  itoa-digits \
50  itoa-udigits \
51  itowa-digits \
52  perror \
53  printf \
54  printf-prs \
55  printf_fp \
56  printf_fphex \
57  printf_size \
58  psiginfo \
59  psignal \
60  putw \
61  reg-modifier \
62  reg-printf \
63  reg-type \
64  remove \
65  rename \
66  renameat \
67  renameat2 \
68  scanf \
69  snprintf \
70  sprintf \
71  sscanf \
72  tempnam \
73  tempname \
74  tmpfile \
75  tmpfile64 \
76  tmpnam \
77  tmpnam_r \
78  vfprintf \
79  vfprintf-internal \
80  vfscanf \
81  vfscanf-internal \
82  vfwprintf \
83  vfwprintf-internal \
84  vfwscanf \
85  vfwscanf-internal \
86  vprintf \
87  # routines
88
89aux := \
90  errlist \
91  errlist-data \
92  errname \
93  fxprintf \
94  printf-parsemb \
95  printf-parsewc \
96  siglist \
97  # aux
98
99tests := \
100  bug-vfprintf-nargs \
101  bug1 \
102  bug10 \
103  bug11 \
104  bug12 \
105  bug13 \
106  bug14 \
107  bug16 \
108  bug17 \
109  bug18 \
110  bug18a \
111  bug19 \
112  bug19a \
113  bug2 \
114  bug20 \
115  bug21 \
116  bug22 \
117  bug23 \
118  bug23-2 \
119  bug23-3 \
120  bug23-4 \
121  bug24 \
122  bug25 \
123  bug26 \
124  bug3 \
125  bug4 \
126  bug5 \
127  bug6 \
128  bug7 \
129  bug8 \
130  bug9 \
131  errnobug \
132  scanf1 \
133  scanf10 \
134  scanf11 \
135  scanf12 \
136  scanf13 \
137  scanf14 \
138  scanf14a \
139  scanf15 \
140  scanf16 \
141  scanf16a \
142  scanf17 \
143  scanf2 \
144  scanf3 \
145  scanf4 \
146  scanf5 \
147  scanf7 \
148  scanf8 \
149  scanf9 \
150  temptest \
151  test-fseek \
152  test-fwrite \
153  test-popen \
154  test-strerr \
155  test-vfprintf \
156  test_rdwr \
157  tfformat \
158  tiformat \
159  tllformat \
160  tst-bz11319 \
161  tst-bz11319-fortify2 \
162  tst-cookie \
163  tst-fdopen \
164  tst-ferror \
165  tst-fgets \
166  tst-fileno \
167  tst-fmemopen \
168  tst-fmemopen2 \
169  tst-fmemopen3 \
170  tst-fmemopen4 \
171  tst-fphex \
172  tst-fphex-wide \
173  tst-fseek \
174  tst-fwrite \
175  tst-gets \
176  tst-grouping \
177  tst-long-dbl-fphex \
178  tst-memstream-string \
179  tst-obprintf \
180  tst-perror \
181  tst-popen \
182  tst-popen2 \
183  tst-printf-binary \
184  tst-printf-bz18872 \
185  tst-printf-bz25691 \
186  tst-printf-fp-free \
187  tst-printf-fp-leak \
188  tst-printf-round \
189  tst-printfsz \
190  tst-put-error \
191  tst-renameat2 \
192  tst-rndseek \
193  tst-scanf-round \
194  tst-setvbuf1 \
195  tst-sprintf \
196  tst-sprintf-errno \
197  tst-sprintf2 \
198  tst-sprintf3 \
199  tst-sscanf \
200  tst-swprintf \
201  tst-swscanf \
202  tst-tmpnam \
203  tst-ungetc \
204  tst-unlockedio \
205  tst-vfprintf-mbs-prec \
206  tst-vfprintf-user-type \
207  tst-vfprintf-width-prec \
208  tst-vfprintf-width-prec-alloc \
209  tst-vfprintf-width-i18n \
210  tst-wc-printf \
211  tstdiomisc \
212  tstgetln \
213  tstscanf \
214  xbug \
215  # tests
216
217generated += \
218  errlist-data-aux-shared.S \
219  errlist-data-aux.S \
220  siglist-aux-shared.S \
221  siglist-aux.S \
222  # generated
223
224test-srcs = tst-unbputc tst-printf tst-printfsz-islongdouble
225
226ifeq ($(run-built-tests),yes)
227tests-special += \
228  $(objpfx)tst-printf-bz18872-mem.out \
229  $(objpfx)tst-printf-bz25691-mem.out \
230  $(objpfx)tst-printf-fp-free-mem.out \
231  $(objpfx)tst-printf-fp-leak-mem.out \
232  $(objpfx)tst-printf.out \
233  $(objpfx)tst-printfsz-islongdouble.out \
234  $(objpfx)tst-setvbuf1-cmp.out \
235  $(objpfx)tst-unbputc.out \
236  $(objpfx)tst-vfprintf-width-prec-mem.out \
237  # tests-special
238
239generated += \
240  tst-printf-bz18872-mem.out \
241  tst-printf-bz18872.c \
242  tst-printf-bz18872.mtrace \
243  tst-printf-bz25691-mem.out \
244  tst-printf-bz25691.mtrace \
245  tst-printf-fp-free-mem.out \
246  tst-printf-fp-free.mtrace \
247  tst-printf-fp-leak-mem.out \
248  tst-printf-fp-leak.mtrace \
249  tst-vfprintf-width-prec-mem.out \
250  tst-vfprintf-width-prec.mtrace \
251  # generated
252endif # $(run-built-tests)
253
254tests-special += $(objpfx)tst-errno-manual.out
255
256include ../Rules
257
258# The errlist.c is built in two phases because compiler might reorder the
259# compat_symbol directive prior the object itself and on binutils older
260# than 2.29 it might generate object sizes different than the expected ones.
261$(objpfx)errlist-data-aux-shared.S: errlist-data-gen.c
262	$(make-target-directory)
263	$(compile-command.c) $(pic-cppflags) $(pic-ccflag) $(no-stack-protector) -S
264
265$(objpfx)errlist-data-aux.S: errlist-data-gen.c
266	$(make-target-directory)
267	$(compile-command.c) $(pie-default) $(no-stack-protector) -S
268
269$(objpfx)errlist-data.os: $(objpfx)errlist-data-aux-shared.S
270$(objpfx)errlist-data.o: $(objpfx)errlist-data-aux.S
271
272$(objpfx)siglist-aux-shared.S: siglist-gen.c
273	$(make-target-directory)
274	$(compile-command.c) $(pic-cppflags) $(pic-ccflag) $(no-stack-protector) -S
275
276$(objpfx)siglist-aux.S: siglist-gen.c
277	$(make-target-directory)
278	$(compile-command.c) $(pie-default) $(no-stack-protector) -S
279
280$(objpfx)siglist.os: $(objpfx)siglist-aux-shared.S
281$(objpfx)siglist.o: $(objpfx)siglist-aux.S
282
283ifeq ($(run-built-tests),yes)
284LOCALES := \
285  de_DE.ISO-8859-1 \
286  de_DE.UTF-8 \
287  en_US.ISO-8859-1 \
288  hi_IN.UTF-8 \
289  ja_JP.EUC-JP \
290  ps_AF.UTF-8 \
291  # LOCALES
292include ../gen-locales.mk
293
294$(objpfx)bug14.out: $(gen-locales)
295$(objpfx)scanf13.out: $(gen-locales)
296$(objpfx)test-vfprintf.out: $(gen-locales)
297$(objpfx)tst-grouping.out: $(gen-locales)
298$(objpfx)tst-sprintf.out: $(gen-locales)
299$(objpfx)tst-sscanf.out: $(gen-locales)
300$(objpfx)tst-swprintf.out: $(gen-locales)
301$(objpfx)tst-vfprintf-mbs-prec.out: $(gen-locales)
302$(objpfx)tst-vfprintf-width-i18n.out: $(gen-locales)
303endif
304
305tst-printf-bz18872-ENV = MALLOC_TRACE=$(objpfx)tst-printf-bz18872.mtrace \
306			LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
307tst-vfprintf-width-prec-ENV = \
308  MALLOC_TRACE=$(objpfx)tst-vfprintf-width-prec.mtrace \
309  LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
310tst-printf-bz25691-ENV = \
311  MALLOC_TRACE=$(objpfx)tst-printf-bz25691.mtrace \
312  LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
313tst-printf-fp-free-ENV = \
314  MALLOC_TRACE=$(objpfx)tst-printf-fp-free.mtrace \
315  LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
316tst-printf-fp-leak-ENV = \
317  MALLOC_TRACE=$(objpfx)tst-printf-fp-leak.mtrace \
318  LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
319
320$(objpfx)tst-unbputc.out: tst-unbputc.sh $(objpfx)tst-unbputc
321	$(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \
322	$(evaluate-test)
323
324$(objpfx)tst-printf.out: tst-printf.sh $(objpfx)tst-printf
325	$(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \
326	$(evaluate-test)
327
328$(objpfx)tst-printfsz-islongdouble.out: \
329  tst-printfsz-islongdouble.sh $(objpfx)tst-printfsz-islongdouble
330	$(SHELL) $^ '$(test-program-prefix)' $@; \
331	$(evaluate-test)
332
333# We generate this source because it requires a printf invocation with
334# 10K arguments.
335$(objpfx)tst-printf-bz18872.c: tst-printf-bz18872.sh
336	rm -f $@ && $(BASH) $^ > $@.new && mv $@.new $@
337
338$(objpfx)tst-%-mem.out: $(objpfx)tst-%.out
339	$(common-objpfx)malloc/mtrace $(objpfx)tst-$*.mtrace > $@; \
340	$(evaluate-test)
341
342errlist-h = $(firstword $(wildcard $(addsuffix /errlist.h,$(sysdirs) .)))
343
344$(objpfx)tst-errno-manual.out: tst-errno-manual.py \
345			       $(errlist-h) \
346			       $(..)manual/errno.texi
347	$(PYTHON) tst-errno-manual.py -m $(..)manual/errno.texi \
348				      -e $(errlist-h) > $@; \
349	$(evaluate-test)
350
351CFLAGS-vfprintf.c += -Wno-uninitialized
352CFLAGS-vfwprintf.c += -Wno-uninitialized
353
354CFLAGS-tmpfile.c += -fexceptions
355CFLAGS-tmpfile64.c += -fexceptions
356CFLAGS-tempname.c += -fexceptions
357CFLAGS-psignal.c += -fexceptions
358CFLAGS-vprintf.c += -fexceptions
359CFLAGS-cuserid.c += -fexceptions
360
361CFLAGS-vfprintf.c += -fexceptions
362CFLAGS-fprintf.c += -fexceptions
363CFLAGS-printf.c += -fexceptions
364CFLAGS-vfwprintf.c += -fexceptions
365CFLAGS-vfscanf.c += -fexceptions
366CFLAGS-vfwscanf.c += -fexceptions
367CFLAGS-fscanf.c += -fexceptions
368CFLAGS-scanf.c += -fexceptions
369CFLAGS-isoc99_vfscanf.c += -fexceptions
370CFLAGS-isoc99_vscanf.c += -fexceptions
371CFLAGS-isoc99_fscanf.c += -fexceptions
372CFLAGS-isoc99_scanf.c += -fexceptions
373
374# scanf14a.c and scanf16a.c test a deprecated extension which is no
375# longer visible under most conformance levels; see the source files
376# for more detail.
377CFLAGS-scanf14a.c += -std=gnu89
378CFLAGS-scanf16a.c += -std=gnu89
379
380CFLAGS-bug3.c += -DOBJPFX=\"$(objpfx)\"
381CFLAGS-bug4.c += -DOBJPFX=\"$(objpfx)\"
382CFLAGS-bug5.c += -DOBJPFX=\"$(objpfx)\"
383CFLAGS-test-fseek.c += -DOBJPFX=\"$(objpfx)\"
384CFLAGS-test-popen.c += -DOBJPFX=\"$(objpfx)\"
385CFLAGS-test_rdwr.c += -DOBJPFX=\"$(objpfx)\"
386
387# tst-gets.c tests a deprecated function.
388CFLAGS-tst-gets.c += -Wno-deprecated-declarations
389
390# BZ #11319 was first fixed for regular vdprintf, then reopened because
391# the fortified version had the same bug.
392CFLAGS-tst-bz11319-fortify2.c += -D_FORTIFY_SOURCE=2
393
394CFLAGS-tst-memstream-string.c += -fno-builtin-fprintf
395
396CPPFLAGS += $(libio-mtsafe)
397
398$(objpfx)tst-setvbuf1.out: /dev/null $(objpfx)tst-setvbuf1
399	$(test-program-cmd) > $@ 2>&1; \
400	$(evaluate-test)
401
402$(objpfx)tst-setvbuf1-cmp.out: tst-setvbuf1.expect $(objpfx)tst-setvbuf1.out
403	cmp $^ > $@; \
404	$(evaluate-test)
405
406$(objpfx)tst-printf-round: $(libm)
407$(objpfx)tst-scanf-round: $(libm)
408