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="path/to/filemon.h"
93 # enables use of filemon(9) by meta mode.
95 # --with-machine="machine"
96 # set "machine" to override that determined by
99 # --with-force-machine="machine"
100 # force "machine" even if uname(3) provides a value.
102 # --with-machine_arch="machine_arch"
103 # set "machine_arch" to override that determined by
106 # --with-default-sys-path="syspath"
107 # set an explicit default "syspath" which is where bmake
108 # will look for sys.mk and friends.
111 # Simon J. Gerraty <sjg@crufty.net>
114 # $Id: boot-strap,v 1.42 2013/01/25 20:20:33 sjg Exp $
116 # @(#) Copyright (c) 2001 Simon J. Gerraty
118 # This file is provided in the hope that it will
119 # be of use. There is absolutely NO WARRANTY.
120 # Permission to copy, redistribute or otherwise
121 # use this file is hereby granted provided that
122 # the above copyright notice and this notice are
125 # Please send copies of changes and bug-fixes to:
133 *) Mydir=`cd "$Mydir" && 'pwd'`;;
137 [ "$1" ] && echo "ERROR: $@" >&2
139 echo "$0 [--<configure_arg> ...][<prefix>][--install]" >&2
153 [ -f "$r" -a -s "$r" ] || continue
154 echo "NOTE: reading $r"
162 # --install[-host-target] will set this
164 # other things we pass to install step
168 # pick a useful default prefix (for me at least ;-)
169 for prefix in /opt/$HOST_TARGET "$HOME/$HOST_TARGET" /usr/pkg /usr/local ""
171 [ -d "${prefix:-.}" ] || continue
175 if [ -d $p/share ]; then
176 INSTALL_BIN=$HOST_TARGET/bin
181 echo "NOTE: default prefix=$prefix ${INSTALL_BIN:+INSTALL_BIN=$INSTALL_BIN}"
189 ${SKIP_RC:+:} source_rc .bmake-boot-strap.rc . "$Mydir/.." "$HOME"
192 expr "x$1" : "x[^=]*=\\(.*\\)"
196 if [ $here = $Mydir ]; then
208 --help) sed -n -e "1d;/RCSid/,\$d" -e '/^#\.[a-z]/d' -e '/^#/s,^# *,,p' $0; exit 0;;
209 --prefix) prefix="$2"; shift;;
210 --prefix=*) prefix=`get_optarg "$1"`;;
211 --src=*) srcdir=`get_optarg "$1"`;;
212 --with-mksrc=*|--mksrc=*) mksrc=`get_optarg "$1"`;;
213 --share=*) share_dir=`get_optarg "$1"`;;
214 --share) share_dir="$2"; shift;;
215 --with-default-sys-path=*)
217 MAKESYSPATH=`get_optarg "$1"`;;
218 --with-default-sys-path)
219 CONFIGURE_ARGS="$1 $2"
220 MAKESYSPATH="$2"; shift;;
221 --install) INSTALL_PREFIX=${INSTALL_PREFIX:-$prefix};;
222 --install-host-target)
223 INSTALL_PREFIX=${INSTALL_PREFIX:-$prefix}
224 INSTALL_BIN=$HOST_TARGET/bin;;
225 --install-destdir=*) INSTALL_DESTDIR=`get_optarg "$1"`;;
226 --install-prefix=*) INSTALL_PREFIX=`get_optarg "$1"`;;
227 -DWITH*) INSTALL_ARGS="$INSTALL_ARGS $1";;
228 -s|--src) srcdir="$2"; shift;;
229 -m|--mksrc) mksrc="$2"; shift;;
230 -o|--objdir) objdir="$2"; shift;;
232 -c) source_rc "$2"; shift;;
233 --*) CONFIGURE_ARGS="$CONFIGURE_ARGS $1";;
234 *=*) eval "$1"; export `expr "x$1" : "x\\(.[^=]*\\)=.*"`;;
241 case " $CONFIGURE_ARGS " in
243 *) CONFIGURE_ARGS="$CONFIGURE_ARGS $1$2";;
254 [ -d "$dir" ] || continue
261 *) [ -s $dir/$fmatch ] || continue;;
264 *./*) cd "$dir" && 'pwd';;
266 *) cd "$dir" && 'pwd';;
278 -C) cd "$2"; shift; shift;;
284 /*) # we shouldn't be here
285 [ $_t "$1" ] && echo "$1"
288 .../*) want=`echo "$1" | sed 's,^.../*,,'`;;
294 if [ $_t "./$want" ]; then
307 # is $1 missing from $2 (or PATH) ?
309 eval "__p=\$${2:-PATH}"
310 case ":$__p:" in *:"$1":*) return 1;; *) return 0;; esac
313 # if $1 exists and is not in path, append it
320 MAKESYSPATH,.../*) ;;
321 *) [ $t ${1:-.} ] || return;;
323 no_path $* && eval ${2:-PATH}="$__p${__p:+:}$1"
327 srcdir=`GetDir /bmake make-bootstrap.sh.in "$srcdir" "$2" "$Mydir" ./bmake* "$Mydir"/../bmake*`
328 [ -d "${srcdir:-/dev/null}" ] || Usage
330 none|-) # we don't want it
333 .../*) # find here or above
334 mksrc=`FindHereOrAbove -C "$Mydir" -s "$mksrc/sys.mk"`
336 mksrc=`dirname $mksrc`
338 *) # guess we want mksrc...
339 mksrc=`GetDir /mk sys.mk "$mksrc" "$3" ./mk* "$srcdir"/mk* "$srcdir"/../mk*`
340 [ -d "${mksrc:-/dev/null}" ] || Usage "Use '-m none' to build without mksrc"
345 objdir="${objdir:-$OBJROOT$HOST_TARGET}"
346 [ -d "$objdir" ] || mkdir -p "$objdir"
347 [ -d "$objdir" ] || mkdir "$objdir"
348 cd "$objdir" || exit 1
354 /) [ -d /share ] || return;;
356 if [ -d "$1/../share" ]; then
357 echo `dirname "$1"`/share
365 # make it easy to force prefix to use $HOST_TARGET
366 : looking at "$prefix"
368 */host?target) prefix=`echo "$prefix" | sed "s,host.target,${HOST_TARGET},"`;;
371 share_dir="${share_dir:-`ShareDir $prefix`}"
373 AddConfigure --prefix= "$prefix"
374 case "$CONFIGURE_ARGS" in
375 *--with-*-sys-path*) ;; # skip
376 *) [ "$share_dir" ] && AddConfigure --with-default-sys-path= "$share_dir/mk";;
378 if [ "$mksrc" ]; then
379 AddConfigure --with-mksrc= "$mksrc"
380 # not all cc's support this
381 CFLAGS_MF= CFLAGS_MD=
382 export CFLAGS_MF CFLAGS_MD
385 # this makes it easy to run the bmake we just built
386 # the :tA dance is needed because 'pwd' and even /bin/pwd
387 # may not give the same result as realpath().
391 MAKESYSPATH=$mksrc SRCTOP=$Mydir OBJTOP=$objdir \
392 MAKEOBJDIR='${.CURDIR:S,${SRCTOP:tA},${OBJTOP:tA},}' \
393 ${BMAKE:-$objdir/bmake} -f $Mydir/Makefile "$@"
397 # make sure test below uses the same diff that configure did
398 TOOL_DIFF=`type diff | sed 's,[()],,g;s,^[^/][^/]*,,;q'`
402 $srcdir/configure $CONFIGURE_ARGS || exit 1
406 [ -s make-bootstrap.sh ] || op_configure
407 chmod 755 make-bootstrap.sh || exit 1
408 ./make-bootstrap.sh || exit 1
415 [ -x bmake ] || op_build
420 if [ -x bmake ]; then
422 BMAKE=$objdir/bmake$$ Bmake clean
424 elif [ $objdir != $srcdir ]; then
431 case "$INSTALL_PREFIX,$INSTALL_BIN,$prefix" in
432 ,$HOST_TARGET/bin,*/$HOST_TARGET)
433 INSTALL_PREFIX=`dirname $prefix`
436 INSTALL_PREFIX=${INSTALL_PREFIX:-$prefix}
437 Bmake install prefix=$INSTALL_PREFIX BINDIR=$INSTALL_PREFIX/${INSTALL_BIN:-bin} ${INSTALL_DESTDIR:+DESTDIR=$INSTALL_DESTDIR} $INSTALL_ARGS || exit 1
441 rm -f make-bootstrap.sh bmake *.o
442 if [ -n "$INSTALL_PREFIX" ]; then
446 MAKE_VERSION=`sed -n '/^MAKE_VERSION/ { s,.*= *,,;p; }' $srcdir/Makefile`
447 echo You can install by running:
449 echo $0 $cmd_args op=install
451 echo "Use --install-prefix=/something to install somewhere other than $prefix"
452 echo "Use --install-destdir=/somewhere to set DESTDIR during install"
453 echo "Use --install-host-target to use INSTALL_BIN=$HOST_TARGET/bin"
454 echo "Use -DWITH_PROG_VERSION to install as bmake-$MAKE_VERSION"
455 echo "Use -DWITHOUT_PROG_LINK to supress bmake -> bmake-$MAKE_VERSION symlink"
456 echo "Use -DWITHOUT_INSTALL_MK to skip installing files to $prefix/share/mk"