]> git.ipfire.org Git - thirdparty/glibc.git/blob - mach/Machrules
Update.
[thirdparty/glibc.git] / mach / Machrules
1 # Rules for MiG interfaces that want to go into the C library.
2
3 # Copyright (C) 1991, 92, 93, 94, 95, 96, 98 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
5
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Library General Public License
8 # as published by the Free Software Foundation; either version 2 of
9 # the License, or (at your option) any later version.
10
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Library General Public License for more details.
15
16 # You should have received a copy of the GNU Library General Public
17 # License along with the GNU C Library; see the file COPYING.LIB. If not,
18 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 # Boston, MA 02111-1307, USA.
20
21 # Makefiles may define these variable before including this file:
22 # user-interfaces Names of interfaces to put user stubs in for.
23 # server-interfaces Names of interfaces to put server stubs in for.
24 # interface-library Name of interface library to build and install.
25 # This file sets:
26 # interface-headers Names of generated interface header files.
27 # interface-routines Names of generated interface routines.
28 # All user stubs are put in individual files, prefixed with RPC_; header
29 # for both __ and non-__ names is put in foo.h. Server interfaces are
30 # written to foo_server.c and foo_server.h; the server functions are called
31 # _S_rpcname.
32
33 # Includers can also add to or modify `migdefines' to set MiG flags.
34
35 all:
36
37 # Make sure no value comes from the environment, since we append to it.
38 # This is done also in ../Rules, but we append to the value before
39 # including Rules, which changes the origin.
40 ifneq "$(findstring env,$(origin generated))" ""
41 generated :=
42 endif
43
44
45 include ../Makeconfig
46
47 MIGFLAGS = -DMACH_IPC_COMPAT=0 -DSTANDALONE -DTypeCheck=0 \
48 $(+includes) $(migdefines) -subrprefix __
49
50 .SUFFIXES: .defs # Just to set specified_rule_matched.
51
52 define nl # This is needed by *.ir.
53
54
55 endef
56 ifdef user-interfaces
57 *.ir := $(addprefix $(objpfx),$(foreach if,$(user-interfaces),$(if).ir))
58 ifndef no_deps
59 ifndef inhibit_interface_rules
60 -include $(*.ir)
61 endif
62 endif
63 ifneq "$(*.ir)" "$(wildcard $(*.ir))"
64 # If any .ir file is missing, we will be unable to make all the deps.
65 no_deps=t
66 endif
67 generated += $(*.ir:$(objpfx)%=%)
68 endif
69
70
71 # %.ir defines a variable `%-calls', which lists the RPCs defined by
72 # %.defs, and a rule to build $(%-calls:%=RPC_$(%-userprefix)%.c) from
73 # %.defs, where $(%-userprefix) is the user prefix given in %.defs. We use
74 # the kludgificacious method of defining a pattern rule to build files
75 # matching patterns we are pretty damn sure will only match the particular
76 # files we have in mind. To be so damn sure, we use the silly names
77 # RPC_*.c and the pattern R%C_*.c because using __*.c and _%*.c (or any
78 # other useful pattern) causes the rule for `host_info' to also match
79 # `xxx_host_info', and analogous lossage.
80 #
81 # Depend on %.h just so they will be built from %.uh in the
82 # makefile-rebuilding run which builds %.ir; otherwise, %.uh is built as an
83 # intermediate in order to make %.ir and then removed before re-exec, when
84 # %.uh is built all over again to build %.h.
85 $(objpfx)%.ir: $(objpfx)%.uh $(objpfx)%.h
86 (awk "NF == 4 && (\$$2 == \"Routine\" || \$$2 == \"SimpleRoutine\")\
87 { printf \"$*-calls += %s\\n\", \$$3 }" $< ;\
88 echo '$$($*-calls:%=$$(objpfx)R\%C_%.c): $$(objpfx)$*.ustamp ;';\
89 ) > $@-new
90 mv $@-new $@
91 vpath Machrules ../mach # Find ourselves.
92
93 ifndef transform-user-stub-output
94 transform-user-stub-output = tmp
95 define transform-user-stub
96 echo "weak_alias (__$$call, $$call)" >> $(objpfx)tmp_$${call}.c;
97 endef
98 endif
99
100
101 # Generate `#include <NAME.defs>', taking $* for NAME.
102 # If $(NAME.defs) is defined use its value in place of `NAME.defs'.
103 define include-%.defs
104 echo '#include <$(firstword $($*.defs) $*.defs)>'
105 endef
106
107 # Not an implicit rule so the stamps are never removed as intermediates!
108 $(patsubst %,$(objpfx)%.ustamp,$(user-interfaces)): $(objpfx)%.ustamp:
109 rm -f $@
110 $(include-%.defs) | \
111 $(MIG) - /dev/null -prefix __ \
112 $(MIGFLAGS) $(user-MIGFLAGS) $(MIGFLAGS-$*) \
113 -i $(objpfx)tmp_ \
114 -server /dev/null -user /dev/null -header /dev/null
115 for call in $($*-calls); do \
116 $(transform-user-stub) \
117 ../move-if-change $(objpfx)$(transform-user-stub-output)_$${call}.c \
118 $(objpfx)RPC_$${call}.c; \
119 done
120 touch $@
121 -include $(patsubst %,$(objpfx)%.udeps,$(user-interfaces))
122 $(patsubst %,$(objpfx)%.udeps,$(user-interfaces)):
123 $(objpfx)%.udeps: $(..)mach/Machrules
124 $(make-target-directory)
125 $(include-%.defs) | \
126 $(CC) $(CPPFLAGS) -M -x c - | \
127 sed -e 's,- *:,$@ $(@:.udeps=.ustamp) $(@:.udeps=.uh) $(@:.udeps=.__h)\
128 $(@:.udeps=_server.c) $(@:.udeps=_server.h):,' \
129 $(sed-remove-objpfx) > $@.new
130 mv -f $@.new $@
131
132 # Look for the server stub files where they will be written.
133 vpath %_server.c $(addprefix $(objpfx),$(sort $(dir $(server-interfaces))))
134
135 # Build the server stubs in $(objdir).
136 $(objpfx)%_server.c $(objpfx)%_server.h:
137 $(include-%.defs) | \
138 $(MIG) - /dev/null -prefix _S_ \
139 $(MIGFLAGS) $(server-MIGFLAGS) $(MIGFLAGS-$*) \
140 -user /dev/null -header /dev/null \
141 -server $(@:.h=.c) -sheader $(@:.c=.h)
142
143 # To get header files that declare both the straight and __ functions,
144 # we generate two files and paste them together.
145 $(objpfx)%.uh:; $(mig.uh)
146 define mig.uh
147 $(make-target-directory)
148 $(include-%.defs) | \
149 $(MIG) - /dev/null $(MIGFLAGS) $(MIGFLAGS-$*) \
150 -header $@ -server /dev/null -user /dev/null
151 endef
152 $(objpfx)%.__h:; $(mig.__h)
153 define mig.__h
154 $(make-target-directory)
155 $(include-%.defs) | \
156 $(MIG) - /dev/null $(MIGFLAGS) $(MIGFLAGS-$*) -prefix __ \
157 -header $@ -server /dev/null -user /dev/null
158 endef
159
160 $(objpfx)%.h: $(objpfx)%.__h $(objpfx)%.uh
161 # The last line of foo.__h is "#endif _foo_user_".
162 # The first two lines of foo.uh are "#ifndef _foo_user_"/"#define _foo_user_".
163 (sed -e '$$d' $<; sed -e '1,2d' $(word 2,$^)) > $@-new
164 mv $@-new $@
165
166 interface-routines := $(foreach if,$(user-interfaces), \
167 $(addprefix RPC_,$($(if)-calls))) \
168 $(server-interfaces:%=%_server)
169 interface-headers := $(user-interfaces:%=%.h) \
170 $(server-interfaces:%=%_server.h)
171
172 # Remove the generated user stub source and header files,
173 # and don't distribute them.
174 mach-generated = $(interface-routines:%=%.c) $(interface-headers) \
175 $(foreach h,$(user-interfaces),$h.uh $h.__h)
176 generated += $(mach-generated)
177
178 # These are needed to generate the dependencies.
179 before-compile += $(interface-headers:%=$(objpfx)%)
180
181 # Don't let these be intermediate files and get removed.
182 $(foreach h,$(interface-headers:%.h=$(objpfx)%),$h.h $h.__h $h.uh) :
183 $(interface-routines:%=$(objpfx)%.c) :
184
185 # Convenient target to generate all the headers.
186 .PHONY: interface-headers
187 interface-headers: $(interface-headers)
188
189 # Don't automatically generate dependencies for the sources we generate.
190 # There are likely to be a whole lot of them, and we know their
191 # dependencies ahead of time anyway because they're boilerplate.
192 omit-deps += $(interface-routines)
193
194 # Choose any single module generated by MiG. We will compute this module's
195 # dependencies and then assume all other MiG-generated modules depend on the
196 # same headers.
197 some-if-rtn := $(firstword $(interface-routines))
198 ifdef some-if-rtn
199 $(foreach o,$(object-suffixes),$(interfaces-routines:%=%$o)): $(some-if-rtn).d
200 generated += $(some-if-rtn).d
201 endif
202 \f
203 # If defined, $(interface-library) is `libNAME'. It is to be a library
204 # containing all the MiG-generated functions for the specified interfaces.
205
206 ifdef interface-library
207
208 $(interface-library)-routines = $(interface-routines)
209 extra-libs += $(interface-library)
210
211 # Avoid -lmachuser requiring -lc, which may not be built yet. If the
212 # shared object is absent, ld may choose a static library someplace and
213 # produce a bogus libmachuser.so.
214 +preinit =
215 +postinit =
216 interface.so = $(interface-library:lib%=%.so)
217 LDFLAGS-$(interface.so) = -nostdlib -nostartfiles
218
219 endif