This is an automated email from the ASF dual-hosted git repository.
xiaofeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new 8b340f95 Get gcc version by script to support cross-compile (#2567)
8b340f95 is described below
commit 8b340f95a3a2ad95867ce2ca75b1737b035fb1d9
Author: Xiaofeng Wang <[email protected]>
AuthorDate: Fri Mar 22 11:13:09 2024 +0800
Get gcc version by script to support cross-compile (#2567)
Fix #1631
---
config_brpc.sh | 2 +-
tools/print_gcc_version.cc | 34 ----------------------------------
tools/print_gcc_version.sh | 41 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 35 deletions(-)
diff --git a/config_brpc.sh b/config_brpc.sh
index 777b76be..cc945d30 100755
--- a/config_brpc.sh
+++ b/config_brpc.sh
@@ -89,7 +89,7 @@ elif [ -z "$CXX" ]; then
exit 1
fi
-GCC_VERSION=$($CXX tools/print_gcc_version.cc -o print_gcc_version &&
./print_gcc_version && rm ./print_gcc_version)
+GCC_VERSION=$(CXX=$CXX tools/print_gcc_version.sh)
if [ $GCC_VERSION -gt 0 ] && [ $GCC_VERSION -lt 40800 ]; then
>&2 $ECHO "GCC is too old, please install a newer version supporting C++11"
exit 1
diff --git a/tools/print_gcc_version.cc b/tools/print_gcc_version.cc
deleted file mode 100644
index cfd615ce..00000000
--- a/tools/print_gcc_version.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include <stdio.h>
-int main() {
-#if defined(__clang__)
- const int major_v = __GNUC__;
- int minor_v = __GNUC_MINOR__;
- if (major_v == 4 && minor_v <= 8) {
- // Make version of clang >= 4.8 so that it's not rejected by
config_brpc.sh
- minor_v = 8;
- }
- printf("%d\n", (major_v * 10000 + minor_v * 100));
-#elif defined(__GNUC__)
- printf("%d\n", (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 +
__GNUC_PATCHLEVEL__));
-#else
- printf("0\n");
-#endif
- return 0;
-}
diff --git a/tools/print_gcc_version.sh b/tools/print_gcc_version.sh
new file mode 100755
index 00000000..00abf6cc
--- /dev/null
+++ b/tools/print_gcc_version.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+while read -r line; do
+ val=$(echo "$line" | awk '{print $3}')
+ if [[ $line =~ __clang__ ]]; then
+ CLANG=${val}
+ elif [[ $line =~ __GNUC__ ]]; then
+ GNUC=${val}
+ elif [[ $line =~ __GNUC_MINOR__ ]]; then
+ GNUC_MINOR=${val}
+ elif [[ $line =~ __GNUC_PATCHLEVEL__ ]]; then
+ GNUC_PATCHLEVEL=${val}
+ fi
+done < <("${CXX:-c++}" -dM -E - < /dev/null | grep
"__clang__\|__GNUC__\|__GNUC_MINOR__\|__GNUC_PATCHLEVEL__")
+
+if [ -n "$GNUC" ] && [ -n "$GNUC_MINOR" ] && [ -n "$GNUC_PATCHLEVEL" ]; then
+ # Calculate GCC/Clang version
+ GCC_VERSION=$((GNUC * 10000 + GNUC_MINOR * 100 + GNUC_PATCHLEVEL))
+ if [ -n "$CLANG" ] && [ "40000" -lt $GCC_VERSION ] && [ $GCC_VERSION -lt
"40800" ]; then
+ # Make version of clang >= 4.8 so that it's not rejected by
config_brpc.sh
+ GCC_VERSION=40800
+ fi
+ echo $GCC_VERSION
+else
+ echo 0
+fi
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]