Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Replace getarch and validatearch with table-driven implement...
details: https://anonhg.NetBSD.org/src/rev/ee15984cc885
branches: trunk
changeset: 782375:ee15984cc885
user: apb <apb%NetBSD.org@localhost>
date: Wed Oct 31 13:05:09 2012 +0000
description:
Replace getarch and validatearch with table-driven implementations.
diffstat:
build.sh | 381 ++++++++++++++++++++++++++++++++++----------------------------
1 files changed, 209 insertions(+), 172 deletions(-)
diffs (truncated from 437 to 300 lines):
diff -r f389ff1733e4 -r ee15984cc885 build.sh
--- a/build.sh Wed Oct 31 10:17:34 2012 +0000
+++ b/build.sh Wed Oct 31 13:05:09 2012 +0000
@@ -1,5 +1,5 @@
#! /usr/bin/env sh
-# $NetBSD: build.sh,v 1.257 2012/10/18 16:15:29 apb Exp $
+# $NetBSD: build.sh,v 1.258 2012/10/31 13:05:09 apb Exp $
#
# Copyright (c) 2001-2011 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -263,6 +263,8 @@
toppid=$$
results=/dev/null
tab=' '
+nl='
+'
trap "exit 1" 1 2 3 15
bomb()
@@ -546,203 +548,238 @@
}
+# valid_MACHINE_ARCH -- A multi-line string, listing all valid
+# MACHINE/MACHINE_ARCH pairs.
+#
+# Each line contains a MACHINE and MACHINE_ARCH value, an optional ALIAS
+# which may be used to refer to the MACHINE/MACHINE_ARCH pair, and an
+# optional DEFAULT or NO_DEFAULT keyword.
+#
+# When a MACHINE corresponds to multiple possible values of
+# MACHINE_ARCH, then this table should list all allowed combinations.
+# If the MACHINE is associated with a default MACHINE_ARCH (to be
+# used when the user specifies the MACHINE but fails to specify the
+# MACHINE_ARCH), then one of the lines should have the "DEFAULT"
+# keyword. If there is no default MACHINE_ARCH for a particular
+# MACHINE, then there should be a line with the "NO_DEFAULT" keyword,
+# and with a blank MACHINE_ARCH.
+#
+valid_MACHINE_ARCH='
+MACHINE=acorn26 MACHINE_ARCH=arm
+MACHINE=acorn32 MACHINE_ARCH=arm
+MACHINE=algor MACHINE_ARCH=mips64el ALIAS=algor64
+MACHINE=algor MACHINE_ARCH=mipsel DEFAULT
+MACHINE=alpha MACHINE_ARCH=alpha
+MACHINE=amd64 MACHINE_ARCH=x86_64
+MACHINE=amiga MACHINE_ARCH=m68k
+MACHINE=amigappc MACHINE_ARCH=powerpc
+MACHINE=arc MACHINE_ARCH=mips64el ALIAS=arc64
+MACHINE=arc MACHINE_ARCH=mipsel DEFAULT
+MACHINE=atari MACHINE_ARCH=m68k
+MACHINE=bebox MACHINE_ARCH=powerpc
+MACHINE=cats MACHINE_ARCH=arm DEFAULT
+MACHINE=cats MACHINE_ARCH=earm
+MACHINE=cesfic MACHINE_ARCH=m68k
+MACHINE=cobalt MACHINE_ARCH=mips64el ALIAS=cobalt64
+MACHINE=cobalt MACHINE_ARCH=mipsel DEFAULT
+MACHINE=dreamcast MACHINE_ARCH=sh3el
+MACHINE=emips MACHINE_ARCH=mipseb
+MACHINE=evbarm MACHINE_ARCH=arm ALIAS=evbarm-el DEFAULT
+MACHINE=evbarm MACHINE_ARCH=armeb ALIAS=evbarm-eb
+MACHINE=evbarm MACHINE_ARCH=earm ALIAS=evbearm-el
+MACHINE=evbarm MACHINE_ARCH=earmeb ALIAS=evbearm-eb
+MACHINE=evbmips MACHINE_ARCH= NO_DEFAULT
+MACHINE=evbmips MACHINE_ARCH=mips64eb ALIAS=evbmips64-eb
+MACHINE=evbmips MACHINE_ARCH=mips64el ALIAS=evbmips64-el
+MACHINE=evbmips MACHINE_ARCH=mipseb ALIAS=evbmips-eb
+MACHINE=evbmips MACHINE_ARCH=mipsel ALIAS=evbmips-el
+MACHINE=evbppc MACHINE_ARCH=powerpc DEFAULT
+MACHINE=evbppc MACHINE_ARCH=powerpc64 ALIAS=evbppc64
+MACHINE=evbsh3 MACHINE_ARCH= NO_DEFAULT
+MACHINE=evbsh3 MACHINE_ARCH=sh3eb ALIAS=evbsh3-eb
+MACHINE=evbsh3 MACHINE_ARCH=sh3el ALIAS=evbsh3-el
+MACHINE=ews4800mips MACHINE_ARCH=mipseb
+MACHINE=hp300 MACHINE_ARCH=m68k
+MACHINE=hp700 MACHINE_ARCH=hppa
+MACHINE=hpcarm MACHINE_ARCH=arm
+MACHINE=hpcmips MACHINE_ARCH=mipsel
+MACHINE=hpcsh MACHINE_ARCH=sh3el
+MACHINE=i386 MACHINE_ARCH=i386
+MACHINE=ia64 MACHINE_ARCH=ia64
+MACHINE=ibmnws MACHINE_ARCH=powerpc
+MACHINE=iyonix MACHINE_ARCH=arm DEFAULT
+MACHINE=iyonix MACHINE_ARCH=earm
+MACHINE=landisk MACHINE_ARCH=sh3el
+MACHINE=luna68k MACHINE_ARCH=m68k
+MACHINE=mac68k MACHINE_ARCH=m68k
+MACHINE=macppc MACHINE_ARCH=powerpc DEFAULT
+MACHINE=macppc MACHINE_ARCH=powerpc64 ALIAS=macppc64
+MACHINE=mipsco MACHINE_ARCH=mipseb
+MACHINE=mmeye MACHINE_ARCH=sh3eb
+MACHINE=mvme68k MACHINE_ARCH=m68k
+MACHINE=mvmeppc MACHINE_ARCH=powerpc
+MACHINE=netwinder MACHINE_ARCH=arm DEFAULT
+MACHINE=netwinder MACHINE_ARCH=earm
+MACHINE=news68k MACHINE_ARCH=m68k
+MACHINE=newsmips MACHINE_ARCH=mipseb
+MACHINE=next68k MACHINE_ARCH=m68k
+MACHINE=ofppc MACHINE_ARCH=powerpc DEFAULT
+MACHINE=ofppc MACHINE_ARCH=powerpc64 ALIAS=ofppc64
+MACHINE=pmax MACHINE_ARCH=mips64el ALIAS=pmax64
+MACHINE=pmax MACHINE_ARCH=mipsel DEFAULT
+MACHINE=prep MACHINE_ARCH=powerpc
+MACHINE=rs6000 MACHINE_ARCH=powerpc
+MACHINE=sandpoint MACHINE_ARCH=powerpc
+MACHINE=sbmips MACHINE_ARCH= NO_DEFAULT
+MACHINE=sbmips MACHINE_ARCH=mips64eb ALIAS=sbmips64-eb
+MACHINE=sbmips MACHINE_ARCH=mips64el ALIAS=sbmips64-el
+MACHINE=sbmips MACHINE_ARCH=mipseb ALIAS=sbmips-eb
+MACHINE=sbmips MACHINE_ARCH=mipsel ALIAS=sbmips-el
+MACHINE=sgimips MACHINE_ARCH=mips64eb ALIAS=sgimips64
+MACHINE=sgimips MACHINE_ARCH=mipseb DEFAULT
+MACHINE=shark MACHINE_ARCH=arm DEFAULT
+MACHINE=shark MACHINE_ARCH=earm
+MACHINE=sparc MACHINE_ARCH=sparc
+MACHINE=sparc64 MACHINE_ARCH=sparc64
+MACHINE=sun2 MACHINE_ARCH=m68000
+MACHINE=sun3 MACHINE_ARCH=m68k
+MACHINE=vax MACHINE_ARCH=vax
+MACHINE=x68k MACHINE_ARCH=m68k
+MACHINE=zaurus MACHINE_ARCH=arm DEFAULT
+MACHINE=zaurus MACHINE_ARCH=earm
+'
+
+# getarch -- find the default MACHINE_ARCH for a MACHINE,
+# or convert an alias to a MACHINE/MACHINE_ARCH pair.
+#
+# Saves MACHINE in makewrappermachine before possibly modifying MACHINE.
+#
+# Sets MACHINE and MACHINE_ARCH if the input MACHINE value is
+# recognised as an alias, or recognised as a machine that has a default
+# MACHINE_ARCH (or that has only one possible MACHINE_ARCH).
+#
+# Leaves MACHINE and MACHINE_ARCH unchanged if MACHINE is recognised
+# as being associated with multiple MACHINE_ARCH values with no default.
+#
+# Bombs if MACHINE is not recognised.
+#
getarch()
{
- # Translate some MACHINE name aliases (known only to build.sh)
- # into proper MACHINE and MACHINE_ARCH names. Save the alias
- # name in makewrappermachine.
- #
- case "${MACHINE}" in
-
- evbearm-e[bl])
- makewrappermachine=${MACHINE}
- # MACHINE_ARCH is "arm" or "armeb", not "armel"
- MACHINE_ARCH=earm${MACHINE##*-}
- MACHINE_ARCH=${MACHINE_ARCH%el}
- MACHINE=evbarm
- ;;
-
- evbarm-e[bl])
- makewrappermachine=${MACHINE}
- # MACHINE_ARCH is "arm" or "armeb", not "armel"
- MACHINE_ARCH=arm${MACHINE##*-}
- MACHINE_ARCH=${MACHINE_ARCH%el}
- MACHINE=${MACHINE%-e[bl]}
- ;;
-
- evbmips-e[bl]|sbmips-e[bl])
- makewrappermachine=${MACHINE}
- MACHINE_ARCH=mips${MACHINE##*-}
- MACHINE=${MACHINE%-e[bl]}
- ;;
-
- evbmips64-e[bl]|sbmips64-e[bl])
- makewrappermachine=${MACHINE}
- MACHINE_ARCH=mips64${MACHINE##*-}
- MACHINE=${MACHINE%64-e[bl]}
- ;;
-
- evbsh3-e[bl])
- makewrappermachine=${MACHINE}
- MACHINE_ARCH=sh3${MACHINE##*-}
- MACHINE=${MACHINE%-e[bl]}
- ;;
-
- esac
-
- # Translate a MACHINE into a default MACHINE_ARCH.
- #
- case "${MACHINE}" in
-
- acorn26|acorn32|cats|hpcarm|iyonix|netwinder|shark|zaurus)
- MACHINE_ARCH=arm
- ;;
-
- evbarm) # unspecified MACHINE_ARCH gets LE
- MACHINE_ARCH=${MACHINE_ARCH:=arm}
- ;;
-
- hp700)
- MACHINE_ARCH=hppa
- ;;
+ local IFS
+ local found=""
+ local line
- sun2)
- MACHINE_ARCH=m68000
- ;;
-
- amiga|atari|cesfic|hp300|luna68k|mac68k|mvme68k|news68k|next68k|sun3|x68k)
- MACHINE_ARCH=m68k
- ;;
-
- evbmips|sbmips) # no default MACHINE_ARCH
- ;;
+ IFS="${nl}"
+ makewrappermachine="${MACHINE}"
+ for line in ${valid_MACHINE_ARCH}; do
+ line="${line%%#*}" # ignore comments
+ line="$( IFS=" ${tab}" ; echo $line )" # normalise white space
+ case "${line} " in
+ "")
+ # skip blank lines or comment lines
+ continue
+ ;;
+ *" ALIAS=${MACHINE} "*)
+ # Found a line with a matching ALIAS=<alias>.
+ found="$line"
+ break
+ ;;
+ "MACHINE=${MACHINE} "*" NO_DEFAULT"*)
+ # Found an explicit "NO_DEFAULT" for this MACHINE.
+ found="$line"
+ break
+ ;;
+ "MACHINE=${MACHINE} "*" DEFAULT"*)
+ # Found an explicit "DEFAULT" for this MACHINE.
+ found="$line"
+ break
+ ;;
+ "MACHINE=${MACHINE} "*)
+ # Found a line for this MACHINE. If it's the
+ # first such line, then tentatively accept it.
+ # If it's not the first matching line, then
+ # remember that there was more than one match.
+ case "$found" in
+ '') found="$line" ;;
+ *) found="MULTIPLE_MATCHES" ; break ;;
+ esac
+ ;;
+ esac
+ done
- sgimips64)
- makewrappermachine=${MACHINE}
- MACHINE=${MACHINE%64}
- MACHINE_ARCH=mips64eb
- ;;
-
- ews4800mips|mipsco|newsmips|sgimips|emips)
- MACHINE_ARCH=mipseb
- ;;
-
- algor64|arc64|cobalt64|pmax64)
- makewrappermachine=${MACHINE}
- MACHINE=${MACHINE%64}
- MACHINE_ARCH=mips64el
- ;;
-
- algor|arc|cobalt|hpcmips|pmax)
- MACHINE_ARCH=mipsel
+ case "$found" in
+ *NO_DEFAULT*|*MULTIPLE_MATCHES*)
+ # MACHINE is OK, but MACHINE_ARCH is still unknown
+ return
;;
-
- evbppc64|macppc64|ofppc64)
- makewrappermachine=${MACHINE}
- MACHINE=${MACHINE%64}
- MACHINE_ARCH=powerpc64
- ;;
-
- amigappc|bebox|evbppc|ibmnws|macppc|mvmeppc|ofppc|prep|rs6000|sandpoint)
- MACHINE_ARCH=powerpc
- ;;
-
- evbsh3) # no default MACHINE_ARCH
+ "MACHINE="*" MACHINE_ARCH="*)
+ # Obey the MACHINE= and MACHINE_ARCH= parts of the line.
+ IFS=" "
+ for frag in ${found}; do
+ case "$frag" in
+ MACHINE=*|MACHINE_ARCH=*)
+ eval "$frag"
+ ;;
+ esac
+ done
;;
-
- mmeye)
- MACHINE_ARCH=sh3eb
- ;;
-
Home |
Main Index |
Thread Index |
Old Index