2003-02-15 Roland McGrath <roland@frob.com>
[platform/upstream/glibc.git] / mach / Makefile
1 # Copyright (C) 1991,92,93,94,95,96,97,98,2001,02
2 #       Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
4
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.
9
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.
14
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.
19
20 subdir := mach
21
22 all:
23
24 # Some things below (but before including Rules) use configuration variables.
25 include ../Makeconfig
26
27
28 headers = mach_init.h mach.h mach_error.h mach-shortcuts.h mach/mach_traps.h \
29           $(interface-headers) mach/mach.h mach/mig_support.h mach/error.h \
30           $(lock-headers) machine-sp.h
31 distribute = thread_state.h
32 lock = spin-solid spin-lock mutex-init mutex-solid
33 lock-headers = lock-intern.h machine-lock.h spin-lock.h
34 routines = $(mach-syscalls) $(mach-shortcuts) \
35            mach_init mig_strncpy msg \
36            mig-alloc mig-dealloc mig-reply \
37            msg-destroy msgserver \
38            mach_error errstring error_compat errsystems \
39            devstream setup-thread $(lock)
40
41 # The RPC interfaces go in a separate library.
42 interface-library := libmachuser
43
44 # We produce mach_interface.h from mach.defs because there is already a
45 # <mach/mach.h> that is not the interface header (thanks CMU).
46 mach-interface-list := $(patsubst mach,mach_interface,$(mach-interface-list))
47 mach/mach_interface.defs = mach/mach.defs
48
49 # Similarly for memory_object_user vs. memory_object
50 mach-interface-list := $(patsubst memory_object,memory_object_user,\
51                                   $(mach-interface-list))
52 mach/memory_object_user.defs = mach/memory_object.defs
53
54 user-interfaces := $(addprefix mach/,$(mach-interface-list)     \
55                                      mach_port mach_host exc    \
56                     )\
57                    $(addprefix device/,device device_request)
58
59 server-interfaces := mach/exc
60
61 # It is important that we do not use the wildcard function to expand
62 # `err_*.sub'.  Leaving the wildcard allows Make-dist to find all matching
63 # files in all sysdep directories.
64 distribute += Machrules syscalls.awk shortcut.awk \
65               errorlib.h err_*.sub errsystems.awk
66
67 # Clear any environment value.
68 generated =
69 \f
70 # Translate GNU names for CPUs into the names used in Mach header files.
71 mach-machine = $(patsubst powerpc,ppc,$(base-machine))
72
73 # Define mach-syscalls and sysno-*.
74 ifndef inhibit_mach_syscalls
75 -include $(objpfx)mach-syscalls.mk
76 endif
77 $(objpfx)mach-syscalls.mk: syscalls.awk Makefile
78 # Go kludges!!!
79         $(make-target-directory)
80 # We must use $(CFLAGS) to get -O flags that affect #if's in header files.
81         echo '#include <mach/syscall_sw.h>' | \
82         DEPENDENCIES_OUTPUT='$@-dep $@' \
83         $(CC) $(CFLAGS) $(CPPFLAGS) -E -x c-header - \
84               -D_MACH_`echo $(mach-machine) | tr a-z A-Z`_SYSCALL_SW_H_=1 | \
85         sed -n -e 's/^kernel_trap(\(.*\),\([-0-9]*\),\([0-9]*\))$$/\1 \2 \3/p'\
86         | $(AWK) -f $< > $@-new
87         cat $@-dep >> $@-new; rm -f $@-dep
88         mv -f $@-new $@
89 generated += mach-syscalls.mk
90
91 ifndef mach-syscalls
92 # We cannot make the deps properly until we know how to make the system
93 # call functions, and for that we must know what they all are.
94 no_deps=t
95 else
96 $(mach-syscalls:%=$(objpfx)%.S): $(objpfx)%.S: $(objpfx)mach-syscalls.mk
97         (echo '#include <sysdep.h>'; \
98          echo 'kernel_trap (__$*,$(sysno-$*),$(nargs-$*))'; \
99          echo 'weak_alias (__$*, $*)') > $@-new
100          mv -f $@-new $@
101 generated += $(mach-syscalls:=.S)
102 endif   # mach-syscalls
103
104 # These syscalls that look like RPCs actually have no RPC equivalents.
105 mach-shortcuts := $(filter-out device_writev_request \
106                                device_read_overwrite_request \
107                                device_read_overwrite \
108                                vm_read_overwrite \
109                                thread_switch \
110                                ,\
111                   $(patsubst syscall_%,%,$(filter syscall_%,$(mach-syscalls))))
112
113 ifndef mach-shortcuts
114 # Forget about mach_interface.defs for this run.  On the next run,
115 # $(mach-shortcuts) will be set, and that will change how
116 # mach_interface.defs is processed: it will get the -D flags below.
117 user-interfaces := $(filter-out $(mach-interface-list:%=mach/%) \
118                                 mach/mach_port mach/mach_host mach/mach4 \
119                                 device/device_request,\
120                                 $(user-interfaces))
121 endif
122
123 # For some reason, the calls in this file are `protected' by an ifdef.
124 MIGFLAGS-mach/mach4=-DMACH_PCSAMPLE
125
126 # Make the MiG stubs for $(mach-shortcuts) be CALL_rpc.
127 migdefines += $(foreach call,$(mach-shortcuts),-D$(call)=$(call)_rpc)
128 $(mach-interface-list:%=mach/%.uh) \
129   mach/mach_host.uh mach/mach_port.uh: $(objpfx)mach-syscalls.mk
130
131 ifdef mach-shortcuts
132 $(mach-shortcuts:%=$(objpfx)%.c): $(objpfx)%.c: shortcut.awk \
133                                                 $(objpfx)RPC_%_rpc.c
134         $(AWK)  -v alias=$* -v call=__$* -v rpc=__$*_rpc \
135                 -v syscall=__syscall_$* -f $^ > $@-new
136         mv -f $@-new $@
137 generated += $(mach-shortcuts:%=%.c)
138 endif   # mach-shortcuts
139
140 # Generate mach-shortcuts.h, which will contain the prototypes for the
141 # shortcutted kernel RPC functions.
142 $(objpfx)mach-shortcuts.h: $(mach-interface-list:%=$(objpfx)mach/%.h) \
143                            $(objpfx)mach/mach_host.h \
144                            $(objpfx)mach/mach_port.h
145 # The first line gets us one paragraph per line, with @s separating real lines.
146 # The second line selects paragraphs for the shortcutted functions.
147 # The third line removes `_rpc' from the names and reconstitutes the lines.
148         cat $^ | tr \\012 @ | sed s/@@/@%/g | tr % \\012 \
149         | grep '^/\* Routine [a-z0-9_]*_rpc \*/' \
150         | sed 's/_rpc//g' | tr @ \\012 > $@-new
151         mv -f $@-new $@
152 generated += mach-shortcuts.h
153
154 before-compile += $(objpfx)mach-shortcuts.h
155 \f
156 include Machrules
157 include ../Rules
158
159
160 # A gcc bug prevents the generated file from working properly,
161 # so we have one in the distribution for the time being.
162 generated += errsystems.c
163 $(objpfx)errsystems.c: errsystems.awk err_*.sub \
164                        $(wildcard $(addsuffix /err_*.sub,$(+sysdep_dirs)))
165         $(AWK) -v subsys='$(filter-out $<,$^)' -f $^ > $@.n
166         mv -f $@.n $@
167
168
169 # Convenient target to update all the generated source files.
170 .PHONY: generated
171 generated: $(addprefix $(common-objpfx),$(common-generated)) \
172            $(addprefix $(objpfx),$(generated))
173
174 .PHONY: mach-before-compile
175 mach-before-compile: $(mach-before-compile)