Fix namespace violation in stdio.h and sys/stat.h if build with optimization. [BZ...
[glibc.git] / posix / Makefile
blob605ddbade863d003b54dd7ffa2d79442d5d1846b
1 # Copyright (C) 1991-2020 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
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.
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.
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/>.
19 # Sub-makefile for POSIX portion of the library.
21 subdir := posix
23 include ../Makeconfig
25 headers := sys/utsname.h sys/times.h sys/wait.h sys/types.h unistd.h \
26 glob.h regex.h wordexp.h fnmatch.h \
27 getopt.h bits/getopt_core.h bits/getopt_ext.h bits/getopt_posix.h \
28 bits/types.h bits/typesizes.h bits/pthreadtypes.h \
29 bits/pthreadtypes-arch.h bits/thread-shared-types.h \
30 bits/posix1_lim.h bits/posix2_lim.h bits/posix_opt.h \
31 bits/local_lim.h tar.h bits/utsname.h bits/confname.h \
32 bits/waitflags.h bits/waitstatus.h sys/unistd.h sched.h \
33 bits/sched.h bits/cpu-set.h re_comp.h wait.h bits/environments.h \
34 cpio.h spawn.h bits/unistd.h bits/types/struct_sched_param.h \
35 bits/unistd_ext.h
37 routines := \
38 uname \
39 times \
40 wait waitpid wait3 wait4 waitid \
41 alarm sleep pause nanosleep \
42 fork vfork _exit \
43 execve fexecve execv execle execl execvp execlp execvpe \
44 getpid getppid \
45 getuid geteuid getgid getegid getgroups setuid setgid group_member \
46 getpgid setpgid getpgrp bsd-getpgrp setpgrp getsid setsid \
47 getresuid getresgid setresuid setresgid \
48 pathconf sysconf fpathconf \
49 glob glob64 globfree globfree64 glob_pattern_p fnmatch regex \
50 glob-lstat-compat glob64-lstat-compat \
51 confstr \
52 getopt getopt1 \
53 sched_setp sched_getp sched_sets sched_gets sched_yield sched_primax \
54 sched_primin sched_rr_gi sched_getaffinity sched_setaffinity \
55 getaddrinfo gai_strerror wordexp \
56 pread pwrite pread64 pwrite64 \
57 spawn_faction_init spawn_faction_destroy spawn_faction_addclose \
58 spawn_faction_addopen spawn_faction_adddup2 spawn_valid_fd \
59 spawn_faction_addchdir spawn_faction_addfchdir \
60 spawnattr_init spawnattr_destroy \
61 spawnattr_getdefault spawnattr_setdefault \
62 spawnattr_getflags spawnattr_setflags \
63 spawnattr_getpgroup spawnattr_setpgroup spawn spawnp spawni \
64 spawnattr_getsigmask spawnattr_getschedpolicy spawnattr_getschedparam \
65 spawnattr_setsigmask spawnattr_setschedpolicy spawnattr_setschedparam \
66 posix_madvise \
67 get_child_max sched_cpucount sched_cpualloc sched_cpufree \
68 streams-compat
70 aux := init-posix environ
71 tests := test-errno tstgetopt testfnm runtests runptests \
72 tst-preadwrite tst-preadwrite64 test-vfork regexbug1 \
73 tst-mmap tst-mmap-offset tst-getaddrinfo tst-truncate \
74 tst-truncate64 tst-fork tst-fnmatch tst-regexloc tst-dir \
75 tst-chmod bug-regex1 bug-regex2 bug-regex3 bug-regex4 \
76 tst-gnuglob tst-gnuglob64 tst-regex bug-regex6 bug-regex7 \
77 bug-regex8 bug-regex9 bug-regex10 bug-regex11 bug-regex12 \
78 bug-regex13 bug-regex14 bug-regex15 bug-regex16 \
79 bug-regex17 bug-regex18 bug-regex19 \
80 bug-regex21 bug-regex22 bug-regex23 bug-regex24 \
81 bug-regex25 bug-regex26 bug-regex27 bug-regex28 \
82 bug-regex29 bug-regex30 bug-regex31 bug-regex32 \
83 tst-nice tst-nanosleep tst-regex2 \
84 transbug tst-rxspencer tst-pcre tst-boost \
85 bug-ga1 tst-vfork1 tst-vfork2 tst-vfork3 \
86 tst-waitid tst-wait4 \
87 tst-getaddrinfo2 bug-glob2 bug-glob3 tst-sysconf \
88 tst-execvp1 tst-execvp2 tst-execlp1 tst-execlp2 \
89 tst-execv1 tst-execv2 tst-execl1 tst-execl2 \
90 tst-execve1 tst-execve2 tst-execle1 tst-execle2 \
91 tst-execvp3 tst-execvp4 \
92 tst-execvpe1 tst-execvpe2 tst-execvpe3 tst-execvpe4 \
93 tst-execvpe5 tst-execvpe6 \
94 tst-getaddrinfo3 tst-fnmatch2 tst-cpucount tst-cpuset \
95 bug-getopt1 bug-getopt2 bug-getopt3 bug-getopt4 \
96 bug-getopt5 tst-getopt_long1 bug-regex34 bug-regex35 \
97 tst-pathconf tst-rxspencer-no-utf8 \
98 tst-fnmatch3 bug-regex36 \
99 tst-fnmatch4 tst-fnmatch5 \
100 tst-posix_spawn-fd tst-posix_spawn-setsid \
101 tst-posix_fadvise tst-posix_fadvise64 \
102 tst-sysconf-empty-chroot tst-glob_symlinks tst-fexecve \
103 tst-glob-tilde test-ssize-max tst-spawn4 bug-regex37 \
104 bug-regex38 tst-regcomp-truncated tst-spawn-chdir \
105 tst-wordexp-nocmd
106 tests-internal := bug-regex5 bug-regex20 bug-regex33 \
107 tst-rfc3484 tst-rfc3484-2 tst-rfc3484-3 \
108 tst-glob_lstat_compat tst-spawn4-compat
109 xtests := bug-ga2 tst-getaddrinfo4 tst-getaddrinfo5
110 ifeq (yes,$(build-shared))
111 test-srcs := globtest
112 tests += wordexp-test tst-exec tst-spawn tst-spawn2 tst-spawn3
113 endif
114 ifeq (yesyes,$(build-shared)$(have-thread-library))
115 tests += tst-getopt-cancel
116 endif
117 tests-static = tst-exec-static tst-spawn-static
118 tests += $(tests-static)
119 others := getconf
120 install-bin := getconf
121 install-others-programs := $(inst_libexecdir)/getconf
123 before-compile += $(objpfx)posix-conf-vars-def.h
125 # So they get cleaned up.
126 generated += $(addprefix wordexp-test-result, 1 2 3 4 5 6 7 8 9 10) \
127 annexc annexc.out wordexp-tst.out bug-regex2-mem.out \
128 bug-regex2.mtrace bug-regex14-mem.out bug-regex14.mtrace \
129 bug-regex21-mem.out bug-regex21.mtrace \
130 bug-regex31-mem.out bug-regex31.mtrace \
131 tst-rxspencer-no-utf8-mem.out tst-rxspencer-no-utf8.mtrace \
132 tst-getconf.out \
133 tst-pcre-mem.out tst-pcre.mtrace tst-boost-mem.out \
134 tst-boost.mtrace bug-ga2.mtrace bug-ga2-mem.out \
135 bug-glob2.mtrace bug-glob2-mem.out tst-vfork3-mem.out \
136 tst-vfork3.mtrace getconf.speclist tst-fnmatch-mem.out \
137 tst-fnmatch.mtrace bug-regex36.mtrace \
138 testcases.h ptestcases.h
140 ifeq ($(run-built-tests),yes)
141 ifeq (yes,$(build-shared))
142 tests-special += $(objpfx)globtest.out $(objpfx)wordexp-tst.out
143 endif
144 endif
146 # Run a test on the header files we use.
147 # XXX Please note that for now we ignore the result of this test.
148 tests-special += $(objpfx)annexc.out
149 ifeq ($(run-built-tests),yes)
150 tests-special += $(objpfx)bug-regex2-mem.out $(objpfx)bug-regex14-mem.out \
151 $(objpfx)bug-regex21-mem.out $(objpfx)bug-regex31-mem.out \
152 $(objpfx)tst-rxspencer-no-utf8-mem.out $(objpfx)tst-pcre-mem.out \
153 $(objpfx)tst-boost-mem.out $(objpfx)tst-getconf.out \
154 $(objpfx)bug-glob2-mem.out $(objpfx)tst-vfork3-mem.out \
155 $(objpfx)tst-fnmatch-mem.out $(objpfx)bug-regex36-mem.out \
156 $(objpfx)tst-glob-tilde-mem.out
157 xtests-special += $(objpfx)bug-ga2-mem.out
158 endif
160 include ../Rules
162 ifeq ($(run-built-tests),yes)
163 # globtest and wordexp-test currently only works with shared libraries
164 ifeq (yes,$(build-shared))
165 $(objpfx)globtest.out: globtest.sh $(objpfx)globtest
166 $(SHELL) $< $(common-objpfx) '$(test-via-rtld-prefix)' \
167 '$(test-program-prefix)' '$(test-wrapper-env)' > $@; \
168 $(evaluate-test)
169 $(objpfx)wordexp-tst.out: wordexp-tst.sh $(objpfx)wordexp-test
170 $(SHELL) $< $(common-objpfx) '$(test-program-prefix-before-env)' \
171 '$(run-program-env)' '$(test-program-prefix-after-env)' > $@; \
172 $(evaluate-test)
173 endif
175 LOCALES := cs_CZ.UTF-8 da_DK.ISO-8859-1 de_DE.ISO-8859-1 de_DE.UTF-8 \
176 en_US.UTF-8 es_US.ISO-8859-1 es_US.UTF-8 ja_JP.EUC-JP tr_TR.UTF-8 \
177 cs_CZ.ISO-8859-2
178 include ../gen-locales.mk
180 $(objpfx)bug-regex1.out: $(gen-locales)
181 $(objpfx)bug-regex4.out: $(gen-locales)
182 $(objpfx)bug-regex5.out: $(gen-locales)
183 $(objpfx)bug-regex6.out: $(gen-locales)
184 $(objpfx)bug-regex17.out: $(gen-locales)
185 $(objpfx)bug-regex18.out: $(gen-locales)
186 $(objpfx)bug-regex19.out: $(gen-locales)
187 $(objpfx)bug-regex20.out: $(gen-locales)
188 $(objpfx)bug-regex22.out: $(gen-locales)
189 $(objpfx)bug-regex23.out: $(gen-locales)
190 $(objpfx)bug-regex25.out: $(gen-locales)
191 $(objpfx)bug-regex26.out: $(gen-locales)
192 $(objpfx)bug-regex30.out: $(gen-locales)
193 $(objpfx)bug-regex32.out: $(gen-locales)
194 $(objpfx)bug-regex33.out: $(gen-locales)
195 $(objpfx)bug-regex34.out: $(gen-locales)
196 $(objpfx)bug-regex35.out: $(gen-locales)
197 $(objpfx)tst-fnmatch.out: $(gen-locales)
198 $(objpfx)tst-fnmatch4.out: $(gen-locales)
199 $(objpfx)tst-fnmatch5.out: $(gen-locales)
200 $(objpfx)tst-regex.out: $(gen-locales)
201 $(objpfx)tst-regex2.out: $(gen-locales)
202 $(objpfx)tst-regexloc.out: $(gen-locales)
203 $(objpfx)tst-rxspencer.out: $(gen-locales)
204 $(objpfx)tst-rxspencer-no-utf8.out: $(gen-locales)
205 $(objpfx)tst-regcomp-truncated.out: $(gen-locales)
206 endif
208 # If we will use the generic uname implementation, we must figure out what
209 # it will say by examining the system, and write the results in config-name.h.
210 uname.c: $(objpfx)config-name.h
211 $(objpfx)config-name.h: $(..)scripts/config-uname.sh $(common-objpfx)config.make
212 $(make-target-directory)
213 $< '$(config-os)' '$(config-release)' \
214 '$(config-machine)-$(config-vendor)' > $@.new
215 mv -f $@.new $@
217 CFLAGS-getaddrinfo.c += -DRESOLVER -fexceptions
218 CFLAGS-pause.c += -fexceptions -fasynchronous-unwind-tables
219 CFLAGS-pread.c += -fexceptions -fasynchronous-unwind-tables
220 CFLAGS-pread64.c += -fexceptions -fasynchronous-unwind-tables
221 CFLAGS-pwrite.c += -fexceptions -fasynchronous-unwind-tables
222 CFLAGS-pwrite64.c += -fexceptions -fasynchronous-unwind-tables
223 CFLAGS-sleep.c += -fexceptions
224 CFLAGS-wait.c += -fexceptions -fasynchronous-unwind-tables
225 CFLAGS-waitid.c += -fexceptions -fasynchronous-unwind-tables
226 CFLAGS-waitpid.c += -fexceptions -fasynchronous-unwind-tables
227 CFLAGS-wait4.c += -fexceptions -fasynchronous-unwind-tables
228 CFLAGS-getopt.c += -fexceptions
229 CFLAGS-wordexp.c += -fexceptions
230 CFLAGS-wordexp.os = -fomit-frame-pointer
231 CFLAGS-sysconf.c += -fexceptions -DGETCONF_DIR='"$(libexecdir)/getconf"'
232 CFLAGS-pathconf.c += -fexceptions
233 CFLAGS-fpathconf.c += -fexceptions
234 CFLAGS-spawn.c += -fexceptions
235 CFLAGS-spawn.os = -fomit-frame-pointer
236 CFLAGS-spawnp.c += -fexceptions
237 CFLAGS-spawnp.os = -fomit-frame-pointer
238 CFLAGS-spawni.c += -fexceptions
239 CFLAGS-spawni.os = -fomit-frame-pointer
240 CFLAGS-glob.c += $(uses-callbacks) -fexceptions
241 CFLAGS-glob64.c += $(uses-callbacks) -fexceptions
242 CFLAGS-getconf.c += -DGETCONF_DIR='"$(libexecdir)/getconf"'
243 CFLAGS-execve.os = -fomit-frame-pointer
244 CFLAGS-fexecve.os = -fomit-frame-pointer
245 CFLAGS-execv.os = -fomit-frame-pointer
246 CFLAGS-execle.os = -fomit-frame-pointer
247 CFLAGS-execl.os = -fomit-frame-pointer
248 CFLAGS-execvp.os = -fomit-frame-pointer
249 CFLAGS-execlp.os = -fomit-frame-pointer
250 CFLAGS-nanosleep.c += -fexceptions -fasynchronous-unwind-tables
252 tstgetopt-ARGS = -a -b -cfoobar --required foobar --optional=bazbug \
253 --none random --col --color --colour
255 tst-exec-ARGS = -- $(host-test-program-cmd)
256 tst-exec-static-ARGS = $(tst-exec-ARGS)
257 tst-execvpe5-ARGS = -- $(host-test-program-cmd)
258 tst-spawn-ARGS = -- $(host-test-program-cmd)
259 tst-spawn-static-ARGS = $(tst-spawn-ARGS)
260 tst-dir-ARGS = `pwd` `cd $(common-objdir)/$(subdir); pwd` `cd $(common-objdir); pwd` $(objpfx)tst-dir
261 tst-chmod-ARGS = $(objdir)
262 tst-vfork3-ARGS = --test-dir=$(objpfx)
264 tst-rxspencer-ARGS = --utf8 rxspencer/tests
265 tst-rxspencer-no-utf8-ARGS = rxspencer/tests
266 tst-pcre-ARGS = PCRE.tests
267 tst-boost-ARGS = BOOST.tests
268 bug-glob1-ARGS = "$(objpfx)"
269 tst-execvp3-ARGS = --test-dir=$(objpfx)
270 CFLAGS-tst-spawn3.c += -DOBJPFX=\"$(objpfx)\"
272 $(objpfx)testcases.h: TESTS TESTS2C.sed
273 LC_ALL=C sed -f TESTS2C.sed < $< > $@T
274 mv $@T $@
275 $(objpfx)runtests.o: $(objpfx)testcases.h
277 $(objpfx)ptestcases.h: PTESTS PTESTS2C.sed
278 LC_ALL=C sed -f PTESTS2C.sed < $< > $@T
279 mv $@T $@
280 $(objpfx)runptests.o: $(objpfx)ptestcases.h
282 $(objpfx)tst-getopt-cancel: $(shared-thread-library)
284 test-xfail-annexc = yes
285 $(objpfx)annexc.out: $(objpfx)annexc
286 $(dir $<)$(notdir $<) '$(CC)' \
287 '$(patsubst %,-I../%,$(sorted-subdirs)) -I../include $(+sysdep-includes) $(sysincludes) -I..' > $@; \
288 $(evaluate-test)
290 annexc-CFLAGS = -O
291 $(objpfx)annexc: annexc.c
292 $(native-compile)
294 tst-fnmatch-ENV += MALLOC_TRACE=$(objpfx)tst-fnmatch.mtrace
296 $(objpfx)tst-fnmatch-mem.out: $(objpfx)tst-fnmatch.out
297 $(common-objpfx)malloc/mtrace $(objpfx)tst-fnmatch.mtrace > $@; \
298 $(evaluate-test)
300 bug-regex2-ENV = MALLOC_TRACE=$(objpfx)bug-regex2.mtrace
302 $(objpfx)bug-regex2-mem.out: $(objpfx)bug-regex2.out
303 $(common-objpfx)malloc/mtrace $(objpfx)bug-regex2.mtrace > $@; \
304 $(evaluate-test)
306 bug-regex14-ENV = MALLOC_TRACE=$(objpfx)bug-regex14.mtrace
308 $(objpfx)bug-regex14-mem.out: $(objpfx)bug-regex14.out
309 $(common-objpfx)malloc/mtrace $(objpfx)bug-regex14.mtrace > $@; \
310 $(evaluate-test)
312 bug-regex21-ENV = MALLOC_TRACE=$(objpfx)bug-regex21.mtrace
314 $(objpfx)bug-regex21-mem.out: $(objpfx)bug-regex21.out
315 $(common-objpfx)malloc/mtrace $(objpfx)bug-regex21.mtrace > $@; \
316 $(evaluate-test)
318 bug-regex31-ENV = MALLOC_TRACE=$(objpfx)bug-regex31.mtrace
320 $(objpfx)bug-regex31-mem.out: $(objpfx)bug-regex31.out
321 $(common-objpfx)malloc/mtrace $(objpfx)bug-regex31.mtrace > $@; \
322 $(evaluate-test)
324 bug-regex36-ENV = MALLOC_TRACE=$(objpfx)bug-regex36.mtrace
326 $(objpfx)bug-regex36-mem.out: $(objpfx)bug-regex36.out
327 $(common-objpfx)malloc/mtrace $(objpfx)bug-regex36.mtrace > $@; \
328 $(evaluate-test)
330 tst-vfork3-ENV = MALLOC_TRACE=$(objpfx)tst-vfork3.mtrace
332 $(objpfx)tst-vfork3-mem.out: $(objpfx)tst-vfork3.out
333 $(common-objpfx)malloc/mtrace $(objpfx)tst-vfork3.mtrace > $@; \
334 $(evaluate-test)
336 # tst-rxspencer.mtrace is not generated, only
337 # tst-rxspencer-no-utf8.mtrace, since otherwise the file has almost
338 # 100M and takes very long time to process.
339 tst-rxspencer-no-utf8-ENV += MALLOC_TRACE=$(objpfx)tst-rxspencer-no-utf8.mtrace
340 $(objpfx)tst-rxspencer-no-utf8-mem.out: $(objpfx)tst-rxspencer-no-utf8.out
341 $(common-objpfx)malloc/mtrace $(objpfx)tst-rxspencer-no-utf8.mtrace \
342 > $@; \
343 $(evaluate-test)
345 tst-pcre-ENV = MALLOC_TRACE=$(objpfx)tst-pcre.mtrace
346 $(objpfx)tst-pcre-mem.out: $(objpfx)tst-pcre.out
347 $(common-objpfx)malloc/mtrace $(objpfx)tst-pcre.mtrace > $@; \
348 $(evaluate-test)
350 tst-boost-ENV = MALLOC_TRACE=$(objpfx)tst-boost.mtrace
351 $(objpfx)tst-boost-mem.out: $(objpfx)tst-boost.out
352 $(common-objpfx)malloc/mtrace $(objpfx)tst-boost.mtrace > $@; \
353 $(evaluate-test)
355 $(objpfx)tst-getconf.out: tst-getconf.sh $(objpfx)getconf
356 $(SHELL) $< $(common-objpfx) '$(built-program-cmd)' > $@; \
357 $(evaluate-test)
359 $(objpfx)bug-ga2-mem.out: $(objpfx)bug-ga2.out
360 $(common-objpfx)malloc/mtrace $(objpfx)bug-ga2.mtrace > $@; \
361 $(evaluate-test)
363 bug-ga2-ENV = MALLOC_TRACE=$(objpfx)bug-ga2.mtrace
365 bug-glob2-ENV = MALLOC_TRACE=$(objpfx)bug-glob2.mtrace
367 $(objpfx)bug-glob2-mem.out: $(objpfx)bug-glob2.out
368 $(common-objpfx)malloc/mtrace $(objpfx)bug-glob2.mtrace > $@; \
369 $(evaluate-test)
371 tst-glob-tilde-ENV = MALLOC_TRACE=$(objpfx)tst-glob-tilde.mtrace
373 $(objpfx)tst-glob-tilde-mem.out: $(objpfx)tst-glob-tilde.out
374 $(common-objpfx)malloc/mtrace $(objpfx)tst-glob-tilde.mtrace > $@; \
375 $(evaluate-test)
377 $(inst_libexecdir)/getconf: $(inst_bindir)/getconf \
378 $(objpfx)getconf.speclist FORCE
379 $(addprefix $(..)./scripts/mkinstalldirs ,\
380 $(filter-out $(wildcard $@),$@))
381 while read spec; do \
382 ln -f $< $@/$$spec.new || $(INSTALL_PROGRAM) $< $@/$$spec.new; \
383 mv -f $@/$$spec.new $@/$$spec; \
384 done < $(objpfx)getconf.speclist
386 $(objpfx)getconf.speclist: getconf-speclist.c posix-envs.def
387 $(compile.c) -E -o - \
388 | sed -n -e '/@@@PRESENT_/s/@@@PRESENT_//p' > $@.new
389 mv -f $@.new $@
391 # This file is only actually needed at install time. But forcing it to
392 # be built both makes it available for eyeball inspection and avoids the
393 # surprise of things that look like compilation being done by 'make install'.
394 others: $(objpfx)getconf.speclist
396 $(objpfx)posix-conf-vars-def.h: $(..)scripts/gen-posix-conf-vars.awk \
397 posix-conf-vars.list Makefile
398 $(make-target-directory)
399 $(AWK) -f $(filter-out Makefile, $^) > $@.tmp
400 mv -f $@.tmp $@