Blame mach/Machrules

Packit 6c4009
# Rules for MiG interfaces that want to go into the C library.
Packit 6c4009
# Copyright (C) 1991-2018 Free Software Foundation, Inc.
Packit 6c4009
# This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
# The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
# modify it under the terms of the GNU Lesser General Public
Packit 6c4009
# License as published by the Free Software Foundation; either
Packit 6c4009
# version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
# The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
# Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
# You should have received a copy of the GNU Lesser General Public
Packit 6c4009
# License along with the GNU C Library; if not, see
Packit 6c4009
# <http://www.gnu.org/licenses/>.
Packit 6c4009
Packit 6c4009
# Makefiles may define these variable before including this file:
Packit 6c4009
#	user-interfaces		Names of interfaces to put user stubs in for.
Packit 6c4009
#	server-interfaces	Names of interfaces to put server stubs in for.
Packit 6c4009
#	interface-library	Name of interface library to build and install.
Packit 6c4009
# This file sets:
Packit 6c4009
#	interface-headers	Names of generated interface header files.
Packit 6c4009
#	interface-routines	Names of generated interface routines.
Packit 6c4009
# All user stubs are put in individual files, prefixed with RPC_; header
Packit 6c4009
# for both __ and non-__ names is put in foo.h.  Server interfaces are
Packit 6c4009
# written to foo_server.c and foo_server.h; the server functions are called
Packit 6c4009
# _S_rpcname.
Packit 6c4009
Packit 6c4009
# Includers can also add to or modify `migdefines' to set MiG flags.
Packit 6c4009
# They can also set `migheaderpipe' to mangle the MiG header output.
Packit 6c4009
Packit 6c4009
all:
Packit 6c4009
Packit 6c4009
# Make sure no value comes from the environment, since we append to it.
Packit 6c4009
# This is done also in ../Rules, but we append to the value before
Packit 6c4009
# including Rules, which changes the origin.
Packit 6c4009
ifneq	"$(findstring env,$(origin generated))" ""
Packit 6c4009
generated :=
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
include ../Makeconfig
Packit 6c4009
Packit 6c4009
# This makefile contains a lot of implicit rules that get optimized
Packit 6c4009
# away if the target directory does not exist.
Packit 6c4009
ifndef no_deps
Packit 6c4009
-include $(objpfx)dummy.mk
Packit 6c4009
endif
Packit 6c4009
$(objpfx)dummy.mk:
Packit 6c4009
	$(make-target-directory)
Packit 6c4009
	echo '# Empty' > $@
Packit 6c4009
Packit 6c4009
MIGFLAGS = -DSTANDALONE -DTypeCheck=0 \
Packit 6c4009
	   $(+includes) $(migdefines) -subrprefix __
Packit 6c4009
# Putting CC in the enivronment makes the mig wrapper script
Packit 6c4009
# use the same compiler setup we are using to run cpp.
Packit 6c4009
MIG := CC='${CC}' CPP='${CPP} -x c' $(MIG)
Packit 6c4009
Packit 6c4009
.SUFFIXES: .defs	# Just to set specified_rule_matched.
Packit 6c4009
Packit 6c4009
define nl	# This is needed by *.ir.
Packit 6c4009
Packit 6c4009
Packit 6c4009
endef
Packit 6c4009
ifdef user-interfaces
Packit 6c4009
*.ir := $(addprefix $(objpfx),$(foreach if,$(user-interfaces),$(if).ir))
Packit 6c4009
ifndef no_deps
Packit 6c4009
ifndef inhibit_interface_rules
Packit 6c4009
-include $(*.ir)
Packit 6c4009
endif
Packit 6c4009
endif
Packit 6c4009
ifneq "$(*.ir)" "$(wildcard $(*.ir))"
Packit 6c4009
# If any .ir file is missing, we will be unable to make all the deps.
Packit 6c4009
no_deps=t
Packit 6c4009
endif
Packit 6c4009
generated += $(*.ir:$(objpfx)%=%)
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
# %.ir defines a variable `%-calls', which lists the RPCs defined by
Packit 6c4009
# %.defs, and a rule to build $(%-calls:%=RPC_$(%-userprefix)%.c) from
Packit 6c4009
# %.defs, where $(%-userprefix) is the user prefix given in %.defs.  We use
Packit 6c4009
# the kludgificacious method of defining a pattern rule to build files
Packit 6c4009
# matching patterns we are pretty damn sure will only match the particular
Packit 6c4009
# files we have in mind.  To be so damn sure, we use the silly names
Packit 6c4009
# RPC_*.c and the pattern R%C_*.c because using __*.c and _%*.c (or any
Packit 6c4009
# other useful pattern) causes the rule for `host_info' to also match
Packit 6c4009
# `xxx_host_info', and analogous lossage.
Packit 6c4009
#
Packit 6c4009
# Depend on %.h just so they will be built from %.uh in the
Packit 6c4009
# makefile-rebuilding run which builds %.ir; otherwise, %.uh is built as an
Packit 6c4009
# intermediate in order to make %.ir and then removed before re-exec, when
Packit 6c4009
# %.uh is built all over again to build %.h.
Packit 6c4009
$(objpfx)%.ir: $(objpfx)%.uh $(objpfx)%.h
Packit 6c4009
	($(AWK) "NF == 4 && (\$$2 == \"Routine\" || \$$2 == \"SimpleRoutine\")\
Packit 6c4009
	        { printf \"$*-calls += %s\\n\", \$$3 }" $<	;\
Packit 6c4009
	 echo '$$($*-calls:%=$$(objpfx)R\%C_%.c): $$(objpfx)$*.ustamp ;';\
Packit 6c4009
	) > $@-new
Packit 6c4009
	mv -f $@-new $@
Packit 6c4009
vpath Machrules ../mach	# Find ourselves.
Packit 6c4009
Packit 6c4009
ifndef transform-user-stub-output
Packit 6c4009
transform-user-stub-output = tmp
Packit 6c4009
define transform-user-stub
Packit 6c4009
echo "weak_alias (__$$call, $$call)" >> $(objpfx)tmp_$${call}.c;
Packit 6c4009
endef
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
# Generate `#include <NAME.defs>', taking $* for NAME.
Packit 6c4009
# If $(NAME.defs) is defined use its value in place of `NAME.defs'.
Packit 6c4009
define include-%.defs
Packit 6c4009
echo '#include <$(firstword $($*.defs) $*.defs)>'
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
ifndef no_deps
Packit 6c4009
# Not an implicit rule so the stamps are never removed as intermediates!
Packit 6c4009
$(patsubst %,$(objpfx)%.ustamp,$(user-interfaces)): $(objpfx)%.ustamp:
Packit 6c4009
	rm -f $@
Packit 6c4009
	$(include-%.defs) | \
Packit 6c4009
	$(MIG) - /dev/null -prefix __ \
Packit 6c4009
	       $(MIGFLAGS) $(user-MIGFLAGS) $(MIGFLAGS-$*) \
Packit 6c4009
	       -i $(objpfx)tmp_ \
Packit 6c4009
	       -server /dev/null -user /dev/null -header /dev/null
Packit 6c4009
	for call in $($*-calls); do \
Packit 6c4009
	  $(transform-user-stub) \
Packit 6c4009
	  $(move-if-change) $(objpfx)$(transform-user-stub-output)_$${call}.c \
Packit 6c4009
			    $(objpfx)RPC_$${call}.c; \
Packit 6c4009
	done
Packit 6c4009
	touch $@
Packit 6c4009
-include $(patsubst %,$(objpfx)%.udeps,$(user-interfaces))
Packit 6c4009
$(patsubst %,$(objpfx)%.udeps,$(user-interfaces)):
Packit 6c4009
  $(objpfx)%.udeps: $(..)mach/Machrules
Packit 6c4009
	$(make-target-directory)
Packit 6c4009
# We must use $(CFLAGS) to get -O flags that affect #if's in header files.
Packit 6c4009
	$(include-%.defs) | \
Packit 6c4009
	$(CC) $(CFLAGS) $(CPPFLAGS) -M -x c - | \
Packit 6c4009
	sed -e 's,- *:,$(.udeps-targets):,' \
Packit 6c4009
	    $(sed-remove-objpfx) > $@.new
Packit 6c4009
	mv -f $@.new $@
Packit 6c4009
.udeps-targets = $@ $(@:.udeps=.ustamp) $(@:.udeps=.uh) $(@:.udeps=.__h) \
Packit 6c4009
		 $(@:.udeps=_server.c) $(@:.udeps=_server.h)
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
# Look for the server stub files where they will be written.
Packit 6c4009
vpath %_server.c $(addprefix $(objpfx),$(sort $(dir $(server-interfaces))))
Packit 6c4009
Packit 6c4009
# Build the server stubs in $(objdir).
Packit 6c4009
$(objpfx)%_server.c $(objpfx)%_server.h:
Packit 6c4009
	$(make-target-directory)
Packit 6c4009
	$(include-%.defs) | \
Packit 6c4009
	$(MIG) - /dev/null -prefix _S_ \
Packit 6c4009
	       $(MIGFLAGS) $(server-MIGFLAGS) $(MIGFLAGS-$*) \
Packit 6c4009
	       -user /dev/null -header /dev/null \
Packit 6c4009
	       -server $(@:.h=.c) -sheader $(@:.c=.h)
Packit 6c4009
Packit 6c4009
# To get header files that declare both the straight and __ functions,
Packit 6c4009
# we generate two files and paste them together.
Packit 6c4009
$(patsubst %,$(objpfx)%.uh,$(user-interfaces)): $(objpfx)%.uh:; $(mig.uh)
Packit 6c4009
define mig.uh
Packit 6c4009
$(make-target-directory)
Packit 6c4009
$(include-%.defs) | \
Packit 6c4009
$(MIG) - /dev/null $(MIGFLAGS) $(MIGFLAGS-$*) \
Packit 6c4009
       -header $@ -server /dev/null -user /dev/null
Packit 6c4009
endef
Packit 6c4009
$(patsubst %,$(objpfx)%.__h,$(user-interfaces)): $(objpfx)%.__h:; $(mig.__h)
Packit 6c4009
define mig.__h
Packit 6c4009
$(make-target-directory)
Packit 6c4009
$(include-%.defs) | \
Packit 6c4009
$(MIG) - /dev/null $(MIGFLAGS) $(MIGFLAGS-$*) -prefix __ \
Packit 6c4009
       -header $@ -server /dev/null -user /dev/null
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
$(patsubst %,$(objpfx)%.h,$(user-interfaces)): $(objpfx)%.h: $(objpfx)%.__h \
Packit 6c4009
							     $(objpfx)%.uh
Packit 6c4009
# The last line of foo.__h is "#endif _foo_user_".
Packit 6c4009
# The first two lines of foo.uh are "#ifndef _foo_user_"/"#define _foo_user_".
Packit 6c4009
	(sed -e '$$d' $<; sed -e '1,2d' $(word 2,$^)) $(migheaderpipe) > $@-new
Packit 6c4009
	mv -f $@-new $@
Packit 6c4009
Packit 6c4009
interface-routines := $(foreach if,$(user-interfaces),			\
Packit 6c4009
				$(addprefix RPC_,$($(if)-calls)))	\
Packit 6c4009
		      $(server-interfaces:%=%_server)
Packit 6c4009
interface-headers := $(user-interfaces:%=%.h) \
Packit 6c4009
		     $(server-interfaces:%=%_server.h)
Packit 6c4009
Packit 6c4009
# Remove the generated user stub source and header files,
Packit 6c4009
# and don't distribute them.
Packit 6c4009
mach-generated = $(interface-routines:%=%.c) $(interface-headers) \
Packit 6c4009
		 $(foreach h,$(user-interfaces),$h.uh $h.__h)
Packit 6c4009
generated += $(mach-generated)
Packit 6c4009
Packit 6c4009
# These are needed to generate the dependencies.
Packit 6c4009
before-compile += $(interface-headers:%=$(objpfx)%)
Packit 6c4009
Packit 6c4009
# Don't let these be intermediate files and get removed.
Packit 6c4009
$(foreach h,$(interface-headers:%.h=$(objpfx)%),$h.h $h.__h $h.uh) :
Packit 6c4009
$(interface-routines:%=$(objpfx)%.c) :
Packit 6c4009
Packit 6c4009
# Convenient target to generate all the headers.
Packit 6c4009
.PHONY: interface-headers
Packit 6c4009
interface-headers: $(interface-headers)
Packit 6c4009
Packit 6c4009
# Don't automatically generate dependencies for the sources we generate.
Packit 6c4009
# There are likely to be a whole lot of them, and we know their
Packit 6c4009
# dependencies ahead of time anyway because they're boilerplate.
Packit 6c4009
omit-deps += $(interface-routines)
Packit 6c4009
Packit 6c4009
# Choose any single module generated by MiG.  We will compute this module's
Packit 6c4009
# dependencies and then assume all other MiG-generated modules depend on the
Packit 6c4009
# same headers.
Packit 6c4009
some-if-rtn := $(firstword $(interface-routines))
Packit 6c4009
ifdef some-if-rtn
Packit 6c4009
$(foreach o,$(object-suffixes),$(interfaces-routines:%=%$o)): $(some-if-rtn).d
Packit 6c4009
generated += $(some-if-rtn).d
Packit 6c4009
endif
Packit 6c4009

Packit 6c4009
# If defined, $(interface-library) is `libNAME'.  It is to be a library
Packit 6c4009
# containing all the MiG-generated functions for the specified interfaces.
Packit 6c4009
Packit 6c4009
ifdef interface-library
Packit 6c4009
Packit 6c4009
$(interface-library)-routines = $(interface-routines) stack_chk_fail_local
Packit 6c4009
extra-libs += $(interface-library)
Packit 6c4009
extra-libs-others += $(interface-library)
Packit 6c4009
Packit 6c4009
ifeq (yes,$(build-shared))
Packit 6c4009
interface.so = $(interface-library:=.so)
Packit 6c4009
Packit 6c4009
# Depend on libc.so so a DT_NEEDED is generated in the shared objects.
Packit 6c4009
$(objpfx)$(interface.so): $(common-objpfx)libc.so
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
endif