Update.
[glibc.git] / sysdeps / unix / Makefile
blobc9c5ed8fdcb0f8d7d1947f48e79df797638b19b6
1 # Copyright (C) 1991, 92, 93, 94, 95, 96, 97 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 Library General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # 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 # Library General Public License for more details.
14 # You should have received a copy of the GNU Library General Public
15 # License along with the GNU C Library; see the file COPYING.LIB. If not,
16 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
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)/stub/ $(common-objpfx),\
23 $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/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)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 := $(before-compile) $(common-objpfx)local_lim.h
42 common-generated := $(common-generated) local_lim.h mk-local_lim
44 endif
46 ifeq (,$(filter-out $(sysdep_dir)/stub/ $(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 _GNU_SYS_PARAM_H'; \
55 echo '#define _GNU_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@^.*:@@' \
78 -e 's@$<@@g' \
79 -e 's@$(sysincludedir)/*@@g' \
80 -e 's@\\$$@@' \
81 -e 's@^@sys/param.h-includes := $$(sys/param.h-includes) @'
82 mv $@-t $@
84 # Get the generated definition of sys/param.h-includes.
85 ifndef no_deps
86 -include $(common-objpfx)param.h.dep
87 endif
89 # Don't preempt our own headers.
90 sys/param.h-includes := \
91 $(filter-out $(patsubst $(..)%,%,\
92 $(wildcard $(addprefix $(..),\
93 $(sys/param.h-includes)))),\
94 $(sys/param.h-includes))
97 .PHONY: sys/param.h-includes
98 sys/param.h-includes: $(addprefix $(common-objpfx),$(sys/param.h-includes))
100 ifdef sys/param.h-includes
101 # Copy the system files to $(common-objdir).
102 $(addprefix $(common-objpfx),$(sys/param.h-includes)): $(common-objpfx)%: \
103 $(sysincludedir)/%
104 $(make-target-directory)
105 # Some of these files sometimes contain conflicting declarations for htons,
106 # ntohs, etc. They also often contain definitions of *_ENDIAN and
107 # BYTE_ORDER, which we define ourselves in <endian.h>.
108 sed -e '/[ ]*[hn]to[nh][sl][ (]*/d' \
109 -e '/^#define[ ]*[A-Z]*_ENDIAN/d' \
110 -e '/^#define[ ]*BYTE_ORDER/d' \
111 $< > $@-t
112 mv $@-t $@
113 endif
115 common-generated := $(common-generated) \
116 sys/param.h $(sys/param.h-includes) param.h.c param.h.dep
119 ifeq ($(subdir),misc)
121 # Install system headers the system sys/param.h uses.
123 sysdep_headers := $(sysdep_headers) $(sys/param.h-includes)
125 endif # misc
127 endif # No sysdep sys/param.h.
129 ifeq (,$(filter-out $(sysdep_dir)/stub/ $(common-objpfx),\
130 $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/errnos.h))))))
132 # These need to exist before any compiling is done,
133 # so cpp doesn't instead find the stub versions.
134 before-compile := $(before-compile) $(common-objpfx)errnos.h
136 $(common-objpfx)errnos.h: $(common-objpfx)make-errnos
137 $(dir $<)$(notdir $<) > $@-tmp
138 mv $@-tmp $@
140 $(common-objpfx)make-errnos: $(common-objpfx)make-errnos.c
141 $(common-objdir-compile)
143 $(common-objpfx)make-errnos.c: $(sysdep_dir)/unix/errnos-tmpl.c \
144 $(sysdep_dir)/unix/errnos.awk $(common-objpfx)errnos
145 awk -f $(word 2,$^) errnos="`tr '\012' ' ' < $(word 3,$^)`" $< > $@T
146 mv $@T $@
148 $(common-objpfx)errnos: $(wildcard $(sysincludedir)/errno.h \
149 $(sysincludedir)/sys/errno.h)
150 sed -n 's/^#define[ ]*\(E[A-Z0-9][A-Z0-9]*\)[ ].*$$/\1/p' \
151 $^ > $@-tmp
152 mv $@-tmp $@
154 common-generated := $(common-generated) \
155 errnos.h errnos make-errnos make-errnos.c
156 endif
158 ifeq (,$(filter-out $(sysdep_dir)/stub/ $(common-objpfx),\
159 $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/ioctls.h))))))
161 before-compile := $(before-compile) $(common-objpfx)ioctls.h
163 $(common-objpfx)ioctls.h: $(common-objpfx)make-ioctls
164 $(dir $<)$(notdir $<) > $@-tmp
165 mv $@-tmp $@
167 ioctl-includes := sys/termios.h net/nit.h
168 ioctl-includes := $(wildcard $(addprefix $(sysincludedir)/,$(ioctl-includes)))
169 make-ioctls-CFLAGS := $(subst /,_,$(subst .,_,\
170 $(patsubst $(sysincludedir)/%,-DHAVE_%,\
171 $(ioctl-includes))))
173 $(common-objpfx)make-ioctls: $(common-objpfx)make-ioctls.c
174 $(common-objdir-compile)
176 $(common-objpfx)make-ioctls.c: $(sysdep_dir)/unix/ioctls-tmpl.c \
177 $(sysdep_dir)/unix/ioctls.awk \
178 $(common-objpfx)ioctls
179 awk -f $(word 2,$^) requests="`cat $(word 3,$^)`" $< > $@T
180 mv $@T $@
183 termbits.h := $(firstword $(wildcard $(+sysdep_dirs:%=%/termbits.h)))
184 ifeq ($(termbits.h),$(sysdep_dir)/generic/termbits.h)
185 termbits.h := # Ignore the generic version.
186 endif
188 # If there is a system-specific <termbits.h> file, we want to omit all the
189 # symbols it defines from ioctls. Otherwise, both ioctls.h and termbits.h
190 # would define them. The system-specific <termbits.h> file presumably
191 # defines them with the same values as we find from the system's headers.
192 # We also want to omit from ioctls the symbols defined in our own
193 # <sys/ttydefaults.h>, to avoid multiple definition conflicts. We use
194 # snarf-ioctls on these files to find what symbols we want to omit. fgrep
195 # -xv gives all lines which do not match in their entirety; without -x,
196 # CSTOP's presence elided TIOCSTOP.
198 $(common-objpfx)ioctls: $(sysdep_dir)/unix/snarf-ioctls \
199 $(sysincludedir)/sys/ioctl.h $(ioctl-includes)
200 $(dir $<)$(notdir $<) $(filter-out $<,$^) \
201 | fgrep -xv "`($(dir $<)$(notdir $<) $(termbits.h) \
202 $(..)termios/sys/ttydefaults.h; \
203 echo NULL) \
204 | sort | uniq`" \
205 | sort | uniq | tr '\012' ' ' > $@-tmp
206 mv $@-tmp $@
208 common-generated := $(common-generated) \
209 ioctls.h ioctls make-ioctls make-ioctls.c
210 endif
212 ifeq ($(subdir),stdio-common)
213 ifeq (,$(filter-out $(sysdep_dir)/stub/ $(objpfx),\
214 $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/errlist.c))))))
216 before-compile: $(objpfx)errlist.c
217 $(objpfx)errlist.c: $(objpfx)make_errlist
218 @rm -f $@
219 $(dir $<)$(notdir $<) > $@-tmp
220 mv $@-tmp $@
222 $(objpfx)make_errlist: $(sysdep_dir)/unix/make_errlist.c
223 $(native-compile)
225 generated := $(generated) make_errlist errlist.c
227 endif
228 endif # stdio-common
230 ifeq (,$(filter-out $(sysdep_dir)/stub/ $(common-objpfx),\
231 $(dir $(firstword $(wildcard $(+sysdep_dirs:%=%/sys/syscall.h))))))
233 # The syscall code assumes a file <sys/syscall.h> that defines macros
234 # `SYS_call' for syscall `call'. Variations on this I have seen include:
235 # it's in <sys/syscall.h>;
236 # it's in <sys.s>;
237 # it defines `CALL' instead of `SYS_call'.
238 # Irix has a <syscall.h> which is not what we want, so check for <sys.s> first.
240 # Find a file that might have these. NOTE: This list of possibilities is
241 # repeated in sysdeps/unix/configure and the two should be kept in sync.
242 syscall.h := $(firstword $(wildcard $(addprefix $(sysincludedir)/, \
243 sys.s sys/sys.s \
244 sys.S sys/sys.S \
245 syscall.h sys/syscall.h \
247 ifdef syscall.h
249 # Transmogrify any of several formats of the file into the one we want.
250 $(common-objpfx)sys/syscall.h: $(syscall.h)
251 $(make-target-directory)
252 tr '[A-Z]' '[a-z]' < $< | \
253 sed -e 's/[ ]sys_/ /' \
254 -e 's/^#define[ ]*\([a-z0-9_]*\)[ ]*/#define SYS_\1 /' \
255 -e 's/[ ]sys_/ SYS_/' \
256 -e 's/SYS_syscall_basenum/syscall_basenum/g' \
257 -e 's/SYS_kerncall_basenum/kerncall_basenum/g' \
258 -e 's/SYS_sysvoffset/sysvoffset/g' \
259 -e '/^#/!d' \
260 -e '/^#ident/d' \
261 -e 's-\(/\*[^*]*\)$$-\1\*/-' \
262 > $@-tmp
263 mv $@-tmp $@
265 before-compile := $(before-compile) $(common-objpfx)syscall.h
266 common-generated := $(common-generated) syscall.h
268 endif
270 endif
272 ifndef inhibit-unix-syscalls
274 # Sysdep dirs unix/... can contain a file syscalls.list,
275 # which specifies objects to be compiled as simple Unix system calls.
277 -include $(common-objpfx)sysd-syscalls
278 omit-deps += $(unix-syscalls)
280 ifeq (misc,$(subdir))
281 sysdep_routines += $(unix-extra-syscalls)
282 endif
284 export sysdirs
285 export asm_CPP := $(COMPILE.S) -E -x assembler-with-cpp
287 $(common-objpfx)sysd-syscalls: $(..)sysdeps/unix/make-syscalls.sh \
288 $(wildcard $(+sysdep_dirs:%=%/syscalls.list))
289 for dir in $(+sysdep_dirs); do \
290 test -f $$dir/syscalls.list && \
291 { $(SHELL) $(dir $<)$(notdir $<) $$dir || exit 1; }; \
292 test $$dir = $(..)sysdeps/unix && break; \
293 done > $@T
294 mv -f $@T $@
296 # This syscall objects depend on s-proto.d, which is generated to
297 # specify dependencies generated syscalls with have on headers.
298 ifdef subdir
299 ifndef no_deps
300 # These deps use file names relative to a subdir, so don't
301 # include them in the parent directory.
302 -include $(common-objpfx)s-proto.d
303 endif
304 endif
306 $(common-objpfx)s-proto.d: $(common-objpfx)%.d: $(..)sysdeps/unix/%.S
307 $(+make-deps)
309 endif