Created
August 16, 2016 09:33
-
-
Save farrokhi/2895f450184135596835e5afc2df3175 to your computer and use it in GitHub Desktop.
Script to detect best cpuflags settings for CC
This file contains hidden or 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
#!/bin/sh | |
COMPILERS="clang gcc gcc45 gcc46 gcc47 gcc48 gcc49 gcc5 gcc6" | |
check_compilers() | |
{ | |
echo "Looking for available C compilers..." | |
for C in ${COMPILERS} | |
do | |
P=`which ${C} 2>&1` | |
RES=$? | |
if [ $RES -eq 0 ]; then | |
echo " - Found ${C} at ${P}" | |
check_flags ${P} | |
echo | |
fi | |
done | |
} | |
check_flags() | |
{ | |
C=$1; shift; | |
printf " Compiler flags:\t" | |
if `echo ${C} | grep -q clang$` | |
then | |
${C} -march=native -E -v - < /dev/null 2>&1 | grep cc1 | grep -o -E '\-target-cpu ([a-zA-Z0-9=\-]+)' | |
else | |
${C} -march=native -E -v - < /dev/null 2>&1 | grep cc1 | grep -o -E '\-march[=]*[a-zA-Z0-9]+' | |
fi | |
} | |
check_compilers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment