Skip to content

Commit 8b340f9

Browse files
authored
Get gcc version by script to support cross-compile (#2567)
Fix #1631
1 parent e11c84d commit 8b340f9

3 files changed

Lines changed: 42 additions & 35 deletions

File tree

config_brpc.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ elif [ -z "$CXX" ]; then
8989
exit 1
9090
fi
9191

92-
GCC_VERSION=$($CXX tools/print_gcc_version.cc -o print_gcc_version && ./print_gcc_version && rm ./print_gcc_version)
92+
GCC_VERSION=$(CXX=$CXX tools/print_gcc_version.sh)
9393
if [ $GCC_VERSION -gt 0 ] && [ $GCC_VERSION -lt 40800 ]; then
9494
>&2 $ECHO "GCC is too old, please install a newer version supporting C++11"
9595
exit 1

tools/print_gcc_version.cc

Lines changed: 0 additions & 34 deletions
This file was deleted.

tools/print_gcc_version.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
while read -r line; do
19+
val=$(echo "$line" | awk '{print $3}')
20+
if [[ $line =~ __clang__ ]]; then
21+
CLANG=${val}
22+
elif [[ $line =~ __GNUC__ ]]; then
23+
GNUC=${val}
24+
elif [[ $line =~ __GNUC_MINOR__ ]]; then
25+
GNUC_MINOR=${val}
26+
elif [[ $line =~ __GNUC_PATCHLEVEL__ ]]; then
27+
GNUC_PATCHLEVEL=${val}
28+
fi
29+
done < <("${CXX:-c++}" -dM -E - < /dev/null | grep "__clang__\|__GNUC__\|__GNUC_MINOR__\|__GNUC_PATCHLEVEL__")
30+
31+
if [ -n "$GNUC" ] && [ -n "$GNUC_MINOR" ] && [ -n "$GNUC_PATCHLEVEL" ]; then
32+
# Calculate GCC/Clang version
33+
GCC_VERSION=$((GNUC * 10000 + GNUC_MINOR * 100 + GNUC_PATCHLEVEL))
34+
if [ -n "$CLANG" ] && [ "40000" -lt $GCC_VERSION ] && [ $GCC_VERSION -lt "40800" ]; then
35+
# Make version of clang >= 4.8 so that it's not rejected by config_brpc.sh
36+
GCC_VERSION=40800
37+
fi
38+
echo $GCC_VERSION
39+
else
40+
echo 0
41+
fi

0 commit comments

Comments
 (0)