2 #@ Out-of-tree compilation support, à la
3 #@ $ cd /tmp && mkdir build && cd build &&
4 #@ ~/src/nail.git/make-emerge.sh && make tangerine DESTDIR=.ddir
7 ## See make-config.sh, the source of all this!
9 # For heaven's sake auto-redirect on SunOS/Solaris
10 if [ "x${SHELL}" = x
] ||
[ "${SHELL}" = /bin
/sh
] && \
11 [ -f /usr
/xpg
4/bin
/sh
] && [ -x /usr
/xpg
4/bin
/sh
]; then
12 SHELL
=/usr
/xpg
4/bin
/sh
14 exec /usr
/xpg
4/bin
/sh
"${0}" "${@}"
16 [ -n "${SHELL}" ] || SHELL
=/bin
/sh
19 ( set -o noglob
) >/dev
/null
2>&1 && noglob_shell
=1 ||
unset noglob_shell
28 printf >&2 -- "${fmt}\\n" "${@}"
31 # which(1) not standardized, command(1) -v may return non-executable: unroll!
32 acmd_test
() { __acmd
"${1}" 1 0 0; }
33 acmd_test_fail
() { __acmd
"${1}" 1 1 0; }
34 acmd_set
() { __acmd
"${2}" 0 0 0 "${1}"; }
35 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
36 acmd_testandset
() { __acmd
"${2}" 1 0 0 "${1}"; }
37 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
38 thecmd_set
() { __acmd
"${2}" 0 0 1 "${1}"; }
39 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
40 thecmd_testandset
() { __acmd
"${2}" 1 0 1 "${1}"; }
41 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
43 pname
=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
45 if [ "${dotest}" -ne 0 ]; then
46 eval dotest
=\$
${varname}
47 if [ -n "${dotest}" ]; then
48 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
49 msg
' . ${%s} ... %s' "${pname}" "${dotest}"
55 [ -n "${noglob_shell}" ] && set -o noglob
57 [ -n "${noglob_shell}" ] && set +o noglob
61 if [ -z "${path}" ] || [ "${path}" = . ]; then
62 if [ -d "${PWD}" ]; then
68 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
69 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
70 msg ' .
${%s} ... %s' "${pname}" "${path}/${pname}"
71 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
76 # We may have no builtin string functions, we yet have no programs we can
77 # use, try to access once from the root, assuming it is an absolute path if
78 # that finds the executable
79 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
80 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
81 msg ' . ${%s} ... %s' "${pname}" "${pname}"
82 [ -n "${varname}" ] && eval ${varname}="${pname}"
86 [ ${dofail} -eq 0 ] && return 1
87 msg
'ERROR: no trace of utility '"${pname}"
92 if [ ${#} -gt 0 ]; then
93 echo >&2 "ERROR: ${*}"
96 echo >&2 'Synopsis: SOURCEDIR/make-emerge.sh [from within target directory]'
100 [ ${#} -eq 0 ] || syno
102 # Rude simple, we should test for Solaris, but who runs this script?
103 if [ -d /usr
/xpg4
]; then
104 PATH
=/usr
/xpg
4/bin
:${PATH}
107 thecmd_testandset_fail
awk awk
108 thecmd_testandset_fail
cp cp
109 thecmd_testandset_fail
dirname dirname
110 thecmd_testandset_fail
pwd pwd
112 srcdir
=`${dirname} ${0}`
114 if [ "${srcdir}" = .
]; then
115 msg
'This is not out of tree?!'
118 echo 'Initializing out-of-tree build.'
119 echo 'Source directory: '"${srcdir}"
120 echo 'Build directory : '"${blddir}"
123 ${awk} -v srcdir="${srcdir}" -v blddir="${blddir}" '
125 gsub(/^CWDDIR=\.\/$/, "CWDDIR
=" blddir)
126 gsub(/^SRCDIR=\.\/$/, "SRCDIR
=" srcdir)
129 ' < "${srcdir}"makefile > ./makefile
131 ${cp} "${srcdir}"config.h ./
132 ${cp} "${srcdir}"gen-version.h ./
133 ${cp} "${srcdir}"make.rc ./
135 echo 'You should now be able to proceed as normal (e.g., "$
make all
")'