1 # Rules for MiG interfaces that want to go into the C library.
3 # Copyright (C) 1991, 1992 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
18 # not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 # Cambridge, MA 02139, USA.
21 # Makefiles 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.
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 __, and a
28 # symbol-alias to the un-__'d form generated; header for both is put in
29 # foo.h. If a server interface is listed as __foo, then its routines are
30 # prefixed with __; server interfaces are written to foo_server.c and
31 # foo_server.h (or __foo_server.c and __foo_server.h).
33 # Includers can also add to or modify `migdefines' to set MiG flags.
42 MIGFLAGS = -DMACH_IPC_COMPAT=0 -DSTANDALONE -DTypeCheck=0 \
43 $(+includes) $(migdefines) -subrprefix __
47 define nl # This is needed by *.ir.
52 interface-includes := $(foreach if,$(user-interfaces),$(if).ir)
53 include $(interface-includes)
54 clean-extras := $(clean-extras) $(interface-includes)
57 # %.ir defines a variable `%-calls', which lists the RPCs defined by
58 # %.defs, and a rule to build $(%-calls:%=__$(%-userprefix)%.c) from
59 # %.defs, where $(%-userprefix) is the user prefix given in %.defs. We use
60 # the kludgificacious method of defining a pattern rule to build files
61 # matching patterns we are pretty damn sure will only match the particular
62 # files we have in mind.
64 (echo 'define $*-calls' ;\
65 awk '/^kern_return_t/ { print $$2 }' $< ;\
67 echo '$*-calls := $$(subst $$(nl), ,$$($*-calls))' ;\
68 echo '$$($*-calls:%=_\%%.c): $*.defs' ;\
69 echo ' $$(generate-user-calls)' \
72 vpath Machrules ../mach # Find ourselves.
74 define generate-user-calls
75 $(MIG) $< $(MIGFLAGS) \
76 -prefix __ -i ./__ -server /dev/null -user /dev/null -header /dev/null
79 __%_server.c __%_server.h: %.defs
80 $(MIG) $< $(MIGFLAGS) -prefix __ \
81 -user /dev/null -header /dev/null \
82 -server $(@:.h=.c) -sheader $(@:.c=.h)
83 %_server.c %_server.h: %.defs
84 $(MIG) $< $(MIGFLAGS) \
85 -user /dev/null -header /dev/null \
86 -server $(@:.h=.c) -sheader $(@:.c=.h)
88 # To get header files that declare both the straight and __ functions,
89 # we generate two files and paste them together.
91 $(MIG) $< $(MIGFLAGS) \
92 -header $@ -server /dev/null -user /dev/null
94 $(MIG) $< $(MIGFLAGS) -prefix __ \
95 -header $@ -server /dev/null -user /dev/null
98 # The last line of foo.uh is "#endif _foo_user_".
99 # The first two lines of foo.__h are "#ifndef _foo_user_"/"#define _foo_user_".
100 (sed '$$d' $<; tail +2 $(word 2,$^)) > $@-new
103 if-calls.c := $(strip $(foreach if,$(user-interfaces),$($(if)-calls:%=%.c)))
106 (echo '#include <gnu-stabs.h>'; \
107 echo 'symbol_alias (__$*, $*)') > $@-new
111 interface-routines := $(foreach if,$(user-interfaces), \
113 $(addprefix __,$($(if)-calls))) \
114 $(server-interfaces:%=%_server)
115 interface-headers := $(user-interfaces:%=%.h) $(server-interfaces:%=%_server.h)
117 # Remove the generated user stub source and header files,
118 # and don't distribute them.
119 mach-generated := $(interface-routines:%=%.c) \
120 $(interface-headers:%=%.h %.uh)
121 clean-extras := $(clean-extras) $(mach-generated)
122 dont_distribute := $(dont_distribute) $(mach-generated)
124 # These are needed to generate the dependencies.
125 before-compile := $(before-compile) $(interface-headers)