Quellcode durchsuchen

enable cross-compiling

kenton@google.com vor 16 Jahren
Ursprung
Commit
9824eda6b5
4 geänderte Dateien mit 59 neuen und 0 gelöschten Zeilen
  1. 2 0
      CHANGES.txt
  2. 23 0
      README.txt
  3. 24 0
      configure.ac
  4. 10 0
      src/Makefile.am

+ 2 - 0
CHANGES.txt

@@ -29,6 +29,8 @@
       optional int32 foo = 1 [deprecated = true];
     Currently this does not have any actual effect, but in the future the code
     generators may generate deprecation annotations in each language.
+  * Cross-compiling should now be possible using the --with-protoc option to
+    configure.  See README.txt for more info.
 
   protoc
   * --error_format=msvs option causes errors to be printed in Visual Studio

+ 23 - 0
README.txt

@@ -33,6 +33,29 @@ For advanced usage information on configure and make, see INSTALL.txt.
   If you already built the package with a different prefix, make sure
   to run "make clean" before building again.
 
+** Note for cross-compiling **
+
+  The makefiles normally invoke the protoc executable that they just
+  built in order to build tests.  When cross-compiling, the protoc
+  executable may not be executable on the host machine.  In this case,
+  you must build a copy of protoc for the host machine first, then use
+  the --with-protoc option to tell configure to use it instead.  For
+  example:
+
+    ./configure --with-protoc=protoc
+
+  This will use the installed protoc (found in your $PATH) instead of
+  trying to execute the one built during the build process.  You can
+  also use an executable that hasn't been installed.  For example, if
+  you built the protobuf package for your host machine in ../host,
+  you might do:
+
+    ./configure --with-protoc=../host/src/protoc
+
+  Either way, you must make sure that the protoc executable you use
+  has the same version as the protobuf source code you are trying to
+  use it with.
+
 ** Note for Solaris users **
 
   Solaris 10 x86 has a bug that will make linking fail, complaining

+ 24 - 0
configure.ac

@@ -30,6 +30,11 @@ AC_ARG_WITH([zlib],
     [include classes for streaming compressed data in and out @<:@default=check@:>@])],
   [],[with_zlib=check])
 
+AC_ARG_WITH([protoc],
+  [AS_HELP_STRING([--with-protoc=COMMAND],
+    [use the given protoc command instead of building a new one when building tests (useful for cross-compiling)])],
+  [],[with_protoc=no])
+
 # Checks for programs.
 AC_PROG_CC
 AC_PROG_CXX
@@ -90,6 +95,25 @@ AS_IF([test "$with_zlib" != no],
      fi])])
 AM_CONDITIONAL([HAVE_ZLIB], [test $HAVE_ZLIB = 1])
 
+AS_IF([test "$with_protoc" != "no"], [
+  PROTOC=$with_protoc
+  AS_IF([test "$with_protoc" == "yes"], [
+    # No argument given.  Use system protoc.
+    PROTOC=protoc
+  ])
+  AS_IF([echo "$PROTOC" | grep -q '^@<:@^/@:>@.*/'], [
+    # Does not start with a slash, but contains a slash.  So, it's a relative
+    # path (as opposed to an absolute path or an executable in $PATH).
+    # Since it will actually be executed from the src directory, prefix with
+    # the current directory.  We also insert $ac_top_build_prefix in case this
+    # is a nested package and --with-protoc was actually given on the outer
+    # package's configure script.
+    PROTOC=`pwd`/${ac_top_build_prefix}$PROTOC
+  ])
+  AC_SUBST([PROTOC])
+])
+AM_CONDITIONAL([USE_EXTERNAL_PROTOC], [test "$with_protoc" != "no"])
+
 ACX_PTHREAD
 AC_CXX_STL_HASH
 

+ 10 - 0
src/Makefile.am

@@ -206,6 +206,14 @@ protoc_outputs =                                               \
 
 BUILT_SOURCES = $(protoc_outputs)
 
+if USE_EXTERNAL_PROTOC
+
+unittest_proto_middleman: $(protoc_inputs)
+	$(PROTOC) -I$(srcdir) --cpp_out=. $(protoc_inputs)
+	touch unittest_proto_middleman
+
+else
+
 # This rule is a little weird.  The first prereq is the protoc executable
 # and the rest are its inputs.  Therefore, $^ -- which expands to the
 # list of prereqs -- is actually a valid command.  We have to place "./" in
@@ -220,6 +228,8 @@ unittest_proto_middleman: protoc$(EXEEXT) $(protoc_inputs)
 	./$^ -I$(srcdir) --cpp_out=.
 	touch unittest_proto_middleman
 
+endif
+
 $(protoc_outputs): unittest_proto_middleman
 
 COMMON_TEST_SOURCES =                                          \