* posix/execvp.c: When executing shell on script, first arg is
[glibc.git] / mach / Machrules
blobd4e9ea0475ae63a906b5ec8943b1637607bd5f53
1 # Rules for MiG interfaces that want to go into the C library.
3 # Copyright (C) 1991, 92, 93, 94, 95, 96 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 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 ifndef MIG
48 MIG = mig
49 endif
50 MIGFLAGS = -DMACH_IPC_COMPAT=0 -DSTANDALONE -DTypeCheck=0 \
51            $(+includes) $(migdefines) -subrprefix __
53 .SUFFIXES: .defs        # Just to set specified_rule_matched.
55 define nl       # This is needed by *.ir.
58 endef
59 ifdef user-interfaces
60 *.ir := $(addprefix $(objpfx),$(foreach if,$(user-interfaces),$(if).ir))
61 ifndef no_deps
62 ifndef inhibit_interface_rules
63 include $(*.ir)
64 endif
65 endif
66 ifneq "$(*.ir)" "$(wildcard $(*.ir))"
67 # If any .ir file is missing, we will be unable to make all the deps.
68 no_deps=t
69 endif
70 generated += $(*.ir:$(objpfx)%=%)
71 endif
74 # %.ir defines a variable `%-calls', which lists the RPCs defined by
75 # %.defs, and a rule to build $(%-calls:%=RPC_$(%-userprefix)%.c) from
76 # %.defs, where $(%-userprefix) is the user prefix given in %.defs.  We use
77 # the kludgificacious method of defining a pattern rule to build files
78 # matching patterns we are pretty damn sure will only match the particular
79 # files we have in mind.  To be so damn sure, we use the silly names
80 # RPC_*.c and the pattern R%C_*.c because using __*.c and _%*.c (or any
81 # other useful pattern) causes the rule for `host_info' to also match
82 # `xxx_host_info', and analogous lossage.
84 # While we're at it, we figure out the imports used by %.defs and give them
85 # as dependencies of the object files for the generated RPC_*.c files.
87 # Depend on %.h just so they will be built from %.uh in the
88 # makefile-rebuilding run which builds %.ir; otherwise, %.uh is built as an
89 # intermediate in order to make %.ir and then removed before re-exec, when
90 # %.uh is built all over again to build %.h.
91 $(objpfx)%.ir: $(objpfx)%.uh $(objpfx)%.h
92         (awk "NF == 4 && (\$$2 == \"Routine\" || \$$2 == \"SimpleRoutine\")\
93                 { printf \"$*-calls += %s\\n\", \$$3 }  \
94               /^#include/ { printf \"$*-imports += %s\\n\", \$$2 }" $<  ;\
95          echo '$$($*-calls:%=$$(objpfx)R\%C_%.c): $$(objpfx)$*.ustamp ;';\
96          echo '$$($*-calls:%=$$(objpfx)RPC_%.o): $$($*-imports:<%>=%)'  ;\
97         ) > $@-new
98         mv $@-new $@
99 vpath Machrules ../mach # Find ourselves.
101 ifndef transform-user-stub-output
102 transform-user-stub-output = tmp
103 define transform-user-stub
104 echo "weak_alias (__$$call, $$call)" >> $(objpfx)tmp_$${call}.c;
105 endef
106 endif
108 # Not an implicit rule so the stamps are never removed as intermediates!
109 $(patsubst %,$(objpfx)%.ustamp,$(user-interfaces)): $(objpfx)%.ustamp: %.defs
110         $(MIG) $< $(MIGFLAGS) $(user-MIGFLAGS) \
111                -prefix __ -i $(objpfx)tmp_ \
112                -server /dev/null -user /dev/null -header /dev/null
113         for call in $($*-calls); do \
114           $(transform-user-stub) \
115           ../move-if-change $(objpfx)$(transform-user-stub-output)_$${call}.c \
116                             $(objpfx)RPC_$${call}.c; \
117         done
118         touch $@
120 # Look for the server stub files where they will be written.
121 vpath %_server.c $(addprefix $(objpfx),$(sort $(dir $(server-interfaces))))
123 # Build the server stubs in $(objdir).
124 $(objpfx)%_server.c $(objpfx)%_server.h: %.defs
125         $(MIG) $< $(MIGFLAGS) $(server-MIGFLAGS) \
126                -prefix _S_ \
127                -user /dev/null -header /dev/null \
128                -server $(@:.h=.c) -sheader $(@:.c=.h)
130 # To get header files that declare both the straight and __ functions,
131 # we generate two files and paste them together.
132 $(objpfx)%.uh: %.defs; $(mig.uh)
133 define mig.uh
134 $(make-target-directory)
135 $(MIG) $< $(MIGFLAGS) \
136        -header $@ -server /dev/null -user /dev/null
137 endef
138 $(objpfx)%.__h: %.defs; $(mig.__h)
139 define mig.__h
140 $(make-target-directory)
141 $(MIG) $< $(MIGFLAGS) -prefix __ \
142        -header $@ -server /dev/null -user /dev/null
143 endef
145 $(objpfx)%.h: $(objpfx)%.__h $(objpfx)%.uh
146 # The last line of foo.__h is "#endif _foo_user_".
147 # The first two lines of foo.uh are "#ifndef _foo_user_"/"#define _foo_user_".
148         (sed -e '$$d' $<; sed -e '1,2d' $(word 2,$^)) > $@-new
149         mv $@-new $@
151 interface-routines := $(foreach if,$(user-interfaces),                  \
152                                 $(addprefix RPC_,$($(if)-calls)))       \
153                       $(server-interfaces:%=%_server)
154 interface-headers := $(user-interfaces:%=%.h) \
155                      $(server-interfaces:%=%_server.h)
157 # Remove the generated user stub source and header files,
158 # and don't distribute them.
159 mach-generated = $(interface-routines:%=%.c) \
160                  $(foreach h,$(interface-headers:%.h=%),$h.h $h.uh $h.__h)
161 generated += $(mach-generated)
163 # These are needed to generate the dependencies.
164 before-compile += $(interface-headers:%=$(objpfx)%)
166 # Don't let these be intermediate files and get removed.
167 $(foreach h,$(interface-headers:%.h=$(objpfx)%),$h.h $h.__h $h.uh) :
168 $(interface-routines:%=$(objpfx)%.c) :
170 # Convenient target to generate all the headers.
171 .PHONY: interface-headers
172 interface-headers: $(interface-headers)
174 # Don't automatically generate dependencies for the sources we generate.
175 # There are likely to be a whole lot of them, and we know their
176 # dependencies ahead of time anyway because they're boilerplate.
177 omit-deps += $(interface-routines)
179 # Specify the static dependencies of the generated files.
180 $(foreach o,$(object-suffixes),\
181 $(foreach if,$(user-interfaces),$($(if)-calls:%=$(objpfx)RPC_%$o))): \
182     mach/boolean.h mach/kern_return.h mach/message.h mach/notify.h \
183     mach/mach_types.h mach/mig_errors.h mach/mig_support.h mach/msg_type.h \
184     $(..)libc-symbols.h $(objpfx)config.h
185 $(foreach o,$(object-suffixes),\
186 $(server-interfaces:%=$(objpfx)%$o)): \
187     mach/boolean.h mach/kern_return.h mach/message.h mach/mig_errors.h \
188     mach/mig_support.h mach/std_types.h
189 # The MiG-generated sources also depend on the imports in their .defs files.
190 # These dependencies are generated into the .ir files above.
192 # If defined, $(interface-library) is `libNAME'.  It is to be a library
193 # containing all the MiG-generated functions for the specified interfaces.
195 ifdef interface-library
197 $(interface-library)-routines = $(interface-routines)
198 extra-libs += $(interface-library)
200 # Avoid -lmachuser requiring -lc, which may not be built yet.  If the
201 # shared object is absent, ld may choose a static library someplace and
202 # produce a bogus libmachuser.so.
203 interface.so = $(interface-library:lib%=%.so)
204 LDFLAGS-$(interface.so) = -nostdlib -nostartfiles
206 endif