(open_socket): Use SOCK_CLOEXEC and SOCK_NONBLOCK if possible.
[glibc/history.git] / sysdeps / unix / Makefile
blob2696e7fb62f2d2aebeafaa1b9b0b95605d31971d
1 # Copyright (C) 1991,1992,1993,1994,1995,1996,1997,1998,1999,2003, 2006, 2008
2 # Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
5 # The GNU C Library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # The GNU C Library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with the GNU C Library; if not, write to the Free
17 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 # 02111-1307 USA.
20 # The unix-specific configure fragment writes `unix-generated' in config.make.
21 config-generated := $(config-generated) $(unix-generated)
23 ifeq (,$(filter-out $(sysdep_dir)/generic/ $(common-objpfx),\
24 $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/bits/local_lim.h))))))
26 ifneq (,$(wildcard $(sysincludedir)/sys/param.h))
27 mk-local_lim-CFLAGS += -DHAVE_SYS_PARAM_H
28 endif
29 ifneq (,$(wildcard $(sysincludedir)/sys/limits.h))
30 mk-local_lim-CFLAGS += -DHAVE_SYS_LIMITS_H
31 endif
32 ifneq (,$(wildcard $(sysincludedir)/limits.h))
33 mk-local_lim-CFLAGS += -DHAVE_LIMITS_H
34 endif
36 $(common-objpfx)bits/local_lim.h: $(common-objpfx)mk-local_lim
37 $(dir $<)$(notdir $<) > $@-t
38 mv -f $@-t $@
39 $(common-objpfx)mk-local_lim: $(sysdep_dir)/unix/mk-local_lim.c
40 $(common-objdir-compile)
42 before-compile += $(common-objpfx)bits/local_lim.h
43 common-generated += bits/local_lim.h mk-local_lim
45 endif
47 ifeq (,$(filter-out $(sysdep_dir)/generic/ $(common-objpfx),\
48 $(patsubst %/sys/param.h,%/,\
49 $(firstword $(wildcard $(+sysdep_dirs:%=%/sys/param.h))))))
51 before-compile := $(before-compile) $(common-objpfx)sys/param.h
53 $(common-objpfx)sys/param.h: $(sysincludedir)/sys/param.h
54 $(make-target-directory)
55 (echo '#ifndef _SYS_PARAM_H'; \
56 echo '#define _SYS_PARAM_H 1'; \
57 echo '#include <endian.h>'; \
58 $(AWK) < $< \
59 '/^#define[ ]*NULL/ { print "#ifndef NULL"; \
60 print $$0; \
61 print "#endif"; \
62 was_null = 1 } \
63 { if (!was_null) print $$0; \
64 was_null = 0 }'; \
65 echo '#ifndef MAXHOSTNAMELEN'; \
66 echo '#define MAXHOSTNAMELEN 64 /* XXX */'; \
67 echo '#endif /* No MAXHOSTNAMELEN. */'; \
68 echo '#endif /* sys/param.h */') > $@-tmp
69 mv $@-tmp $@
71 $(common-objpfx)param.h.c: $(sysincludedir)/sys/param.h
72 rm -f $@
73 cp $< $@
74 $(common-objpfx)param.h.dep: $(common-objpfx)param.h.c \
75 $(sysdep_dir)/unix/Makefile
76 $(+mkdep) -I$(sysincludedir) $< \
77 | sed > $@-t \
78 -e 's@$(sysincludedir)/sys/param.h@@' \
79 -e 's@^.*:@@' \
80 -e 's@$<@@g' \
81 -e 's@$(sysincludedir)/*@@g' \
82 -e 's@\\$$@@' \
83 -e 's@^@sys/param.h-includes := $$(sys/param.h-includes) @'
84 mv $@-t $@
86 # Get the generated definition of sys/param.h-includes.
87 ifndef no_deps
88 -include $(common-objpfx)param.h.dep
89 endif
91 # Don't preempt our own headers.
92 sys/param.h-includes := \
93 $(filter-out $(patsubst $(..)%,%,\
94 $(wildcard $(addprefix $(..),\
95 $(sys/param.h-includes)))),\
96 $(sys/param.h-includes))
99 .PHONY: sys/param.h-includes
100 sys/param.h-includes: $(addprefix $(common-objpfx),$(sys/param.h-includes))
102 ifdef sys/param.h-includes
103 # Copy the system files to $(common-objdir).
104 $(addprefix $(common-objpfx),$(sys/param.h-includes)): $(common-objpfx)%: \
105 $(sysincludedir)/%
106 $(make-target-directory)
107 # Some of these files sometimes contain conflicting declarations for htons,
108 # ntohs, etc. They also often contain definitions of *_ENDIAN and
109 # BYTE_ORDER, which we define ourselves in <endian.h>.
110 sed -e '/[ ]*[hn]to[nh][sl][ (]*/d' \
111 -e '/^#define[ ]*[A-Z]*_ENDIAN/d' \
112 -e '/^#define[ ]*BYTE_ORDER/d' \
113 $< > $@-t
114 mv $@-t $@
115 endif
117 common-generated := $(common-generated) \
118 sys/param.h $(sys/param.h-includes) param.h.c param.h.dep
121 ifeq ($(subdir),misc)
123 # Install system headers the system sys/param.h uses.
125 sysdep_headers := $(sysdep_headers) $(sys/param.h-includes)
127 endif # misc
129 endif # No sysdep sys/param.h.
131 ifeq (,$(filter-out $(sysdep_dir)/generic/ $(common-objpfx),\
132 $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/bits/errno.h))))))
134 # These need to exist before any compiling is done,
135 # so cpp doesn't instead find the generic versions.
136 before-compile := $(before-compile) $(common-objpfx)bits/errno.h
138 $(common-objpfx)bits/errno.h: $(common-objpfx)make-errnos
139 $(dir $<)$(notdir $<) > $@-tmp
140 mv $@-tmp $@
142 $(common-objpfx)make-errnos: $(common-objpfx)make-errnos.c
143 $(common-objdir-compile)
145 $(common-objpfx)make-errnos.c: $(sysdep_dir)/unix/errnos-tmpl.c \
146 $(sysdep_dir)/unix/errnos.awk $(common-objpfx)errnos
147 $(AWK) -f $(word 2,$^) errnos="`tr '\012' ' ' < $(word 3,$^)`" $< > $@T
148 mv $@T $@
150 $(common-objpfx)errnos: $(wildcard $(sysincludedir)/errno.h \
151 $(sysincludedir)/sys/errno.h)
152 sed -n 's/^#define[ ]*\(E[A-Z0-9][A-Z0-9]*\)[ ].*$$/\1/p' \
153 $^ > $@-tmp
154 mv $@-tmp $@
156 common-generated := $(common-generated) \
157 errnos.h errnos make-errnos make-errnos.c
158 endif
160 ifeq (,$(filter-out $(sysdep_dir)/generic/ $(common-objpfx),\
161 $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/bits/ioctls.h))))))
163 before-compile := $(before-compile) $(common-objpfx)bits/ioctls.h
165 $(common-objpfx)bits/ioctls.h: $(common-objpfx)make-ioctls
166 $(dir $<)$(notdir $<) > $@-tmp
167 mv $@-tmp $@
169 ioctl-includes := sys/termios.h net/nit.h
170 ioctl-includes := $(wildcard $(addprefix $(sysincludedir)/,$(ioctl-includes)))
171 make-ioctls-CFLAGS := $(subst /,_,$(subst .,_,\
172 $(patsubst $(sysincludedir)/%,-DHAVE_%,\
173 $(ioctl-includes))))
175 $(common-objpfx)make-ioctls: $(common-objpfx)make-ioctls.c
176 $(common-objdir-compile)
178 $(common-objpfx)make-ioctls.c: $(sysdep_dir)/unix/ioctls-tmpl.c \
179 $(sysdep_dir)/unix/ioctls.awk \
180 $(common-objpfx)ioctls
181 $(AWK) -f $(word 2,$^) requests="`cat $(word 3,$^)`" $< > $@T
182 mv $@T $@
185 bits_termios.h := $(firstword $(wildcard $(+sysdep_dirs:%=%/bits/termios.h)))
186 ifeq ($(bits_termios.h),$(sysdep_dir)/generic/bits/termios.h)
187 bits_termios.h := # Ignore the generic version.
188 endif
190 # If there is a system-specific <bits/termios.h> file, we want to omit
191 # all the symbols it defines from ioctls. Otherwise, both
192 # <bits/ioctls.h> and <bits/termios.h> would define them. The
193 # system-specific <bits/termios.h> file presumably defines them with
194 # the same values as we find from the system's headers. We also want
195 # to omit from ioctls the symbols defined in our own
196 # <sys/ttydefaults.h>, to avoid multiple definition conflicts. We use
197 # snarf-ioctls on these files to find what symbols we want to omit.
198 # fgrep -xv gives all lines which do not match in their entirety;
199 # without -x, CSTOP's presence elided TIOCSTOP.
201 $(common-objpfx)ioctls: $(sysdep_dir)/unix/snarf-ioctls \
202 $(sysincludedir)/sys/ioctl.h $(ioctl-includes)
203 $(dir $<)$(notdir $<) $(filter-out $<,$^) \
204 | fgrep -xv "`($(dir $<)$(notdir $<) $(bits_termios.h) \
205 $(..)sysdeps/generic/sys/ttydefaults.h; \
206 echo NULL) \
207 | sort | uniq`" \
208 | sort | uniq | tr '\012' ' ' > $@-tmp
209 mv $@-tmp $@
211 common-generated := $(common-generated) \
212 bits/ioctls.h ioctls make-ioctls make-ioctls.c
213 endif
215 ifeq (,$(filter-out $(sysdep_dir)/generic/ $(common-objpfx),\
216 $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/sys/syscall.h))))))
218 # The syscall code assumes a file <sys/syscall.h> that defines macros
219 # `SYS_call' for syscall `call'. Variations on this I have seen include:
220 # it's in <sys/syscall.h>;
221 # it's in <sys.s>;
222 # it defines `CALL' instead of `SYS_call'.
223 # Irix has a <syscall.h> which is not what we want, so check for <sys.s> first.
225 # Find a file that might have these. NOTE: This list of possibilities is
226 # repeated in sysdeps/unix/configure and the two should be kept in sync.
227 syscall.h := $(firstword $(wildcard $(addprefix $(sysincludedir)/, \
228 sys.s sys/sys.s \
229 sys.S sys/sys.S \
230 syscall.h sys/syscall.h \
232 ifdef syscall.h
234 # Transmogrify any of several formats of the file into the one we want.
235 $(common-objpfx)sys/syscall.h: $(syscall.h)
236 $(make-target-directory)
237 tr '[A-Z]' '[a-z]' < $< | \
238 sed -e 's/[ ]sys_/ /' \
239 -e 's/^#define[ ]*\([a-z0-9_]*\)[ ]*/#define SYS_\1 /' \
240 -e 's/[ ]sys_/ SYS_/' \
241 -e 's/SYS_syscall_basenum/syscall_basenum/g' \
242 -e 's/SYS_kerncall_basenum/kerncall_basenum/g' \
243 -e 's/SYS_sysvoffset/sysvoffset/g' \
244 -e '/^#/!d' \
245 -e '/^#ident/d' \
246 -e 's-\(/\*[^*]*\)$$-\1\*/-' \
247 > $@-tmp
248 mv $@-tmp $@
250 before-compile += $(common-objpfx)sys/syscall.h
251 common-generated += sys/syscall.h
253 endif
255 endif
257 ifndef inhibit-unix-syscalls
259 # Sysdep dirs unix/... can contain a file syscalls.list,
260 # which specifies objects to be compiled as simple Unix system calls.
262 -include $(common-objpfx)sysd-syscalls
263 omit-deps += $(foreach t,$(sysd-rules-targets),$(unix-syscalls:%=$t))
265 ifeq (misc,$(subdir))
266 sysdep_routines += $(unix-extra-syscalls)
268 ifdef unix-stub-syscalls
269 # The system call entry points in this list are supposed to be additional
270 # functions not overriding any other sysdeps/.../call.c implementation, but
271 # their system call numbers are unavailable in the kernel headers we're
272 # using. Instead of a system call stub, these get a function that fails
273 # with ENOSYS. We just generate a single module defining one function and
274 # making all these entry point names aliases for it.
275 sysdep_routines += stub-syscalls
276 $(objpfx)stub-syscalls.c: $(common-objpfx)sysd-syscalls \
277 $(..)sysdeps/unix/Makefile
278 $(make-target-directory)
279 (for call in $(unix-stub-syscalls); do \
280 echo "#define $$call RENAMED_$$call"; \
281 done; \
282 echo '#include <errno.h>'; \
283 for call in $(unix-stub-syscalls); do \
284 echo "#undef $$call"; \
285 done; \
286 echo 'long int _no_syscall (void)'; \
287 echo '{ __set_errno (ENOSYS); return -1L; }'; \
288 for call in $(unix-stub-syscalls); do \
289 case $$call in \
290 *@@*) ver=$${call##*@}; call=$${call%%*@}; \
291 echo "strong_alias (_no_syscall, $${call}_$${ver})"; \
292 echo "default_symbol_version \
293 ($${call}_$${ver}, $$call, $$ver);" ;; \
294 *@@*) ver=$${call##*@}; call=$${call%%*@}; \
295 echo "strong_alias (_no_syscall, $${call}_$${ver})"; \
296 echo "symbol_version ($${call}_$${ver}, $$call, $$ver);" ;; \
297 *) echo "weak_alias (_no_syscall, $$call)"; \
298 echo "stub_warning ($$call)"; \
299 echo "weak_alias (_no_syscall, __GI_$$call)" ;; \
300 esac; \
301 echo '#include <stub-tag.h>'; \
302 done) > $@T
303 mv -f $@T $@
304 generated += stub-syscalls.c
305 endif
306 endif
308 # This is the end of the pipeline for compiling the syscall stubs.
309 # The stdin in assembler with cpp using sysdep.h macros.
310 # Be sure to disable debugging info since it would all just say "<stdin>".
311 compile-syscall = $(filter-out -g%,$(COMPILE.S)) -x assembler-with-cpp -o $@ -
313 ifndef avoid-generated
314 $(common-objpfx)sysd-syscalls: $(..)sysdeps/unix/make-syscalls.sh \
315 $(wildcard $(+sysdep_dirs:%=%/syscalls.list))
316 for dir in $(+sysdep_dirs); do \
317 test -f $$dir/syscalls.list && \
318 { sysdirs='$(sysdirs)' \
319 asm_CPP='$(COMPILE.S) -E -x assembler-with-cpp' \
320 $(SHELL) $(dir $<)$(notdir $<) $$dir || exit 1; }; \
321 test $$dir = $(..)sysdeps/unix && break; \
322 done > $@T
323 mv -f $@T $@
324 endif
326 # The syscall objects depend on s-proto.d or s-proto-cancel.d, which
327 # are generated to specify dependencies generated syscalls have on
328 # headers.
329 # These deps use file names relative to a subdir, so don't
330 # include them in the parent directory.
331 ifneq (,$(filter $(unix-syscalls),$(routines) $(sysdep_routines) $(aux)))
332 ifndef no_deps
333 -include $(common-objpfx)s-proto.d
334 -include $(common-objpfx)s-proto-bp.d
335 -include $(common-objpfx)s-proto-cancel.d
336 endif
337 endif
339 $(common-objpfx)s-%.d: $(..)sysdeps/unix/s-%.S \
340 $(wildcard $(+sysdep_dirs:%=%/syscalls.list))
341 $(+make-deps)
343 common-generated += s-proto.d s-proto-bp.d s-proto-cancel.d
344 postclean-generated += sysd-syscalls
346 endif