|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -# Builds protoc executable into target/protoc.exe |
| 3 | +# Builds protoc executable into target/protoc.exe; optionally build protoc |
| 4 | +# plugins into target/protoc-gen-*.exe |
4 | 5 | # To be run from Maven. |
5 | | -# Usage: build-protoc.sh <OS> <ARCH> |
| 6 | +# Usage: build-protoc.sh <OS> <ARCH> <TARGET> |
6 | 7 | # <OS> and <ARCH> are ${os.detected.name} and ${os.detected.arch} from os-maven-plugin |
| 8 | +# <TARGET> can be "protoc" or "protoc-gen-javalite" |
7 | 9 | OS=$1 |
8 | 10 | ARCH=$2 |
| 11 | +MAKE_TARGET=$3 |
9 | 12 |
|
10 | | -if [[ $# < 2 ]]; then |
| 13 | +if [[ $# < 3 ]]; then |
11 | 14 | echo "No arguments provided. This script is intended to be run from Maven." |
12 | 15 | exit 1 |
13 | 16 | fi |
14 | 17 |
|
| 18 | +case $MAKE_TARGET in |
| 19 | + protoc-gen-javalite) |
| 20 | + ;; |
| 21 | + protoc) |
| 22 | + ;; |
| 23 | + *) |
| 24 | + echo "Target ""$TARGET"" invalid." |
| 25 | + exit 1 |
| 26 | +esac |
| 27 | + |
15 | 28 | # Under Cygwin, bash doesn't have these in PATH when called from Maven which |
16 | 29 | # runs in Windows version of Java. |
17 | 30 | export PATH="/bin:/usr/bin:$PATH" |
@@ -126,15 +139,14 @@ checkDependencies () |
126 | 139 | } |
127 | 140 | ############################################################################ |
128 | 141 |
|
129 | | -echo "Building protoc, OS=$OS ARCH=$ARCH" |
| 142 | +echo "Building protoc, OS=$OS ARCH=$ARCH TARGET=$TARGET" |
130 | 143 |
|
131 | 144 | # Nested double quotes are unintuitive, but it works. |
132 | 145 | cd "$(dirname "$0")" |
133 | 146 |
|
134 | 147 | WORKING_DIR=$(pwd) |
135 | 148 | CONFIGURE_ARGS="--disable-shared" |
136 | 149 |
|
137 | | -MAKE_TARGET="protoc" |
138 | 150 | if [[ "$OS" == windows ]]; then |
139 | 151 | MAKE_TARGET="${MAKE_TARGET}.exe" |
140 | 152 | fi |
|
209 | 221 |
|
210 | 222 | export CXXFLAGS LDFLAGS |
211 | 223 |
|
212 | | -TARGET_FILE=target/protoc.exe |
| 224 | +TARGET_FILE=target/$MAKE_TARGET.exe |
213 | 225 |
|
214 | 226 | cd "$WORKING_DIR"/.. && ./configure $CONFIGURE_ARGS && |
215 | | - cd src && make clean && make $MAKE_TARGET && |
| 227 | + cd src && make clean && make $MAKE_TARGET -j4 && |
216 | 228 | cd "$WORKING_DIR" && mkdir -p target && |
217 | | - (cp ../src/protoc $TARGET_FILE || cp ../src/protoc.exe $TARGET_FILE) || |
| 229 | + (cp ../src/$MAKE_TARGET $TARGET_FILE || |
| 230 | + cp ../src/$MAKE_TARGET.exe $TARGET_FILE) || |
218 | 231 | exit 1 |
219 | 232 |
|
220 | 233 | if [[ "$OS" == osx ]]; then |
|
0 commit comments