Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / unix / Makefile
blob4b887a7a8705c5f48a30764db5a8fddb0a377dbf
1 # Copyright (C) 1991,1992,1993,1994,1995,1996,1997,1998,1999,2003,2006,2008,2009
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, see
17 # <http://www.gnu.org/licenses/>.
19 # The unix-specific configure fragment writes `unix-generated' in config.make.
20 config-generated := $(config-generated) $(unix-generated)
22 ifeq (,$(filter-out $(sysdep_dir)/generic/ $(common-objpfx),\
23 $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/bits/local_lim.h))))))
25 ifneq (,$(wildcard $(sysincludedir)/sys/param.h))
26 mk-local_lim-CFLAGS += -DHAVE_SYS_PARAM_H
27 endif
28 ifneq (,$(wildcard $(sysincludedir)/sys/limits.h))
29 mk-local_lim-CFLAGS += -DHAVE_SYS_LIMITS_H
30 endif
31 ifneq (,$(wildcard $(sysincludedir)/limits.h))
32 mk-local_lim-CFLAGS += -DHAVE_LIMITS_H
33 endif
35 $(common-objpfx)bits/local_lim.h: $(common-objpfx)mk-local_lim
36 $(dir $<)$(notdir $<) > $@-t
37 mv -f $@-t $@
38 $(common-objpfx)mk-local_lim: $(sysdep_dir)/unix/mk-local_lim.c
39 $(common-objdir-compile)
41 before-compile += $(common-objpfx)bits/local_lim.h
42 common-generated += bits/local_lim.h mk-local_lim
44 endif
46 ifeq (,$(filter-out $(sysdep_dir)/generic/ $(common-objpfx),\
47 $(patsubst %/sys/param.h,%/,\
48 $(firstword $(wildcard $(+sysdep_dirs:%=%/sys/param.h))))))
50 before-compile := $(before-compile) $(common-objpfx)sys/param.h
52 $(common-objpfx)sys/param.h: $(sysincludedir)/sys/param.h
53 $(make-target-directory)
54 (echo '#ifndef _SYS_PARAM_H'; \
55 echo '#define _SYS_PARAM_H 1'; \
56 echo '#include <endian.h>'; \
57 $(AWK) < $< \
58 '/^#define[ ]*NULL/ { print "#ifndef NULL"; \
59 print $$0; \
60 print "#endif"; \
61 was_null = 1 } \
62 { if (!was_null) print $$0; \
63 was_null = 0 }'; \
64 echo '#ifndef MAXHOSTNAMELEN'; \
65 echo '#define MAXHOSTNAMELEN 64 /* XXX */'; \
66 echo '#endif /* No MAXHOSTNAMELEN. */'; \
67 echo '#endif /* sys/param.h */') > $@-tmp
68 mv $@-tmp $@
70 $(common-objpfx)param.h.c: $(sysincludedir)/sys/param.h
71 rm -f $@
72 cp $< $@
73 $(common-objpfx)param.h.dep: $(common-objpfx)param.h.c \
74 $(sysdep_dir)/unix/Makefile
75 $(+mkdep) -I$(sysincludedir) $< \
76 | sed > $@-t \
77 -e 's@$(sysincludedir)/sys/param.h@@' \
78 -e 's@^.*:@@' \
79 -e 's@$<@@g' \
80 -e 's@$(sysincludedir)/*@@g' \
81 -e 's@\\$$@@' \
82 -e 's@^@sys/param.h-includes := $$(sys/param.h-includes) @'
83 mv $@-t $@
85 # Get the generated definition of sys/param.h-includes.
86 ifndef no_deps
87 -include $(common-objpfx)param.h.dep
88 endif
90 # Don't preempt our own headers.
91 sys/param.h-includes := \
92 $(filter-out $(patsubst $(..)%,%,\
93 $(wildcard $(addprefix $(..),\
94 $(sys/param.h-includes)))),\
95 $(sys/param.h-includes))
98 .PHONY: sys/param.h-includes
99 sys/param.h-includes: $(addprefix $(common-objpfx),$(sys/param.h-includes))
101 ifdef sys/param.h-includes
102 # Copy the system files to $(common-objdir).
103 $(addprefix $(common-objpfx),$(sys/param.h-includes)): $(common-objpfx)%: \
104 $(sysincludedir)/%
105 $(make-target-directory)
106 # Some of these files sometimes contain conflicting declarations for htons,
107 # ntohs, etc. They also often contain definitions of *_ENDIAN and
108 # BYTE_ORDER, which we define ourselves in <endian.h>.
109 sed -e '/[ ]*[hn]to[nh][sl][ (]*/d' \
110 -e '/^#define[ ]*[A-Z]*_ENDIAN/d' \
111 -e '/^#define[ ]*BYTE_ORDER/d' \
112 $< > $@-t
113 mv $@-t $@
114 endif
116 common-generated := $(common-generated) \
117 sys/param.h $(sys/param.h-includes) param.h.c param.h.dep
120 ifeq ($(subdir),misc)
122 # Install system headers the system sys/param.h uses.
124 sysdep_headers := $(sysdep_headers) $(sys/param.h-includes)
126 endif # misc
128 endif # No sysdep sys/param.h.
130 ifeq (,$(filter-out $(sysdep_dir)/generic/ $(common-objpfx),\
131 $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/bits/errno.h))))))
133 # These need to exist before any compiling is done,
134 # so cpp doesn't instead find the generic versions.
135 before-compile := $(before-compile) $(common-objpfx)bits/errno.h
137 $(common-objpfx)bits/errno.h: $(common-objpfx)make-errnos
138 $(dir $<)$(notdir $<) > $@-tmp
139 mv $@-tmp $@
141 $(common-objpfx)make-errnos: $(common-objpfx)make-errnos.c
142 $(common-objdir-compile)
144 $(common-objpfx)make-errnos.c: $(sysdep_dir)/unix/errnos-tmpl.c \
145 $(sysdep_dir)/unix/errnos.awk $(common-objpfx)errnos
146 $(AWK) -f $(word 2,$^) errnos="`tr '\012' ' ' < $(word 3,$^)`" $< > $@T
147 mv $@T $@
149 $(common-objpfx)errnos: $(wildcard $(sysincludedir)/errno.h \
150 $(sysincludedir)/sys/errno.h)
151 sed -n 's/^#define[ ]*\(E[A-Z0-9][A-Z0-9]*\)[ ].*$$/\1/p' \
152 $^ > $@-tmp
153 mv $@-tmp $@
155 common-generated := $(common-generated) \
156 errnos.h errnos make-errnos make-errnos.c
157 endif
159 ifeq (,$(filter-out $(sysdep_dir)/generic/ $(common-objpfx),\
160 $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/bits/ioctls.h))))))
162 before-compile := $(before-compile) $(common-objpfx)bits/ioctls.h
164 $(common-objpfx)bits/ioctls.h: $(common-objpfx)make-ioctls
165 $(dir $<)$(notdir $<) > $@-tmp
166 mv $@-tmp $@
168 ioctl-includes := sys/termios.h net/nit.h
169 ioctl-includes := $(wildcard $(addprefix $(sysincludedir)/,$(ioctl-includes)))
170 make-ioctls-CFLAGS := $(subst /,_,$(subst .,_,\
171 $(patsubst $(sysincludedir)/%,-DHAVE_%,\
172 $(ioctl-includes))))
174 $(common-objpfx)make-ioctls: $(common-objpfx)make-ioctls.c
175 $(common-objdir-compile)
177 $(common-objpfx)make-ioctls.c: $(sysdep_dir)/unix/ioctls-tmpl.c \
178 $(sysdep_dir)/unix/ioctls.awk \
179 $(common-objpfx)ioctls
180 $(AWK) -f $(word 2,$^) requests="`cat $(word 3,$^)`" $< > $@T
181 mv $@T $@
184 bits_termios.h := $(firstword $(wildcard $(+sysdep_dirs:%=%/bits/termios.h)))
185 ifeq ($(bits_termios.h),$(sysdep_dir)/generic/bits/termios.h)
186 bits_termios.h := # Ignore the generic version.
187 endif
189 # If there is a system-specific <bits/termios.h> file, we want to omit
190 # all the symbols it defines from ioctls. Otherwise, both
191 # <bits/ioctls.h> and <bits/termios.h> would define them. The
192 # system-specific <bits/termios.h> file presumably defines them with
193 # the same values as we find from the system's headers. We also want
194 # to omit from ioctls the symbols defined in our own
195 # <sys/ttydefaults.h>, to avoid multiple definition conflicts. We use
196 # snarf-ioctls on these files to find what symbols we want to omit.
197 # fgrep -xv gives all lines which do not match in their entirety;
198 # without -x, CSTOP's presence elided TIOCSTOP.
200 $(common-objpfx)ioctls: $(sysdep_dir)/unix/snarf-ioctls \
201 $(sysincludedir)/sys/ioctl.h $(ioctl-includes)
202 $(dir $<)$(notdir $<) $(filter-out $<,$^) \
203 | fgrep -xv "`($(dir $<)$(notdir $<) $(bits_termios.h) \
204 $(..)sysdeps/generic/sys/ttydefaults.h; \
205 echo NULL) \
206 | sort | uniq`" \
207 | sort | uniq | tr '\012' ' ' > $@-tmp
208 mv $@-tmp $@
210 common-generated := $(common-generated) \
211 bits/ioctls.h ioctls make-ioctls make-ioctls.c
212 endif
214 ifeq (,$(filter-out $(sysdep_dir)/generic/ $(common-objpfx),\
215 $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/sys/syscall.h))))))
217 # The syscall code assumes a file <sys/syscall.h> that defines macros
218 # `SYS_call' for syscall `call'. Variations on this I have seen include:
219 # it's in <sys/syscall.h>;
220 # it's in <sys.s>;
221 # it defines `CALL' instead of `SYS_call'.
222 # Irix has a <syscall.h> which is not what we want, so check for <sys.s> first.
224 # Find a file that might have these. NOTE: This list of possibilities is
225 # repeated in sysdeps/unix/configure and the two should be kept in sync.
226 syscall.h := $(firstword $(wildcard $(addprefix $(sysincludedir)/, \
227 sys.s sys/sys.s \
228 sys.S sys/sys.S \
229 syscall.h sys/syscall.h \
231 ifdef syscall.h
233 # Transmogrify any of several formats of the file into the one we want.
234 $(common-objpfx)sys/syscall.h: $(syscall.h)
235 $(make-target-directory)
236 tr '[A-Z]' '[a-z]' < $< | \
237 sed -e 's/[ ]sys_/ /' \
238 -e 's/^#define[ ]*\([a-z0-9_]*\)[ ]*/#define SYS_\1 /' \
239 -e 's/[ ]sys_/ SYS_/' \
240 -e 's/SYS_syscall_basenum/syscall_basenum/g' \
241 -e 's/SYS_kerncall_basenum/kerncall_basenum/g' \
242 -e 's/SYS_sysvoffset/sysvoffset/g' \
243 -e '/^#/!d' \
244 -e '/^#ident/d' \
245 -e 's-\(/\*[^*]*\)$$-\1\*/-' \
246 > $@-tmp
247 mv $@-tmp $@
249 before-compile += $(common-objpfx)sys/syscall.h
250 common-generated += sys/syscall.h
252 endif
254 endif
256 ifndef inhibit-unix-syscalls
258 # Sysdep dirs unix/... can contain a file syscalls.list,
259 # which specifies objects to be compiled as simple Unix system calls.
261 -include $(common-objpfx)sysd-syscalls
263 ifeq (misc,$(subdir))
264 sysdep_routines += $(unix-extra-syscalls)
266 ifdef unix-stub-syscalls
267 # The system call entry points in this list are supposed to be additional
268 # functions not overriding any other sysdeps/.../call.c implementation, but
269 # their system call numbers are unavailable in the kernel headers we're
270 # using. Instead of a system call stub, these get a function that fails
271 # with ENOSYS. We just generate a single module defining one function and
272 # making all these entry point names aliases for it.
273 sysdep_routines += stub-syscalls
274 $(objpfx)stub-syscalls.c: $(common-objpfx)sysd-syscalls \
275 $(..)sysdeps/unix/Makefile
276 $(make-target-directory)
277 (for call in $(unix-stub-syscalls); do \
278 echo "#define $$call RENAMED_$$call"; \
279 done; \
280 echo '#include <errno.h>'; \
281 for call in $(unix-stub-syscalls); do \
282 echo "#undef $$call"; \
283 done; \
284 echo 'long int _no_syscall (void)'; \
285 echo '{ __set_errno (ENOSYS); return -1L; }'; \
286 for call in $(unix-stub-syscalls); do \
287 case $$call in \
288 *@@*) ver=$${call##*@}; call=$${call%%*@}; \
289 echo "strong_alias (_no_syscall, $${call}_$${ver})"; \
290 echo "default_symbol_version \
291 ($${call}_$${ver}, $$call, $$ver);" ;; \
292 *@@*) ver=$${call##*@}; call=$${call%%*@}; \
293 echo "strong_alias (_no_syscall, $${call}_$${ver})"; \
294 echo "symbol_version ($${call}_$${ver}, $$call, $$ver);" ;; \
295 *) echo "weak_alias (_no_syscall, $$call)"; \
296 echo "stub_warning ($$call)"; \
297 echo "weak_alias (_no_syscall, __GI_$$call)" ;; \
298 esac; \
299 echo '#include <stub-tag.h>'; \
300 done) > $@T
301 mv -f $@T $@
302 generated += stub-syscalls.c
303 endif
304 endif
306 # This is the end of the pipeline for compiling the syscall stubs.
307 # The stdin is assembler with cpp using sysdep.h macros.
308 compile-syscall = $(COMPILE.S) -o $@ -x assembler-with-cpp - \
309 $(compile-mkdep-flags)
311 ifndef avoid-generated
312 $(common-objpfx)sysd-syscalls: $(..)sysdeps/unix/make-syscalls.sh \
313 $(wildcard $(+sysdep_dirs:%=%/syscalls.list))
314 for dir in $(+sysdep_dirs); do \
315 test -f $$dir/syscalls.list && \
316 { sysdirs='$(sysdirs)' \
317 asm_CPP='$(COMPILE.S) -E -x assembler-with-cpp' \
318 $(SHELL) $(dir $<)$(notdir $<) $$dir || exit 1; }; \
319 test $$dir = $(..)sysdeps/unix && break; \
320 done > $@T
321 mv -f $@T $@
322 endif
324 # The $(bppfx)syscall.ob objects depend on s-proto-bp.d, which are
325 # generated to specify dependencies generated BP stubs have on headers.
326 # These deps use file names relative to a subdir, so don't
327 # include them in the parent directory.
328 ifneq (,$(filter $(unix-syscalls),$(routines) $(sysdep_routines) $(aux)))
329 ifndef no_deps
330 -include $(common-objpfx)s-proto-bp.d
331 endif
332 endif
334 $(common-objpfx)s-%.d: $(..)sysdeps/unix/s-%.S \
335 $(wildcard $(+sysdep_dirs:%=%/syscalls.list))
336 $(+make-deps)
338 common-generated += s-proto-bp.d
339 postclean-generated += sysd-syscalls
341 endif