aboutsummaryrefslogtreecommitdiff
path: root/protoc-artifacts
diff options
context:
space:
mode:
authorKun Zhang <zhangkun@google.com>2015-04-01 16:23:15 -0700
committerKun Zhang <zhangkun@google.com>2015-04-01 16:23:15 -0700
commitc8eda8e9d8e91a94b7e060b4a0d3ef21f4224a5a (patch)
treeb52cdc823080e58b5e4b9b2e9469eb17df2b057a /protoc-artifacts
parente499956536ca12f151715b8f9f79739df9da15ff (diff)
downloadprotobuf-c8eda8e9d8e91a94b7e060b4a0d3ef21f4224a5a.tar.gz
protobuf-c8eda8e9d8e91a94b7e060b4a0d3ef21f4224a5a.tar.bz2
protobuf-c8eda8e9d8e91a94b7e060b4a0d3ef21f4224a5a.zip
Run make protoc(.exe) instead of just make, because the latter fails on Cygwin with mingw gcc; build-protoc.sh works under Cygwin; build-protoc.sh will use the --host parameter consistent with what os-maven-plugin has detected
Diffstat (limited to 'protoc-artifacts')
-rwxr-xr-xprotoc-artifacts/build-protoc.sh88
-rw-r--r--protoc-artifacts/pom.xml2
2 files changed, 81 insertions, 9 deletions
diff --git a/protoc-artifacts/build-protoc.sh b/protoc-artifacts/build-protoc.sh
index 4e0e5498..f8afa95a 100755
--- a/protoc-artifacts/build-protoc.sh
+++ b/protoc-artifacts/build-protoc.sh
@@ -1,7 +1,84 @@
#!/bin/bash
+# Builds protoc executable into target/protoc.exe
+# To be run from Maven.
+# Usage: build-protoc.sh <OS> <ARCH>
+# <OS> and <ARCH> are ${os.detected.name} and ${os.detected.arch} from os-maven-plugin
+OS=$1
+ARCH=$2
+
+# Under Cygwin, bash doesn't have these in PATH when called from Maven which
+# runs in Windows version of Java.
+export PATH="/bin:/usr/bin:$PATH"
+
+############################################################################
+# Helper functions
+############################################################################
+E_PARAM_ERR=98
+E_ASSERT_FAILED=99
+
+fail()
+{
+ echo "Error: $1"
+ exit $E_ASSERT_FAILED
+}
+
+# Usage: assertEq VAL1 VAL2 $LINENO
+assertEq ()
+{
+ lineno=$3
+ if [ -z "$lineno" ]; then
+ echo "lineno not given"
+ exit $E_PARAM_ERR
+ fi
+
+ if [[ "$1" != "$2" ]]; then
+ echo "Assertion failed: \"$1\" == \"$2\""
+ echo "File \"$0\", line $lineno" # Give name of file and line number.
+ exit $E_ASSERT_FAILED
+ fi
+}
+############################################################################
+
+echo "Building protoc, OS=$OS ARCH=$ARCH"
+
cd $(dirname "$0")
WORKING_DIR=$(pwd)
+CONFIGURE_ARGS="--disable-shared"
+
+MAKE_TARGET="protoc"
+if [[ "$OS" == windows ]]; then
+ MAKE_TARGET="${MAKE_TARGET}.exe"
+fi
+
+if [[ "$(uname)" == CYGWIN* ]]; then
+ assertEq "$OS" windows $LINENO
+ # Use mingw32 compilers because executables produced by Cygwin compiler
+ # always have dependency on Cygwin DLL.
+ if [[ "$ARCH" == x86_64 ]]; then
+ CONFIGURE_ARGS="$CONFIGURE_ARGS --host=x86_64-w64-mingw32"
+ elif [[ "$ARCH" == x86_32 ]]; then
+ CONFIGURE_ARGS="$CONFIGURE_ARGS --host=i686-pc-mingw32"
+ else
+ fail "Unsupported arch by CYGWIN: $ARCH"
+ fi
+elif [[ "$(uname)" == MINGW32* ]]; then
+ assertEq "$OS" windows $LINENO
+ assertEq "$ARCH" x86_32 $LINENO
+elif [[ "$(uname)" == Linux* ]]; then
+ assertEq "$OS" linux $LINENO
+ if [[ "$ARCH" == x86_64 ]]; then
+ CONFIGURE_ARGS="$CONFIGURE_ARGS --host=x86_64-linux-gnu"
+ elif [[ "$ARCH" == x86_32 ]]; then
+ CONFIGURE_ARGS="$CONFIGURE_ARGS --host=i686-linux-gnu"
+ else
+ fail "Unsupported arch by CYGWIN: $ARCH"
+ fi
+elif [[ "$(uname)" == Darwin* ]]; then
+ assertEq "$OS" osx $LINENO
+else
+ fail "Unsupported system: $(uname)"
+fi
# Override the default value set in configure.ac that has '-g' which produces
# huge binary.
@@ -11,14 +88,7 @@ export CXXFLAGS="-DNDEBUG"
# -s to produce stripped binary
export LDFLAGS="-static-libgcc -static-libstdc++ -s"
-# Under Cygwin we use MinGW GCC because the executable produced by Cygwin GCC
-# depends on Cygwin DLL.
-if [[ "$(uname)" == CYGWIN* ]]; then
- export CC=i686-pc-mingw32-gcc
- export CXX=i686-pc-mingw32-c++
- export CXXCPP=i686-pc-mingw32-cpp
-fi
-
-cd "$WORKING_DIR"/.. && ./configure --disable-shared && make clean && make &&
+cd "$WORKING_DIR"/.. && ./configure $CONFIGURE_ARGS &&
+ cd src && make clean && make $MAKE_TARGET &&
cd "$WORKING_DIR" && mkdir -p target &&
(cp ../src/protoc target/protoc.exe || cp ../src/protoc.exe target/protoc.exe)
diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml
index f7bc8818..2536cad6 100644
--- a/protoc-artifacts/pom.xml
+++ b/protoc-artifacts/pom.xml
@@ -57,6 +57,8 @@
<executable>bash</executable>
<arguments>
<argument>build-protoc.sh</argument>
+ <argument>${os.detected.name}</argument>
+ <argument>${os.detected.arch}</argument>
</arguments>
</configuration>
</plugin>