-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to check supported compiler options on Linux
Eg Alpine may not have the sanitizers available, so check for them before trying to use them.
- Loading branch information
Showing
3 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/bin/sh | ||
|
||
rm -f ../mconfig | ||
|
||
INST_PATH_OPTS=$( | ||
echo "# Installation path options."; | ||
echo ""; | ||
echo "SBINDIR=/sbin"; | ||
echo "MANDIR=/usr/share/man"; | ||
echo "SYSCONTROLSOCKET=/dev/dinitctl" | ||
) | ||
|
||
test_compiler_arg() { | ||
"$1" -c "$2" testfile.cc -o testfile.o > /dev/null 2>&1 | ||
if test $? = 0; then | ||
supported_opts="$supported_opts $2" | ||
supported_opts=${supported_opts# } | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
for compiler in g++ clang++ c++ ""; do | ||
if test -z "$compiler"; then | ||
break # none found | ||
fi | ||
type $compiler > /dev/null | ||
if test $? = 0; then | ||
break # found | ||
fi | ||
done | ||
|
||
if test -z "$compiler"; then | ||
echo "*** No compiler found ***" | ||
exit 1 | ||
fi | ||
|
||
echo "Compiler found : $compiler" | ||
|
||
touch testfile.cc | ||
supported_opts="" | ||
test_compiler_arg "$compiler" -flto | ||
HAS_LTO=$? | ||
test_compiler_arg "$compiler" -fno-rtti | ||
test_compiler_arg "$compiler" -fno-plt | ||
BUILD_OPTS="-D_GLIBCXX_USE_CXX11_ABI=1 -std=c++11 -Os -Wall $supported_opts" | ||
if test $HAS_LTO = 0; then | ||
LD_OPTS="-flto -Os" | ||
else | ||
LD_OPTS="" | ||
fi | ||
|
||
echo "Using build options : $supported_opts" | ||
|
||
supported_opts="" | ||
test_compiler_arg "$compiler" -fsanitize=address,undefined | ||
SANITIZE_OPTS="$supported_opts" | ||
|
||
echo "Sanitize options : $SANITIZE_OPTS" | ||
|
||
rm testfile.cc | ||
|
||
GENERAL_BUILD_SETTINGS=$( | ||
echo "" | ||
echo "" | ||
echo "# General build options." | ||
echo "" | ||
echo "# Linux (GCC). Note with GCC 5.x/6.x you must use the old ABI, with GCC 7.x you must use" | ||
echo "# the new ABI. See BUILD.txt file for more information." | ||
echo "CXX=$compiler" | ||
echo "CXXOPTS=$BUILD_OPTS" | ||
echo "LDFLAGS=$LD_OPTS" | ||
echo "BUILD_SHUTDOWN=yes" | ||
echo "SANITIZEOPTS=$SANITIZE_OPTS" | ||
echo "" | ||
echo "# Notes:" | ||
echo "# -D_GLIBCXX_USE_CXX11_ABI=1 : force use of new ABI, see above / BUILD.txt" | ||
echo "# -fno-rtti (optional) : Dinit does not require C++ Run-time Type Information" | ||
echo "# -fno-plt (optional) : Recommended optimisation" | ||
echo "# -flto (optional) : Perform link-time optimisation" | ||
echo "# -fsanitize=address,undefined : Apply sanitizers (during unit tests)" | ||
) | ||
|
||
#echo "$INST_PATH_OPTS" | ||
#echo "$GENERAL_BUILD_SETTINGS" | ||
|
||
( | ||
echo "$INST_PATH_OPTS" | ||
echo "$GENERAL_BUILD_SETTINGS" | ||
) >> ../mconfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters