Update.
[glibc.git] / mach / Machrules
blob89ac567b394f862db09ecccc4a1cd6cbce4c10ad
1 # Rules for MiG interfaces that want to go into the C library.
3 # Copyright (C) 1991, 92, 93, 94, 95, 96, 98 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
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.
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.
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.
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.
33 # Includers can also add to or modify `migdefines' to set MiG flags.
35 all:
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
45 include ../Makeconfig
47 MIGFLAGS = -DMACH_IPC_COMPAT=0 -DSTANDALONE -DTypeCheck=0 \
48            $(+includes) $(migdefines) -subrprefix __
50 .SUFFIXES: .defs        # Just to set specified_rule_matched.
52 define nl       # This is needed by *.ir.
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
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.
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 -f $@-new $@
91 vpath Machrules ../mach # Find ourselves.
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
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
107 ifndef no_deps
108 # Not an implicit rule so the stamps are never removed as intermediates!
109 $(patsubst %,$(objpfx)%.ustamp,$(user-interfaces)): $(objpfx)%.ustamp:
110         rm -f $@
111         $(include-%.defs) | \
112         $(MIG) - /dev/null -prefix __ \
113                $(MIGFLAGS) $(user-MIGFLAGS) $(MIGFLAGS-$*) \
114                -i $(objpfx)tmp_ \
115                -server /dev/null -user /dev/null -header /dev/null
116         for call in $($*-calls); do \
117           $(transform-user-stub) \
118           $(move-if-change) $(objpfx)$(transform-user-stub-output)_$${call}.c \
119                             $(objpfx)RPC_$${call}.c; \
120         done
121         touch $@
122 -include $(patsubst %,$(objpfx)%.udeps,$(user-interfaces))
123 $(patsubst %,$(objpfx)%.udeps,$(user-interfaces)):
124   $(objpfx)%.udeps: $(..)mach/Machrules
125         $(make-target-directory)
126         $(include-%.defs) | \
127         $(CC) $(CPPFLAGS) -M -x c - | \
128         sed -e 's,- *:,$@ $(@:.udeps=.ustamp) $(@:.udeps=.uh) $(@:.udeps=.__h)\
129                           $(@:.udeps=_server.c) $(@:.udeps=_server.h):,' \
130             $(sed-remove-objpfx) > $@.new
131         mv -f $@.new $@
132 endif
134 # Look for the server stub files where they will be written.
135 vpath %_server.c $(addprefix $(objpfx),$(sort $(dir $(server-interfaces))))
137 # Build the server stubs in $(objdir).
138 $(objpfx)%_server.c $(objpfx)%_server.h:
139         $(include-%.defs) | \
140         $(MIG) - /dev/null -prefix _S_ \
141                $(MIGFLAGS) $(server-MIGFLAGS) $(MIGFLAGS-$*) \
142                -user /dev/null -header /dev/null \
143                -server $(@:.h=.c) -sheader $(@:.c=.h)
145 # To get header files that declare both the straight and __ functions,
146 # we generate two files and paste them together.
147 $(objpfx)%.uh:; $(mig.uh)
148 define mig.uh
149 $(make-target-directory)
150 $(include-%.defs) | \
151 $(MIG) - /dev/null $(MIGFLAGS) $(MIGFLAGS-$*) \
152        -header $@ -server /dev/null -user /dev/null
153 endef
154 $(objpfx)%.__h:; $(mig.__h)
155 define mig.__h
156 $(make-target-directory)
157 $(include-%.defs) | \
158 $(MIG) - /dev/null $(MIGFLAGS) $(MIGFLAGS-$*) -prefix __ \
159        -header $@ -server /dev/null -user /dev/null
160 endef
162 $(objpfx)%.h: $(objpfx)%.__h $(objpfx)%.uh
163 # The last line of foo.__h is "#endif _foo_user_".
164 # The first two lines of foo.uh are "#ifndef _foo_user_"/"#define _foo_user_".
165         (sed -e '$$d' $<; sed -e '1,2d' $(word 2,$^)) > $@-new
166         mv -f $@-new $@
168 interface-routines := $(foreach if,$(user-interfaces),                  \
169                                 $(addprefix RPC_,$($(if)-calls)))       \
170                       $(server-interfaces:%=%_server)
171 interface-headers := $(user-interfaces:%=%.h) \
172                      $(server-interfaces:%=%_server.h)
174 # Remove the generated user stub source and header files,
175 # and don't distribute them.
176 mach-generated = $(interface-routines:%=%.c) $(interface-headers) \
177                  $(foreach h,$(user-interfaces),$h.uh $h.__h)
178 generated += $(mach-generated)
180 # These are needed to generate the dependencies.
181 before-compile += $(interface-headers:%=$(objpfx)%)
183 # Don't let these be intermediate files and get removed.
184 $(foreach h,$(interface-headers:%.h=$(objpfx)%),$h.h $h.__h $h.uh) :
185 $(interface-routines:%=$(objpfx)%.c) :
187 # Convenient target to generate all the headers.
188 .PHONY: interface-headers
189 interface-headers: $(interface-headers)
191 # Don't automatically generate dependencies for the sources we generate.
192 # There are likely to be a whole lot of them, and we know their
193 # dependencies ahead of time anyway because they're boilerplate.
194 omit-deps += $(interface-routines)
196 # Choose any single module generated by MiG.  We will compute this module's
197 # dependencies and then assume all other MiG-generated modules depend on the
198 # same headers.
199 some-if-rtn := $(firstword $(interface-routines))
200 ifdef some-if-rtn
201 $(foreach o,$(object-suffixes),$(interfaces-routines:%=%$o)): $(some-if-rtn).d
202 generated += $(some-if-rtn).d
203 endif
205 # If defined, $(interface-library) is `libNAME'.  It is to be a library
206 # containing all the MiG-generated functions for the specified interfaces.
208 ifdef interface-library
210 $(interface-library)-routines = $(interface-routines)
211 extra-libs += $(interface-library)
213 # Avoid -lmachuser requiring -lc, which may not be built yet.  If the
214 # shared object is absent, ld may choose a static library someplace and
215 # produce a bogus libmachuser.so.
216 +preinit =
217 +postinit =
218 +interp =
219 interface.so = $(interface-library:lib%=%.so)
220 LDFLAGS-$(interface.so) = -nostdlib -nostartfiles
222 endif