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