version 1.167, 2007/04/05 10:02:10 |
version 1.168, 2007/04/07 14:49:40 |
|
|
statusmsg "Warning: $@" |
statusmsg "Warning: $@" |
} |
} |
|
|
# Find a program in the PATH |
# Find a program in the PATH, and print the result. If not found, |
|
# print a default. If $2 is defined (even if it is an empty string), |
|
# then that is the default; otherwise, $1 is used as the default. |
find_in_PATH() |
find_in_PATH() |
{ |
{ |
local prog="$1" |
local prog="$1" |
|
local result="${2-"$1"}" |
local oldIFS="${IFS}" |
local oldIFS="${IFS}" |
local dir |
local dir |
IFS=":" |
IFS=":" |
for dir in ${PATH}; do |
for dir in ${PATH}; do |
if [ -x "${dir}/${prog}" ]; then |
if [ -x "${dir}/${prog}" ]; then |
prog="${dir}/${prog}" |
result="${dir}/${prog}" |
break |
break |
fi |
fi |
done |
done |
IFS="${oldIFS}" |
IFS="${oldIFS}" |
echo "${prog}" |
echo "${result}" |
} |
} |
|
|
# Try to find a working POSIX shell, and set HOST_SH to refer to it. |
# Try to find a working POSIX shell, and set HOST_SH to refer to it. |
|
|
[ -f share/mk/bsd.own.mk ] || |
[ -f share/mk/bsd.own.mk ] || |
bomb "src/share/mk is missing; please re-fetch the source tree" |
bomb "src/share/mk is missing; please re-fetch the source tree" |
|
|
# Find information about the build platform. |
# Find information about the build platform. Note that "uname -p" |
|
# is not part of POSIX, but NetBSD's uname -p prints MACHINE_ARCH, |
|
# while uname -m prints MACHINE. |
# |
# |
uname_s=$(uname -s 2>/dev/null) |
uname_s=$(uname -s 2>/dev/null) |
uname_r=$(uname -r 2>/dev/null) |
uname_r=$(uname -r 2>/dev/null) |
uname_m=$(uname -m 2>/dev/null) |
uname_m=$(uname -m 2>/dev/null) |
|
uname_p=$(uname -p 2>/dev/null || uname -m 2>/dev/null) |
|
|
# If $PWD is a valid name of the current directory, POSIX mandates |
# If $PWD is a valid name of the current directory, POSIX mandates |
# that pwd return it by default which causes problems in the |
# that pwd return it by default which causes problems in the |
|
|
bomb "MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'" |
bomb "MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'" |
} |
} |
|
|
raw_getmakevar() |
nobomb_getmakevar() |
{ |
{ |
[ -x "${make}" ] || bomb "raw_getmakevar $1: ${make} is not executable" |
[ -x "${make}" ] || return 1 |
"${make}" -m ${TOP}/share/mk -s -B -f- _x_ <<EOF || bomb "raw_getmakevar $1: ${make} failed" |
"${make}" -m ${TOP}/share/mk -s -B -f- _x_ <<EOF || return 1 |
_x_: |
_x_: |
echo \${$1} |
echo \${$1} |
.include <bsd.prog.mk> |
.include <bsd.prog.mk> |
|
|
EOF |
EOF |
} |
} |
|
|
|
raw_getmakevar() |
|
{ |
|
[ -x "${make}" ] || bomb "raw_getmakevar $1: ${make} is not executable" |
|
nobomb_getmakevar "$1" || bomb "raw_getmakevar $1: ${make} failed" |
|
} |
|
|
getmakevar() |
getmakevar() |
{ |
{ |
# raw_getmakevar() doesn't work properly if $make hasn't yet been |
# raw_getmakevar() doesn't work properly if $make hasn't yet been |
|
|
esac |
esac |
} |
} |
|
|
|
# Try to set a value for TOOLDIR. This is difficult because of a cyclic |
|
# dependency: TOOLDIR may be affected by settings in /etc/mk.conf, so |
|
# we would like to use getmakevar to get the value of TOOLDIR, but we |
|
# can't use getmakevar before we have an up to date version of nbmake; |
|
# we might already have an up to date version of nbmake in TOOLDIR, but |
|
# we don't yet know where TOOLDIR is. |
|
# |
|
# In principle, we could break the cycle by building a copy of nbmake |
|
# in a temporary directory. However, people who use the default value |
|
# of TOOLDIR do not like to have nbmake rebuilt every time they run |
|
# build.sh. |
|
# |
|
# We try to please everybody as follows: |
|
# |
|
# * If TOOLDIR was set in the environment or on the command line, use |
|
# that value. |
|
# * Otherwise try to guess what TOOLDIR would be if not overridden by |
|
# /etc/mk.conf, and check whether the resulting directory contains |
|
# a copy of ${toolprefix}make (this should work for everybody who |
|
# doesn't override TOOLDIR via /etc/mk.conf); |
|
# * Failing that, search for ${toolprefix}make, nbmake, bmake, or make, |
|
# in the PATH (this might accidentally find a non-NetBSD version of |
|
# make, which will lead to failure in the next step); |
|
# * If a copy of make was found above, try to use it with |
|
# nobomb_getmakevar to find the correct value for TOOLDIR; |
|
# * If all else fails, leave TOOLDIR unset. Our caller is expected to |
|
# be able to cope with this. |
|
# |
|
try_set_TOOLDIR() |
|
{ |
|
[ -n "${TOOLDIR}" ] && return |
|
|
|
# Set guess_TOOLDIR, in the same way that <bsd.own.mk> would set |
|
# TOOLDIR if /etc/mk.conf sisn't interfere. |
|
local topobjdir="${TOP}" |
|
[ -n "${makeobjdir}" ] && topobjdir="${topobjdir}/${makeobjdir}" |
|
local host_ostype="${uname_s}-$( |
|
echo "${uname_r}" | sed -e 's/([^)]*)//g' -e 's/ /_/g' |
|
)$( |
|
echo "${uname_p}" | sed -e 's/([^)]*)//g' -e 's/ /_/g' |
|
)" |
|
local guess_TOOLDIR="${topobjdir}/tooldir.${host_ostype}" |
|
|
|
# Look for a suitable ${toolprefix}make, nbmake, bmake, or make. |
|
guess_make="${guess_TOOLDIR}/bin/${toolprefix}make" |
|
[ -x "${guess_make}" ] || guess_make="" |
|
: ${guess_make:=$(find_in_PATH ${toolprefix}make '')} |
|
: ${guess_make:=$(find_in_PATH nbmake '')} |
|
: ${guess_make:=$(find_in_PATH bmake '')} |
|
: ${guess_make:=$(find_in_PATH make '')} |
|
|
|
# Use ${guess_make} with nobomb_getmakevar |
|
if [ -x "${guess_make}" ]; then |
|
TOOLDIR=$(make="${guess_make}" nobomb_getmakevar TOOLDIR) |
|
[ -n "${TOOLDIR}" ] || unset TOOLDIR |
|
fi |
|
} |
|
|
rebuildmake() |
rebuildmake() |
{ |
{ |
# Test make source file timestamps against installed ${toolprefix}make |
# Test make source file timestamps against installed ${toolprefix}make |
# binary, if TOOLDIR is pre-set. |
# binary, if TOOLDIR is pre-set or if try_set_TOOLDIR can set it. |
# |
|
# Note that we do NOT try to grovel "mk.conf" here to find out if |
|
# TOOLDIR is set there, because it can contain make variable |
|
# expansions and other stuff only parseable *after* we have a working |
|
# ${toolprefix}make. So this logic can only work if the user has |
|
# pre-set TOOLDIR in the environment or used the -T option to build.sh. |
|
# |
# |
|
try_set_TOOLDIR |
make="${TOOLDIR-nonexistent}/bin/${toolprefix}make" |
make="${TOOLDIR-nonexistent}/bin/${toolprefix}make" |
if [ -x "${make}" ]; then |
if [ -x "${make}" ]; then |
for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do |
for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do |