Turn a_head_customhdr__sep() to n_strsep_esc()
[s-mailx.git] / make-emerge.sh
blobfa2306cfc1806822d3ad50aa4b72af5c49df987c
1 #!/bin/sh -
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
5 # Public Domain
7 # See make-config.sh, the source of all this!
9 ( set -o noglob ) >/dev/null 2>&1 && noglob_shell=1 || unset noglob_shell
11 config_exit() {
12 exit ${1}
15 msg() {
16 fmt=${1}
17 shift
18 printf >&2 -- "${fmt}\\n" "${@}"
21 # which(1) not standardized, command(1) -v may return non-executable: unroll!
22 acmd_test() { __acmd "${1}" 1 0 0; }
23 acmd_test_fail() { __acmd "${1}" 1 1 0; }
24 acmd_set() { __acmd "${2}" 0 0 0 "${1}"; }
25 acmd_set_fail() { __acmd "${2}" 0 1 0 "${1}"; }
26 acmd_testandset() { __acmd "${2}" 1 0 0 "${1}"; }
27 acmd_testandset_fail() { __acmd "${2}" 1 1 0 "${1}"; }
28 thecmd_set() { __acmd "${2}" 0 0 1 "${1}"; }
29 thecmd_set_fail() { __acmd "${2}" 0 1 1 "${1}"; }
30 thecmd_testandset() { __acmd "${2}" 1 0 1 "${1}"; }
31 thecmd_testandset_fail() { __acmd "${2}" 1 1 1 "${1}"; }
32 __acmd() {
33 pname=${1} dotest=${2} dofail=${3} verbok=${4} varname=${5}
35 if [ "${dotest}" -ne 0 ]; then
36 eval dotest=\$${varname}
37 if [ -n "${dotest}" ]; then
38 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
39 msg ' . ${%s} ... %s' "${pname}" "${dotest}"
40 return 0
44 oifs=${IFS} IFS=:
45 [ -n "${noglob_shell}" ] && set -o noglob
46 set -- ${PATH}
47 [ -n "${noglob_shell}" ] && set +o noglob
48 IFS=${oifs}
49 for path
51 if [ -z "${path}" ] || [ "${path}" = . ]; then
52 if [ -d "${PWD}" ]; then
53 path=${PWD}
54 else
55 path=.
58 if [ -f "${path}/${pname}" ] && [ -x "${path}/${pname}" ]; then
59 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
60 msg ' . ${%s} ... %s' "${pname}" "${path}/${pname}"
61 [ -n "${varname}" ] && eval ${varname}="${path}/${pname}"
62 return 0
64 done
66 # We may have no builtin string functions, we yet have no programs we can
67 # use, try to access once from the root, assuming it is an absolute path if
68 # that finds the executable
69 if ( cd && [ -f "${pname}" ] && [ -x "${pname}" ] ); then
70 [ -n "${VERBOSE}" ] && [ ${verbok} -ne 0 ] &&
71 msg ' . ${%s} ... %s' "${pname}" "${pname}"
72 [ -n "${varname}" ] && eval ${varname}="${pname}"
73 return 0
76 [ ${dofail} -eq 0 ] && return 1
77 msg 'ERROR: no trace of utility '"${pname}"
78 exit 1
81 syno() {
82 if [ ${#} -gt 0 ]; then
83 echo >&2 "ERROR: ${*}"
84 echo >&2
86 echo >&2 'Synopsis: SOURCEDIR/make-emerge.sh [from within target directory]'
87 exit 1
90 [ ${#} -eq 0 ] || syno
92 # Rude simple, we should test for Solaris, but who runs this script?
93 if [ -d /usr/xpg4 ]; then
94 PATH=/usr/xpg4/bin:${PATH}
97 thecmd_testandset_fail awk awk
98 thecmd_testandset_fail cp cp
99 thecmd_testandset_fail dirname dirname
100 thecmd_testandset_fail pwd pwd
102 srcdir=`${dirname} ${0}`
103 blddir=`${pwd}`
104 if [ "${srcdir}" = . ]; then
105 msg 'This is not out of tree?!'
106 config_exit 1
108 echo 'Initializing out-of-tree build.'
109 echo 'Source directory: '"${srcdir}"
110 echo 'Build directory : '"${blddir}"
111 srcdir="${srcdir}"/
113 ${awk} -v srcdir="${srcdir}" -v blddir="${blddir}" '
115 gsub(/^SRCDIR=\.\/$/, "SRCDIR=" srcdir)
116 print
118 ' < "${srcdir}"makefile > ./makefile
120 ${cp} "${srcdir}"config.h ./
121 ${cp} "${srcdir}"gen-version.h ./
122 ${cp} "${srcdir}"make.rc ./
124 echo 'You should now be able to proceed as normal (e.g., "$ make all")'
126 # s-sh-mode