#!/bin/sh # $NetBSD: cpuflags.NetBSD,v 1.62 2005/10/23 18:47:24 minskim Exp $ PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH AWK=awk display_hw_details() { echo " OS : '$(uname)'" echo " hw.model : '$hw_model'" echo " hw.machine : '$hw_machine'" echo " hw.machine_arch : '$hw_machine_arch'" echo " cpu details :" sed -n -e 's/^/ /' -e '/^ cpu/p' /var/run/dmesg.boot } hw_model=$(sysctl -n hw.model) hw_machine=$(sysctl -n hw.machine) hw_machine_arch=$(sysctl -n hw.machine_arch) # We're almost certainly crosscompiling if [ -n "$MACHINE" -a $hw_machine != "$MACHINE" ]; then echo exit fi # When adding $hw_model tests use maximum context (such as trailing space) case $hw_machine_arch in alpha) # cpu0 at mainbus0: ID 0 (primary), 21164A-0 (unknown ... case "$(egrep '^cpu0 ' /var/run/dmesg.boot)" in *[\(\ ]2106[46][-A\ \)]*) FLAGS="-mcpu=21064" ;; *[\(\ ]21164[-\ \)]*) FLAGS="-mcpu=21164" ;; *[\(\ ]21164A[-\ \)]*) FLAGS="-mcpu=21164a" ;; *[\(\ ]21264[-\ \)]*) FLAGS="-mcpu=21264" ;; *[\(\ ]21264[AB][-\ \)]*) FLAGS="-mcpu=21264a" ;; *\ PCA56-2) FLAGS="-mcpu=21164pc" ;; esac ;; arm | arm32) case $hw_model in ARM610*) FLAGS="-mcpu=arm610" ;; # risc pc ARM710*) FLAGS="-mcpu=arm710" ;; # risc pc i80321\ *) FLAGS="-mcpu=xscale" ;; # iyonix SA-110*) case $hw_machine in # arm32 split post 1.5 cats|shark|hpcarm|netwinder) FLAGS="-mcpu=strongarm110" ;; acorn32) FLAGS="-march=armv3m -mtune=strongarm" ;; *) # memorybus in strongarm risc pc machines cannot support # certain strongarm instructions, but in 1.5 and earlier # all strongarm machines are 'arm32', so uname and sysctl # no use if egrep -q 'ofbus0|footbridge0' /var/run/dmesg.boot \ 2>/dev/null ; then FLAGS="-mcpu=strongarm110" # shark/cats else FLAGS="-march=armv3m -mtune=strongarm" # risc pc fi esac ;; esac ;; i386) case $hw_model in *Intel\ Pentium/MMX\ *) FLAGS='-march=pentium-mmx' ;; *Intel\ Pentium\ II\ *) FLAGS='-march=pentium2' ;; *Intel\ Pentium\ III\ *) FLAGS='-march=pentium3' ;; *Intel\ Mobile\ Pentium\ III\ *) FLAGS='-march=pentium3' ;; *Intel\ Celeron\ \(Mendocino\)\ *) FLAGS='-march=pentium3 -mno-sse' ;; *Intel\ Pentium\ M\ \(\Dothan\)\ *) FLAGS='-march=pentium4m' ;; *Intel\ Pentium\ M\ *) FLAGS='-march=pentium3m' ;; *Intel\ Mobile\ Pentium\ 4\ *) FLAGS='-march=pentium4m' ;; *Intel\ Pentium\ 4\ *) FLAGS='-march=pentium4' ;; *VIA\ C3*\ *) FLAGS='-march=c3' ;; *AMD\ K6-III*) FLAGS='-march=k6-3' ;; *AMD\ K6-2*) FLAGS='-march=k6-2' ;; *AMD\ K6*) FLAGS='-march=k6' ;; *AMD\ Duron*) FLAGS='-march=athlon' ;; *AMD\ Athlon\ 4*) FLAGS='-march=athlon-4' ;; *AMD\ Athlon\ Model\ 4\ \(Thunderbird\)*) FLAGS='-march=athlon-tbird';; *AMD\ Athlon\ MP*) FLAGS='-march=athlon-mp' ;; *AMD\ K7\ \(Athlon\)\ XP\ *) FLAGS='-march=athlon-xp' ;; *AMD\ Athlon\ XP\ *) FLAGS='-march=athlon-xp' ;; *AMD\ K7*|*AMD\ Athlon*) FLAGS='-march=athlon' ;; *AMD\ Unknown\ K7\ \(Athlon\)*) FLAGS='-march=athlon' ;; *386-class*) FLAGS='-march=i386' ;; *486-class*) FLAGS='-march=i486' ;; *586-class*) FLAGS='-march=pentium' ;; *686-class*) FLAGS='-march=pentiumpro' ;; esac ;; m68k) case $hw_model in # Examples *\(68020*|*\ MC68020\ *) FLAGS='-m68020' ;; # Untested *\(68030*|*\ MC68030\ *) FLAGS='-m68030' ;; # Mac LC III *\(68040*|*\ MC68040\ *) FLAGS='-m68040' ;; # Untested *\(68060*|*\ MC68060\ *) FLAGS='-m68060' ;; # Upgr amiga 3000 esac case "$(egrep '^fpu0 ' /var/run/dmesg.boot)" in *\(emulator\)*) FLAGS="$FLAGS -msoft-float" ;; *\(no\ math\ support\)*) FLAGS="$FLAGS -msoft-float" ;; esac ;; mipseb|mipsel) # cpu0 at mainbus0: QED R4600 Orion CPU (0x2020) Rev. 2.0 with ... case "$(egrep '^cpu0 ' /var/run/dmesg.boot)" in *\ MIPS\ R2000\ *) FLAGS="-march=r2000" ;; *\ MIPS\ R3000\ *) FLAGS="-march=r3000" ;; *\ MIPS\ R3000A\ *) FLAGS="-march=r3000" ;; *\ Toshiba\ TX3912\ *) FLAGS="-march=r3900" ;; *\ Toshiba\ TX392[27]\ *) FLAGS="-march=r3900" ;; *\ MIPS\ R4000\ *) FLAGS="-mtune=r4000 -mips2" ;; # really mips3 *\ MIPS\ R4400\ *) FLAGS="-mtune=r4400 -mips2" ;; # really mips3 *\ NEC\ VR4100\ *) FLAGS="-mtune=r4100 -mips2" ;; # really mips3 *\ NEC\ VR4300\ *) FLAGS="-mtune=r4300 -mips2" ;; # really mips3 *\ QED\ R4600\ *) FLAGS="-mtune=r4600 -mips2" ;; # really mips3 *\ MIPS\ R5000\ *) FLAGS="-mtune=r5000 -mips2" ;; # really mips4 *\ QED\ RM5200\ *) FLAGS="-mtune=r5000 -mips2" ;; # really mips4 *\ MIPS\ R6000\ *) FLAGS="-mtune=r6000 -mips2" ;; *\ MIPS\ R8000\ *) FLAGS="-mtune=r8000 -mips2" ;; # really mips4 esac ;; powerpc) case $hw_model in # Examples 601\ *) FLAGS='-mcpu=601' ;; # Untested 602\ *) FLAGS='-mcpu=602' ;; # Untested 603\ *) FLAGS='-mcpu=603' ;; # Untested 603e\ *|603ev\ *) FLAGS='-mcpu=603e' ;; # Umax C500 / PM4400 604\ *) FLAGS='-mcpu=604' ;; # Mac 8500 604e\ *) FLAGS='-mcpu=604e' ;; # upgr B&W G3 604ev\ *) FLAGS='-mcpu=604e' ;; # usually 604e 620\ *) FLAGS='-mcpu=620' ;; # Untested 7400\ *) FLAGS='-mcpu=7400' ;; # AGP G4/400 Mac 7410\ *) FLAGS='-mcpu=7400' ;; # powerbook g4 740\ *) FLAGS='-mcpu=740' ;; # Untested 7450\ *) FLAGS='-mcpu=7450' ;; # tibook 550 750\ *) FLAGS='-mcpu=750' ;; # Untested esac ;; sparc | sparc64) case " $hw_model" in # Examples *[\ \(]MB86900/1A*) FLAGS='-mcpu=cypress' ;; # ss1+ *[\ \(]L64811*) FLAGS='-mcpu=cypress' ;; # sun4/sun4c *[\ \(]CY7C601*) FLAGS='-mcpu=cypress' ;; # ss2 *[\ \(]W8601/8701*) FLAGS='-mcpu=cypress' ;; # elc *[\ \(]MB86904*) FLAGS='-mcpu=supersparc' ;; # ss5 usparc *[\ \(]MB86907*) FLAGS='-mcpu=supersparc' ;; # ss5 usparc *[\ \(]TMS390S10*) FLAGS='-mcpu=supersparc' ;; # classic " *[\ \(]TMS390Z50*) FLAGS='-mcpu=supersparc' ;; # ss10/ss20 *[\ \(]RT620/625*) FLAGS='-mcpu=hypersparc' ;; # ss20 ross *[\ \(]MB86930*) FLAGS='-mcpu=sparclite' ;; # from gcc *[\ \(]MB86934*) FLAGS='-mcpu=sparclite' ;; # from gcc # under 1.5.1 -mcpu=ultrasparc chokes egcs-2.91.66 compiling perl *[\ \(]SUNW,UltraSPARC*) FLAGS='-mcpu=v9' ;; # Ultra esac ;; x86_64) # No x86_64 specific gcc optimisations yet NONE=1 ;; vax) # No VAX specific gcc optimisations available NONE=1 ;; esac ############ # Everything from this point common between all cpuflags variants. if [ "$1" = -v ] ; then shift opt_v=1 fi if [ -n "$1" ]; then CC=$1 else CC=gcc fi if [ -n "$opt_v" ] ; then if [ -n "$FLAGS" ]; then echo "CPUFLAGS=$FLAGS" elif [ -z "$NONE" ] ; then echo "CPUFLAGS=Unknown" else echo "CPUFLAGS=None" fi display_hw_details exit fi if [ -z "$FLAGS" -a -z "$NONE" ] ; then echo 'Unknown machine - please send details to abs@absd.org' >&2 display_hw_details >&2 fi # Fixup options for older gccs. # Entries can be recursive - eg: # -march=k6-3 -> -march=k6 -> -march=pentium -> -march=i486 # # The format of table is # gcc_version_in_which_option_was_introduced new_option old_option if [ -n "$FLAGS" ]; then gcc_ver=`${CC} -dumpversion | sed 's/^egcs-//'` FLAGS=`$AWK -F: -v "flags=$FLAGS" -v "gcc_ver=$gcc_ver" ' { if (gcc_ver < $1){map[$2] = ""$3} } END { while (flags in map) {flags = map[flags]} print flags } ' <