6 # boot-strap ["options"]
7 # boot-strap --prefix=/opt --install
8 # boot-strap --prefix=$HOME --install-host-target -DWITH_PROG_VERSION
9 # boot-strap ["options"] op=build
10 # boot-strap ["options"] op=install
13 # This script is used to configure/build bmake it builds for
14 # each host-target in a different subdir to keep the src clean.
15 # There is no requirement for an existing make(1).
17 # On successful completion if no '--install' flag is given,
18 # it echos a command to do installation.
20 # The variable "op" defaults to 'all', and is affected by
21 # '--install' flag as above.
22 # Other values include:
25 # Just run 'configure'
28 # If 'configure' has not been done, do it, then
29 # run the build script, and finally 'test'.
32 # If 'build' has not been done, do it, 'test' then
39 # run the unit-tests. Done automatically after 'build'
40 # and before 'install'.
42 # The above are leveraged by a trivial makefile for the benefit
43 # of those that have './configure; make; make install' baked
49 # Pick up settings from "rc".
50 # We look for '.bmake-boot-strap.rc' before processing
51 # options (unless SKIP_RC is set in environment).
54 # Where to put man pages and mk files.
55 # If $prefix ends in $HOST_TARGET, and $prefix/../share
56 # exits, the default will be that rather than $prefix/share.
59 # Indicate where the mk files can be found.
60 # Default is $Mydir/mk
63 # If build and test work, run bmake install.
65 # SHAREDIR=$prefix/share
67 # --install-host-target
68 # As for '--install' but BINDIR=$prefix/$HOST_TARGET/bin
69 # This is useful when $prefix/ is shared by multiple
72 # Flags relevant when installing:
74 # -DWITHOUT_INSTALL_MK
75 # Skip installing mk files.
76 # By default they will be installed to $prefix/share/mk
79 # Install 'bmake' as 'bmake-$MAKE_VERSION'
80 # A symlink will be made as 'bmake' unless
81 # -DWITHOUT_PROG_LINK is set.
83 # Possibly useful configure_args:
86 # disable use of meta mode.
89 # disable use of filemon(9) which is currently only
90 # available for NetBSD and FreeBSD.
92 # --with-filemon=ktrace
93 # on NetBSD or others with fktrace(2), use ktrace
96 # --with-filemon="path/to/filemon.h"
97 # enables use of filemon(9) by meta mode.
99 # --with-machine="machine"
100 # set "machine" to override that determined by
103 # --with-force-machine="machine"
104 # force "machine" even if uname(3) provides a value.
106 # --with-machine_arch="machine_arch"
107 # set "machine_arch" to override that determined by
110 # --with-default-sys-path="syspath"
111 # set an explicit default "syspath" which is where bmake
112 # will look for sys.mk and friends.
115 # Simon J. Gerraty <sjg@crufty.net>
118 # $Id: boot-strap,v 1.51 2020/02/19 16:46:23 sjg Exp $
120 # @(#) Copyright (c) 2001 Simon J. Gerraty
122 # This file is provided in the hope that it will
123 # be of use. There is absolutely NO WARRANTY.
124 # Permission to copy, redistribute or otherwise
125 # use this file is hereby granted provided that
126 # the above copyright notice and this notice are
129 # Please send copies of changes and bug-fixes to:
137 *) Mydir=`cd "$Mydir" && 'pwd'`;;
141 [ "$1" ] && echo "ERROR: $@" >&2
143 echo "$0 [--<configure_arg> ...][<prefix>][--install]" >&2
157 [ -f "$r" -a -s "$r" ] || continue
158 echo "NOTE: reading $r"
166 # clear some things from the environment that we care about
167 unset MAKEOBJDIR MAKEOBJDIRPREFIX
168 # or that might be incompatible
171 # --install[-host-target] will set this
173 # other things we pass to install step
177 # pick a useful default prefix (for me at least ;-)
178 for prefix in /opt/$HOST_TARGET "$HOME/$HOST_TARGET" /usr/pkg /usr/local ""
180 [ -d "${prefix:-.}" ] || continue
184 if [ -d $p/share ]; then
185 INSTALL_BIN=$HOST_TARGET/bin
190 echo "NOTE: default prefix=$prefix ${INSTALL_BIN:+INSTALL_BIN=$INSTALL_BIN}"
198 ${SKIP_RC:+:} source_rc .bmake-boot-strap.rc . "$Mydir/.." "$HOME"
201 expr "x$1" : "x[^=]*=\\(.*\\)"
205 if [ $here = $Mydir ]; then
217 --help) sed -n -e "1d;/RCSid/,\$d" -e '/^#\.[a-z]/d' -e '/^#/s,^# *,,p' $0; exit 0;;
218 --prefix) prefix="$2"; shift;;
219 --prefix=*) prefix=`get_optarg "$1"`;;
220 --src=*) srcdir=`get_optarg "$1"`;;
221 --with-mksrc=*|--mksrc=*) mksrc=`get_optarg "$1"`;;
222 --share=*) share_dir=`get_optarg "$1"`;;
223 --share) share_dir="$2"; shift;;
224 --with-default-sys-path=*)
225 CONFIGURE_ARGS="$1";;
226 --with-default-sys-path)
227 CONFIGURE_ARGS="$1 $2";;
228 --install) INSTALL_PREFIX=${INSTALL_PREFIX:-$prefix};;
229 --install-host-target)
230 INSTALL_PREFIX=${INSTALL_PREFIX:-$prefix}
231 INSTALL_BIN=$HOST_TARGET/bin;;
232 --install-destdir=*) INSTALL_DESTDIR=`get_optarg "$1"`;;
233 --install-prefix=*) INSTALL_PREFIX=`get_optarg "$1"`;;
234 -DWITH*) INSTALL_ARGS="$INSTALL_ARGS $1";;
235 -s|--src) srcdir="$2"; shift;;
236 -m|--mksrc) mksrc="$2"; shift;;
237 -o|--objdir) objdir="$2"; shift;;
239 -c) source_rc "$2"; shift;;
240 --*) CONFIGURE_ARGS="$CONFIGURE_ARGS $1";;
241 *=*) eval "$1"; export `expr "x$1" : "x\\(.[^=]*\\)=.*"`;;
248 case " $CONFIGURE_ARGS " in
250 *) CONFIGURE_ARGS="$CONFIGURE_ARGS $1$2";;
261 [ -d "$dir" ] || continue
268 *) [ -s $dir/$fmatch ] || continue;;
271 *./*) cd "$dir" && 'pwd';;
273 *) cd "$dir" && 'pwd';;
285 -C) cd "$2"; shift; shift;;
291 /*) # we shouldn't be here
292 [ $_t "$1" ] && echo "$1"
295 .../*) want=`echo "$1" | sed 's,^.../*,,'`;;
301 if [ $_t "./$want" ]; then
314 # is $1 missing from $2 (or PATH) ?
316 eval "__p=\$${2:-PATH}"
317 case ":$__p:" in *:"$1":*) return 1;; *) return 0;; esac
320 # if $1 exists and is not in path, append it
327 MAKESYSPATH,.../*) ;;
328 *) [ $t ${1:-.} ] || return;;
330 no_path $* && eval ${2:-PATH}="$__p${__p:+:}$1"
334 srcdir=`GetDir /bmake make-bootstrap.sh.in "$srcdir" "$2" "$Mydir" ./bmake* "$Mydir"/../bmake*`
335 [ -d "${srcdir:-/dev/null}" ] || Usage
337 none|-) # we ignore this now
340 .../*) # find here or above
341 mksrc=`FindHereOrAbove -C "$Mydir" -s "$mksrc/sys.mk"`
343 mksrc=`dirname $mksrc`
345 *) # guess we want mksrc...
346 mksrc=`GetDir /mk sys.mk "$mksrc" "$3" ./mk* "$srcdir"/mk* "$srcdir"/../mk*`
347 [ -d "${mksrc:-/dev/null}" ] || Usage "Use '-m none' to build without mksrc"
352 objdir="${objdir:-$OBJROOT$HOST_TARGET}"
353 [ -d "$objdir" ] || mkdir -p "$objdir"
354 [ -d "$objdir" ] || mkdir "$objdir"
355 cd "$objdir" || exit 1
361 /) [ -d /share ] || return;;
363 if [ -d "$1/../share" ]; then
364 echo `dirname "$1"`/share
372 # make it easy to force prefix to use $HOST_TARGET
373 : looking at "$prefix"
375 */host?target) prefix=`echo "$prefix" | sed "s,host.target,${HOST_TARGET},"`;;
378 share_dir="${share_dir:-`ShareDir $prefix`}"
380 AddConfigure --prefix= "$prefix"
381 case "$CONFIGURE_ARGS" in
382 *--with-*-sys-path*) ;; # skip
383 *) [ "$share_dir" ] && AddConfigure --with-default-sys-path= "$share_dir/mk";;
385 if [ "$mksrc" ]; then
386 AddConfigure --with-mksrc= "$mksrc"
387 # not all cc's support this
388 CFLAGS_MF= CFLAGS_MD=
389 export CFLAGS_MF CFLAGS_MD
392 # this makes it easy to run the bmake we just built
393 # the :tA dance is needed because 'pwd' and even /bin/pwd
394 # may not give the same result as realpath().
398 MAKESYSPATH=$mksrc SRCTOP=$Mydir OBJTOP=$objdir \
399 MAKEOBJDIR='${.CURDIR:S,${SRCTOP:tA},${OBJTOP:tA},}' \
400 ${BMAKE:-$objdir/bmake} -f $Mydir/Makefile "$@"
404 # there is actually a shell where type is not a builtin
405 # if type is missing, which(1) had better exists!
406 if (type cat) > /dev/null 2>&1; then
408 type "$@" | sed 's,[()],,g;s,^[^/][^/]*,,;q'
411 # make sure test below uses the same diff that configure did
412 TOOL_DIFF=`which diff`
416 $srcdir/configure $CONFIGURE_ARGS || exit 1
420 [ -s make-bootstrap.sh ] || op_configure
421 chmod 755 make-bootstrap.sh || exit 1
422 ./make-bootstrap.sh || exit 1
429 [ -x bmake ] || op_build
434 if [ -x bmake ]; then
436 BMAKE=$objdir/bmake$$ Bmake clean
438 elif [ $objdir != $srcdir ]; then
445 case "$INSTALL_PREFIX,$INSTALL_BIN,$prefix" in
446 ,$HOST_TARGET/bin,*/$HOST_TARGET)
447 INSTALL_PREFIX=`dirname $prefix`
450 INSTALL_PREFIX=${INSTALL_PREFIX:-$prefix}
451 Bmake install prefix=$INSTALL_PREFIX BINDIR=$INSTALL_PREFIX/${INSTALL_BIN:-bin} ${INSTALL_DESTDIR:+DESTDIR=$INSTALL_DESTDIR} $INSTALL_ARGS || exit 1
455 rm -f make-bootstrap.sh bmake *.o
456 if [ -n "$INSTALL_PREFIX" ]; then
460 MAKE_VERSION=`sed -n '/^_MAKE_VERSION/ { s,.*= *,,;p; }' $srcdir/Makefile`
461 echo You can install by running:
463 echo $0 $cmd_args op=install
465 echo "Use --install-prefix=/something to install somewhere other than $prefix"
466 echo "Use --install-destdir=/somewhere to set DESTDIR during install"
467 echo "Use --install-host-target to use INSTALL_BIN=$HOST_TARGET/bin"
468 echo "Use -DWITH_PROG_VERSION to install as bmake-$MAKE_VERSION"
469 echo "Use -DWITHOUT_PROG_LINK to suppress bmake -> bmake-$MAKE_VERSION symlink"
470 echo "Use -DWITHOUT_INSTALL_MK to skip installing files to $prefix/share/mk"