]> sourceware.org Git - glibc.git/blob - mach/Machrules
2002-02-16 Roland McGrath <roland@frob.com>
[glibc.git] / mach / Machrules
1 # Rules for MiG interfaces that want to go into the C library.
2 # Copyright (C) 1991,92,93,94,95,96,98,99,2001 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 # Makefiles may define these variable before including this file:
21 # user-interfaces Names of interfaces to put user stubs in for.
22 # server-interfaces Names of interfaces to put server stubs in for.
23 # interface-library Name of interface library to build and install.
24 # This file sets:
25 # interface-headers Names of generated interface header files.
26 # interface-routines Names of generated interface routines.
27 # All user stubs are put in individual files, prefixed with RPC_; header
28 # for both __ and non-__ names is put in foo.h. Server interfaces are
29 # written to foo_server.c and foo_server.h; the server functions are called
30 # _S_rpcname.
31
32 # Includers can also add to or modify `migdefines' to set MiG flags.
33
34 all:
35
36 # Make sure no value comes from the environment, since we append to it.
37 # This is done also in ../Rules, but we append to the value before
38 # including Rules, which changes the origin.
39 ifneq "$(findstring env,$(origin generated))" ""
40 generated :=
41 endif
42
43
44 include ../Makeconfig
45
46 # This makefile contains a lot of implicit rules that get optimized
47 # away if the target directory does not exist.
48 ifndef no_deps
49 -include $(objpfx)dummy.mk
50 endif
51 $(objpfx)dummy.mk:
52 $(make-target-directory)
53 echo '# Empty' > $@
54
55 MIGFLAGS = -DMACH_IPC_COMPAT=0 -DSTANDALONE -DTypeCheck=0 \
56 $(+includes) $(migdefines) -subrprefix __
57 # Putting CC in the enivronment makes the mig wrapper script
58 # use the same compiler setup we are using to run cpp.
59 MIG := CC='${CC}' CPP='${CPP}' $(MIG)
60
61 .SUFFIXES: .defs # Just to set specified_rule_matched.
62
63 define nl # This is needed by *.ir.
64
65
66 endef
67 ifdef user-interfaces
68 *.ir := $(addprefix $(objpfx),$(foreach if,$(user-interfaces),$(if).ir))
69 ifndef no_deps
70 ifndef inhibit_interface_rules
71 -include $(*.ir)
72 endif
73 endif
74 ifneq "$(*.ir)" "$(wildcard $(*.ir))"
75 # If any .ir file is missing, we will be unable to make all the deps.
76 no_deps=t
77 endif
78 generated += $(*.ir:$(objpfx)%=%)
79 endif
80
81
82 # %.ir defines a variable `%-calls', which lists the RPCs defined by
83 # %.defs, and a rule to build $(%-calls:%=RPC_$(%-userprefix)%.c) from
84 # %.defs, where $(%-userprefix) is the user prefix given in %.defs. We use
85 # the kludgificacious method of defining a pattern rule to build files
86 # matching patterns we are pretty damn sure will only match the particular
87 # files we have in mind. To be so damn sure, we use the silly names
88 # RPC_*.c and the pattern R%C_*.c because using __*.c and _%*.c (or any
89 # other useful pattern) causes the rule for `host_info' to also match
90 # `xxx_host_info', and analogous lossage.
91 #
92 # Depend on %.h just so they will be built from %.uh in the
93 # makefile-rebuilding run which builds %.ir; otherwise, %.uh is built as an
94 # intermediate in order to make %.ir and then removed before re-exec, when
95 # %.uh is built all over again to build %.h.
96 $(objpfx)%.ir: $(objpfx)%.uh $(objpfx)%.h
97 ($(AWK) "NF == 4 && (\$$2 == \"Routine\" || \$$2 == \"SimpleRoutine\")\
98 { printf \"$*-calls += %s\\n\", \$$3 }" $< ;\
99 echo '$$($*-calls:%=$$(objpfx)R\%C_%.c): $$(objpfx)$*.ustamp ;';\
100 ) > $@-new
101 mv -f $@-new $@
102 vpath Machrules ../mach # Find ourselves.
103
104 ifndef transform-user-stub-output
105 transform-user-stub-output = tmp
106 define transform-user-stub
107 echo "weak_alias (__$$call, $$call)" >> $(objpfx)tmp_$${call}.c;
108 endef
109 endif
110
111
112 # Generate `#include <NAME.defs>', taking $* for NAME.
113 # If $(NAME.defs) is defined use its value in place of `NAME.defs'.
114 define include-%.defs
115 echo '#include <$(firstword $($*.defs) $*.defs)>'
116 endef
117
118 ifndef no_deps
119 # Not an implicit rule so the stamps are never removed as intermediates!
120 $(patsubst %,$(objpfx)%.ustamp,$(user-interfaces)): $(objpfx)%.ustamp:
121 rm -f $@
122 $(include-%.defs) | \
123 $(MIG) - /dev/null -prefix __ \
124 $(MIGFLAGS) $(user-MIGFLAGS) $(MIGFLAGS-$*) \
125 -i $(objpfx)tmp_ \
126 -server /dev/null -user /dev/null -header /dev/null
127 for call in $($*-calls); do \
128 $(transform-user-stub) \
129 $(move-if-change) $(objpfx)$(transform-user-stub-output)_$${call}.c \
130 $(objpfx)RPC_$${call}.c; \
131 done
132 touch $@
133 -include $(patsubst %,$(objpfx)%.udeps,$(user-interfaces))
134 $(patsubst %,$(objpfx)%.udeps,$(user-interfaces)):
135 $(objpfx)%.udeps: $(..)mach/Machrules
136 $(make-target-directory)
137 # We must use $(CFLAGS) to get -O flags that affect #if's in header files.
138 $(include-%.defs) | \
139 $(CC) $(CFLAGS) $(CPPFLAGS) -M -x c - | \
140 sed -e 's,- *:,$@ $(@:.udeps=.ustamp) $(@:.udeps=.uh) $(@:.udeps=.__h)\
141 $(@:.udeps=_server.c) $(@:.udeps=_server.h):,' \
142 $(sed-remove-objpfx) > $@.new
143 mv -f $@.new $@
144 endif
145
146 # Look for the server stub files where they will be written.
147 vpath %_server.c $(addprefix $(objpfx),$(sort $(dir $(server-interfaces))))
148
149 # Build the server stubs in $(objdir).
150 $(objpfx)%_server.c $(objpfx)%_server.h:
151 $(make-target-directory)
152 $(include-%.defs) | \
153 $(MIG) - /dev/null -prefix _S_ \
154 $(MIGFLAGS) $(server-MIGFLAGS) $(MIGFLAGS-$*) \
155 -user /dev/null -header /dev/null \
156 -server $(@:.h=.c) -sheader $(@:.c=.h)
157
158 # To get header files that declare both the straight and __ functions,
159 # we generate two files and paste them together.
160 $(objpfx)%.uh:; $(mig.uh)
161 define mig.uh
162 $(make-target-directory)
163 $(include-%.defs) | \
164 $(MIG) - /dev/null $(MIGFLAGS) $(MIGFLAGS-$*) \
165 -header $@ -server /dev/null -user /dev/null
166 endef
167 $(objpfx)%.__h:; $(mig.__h)
168 define mig.__h
169 $(make-target-directory)
170 $(include-%.defs) | \
171 $(MIG) - /dev/null $(MIGFLAGS) $(MIGFLAGS-$*) -prefix __ \
172 -header $@ -server /dev/null -user /dev/null
173 endef
174
175 $(objpfx)%.h: $(objpfx)%.__h $(objpfx)%.uh
176 # The last line of foo.__h is "#endif _foo_user_".
177 # The first two lines of foo.uh are "#ifndef _foo_user_"/"#define _foo_user_".
178 (sed -e '$$d' $<; sed -e '1,2d' $(word 2,$^)) > $@-new
179 mv -f $@-new $@
180
181 interface-routines := $(foreach if,$(user-interfaces), \
182 $(addprefix RPC_,$($(if)-calls))) \
183 $(server-interfaces:%=%_server)
184 interface-headers := $(user-interfaces:%=%.h) \
185 $(server-interfaces:%=%_server.h)
186
187 # Remove the generated user stub source and header files,
188 # and don't distribute them.
189 mach-generated = $(interface-routines:%=%.c) $(interface-headers) \
190 $(foreach h,$(user-interfaces),$h.uh $h.__h)
191 generated += $(mach-generated)
192
193 # These are needed to generate the dependencies.
194 before-compile += $(interface-headers:%=$(objpfx)%)
195
196 # Don't let these be intermediate files and get removed.
197 $(foreach h,$(interface-headers:%.h=$(objpfx)%),$h.h $h.__h $h.uh) :
198 $(interface-routines:%=$(objpfx)%.c) :
199
200 # Convenient target to generate all the headers.
201 .PHONY: interface-headers
202 interface-headers: $(interface-headers)
203
204 # Don't automatically generate dependencies for the sources we generate.
205 # There are likely to be a whole lot of them, and we know their
206 # dependencies ahead of time anyway because they're boilerplate.
207 omit-deps += $(interface-routines)
208
209 # Choose any single module generated by MiG. We will compute this module's
210 # dependencies and then assume all other MiG-generated modules depend on the
211 # same headers.
212 some-if-rtn := $(firstword $(interface-routines))
213 ifdef some-if-rtn
214 $(foreach o,$(object-suffixes),$(interfaces-routines:%=%$o)): $(some-if-rtn).d
215 generated += $(some-if-rtn).d
216 endif
217 \f
218 # If defined, $(interface-library) is `libNAME'. It is to be a library
219 # containing all the MiG-generated functions for the specified interfaces.
220
221 ifdef interface-library
222
223 $(interface-library)-routines = $(interface-routines)
224 extra-libs += $(interface-library)
225 extra-libs-others += $(interface-library)
226
227 ifeq (yes,$(build-shared))
228 interface.so = $(interface-library:=.so)
229
230 # Depend on libc.so so a DT_NEEDED is generated in the shared objects.
231 $(objpfx)$(interface.so): $(common-objpfx)libc.so
232 endif
233
234 endif
This page took 0.044859 seconds and 5 git commands to generate.