OLD | NEW |
1 #!/bin/bash | 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 # To be run from Maven. | 5 # To be run from Maven. |
5 # Usage: build-protoc.sh <OS> <ARCH> | 6 # Usage: build-protoc.sh <OS> <ARCH> <TARGET> |
6 # <OS> and <ARCH> are ${os.detected.name} and ${os.detected.arch} from os-maven-
plugin | 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 OS=$1 | 9 OS=$1 |
8 ARCH=$2 | 10 ARCH=$2 |
| 11 MAKE_TARGET=$3 |
9 | 12 |
10 if [[ $# < 2 ]]; then | 13 if [[ $# < 3 ]]; then |
11 echo "No arguments provided. This script is intended to be run from Maven." | 14 echo "No arguments provided. This script is intended to be run from Maven." |
12 exit 1 | 15 exit 1 |
13 fi | 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 # Under Cygwin, bash doesn't have these in PATH when called from Maven which | 28 # Under Cygwin, bash doesn't have these in PATH when called from Maven which |
16 # runs in Windows version of Java. | 29 # runs in Windows version of Java. |
17 export PATH="/bin:/usr/bin:$PATH" | 30 export PATH="/bin:/usr/bin:$PATH" |
18 | 31 |
19 ############################################################################ | 32 ############################################################################ |
20 # Helper functions | 33 # Helper functions |
21 ############################################################################ | 34 ############################################################################ |
22 E_PARAM_ERR=98 | 35 E_PARAM_ERR=98 |
23 E_ASSERT_FAILED=99 | 36 E_ASSERT_FAILED=99 |
24 | 37 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 if [[ $ret == 0 ]]; then | 132 if [[ $ret == 0 ]]; then |
120 fail "found unexpected dependencies (listed above)." | 133 fail "found unexpected dependencies (listed above)." |
121 elif [[ $ret != 1 ]]; then | 134 elif [[ $ret != 1 ]]; then |
122 fail "Error when checking dependencies." | 135 fail "Error when checking dependencies." |
123 fi # grep returns 1 when "not found", which is what we expect | 136 fi # grep returns 1 when "not found", which is what we expect |
124 echo "Dependencies look good." | 137 echo "Dependencies look good." |
125 echo | 138 echo |
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 # Nested double quotes are unintuitive, but it works. | 144 # Nested double quotes are unintuitive, but it works. |
132 cd "$(dirname "$0")" | 145 cd "$(dirname "$0")" |
133 | 146 |
134 WORKING_DIR=$(pwd) | 147 WORKING_DIR=$(pwd) |
135 CONFIGURE_ARGS="--disable-shared" | 148 CONFIGURE_ARGS="--disable-shared" |
136 | 149 |
137 MAKE_TARGET="protoc" | 150 TARGET_FILE=target/$MAKE_TARGET.exe |
138 if [[ "$OS" == windows ]]; then | 151 if [[ "$OS" == windows ]]; then |
139 MAKE_TARGET="${MAKE_TARGET}.exe" | 152 MAKE_TARGET="${MAKE_TARGET}.exe" |
140 fi | 153 fi |
141 | 154 |
142 # Override the default value set in configure.ac that has '-g' which produces | 155 # Override the default value set in configure.ac that has '-g' which produces |
143 # huge binary. | 156 # huge binary. |
144 CXXFLAGS="-DNDEBUG" | 157 CXXFLAGS="-DNDEBUG" |
145 LDFLAGS="" | 158 LDFLAGS="" |
146 | 159 |
147 if [[ "$(uname)" == CYGWIN* ]]; then | 160 if [[ "$(uname)" == CYGWIN* ]]; then |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 215 |
203 # Statically link libgcc and libstdc++. | 216 # Statically link libgcc and libstdc++. |
204 # -s to produce stripped binary. | 217 # -s to produce stripped binary. |
205 # And they don't work under Mac. | 218 # And they don't work under Mac. |
206 if [[ "$OS" != osx ]]; then | 219 if [[ "$OS" != osx ]]; then |
207 LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++ -s" | 220 LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++ -s" |
208 fi | 221 fi |
209 | 222 |
210 export CXXFLAGS LDFLAGS | 223 export CXXFLAGS LDFLAGS |
211 | 224 |
212 TARGET_FILE=target/protoc.exe | |
213 | |
214 cd "$WORKING_DIR"/.. && ./configure $CONFIGURE_ARGS && | 225 cd "$WORKING_DIR"/.. && ./configure $CONFIGURE_ARGS && |
215 cd src && make clean && make $MAKE_TARGET && | 226 cd src && make clean && make $MAKE_TARGET && |
216 cd "$WORKING_DIR" && mkdir -p target && | 227 cd "$WORKING_DIR" && mkdir -p target && |
217 (cp ../src/protoc $TARGET_FILE || cp ../src/protoc.exe $TARGET_FILE) || | 228 cp ../src/$MAKE_TARGET $TARGET_FILE || |
218 exit 1 | 229 exit 1 |
219 | 230 |
220 if [[ "$OS" == osx ]]; then | 231 if [[ "$OS" == osx ]]; then |
221 # Since Mac linker doesn't accept "-s", we need to run strip | 232 # Since Mac linker doesn't accept "-s", we need to run strip |
222 strip $TARGET_FILE || exit 1 | 233 strip $TARGET_FILE || exit 1 |
223 fi | 234 fi |
224 | 235 |
225 checkArch $TARGET_FILE && checkDependencies $TARGET_FILE | 236 checkArch $TARGET_FILE && checkDependencies $TARGET_FILE |
OLD | NEW |