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