Use ${HOST_SH} instead of the host system's /bin/sh wherever possible:
* Try to guess a suitable value for HOST_SH, if it was not set in the environment. First try host-specific heuristics (Solaris has /usr/xpg4/bin/sh); then try to find the name of the shell that was used to run build.sh itself (by parsing the output from ps -p $$ -o comm); then fall back to "sh". * Having found a value for HOST_SH, copy it to BSHELL and CONFIG_SHELL. * Use ${HOST_SH} instead of /bin/sh when creating the make wrapper. * Use ${HOST_SH} instead of unqualified sh when running shell scripts.
This commit is contained in:
parent
804dfaa036
commit
1889c0e175
113
build.sh
113
build.sh
|
@ -1,5 +1,5 @@
|
||||||
#! /usr/bin/env sh
|
#! /usr/bin/env sh
|
||||||
# $NetBSD: build.sh,v 1.152 2006/09/01 21:52:55 uwe Exp $
|
# $NetBSD: build.sh,v 1.153 2006/09/29 19:53:54 apb Exp $
|
||||||
#
|
#
|
||||||
# Copyright (c) 2001-2005 The NetBSD Foundation, Inc.
|
# Copyright (c) 2001-2005 The NetBSD Foundation, Inc.
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
|
@ -38,12 +38,13 @@
|
||||||
#
|
#
|
||||||
# Top level build wrapper, for a system containing no tools.
|
# Top level build wrapper, for a system containing no tools.
|
||||||
#
|
#
|
||||||
# This script should run on any POSIX-compliant shell. For systems
|
# This script should run on any POSIX-compliant shell. If the
|
||||||
# with a strange /bin/sh, "ksh" or "bash" may be an ample alternative.
|
# first "sh" found in the PATH is a POSIX-compliant shell, then
|
||||||
#
|
# you should not need to take any special action. Otherwise, you
|
||||||
# Note, however, that due to the way the interpreter is invoked above,
|
# should set the environment variable HOST_SH to a POSIX-compliant
|
||||||
# if a POSIX-compliant shell is the first in the PATH, you won't have
|
# shell, and invoke build.sh with that shell. (Depending on your
|
||||||
# to take any further action.
|
# system, one of /bin/ksh, /usr/local/bin/bash, or /usr/xpg4/bin/sh
|
||||||
|
# might be a suitable shell.)
|
||||||
#
|
#
|
||||||
|
|
||||||
progname=${0##*/}
|
progname=${0##*/}
|
||||||
|
@ -68,6 +69,83 @@ statusmsg()
|
||||||
${runcmd} echo "===> $@" | tee -a "${results}"
|
${runcmd} echo "===> $@" | tee -a "${results}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Find a program in the PATH
|
||||||
|
find_in_PATH()
|
||||||
|
{
|
||||||
|
local prog="$1"
|
||||||
|
local oldIFS="${IFS}"
|
||||||
|
local dir
|
||||||
|
IFS=":"
|
||||||
|
for dir in ${PATH}; do
|
||||||
|
if [ -x "${dir}/${prog}" ]; then
|
||||||
|
prog="${dir}/${prog}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
IFS="${oldIFS}"
|
||||||
|
echo "${prog}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Try to find a working POSIX shell, and set HOST_SH to refer to it.
|
||||||
|
# Assumes that uname_s, uname_m, and PWD have been set.
|
||||||
|
set_HOST_SH()
|
||||||
|
{
|
||||||
|
# Even if ${HOST_SH} is already defined, we still do the
|
||||||
|
# sanity checks at the end.
|
||||||
|
|
||||||
|
# Solaris has /usr/xpg4/bin/sh.
|
||||||
|
#
|
||||||
|
[ -z "${HOST_SH}" ] && [ x"${uname_s}" = x"SunOS" ] && \
|
||||||
|
[ -x /usr/xpg4/bin/sh ] && HOST_SH="/usr/xpg4/bin/sh"
|
||||||
|
|
||||||
|
# Try to get the name of the shell that's running this script,
|
||||||
|
# by parsing the output from "ps". We assume that, if the host
|
||||||
|
# system's ps command supports -o comm at all, it will do so
|
||||||
|
# in the usual way: a one-line header followed by a one-line
|
||||||
|
# result, possibly including trailing white space. And if the
|
||||||
|
# host system's ps command doesn't support -o comm, we assume
|
||||||
|
# that we'll get an error message on stderr and nothing on
|
||||||
|
# stdout. (We don't try to use ps -o 'comm=' to suppress the
|
||||||
|
# header line, because that is less widely supported.)
|
||||||
|
#
|
||||||
|
# If we get the wrong result here, the user can override it by
|
||||||
|
# specifying HOST_SH in the environment.
|
||||||
|
#
|
||||||
|
[ -z "${HOST_SH}" ] && HOST_SH="$(
|
||||||
|
(ps -p $$ -o comm | sed -ne '2s/[ \t]*$//p') 2>/dev/null )"
|
||||||
|
|
||||||
|
# If nothing above worked, use "sh". We will later find the
|
||||||
|
# first directory in the PATH that has a "sh" program.
|
||||||
|
#
|
||||||
|
[ -z "${HOST_SH}" ] && HOST_SH="sh"
|
||||||
|
|
||||||
|
# If the result so far is not an absolute path, try to prepend
|
||||||
|
# PWD or search the PATH.
|
||||||
|
#
|
||||||
|
case "${HOST_SH}" in
|
||||||
|
/*) :
|
||||||
|
;;
|
||||||
|
*/*) HOST_SH="${PWD}/${HOST_SH}"
|
||||||
|
;;
|
||||||
|
*) HOST_SH="$(find_in_PATH "${HOST_SH}")"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# If we don't have an absolute path by now, bomb.
|
||||||
|
#
|
||||||
|
case "${HOST_SH}" in
|
||||||
|
/*) :
|
||||||
|
;;
|
||||||
|
*) bomb "HOST_SH=\"${HOST_SH}\" is not an absolute path."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# If HOST_SH is not executable, bomb.
|
||||||
|
#
|
||||||
|
[ -x "${HOST_SH}" ] ||
|
||||||
|
bomb "HOST_SH=\"${HOST_SH}\" is not executable."
|
||||||
|
}
|
||||||
|
|
||||||
initdefaults()
|
initdefaults()
|
||||||
{
|
{
|
||||||
cd "$(dirname $0)"
|
cd "$(dirname $0)"
|
||||||
|
@ -89,6 +167,15 @@ initdefaults()
|
||||||
unset PWD
|
unset PWD
|
||||||
TOP=$(/bin/pwd -P 2>/dev/null || /bin/pwd 2>/dev/null)
|
TOP=$(/bin/pwd -P 2>/dev/null || /bin/pwd 2>/dev/null)
|
||||||
|
|
||||||
|
# The user can set HOST_SH in the environment, or we try to
|
||||||
|
# guess an appropriate value. Then we set several other
|
||||||
|
# variables from HOST_SH.
|
||||||
|
#
|
||||||
|
set_HOST_SH
|
||||||
|
setmakeenv HOST_SH "${HOST_SH}"
|
||||||
|
setmakeenv BSHELL "${HOST_SH}"
|
||||||
|
setmakeenv CONFIG_SHELL "${HOST_SH}"
|
||||||
|
|
||||||
# Set defaults.
|
# Set defaults.
|
||||||
#
|
#
|
||||||
toolprefix=nb
|
toolprefix=nb
|
||||||
|
@ -711,9 +798,9 @@ rebuildmake()
|
||||||
${runcmd} cd "${tmpdir}"
|
${runcmd} cd "${tmpdir}"
|
||||||
${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
|
${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
|
||||||
CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
|
CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
|
||||||
sh "${TOP}/tools/make/configure" ||
|
${HOST_SH} "${TOP}/tools/make/configure" ||
|
||||||
bomb "Configure of ${toolprefix}make failed"
|
bomb "Configure of ${toolprefix}make failed"
|
||||||
${runcmd} sh buildmake.sh ||
|
${runcmd} ${HOST_SH} buildmake.sh ||
|
||||||
bomb "Build of ${toolprefix}make failed"
|
bomb "Build of ${toolprefix}make failed"
|
||||||
make="${tmpdir}/${toolprefix}make"
|
make="${tmpdir}/${toolprefix}make"
|
||||||
${runcmd} cd "${TOP}"
|
${runcmd} cd "${TOP}"
|
||||||
|
@ -819,7 +906,7 @@ validatemakeparams()
|
||||||
fi
|
fi
|
||||||
if ${do_build} || ${do_distribution} || ${do_release}; then
|
if ${do_build} || ${do_distribution} || ${do_release}; then
|
||||||
if ! ${do_expertmode} && \
|
if ! ${do_expertmode} && \
|
||||||
[ $(id -u 2>/dev/null) -ne 0 ] && \
|
[ "$(id -u 2>/dev/null)" -ne 0 ] && \
|
||||||
[ "${MKUNPRIVED}" = "no" ] ; then
|
[ "${MKUNPRIVED}" = "no" ] ; then
|
||||||
bomb "-U or -E must be set for build as an unprivileged user."
|
bomb "-U or -E must be set for build as an unprivileged user."
|
||||||
fi
|
fi
|
||||||
|
@ -879,9 +966,9 @@ createmakewrapper()
|
||||||
esac
|
esac
|
||||||
|
|
||||||
eval cat <<EOF ${makewrapout}
|
eval cat <<EOF ${makewrapout}
|
||||||
#! /bin/sh
|
#! ${HOST_SH}
|
||||||
# Set proper variables to allow easy "make" building of a NetBSD subtree.
|
# Set proper variables to allow easy "make" building of a NetBSD subtree.
|
||||||
# Generated from: \$NetBSD: build.sh,v 1.152 2006/09/01 21:52:55 uwe Exp $
|
# Generated from: \$NetBSD: build.sh,v 1.153 2006/09/29 19:53:54 apb Exp $
|
||||||
# with these arguments: ${_args}
|
# with these arguments: ${_args}
|
||||||
#
|
#
|
||||||
EOF
|
EOF
|
||||||
|
@ -1030,6 +1117,8 @@ main()
|
||||||
statusmsg "${progname} command: $0 $@"
|
statusmsg "${progname} command: $0 $@"
|
||||||
statusmsg "${progname} started: ${build_start}"
|
statusmsg "${progname} started: ${build_start}"
|
||||||
|
|
||||||
|
statusmsg "HOST_SH: ${HOST_SH}"
|
||||||
|
|
||||||
rebuildmake
|
rebuildmake
|
||||||
validatemakeparams
|
validatemakeparams
|
||||||
createmakewrapper
|
createmakewrapper
|
||||||
|
|
Loading…
Reference in New Issue