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