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#	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	ctermid cuserid							      \
29	_itoa _itowa itoa-digits itoa-udigits itowa-digits		      \
30	vfprintf vprintf printf_fp reg-printf printf-prs printf_fphex	      \
31	reg-modifier reg-type						      \
32	printf_size fprintf printf snprintf sprintf asprintf dprintf	      \
33	vfwprintf vfscanf vfwscanf					      \
34	fscanf scanf sscanf						      \
35	perror psignal							      \
36	tmpfile tmpfile64 tmpnam tmpnam_r tempnam tempname		      \
37	getline getw putw						      \
38	remove rename renameat renameat2				      \
39	flockfile ftrylockfile funlockfile				      \
40	isoc99_scanf isoc99_vscanf isoc99_fscanf isoc99_vfscanf isoc99_sscanf \
41	isoc99_vsscanf							      \
42	psiginfo gentempfd						      \
43	vfscanf-internal vfwscanf-internal iovfscanf			      \
44	vfprintf-internal vfwprintf-internal
45
46aux	:= errlist siglist printf-parsemb printf-parsewc fxprintf
47
48tests := tstscanf test_rdwr test-popen tstgetln test-fseek \
49	 temptest tst-fileno test-fwrite tst-ungetc tst-ferror \
50	 xbug errnobug \
51	 bug1 bug2 bug3 bug4 bug5 bug6 bug7 bug8 bug9 bug10 bug11 bug12 bug13 \
52	 tfformat tiformat tllformat tstdiomisc tst-printfsz tst-wc-printf \
53	 scanf1 scanf2 scanf3 scanf4 scanf5 scanf7 scanf8 scanf9 scanf10 \
54	 scanf11 scanf12 tst-tmpnam tst-cookie tst-obprintf tst-sscanf \
55	 tst-swprintf tst-fseek tst-fmemopen test-vfprintf tst-gets \
56	 tst-perror tst-sprintf tst-rndseek tst-fdopen tst-fphex bug14 \
57	 tst-popen tst-unlockedio tst-fmemopen2 tst-put-error tst-fgets \
58	 tst-fwrite bug16 bug17 tst-swscanf tst-sprintf2 bug18 bug18a \
59	 bug19 bug19a tst-popen2 scanf13 scanf14 scanf15 bug20 bug21 bug22 \
60	 scanf16 scanf17 tst-setvbuf1 tst-grouping bug23 bug24 \
61	 bug-vfprintf-nargs tst-long-dbl-fphex tst-fphex-wide tst-sprintf3 \
62	 bug25 tst-printf-round bug23-2 bug23-3 bug23-4 bug26 tst-fmemopen3 \
63	 tst-printf-bz18872 tst-vfprintf-width-prec tst-fmemopen4 \
64	 tst-vfprintf-user-type \
65	 tst-vfprintf-mbs-prec \
66	 tst-scanf-round \
67	 tst-renameat2 tst-bz11319 tst-bz11319-fortify2 \
68	 scanf14a scanf16a \
69	 tst-printf-bz25691 \
70	 tst-vfprintf-width-prec-alloc \
71	 tst-printf-fp-free \
72	 tst-printf-fp-leak \
73	 test-strerr \
74	 tst-printf-binary \
75	 tst-sprintf-errno \
76	 # tests
77
78
79test-srcs = tst-unbputc tst-printf tst-printfsz-islongdouble
80
81ifeq ($(run-built-tests),yes)
82tests-special += $(objpfx)tst-unbputc.out $(objpfx)tst-printf.out \
83		 $(objpfx)tst-printf-bz18872-mem.out \
84		 $(objpfx)tst-setvbuf1-cmp.out \
85		 $(objpfx)tst-vfprintf-width-prec-mem.out \
86		 $(objpfx)tst-printfsz-islongdouble.out \
87		 $(objpfx)tst-printf-bz25691-mem.out \
88		 $(objpfx)tst-printf-fp-free-mem.out \
89		 $(objpfx)tst-printf-fp-leak-mem.out
90generated += tst-printf-bz18872.c tst-printf-bz18872.mtrace \
91	     tst-printf-bz18872-mem.out \
92	     tst-vfprintf-width-prec.mtrace tst-vfprintf-width-prec-mem.out \
93	     tst-printf-bz25691.mtrace tst-printf-bz25691-mem.out \
94	     tst-printf-fp-free.mtrace tst-printf-fp-free-mem.out \
95	     tst-printf-fp-leak.mtrace tst-printf-fp-leak-mem.out
96endif
97
98tests-special += $(objpfx)tst-errno-manual.out
99
100include ../Rules
101
102ifeq ($(run-built-tests),yes)
103LOCALES := de_DE.ISO-8859-1 de_DE.UTF-8 en_US.ISO-8859-1 ja_JP.EUC-JP
104include ../gen-locales.mk
105
106$(objpfx)bug14.out: $(gen-locales)
107$(objpfx)scanf13.out: $(gen-locales)
108$(objpfx)test-vfprintf.out: $(gen-locales)
109$(objpfx)tst-grouping.out: $(gen-locales)
110$(objpfx)tst-sprintf.out: $(gen-locales)
111$(objpfx)tst-sscanf.out: $(gen-locales)
112$(objpfx)tst-swprintf.out: $(gen-locales)
113$(objpfx)tst-vfprintf-mbs-prec.out: $(gen-locales)
114endif
115
116tst-printf-bz18872-ENV = MALLOC_TRACE=$(objpfx)tst-printf-bz18872.mtrace \
117			LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
118tst-vfprintf-width-prec-ENV = \
119  MALLOC_TRACE=$(objpfx)tst-vfprintf-width-prec.mtrace \
120  LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
121tst-printf-bz25691-ENV = \
122  MALLOC_TRACE=$(objpfx)tst-printf-bz25691.mtrace \
123  LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
124tst-printf-fp-free-ENV = \
125  MALLOC_TRACE=$(objpfx)tst-printf-fp-free.mtrace \
126  LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
127tst-printf-fp-leak-ENV = \
128  MALLOC_TRACE=$(objpfx)tst-printf-fp-leak.mtrace \
129  LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
130
131$(objpfx)tst-unbputc.out: tst-unbputc.sh $(objpfx)tst-unbputc
132	$(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \
133	$(evaluate-test)
134
135$(objpfx)tst-printf.out: tst-printf.sh $(objpfx)tst-printf
136	$(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \
137	$(evaluate-test)
138
139$(objpfx)tst-printfsz-islongdouble.out: \
140  tst-printfsz-islongdouble.sh $(objpfx)tst-printfsz-islongdouble
141	$(SHELL) $^ '$(test-program-prefix)' $@; \
142	$(evaluate-test)
143
144# We generate this source because it requires a printf invocation with
145# 10K arguments.
146$(objpfx)tst-printf-bz18872.c: tst-printf-bz18872.sh
147	rm -f $@ && $(BASH) $^ > $@.new && mv $@.new $@
148
149$(objpfx)tst-%-mem.out: $(objpfx)tst-%.out
150	$(common-objpfx)malloc/mtrace $(objpfx)tst-$*.mtrace > $@; \
151	$(evaluate-test)
152
153errlist-h = $(firstword $(wildcard $(addsuffix /errlist.h,$(sysdirs) .)))
154
155$(objpfx)tst-errno-manual.out: tst-errno-manual.py \
156			       $(errlist-h) \
157			       $(..)manual/errno.texi
158	$(PYTHON) tst-errno-manual.py -m $(..)manual/errno.texi \
159				      -e $(errlist-h) > $@; \
160	$(evaluate-test)
161
162CFLAGS-vfprintf.c += -Wno-uninitialized
163CFLAGS-vfwprintf.c += -Wno-uninitialized
164
165CFLAGS-tmpfile.c += -fexceptions
166CFLAGS-tmpfile64.c += -fexceptions
167CFLAGS-tempname.c += -fexceptions
168CFLAGS-psignal.c += -fexceptions
169CFLAGS-vprintf.c += -fexceptions
170CFLAGS-cuserid.c += -fexceptions
171
172CFLAGS-vfprintf.c += -fexceptions
173CFLAGS-fprintf.c += -fexceptions
174CFLAGS-printf.c += -fexceptions
175CFLAGS-vfwprintf.c += -fexceptions
176CFLAGS-vfscanf.c += -fexceptions
177CFLAGS-vfwscanf.c += -fexceptions
178CFLAGS-fscanf.c += -fexceptions
179CFLAGS-scanf.c += -fexceptions
180CFLAGS-isoc99_vfscanf.c += -fexceptions
181CFLAGS-isoc99_vscanf.c += -fexceptions
182CFLAGS-isoc99_fscanf.c += -fexceptions
183CFLAGS-isoc99_scanf.c += -fexceptions
184CFLAGS-errlist.c += $(fno-unit-at-a-time)
185CFLAGS-siglist.c += $(fno-unit-at-a-time)
186
187# scanf14a.c and scanf16a.c test a deprecated extension which is no
188# longer visible under most conformance levels; see the source files
189# for more detail.
190CFLAGS-scanf14a.c += -std=gnu89
191CFLAGS-scanf16a.c += -std=gnu89
192
193CFLAGS-bug3.c += -DOBJPFX=\"$(objpfx)\"
194CFLAGS-bug4.c += -DOBJPFX=\"$(objpfx)\"
195CFLAGS-bug5.c += -DOBJPFX=\"$(objpfx)\"
196CFLAGS-test-fseek.c += -DOBJPFX=\"$(objpfx)\"
197CFLAGS-test-popen.c += -DOBJPFX=\"$(objpfx)\"
198CFLAGS-test_rdwr.c += -DOBJPFX=\"$(objpfx)\"
199
200# tst-gets.c tests a deprecated function.
201CFLAGS-tst-gets.c += -Wno-deprecated-declarations
202
203# BZ #11319 was first fixed for regular vdprintf, then reopened because
204# the fortified version had the same bug.
205CFLAGS-tst-bz11319-fortify2.c += -D_FORTIFY_SOURCE=2
206
207CPPFLAGS += $(libio-mtsafe)
208
209$(objpfx)tst-setvbuf1.out: /dev/null $(objpfx)tst-setvbuf1
210	$(test-program-cmd) > $@ 2>&1; \
211	$(evaluate-test)
212
213$(objpfx)tst-setvbuf1-cmp.out: tst-setvbuf1.expect $(objpfx)tst-setvbuf1.out
214	cmp $^ > $@; \
215	$(evaluate-test)
216
217$(objpfx)tst-printf-round: $(libm)
218$(objpfx)tst-scanf-round: $(libm)
219