Last active
August 31, 2019 11:08
-
-
Save loopyd/02705b00f3a8fff24a67a0bea1ca2fbc to your computer and use it in GitHub Desktop.
Programmable CPU architecture table for use with Gentoo. Fill out the table as you like. ``/proc/cpuinfo`` is used to match at least 1 entry in the table.
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 gist is a useful little programmable tool I wrote to test and | |
# expand CPU arcitecture auto-detection for Gentoo. It allows you to identify | |
# for cross-compiler what machine you will be building the system for. | |
# ...and now its a programmable gist ! Enjoy ! - Heavy H. Paws | |
# | |
function cpu_arch () { | |
local OS_ARCH= | |
## Examples | |
## | |
## Will identify: 32 and 64 bit intel processors | |
## 32 and 64 bit amd processors | |
## raspberry pi 3 model b+ armv7 | |
## pi zero | |
CPU_TABLE=$(echo "amd64|flags,lm,vendor_id,genuineintel;"\ | |
"x86|vendor_id,genuineintel;"\ | |
"amd64|flags,lm,vendor_id,authenticamd;"\ | |
"amd|vendor_id,authenticamd;"\ | |
"armhf|flags,lm,model name,armv7;"\ | |
"arm|model name,armv6") | |
OS_CPU=$(IFS=';' | |
for CPU_ENTRY in $CPU_TABLE | |
do | |
CPU_ARCH=$(echo "${CPU_ENTRY}" | cut -d'|' -f1) | |
CPU_ENTRY=$(echo "${CPU_ENTRY}" | sed -e "s/^${CPU_ARCH}[|]//g") | |
MATCH_RESULT=0 | |
while [[ "${CPU_ENTRY}x" != "x" ]]; do | |
F1=$(echo "${CPU_ENTRY}" | cut -d ',' -f1) | |
F2=$(echo "${CPU_ENTRY}" | cut -d ',' -f2) | |
if cat /proc/cpuinfo | egrep -i "${F1}" | cut -d':' -f2 2>/dev/null | egrep -i "$F2" >/dev/null ; then | |
MATCH_RESULT=1 | |
else | |
MATCH_RESULT=0 | |
fi | |
CPU_ENTRY=$(echo "${CPU_ENTRY}" | sed -e "s/^${F1}[,]${F2}[,]\?//g") | |
done | |
if [ $MATCH_RESULT -eq 1 ]; then | |
echo -n "${CPU_ARCH}" | |
break | |
fi | |
done | |
IFS='') | |
echo "${OS_CPU}" | |
} | |
# Example: Set ARCH= parameter in /etc/portage/make.conf for cross-compiler. | |
# | |
# echo 'Setting ARCH...' | |
# perl -pi -e 's|(ARCH\=\")(.*)(")|${1}'$(cpu_arch)'${3}|g;' /etc/portage/make.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment