This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Build rpcgen-generated files when cross compiling


This patch enables building rpcgen-generated files when cross
compiling, by building rpcgen for the build system, so eliminating one
difference between what you get installed from native and cross builds
of glibc.

There are two approaches that could be taken here: always build the
separate rpcgen for the build system and use it to generate these
files, or only build it in the cross case.  This one only builds it in
the cross case - the approach resulting in a larger patch, but more
conservative as to changing existing build behavior.  It would be
possible to simplify it by always building and using cross-rpcgen, and
that simplification would also allow install-headers in the native
case to work without building the whole library in the process to link
rpcgen.  (Bootstrap uses of install-headers are only relevant to cross
builds, not native, so that's more a matter of cleanliness and
convenience of testing install-headers than a practical problem with
using it.)

Eventually one might hope for the libtirpc project to provide both the
rpcgen program and the librpcsvc library and headers generated using
it, but I generally prefer to avoid artificial dependencies between
different glibc development projects (here, (a) getting cross builds
to produce the same results as native ones and (b) moving RPC
functionality to the libtirpc project) and think it's appropriate to
put such improvements in now although eventually this code may no
longer be needed in glibc.

Tested x86_64 (both native, and bootstrapped cross together with the
previously posted patches for bits/syscall.h and gnu/stubs.h).

2012-03-12  Maxim Kuvyrkov  <maxim@codesourcery.com>
	    Joseph Myers  <joseph@codesourcery.com>
	    Paul Pluzhnikov  <ppluzhnikov@google.com>

	* sunrpc/Makefile [cross-compiling] (headers): Enable additions
	requiring rpcgen.
	[cross-compiling] (extra-libs): Likewise.
	[cross-compiling] (extra-libs-others): Likewise.
	[cross-compiling] (librpcsvc-routines): Likewise.
	[cross-compiling] (librpcsvc-inhibit-o): Likewise.
	[cross-compiling] (omit-deps): Likewise.
	($(addprefix $(objpfx)cross-,$(rpcgen-objs))): New rule.
	($(objpfx)cross-rpcgen): Likewise.
	[cross-compiling] (rpcgen-cmd): Define to use cross-rpcgen.
	(rpcgen-dep): New variable.
	($(objpfx)rpcsvc/%.stmp): Depend on $(rpcgen-dep).
	($(objpfx)x%.stmp): Likewise.
	* sunrpc/proto.h [_CROSS_RPCGEN_] (_): Define.
	[_CROSS_RPCGEN_] (_libc_intl_domainname): Likewise.

diff --git a/sunrpc/Makefile b/sunrpc/Makefile
index e0339ad..0a7f4dc 100644
--- a/sunrpc/Makefile
+++ b/sunrpc/Makefile
@@ -102,15 +102,12 @@ otherlibs += $(nssobjdir)/libnss_files.a $(resolvobjdir)/libnss_dns.a \
 	     $(resolvobjdir)/libresolv.a
 endif
 
-ifeq (no,$(cross-compiling))
-# We can only build this library if we can run the rpcgen we build.
 headers += $(rpcsvc:%.x=rpcsvc/%.h)
 extra-libs := librpcsvc
 extra-libs-others := librpcsvc # Make it in `others' pass, not `lib' pass.
 librpcsvc-routines = $(rpcsvc:%.x=x%)
 librpcsvc-inhibit-o = .os # Build no shared rpcsvc library.
 omit-deps = $(librpcsvc-routines)
-endif
 
 include ../Rules
 
@@ -152,13 +149,30 @@ $(objpfx)tst-xdrmem2: $(common-objpfx)linkobj/libc.so
 
 $(objpfx)rpcgen: $(addprefix $(objpfx),$(rpcgen-objs))
 
+$(addprefix $(objpfx)cross-,$(rpcgen-objs)): $(objpfx)cross-%.o: %.c
+	$(make-target-directory)
+	$(BUILD_CC) $< -c -D_GNU_SOURCE -D_RPC_THREAD_SAFE_ -D_CROSS_RPCGEN_ \
+		$(OUTPUT_OPTION) $(compile-mkdep-flags)
+
+$(objpfx)cross-rpcgen: $(addprefix $(objpfx)cross-,$(rpcgen-objs))
+	$(BUILD_CC) $^ -o $@
+
 # This makes sure -DNOT_IN_libc is passed for all these modules.
 cpp-srcs-left := $(rpcgen-objs:.o=.c)
 lib := nonlib
 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
 
+ifeq (no,$(cross-compiling))
 # Tell rpcgen where to find the C preprocessor.
 rpcgen-cmd = CPP='$(CC) -E -x c-header' $(built-program-cmd) -Y ../scripts
+# Depend rpcsvc headers and sources on rpcgen.
+rpcgen-dep = $(objpfx)rpcgen
+else
+# Tell rpcgen where to find the C preprocessor.
+rpcgen-cmd = CPP='$(CC) -E -x c-header' $(objpfx)cross-rpcgen -Y ../scripts
+# Depend rpcsvc headers and sources on cross-rpcgen.
+rpcgen-dep = $(objpfx)cross-rpcgen
+endif
 
 # Install the rpc data base file.
 $(inst_sysconfdir)/rpc: etc.rpc $(+force)
@@ -169,7 +183,7 @@ $(inst_sysconfdir)/rpc: etc.rpc $(+force)
 # relinked.
 $(rpcsvc:%.x=$(objpfx)rpcsvc/%.h): $(objpfx)rpcsvc/%.h: $(objpfx)rpcsvc/%.stmp
 	@:
-$(objpfx)rpcsvc/%.stmp: rpcsvc/%.x $(objpfx)rpcgen
+$(objpfx)rpcsvc/%.stmp: rpcsvc/%.x $(rpcgen-dep)
 	$(make-target-directory)
 	-@rm -f ${@:stmp=T} $@
 	$(rpcgen-cmd) -h $< -o ${@:stmp=T}
@@ -179,7 +193,7 @@ $(objpfx)rpcsvc/%.stmp: rpcsvc/%.x $(objpfx)rpcgen
 # Generate the rpcsvc XDR functions with rpcgen.
 $(rpcsvc:%.x=$(objpfx)x%.c): $(objpfx)x%.c: $(objpfx)x%.stmp
 	@:
-$(objpfx)x%.stmp: rpcsvc/%.x $(objpfx)rpcgen
+$(objpfx)x%.stmp: rpcsvc/%.x $(rpcgen-dep)
 	-@rm -f ${@:stmp=T} $@
 	$(rpcgen-cmd) -c $< -o ${@:stmp=T}
 	$(move-if-change) $(@:stmp=T) $(@:stmp=c)
diff --git a/sunrpc/proto.h b/sunrpc/proto.h
index 3e1ecd1..56f9155 100644
--- a/sunrpc/proto.h
+++ b/sunrpc/proto.h
@@ -50,3 +50,14 @@ void crash(void) __attribute__ ((noreturn));
 void tabify(FILE *f, int tab);
 char *make_argname(const char *pname, const char *vname);
 void add_type(int len, const char *type);
+
+/* This header is the last one included in all rpc_*.c files,
+   so we define stuff for cross-rpcgen here to avoid conflicts with
+   $build's C library and $host's glibc.  */
+
+#ifdef _CROSS_RPCGEN_
+
+#define _(X) (X)
+#define _libc_intl_domainname "libc"
+
+#endif

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]