3 # $NetBSD: bootstrap,v 1.89 2004/03/11 01:08:14 tv Exp $
6 # Copyright (c) 2001-2002 Alistair G. Crooks. All rights reserved.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # 3. All advertising materials mentioning features or use of this software
17 # must display the following acknowledgement:
18 # This product includes software developed by Alistair G. Crooks
19 # for the NetBSD project.
20 # 4. The name of the author may not be used to endorse or promote
21 # products derived from this software without specific prior written
24 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
25 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
28 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
30 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 BOOTSTRAP_VERSION=20040214
40 # set defaults for system locations
50 [ --pkgdbdir=<pkgdbdir> ]
51 [ --pkgsrcdir=<pkgsrcdir> ]
52 [ --ignore-case-check ]
53 [ --ignore-user-check ]
56 # this replicates some of the logic in bsd.prefs.mk. until
57 # bootstrap-pkgsrc is merged into pkgsrc, we need to determine the
58 # right value for OPSYS and MACHINE_ARCH.
61 opsys=`uname -s | tr -d /`
79 abi=`sed -e 's/.*\(abi=\)\([on]*[36][24]\).*/\2/' /etc/compiler.defaults`
80 isa=`sed -e 's/.*\(isa=mips\)\([1234]\).*/\2/' /etc/compiler.defaults`
83 imakeopts="-DBuildO32 -DSgiISAo32=$isa"
86 n32) imakeopts="-DBuildN32 -DSgiISA32=$isa"
90 imakeopts="-DBuild64bit -DSgiISA64=$isa"
102 _var="$1"; _name="$2"
104 eval _tmp=\"\$$_var\"
105 if [ "x$_tmp" != "x" ]; then
106 # Variable is already set (by the user, for example)
110 for _d in `echo $PATH | tr ':' ' '`; do
111 if [ -x "$_d/$_name" ]; then
113 eval $_var=\""$_d/$_name"\"
118 die "$_name not found in path."
125 # setting X11BASE to /usr breaks buildlink
126 if [ ! -e /usr/X11R6 ]; then
127 ln -sf /usr /usr/X11R6
129 if [ ! -z $imakeopts ]; then
130 echo "IMAKEOPTS+=$imakeopts" >> mk.conf.example
132 patch -d / --forward --quiet -E -p0 \
133 < files/irix.patch 2>/dev/null || true
140 if [ `$idprog -u` != 0 ]; then
146 # run a command, abort if it fails
149 echo_msg "running: $@"
152 if [ $ret -ne 0 ]; then
153 echo_msg "exited with status $ret"
159 echo_msg "bootstrap command: $0 $@"
160 echo_msg "bootstrap started: $build_start"
171 check_prog mtreeprog mtree
172 machine_arch=`uname -p`
181 machine_arch=`uname -p`
192 if [ -d "/usr/freeware/bin" ]; then
193 overpath="/usr/freeware/bin:$overpath"
195 if [ -d "/usr/bsd/bin" ]; then
196 overpath="/usr/bsd/bin:$overpath"
202 configargs="--with-machine_arch=mipseb"
209 if [ -f /etc/debian_version ]; then
218 machine_arch=`uname -m | sed -e 's/i.86/i386/'`
227 check_prog paxprog pax
228 check_prog tarprog tar
229 check_prog mtreeprog mtree
230 machine_arch=`uname -p`
239 check_prog mtreeprog mtree
240 machine_arch=`uname -p`
243 if [ -d "/usr/xpg4/bin" ]; then
244 overpath="/usr/xpg4/bin:$overpath"
252 whoamiprog=/usr/ucb/whoami
253 machine_arch=`uname -p | sed -e 's/i86pc/i386/'`
266 root_group=+Administrators
273 CC="gcc -D_ALL_SOURCE"; export CC
276 echo "This platform ($opsys) is untried - good luck, and thanks for using pkgsrc"
286 # export OPSYS and MACHINE_ARCH for pkg_install. we only set
287 # MACHINE_ARCH on platforms where we override bmake's value.
290 if [ "${machine_arch}" != "" ]; then
291 MACHINE_ARCH=${machine_arch}
295 if [ "x${PRESERVE_PATH}" != "xyes" ]; then
296 PATH="$overpath:$PATH"
299 check_prog awkprog awk
302 check_prog groupsprog groups
304 check_prog mkdirprog mkdir
305 check_prog rmdirprog rmdir
306 check_prog sedprog sed
308 check_prog whoamiprog whoami
310 while [ $# -gt 0 ]; do
312 --prefix=*) prefix=`echo $1 | $sedprog -e 's|--prefix=||'` ;;
313 --pkgdbdir=*) pkgdbdir=`echo $1 | $sedprog -e 's|--pkgdbdir=||'` ;;
314 --pkgsrcdir=*) pkgsrcdir=`echo $1 | $sedprog -e 's|--pkgsrcdir=||'` ;;
315 --ignore-case-check) ignorecasecheck=yes ;;
316 --ignore-user-check) ignoreusercheck=yes ;;
317 --help) echo "$usage"; exit ;;
318 -h) echo "$usage"; exit ;;
319 --*) echo "$usage"; exit 1 ;;
329 if [ $ignoreusercheck = "no" ]; then
330 die "You must be root to install bootstrap-pkgsrc."
334 group=`$groupsprog | $awkprog '{print $1}'`
335 echo_msg "building as unprivileged user $user/$group"
337 # force bmake install target to use $user and $group
343 MANGRP=$group" > Makefile.inc
346 # make sure we're using a case-sensitive file system on Darwin
347 if [ $ignorecasecheck = "no" ]; then
350 echo_msg "Testing file system case sensitivity"
351 for fs in "$prefix" "$pkgsrcdir"; do
352 testdir="pkgsrc-REQUIRES-case-SENSITIVE-filesystem"
353 testdir_mangled="PKGSRC-requires-CASE-sensitive-FILESYSTEM"
354 $mkdirprog -p "$fs/$testdir" || die "can't verify filesystem ($fs) case-sensitivity"
355 if [ -d "$fs/$testdir_mangled" ]; then
356 $rmdirprog "$fs/$testdir"
357 die "\"$fs\" needs to be on a case-sensitive filesystem (see README.Darwin)"
359 $rmdirprog "$fs/$testdir"
365 # export the proper environment
366 PATH=$prefix/bin:$prefix/sbin:${PATH}; export PATH
367 if [ -d /usr/ccs/bin -a -x /usr/ccs/bin/make ]; then
368 PATH=/usr/ccs/bin:$PATH; export PATH
370 PKG_DBDIR=$pkgdbdir; export PKG_DBDIR
371 LOCALBASE=$prefix; export LOCALBASE
373 # set up an example mk.conf file
374 echo_msg "Creating sample mk.conf"
375 echo "# Example /etc/mk.conf file produced by bootstrap-pkgsrc" > mk.conf.example
376 echo "# `date`" >> mk.conf.example
377 echo "" >> mk.conf.example
378 echo ".ifdef BSD_PKG_MK # begin pkgsrc settings" >> mk.conf.example
379 echo "" >> mk.conf.example
381 # IRIX64 needs to be set to IRIX, for example
382 if [ "$set_opsys" = "yes" ]; then
383 echo "OPSYS=$opsys" >> mk.conf.example
386 if [ ! -z "$abi" ]; then
387 echo "ABI=$abi" >> mk.conf.example
390 # save environment in example mk.conf
391 echo "PKG_DBDIR=$pkgdbdir" >> mk.conf.example
392 echo "LOCALBASE=$prefix" >> mk.conf.example
395 run_cmd "$mkdirprog -p $prefix $pkgdbdir $prefix/sbin"
396 run_cmd "$mkdirprog -p $prefix/man/man1 $prefix/man/cat1"
397 run_cmd "$mkdirprog -p $prefix/man/man8 $prefix/man/cat8"
399 # bootstrap make and *.mk files
400 run_cmd "$mkdirprog -p $prefix/share/mk $prefix/lib"
402 if [ -f ../../mods/mk/$opsys.sys.mk ]; then
403 run_cmd "$cpprog ../../mods/mk/$opsys.sys.mk $prefix/share/mk/sys.mk"
405 run_cmd "$cpprog ../../mods/mk/generic.sys.mk $prefix/share/mk/sys.mk"
407 run_cmd "$cpprog bsd.*.mk $prefix/share/mk")
409 if [ -f mods/mk/$opsys.bsd.lib.mk ] ; then
410 run_cmd "$cpprog bmake/mk/bsd.lib.mk bmake/mk/bsd.lib.mk.orig"
411 run_cmd "$cpprog mods/mk/$opsys.bsd.lib.mk bmake/mk/bsd.lib.mk"
414 run_cmd "$cpprog bmake/mk/bsd.man.mk bmake/mk/bsd.man.mk.orig"
415 if [ -f mods/mk/$opsys.bsd.man.mk ] ; then
416 run_cmd "$cpprog mods/mk/$opsys.bsd.man.mk bmake/mk/bsd.man.mk"
417 run_cmd "$cpprog mods/mk/$opsys.bsd.man.mk $prefix/share/mk/bsd.man.mk"
420 if [ -f mods/mk/$opsys.bsd.prog.mk ] ; then
421 run_cmd "$cpprog mods/mk/$opsys.bsd.own.mk $prefix/share/mk/bsd.own.mk"
423 run_cmd "$sedprog -e 's|@ROOT_GROUP@|'$root_group'|g' mods/mk/bsd.own.mk.in > $prefix/share/mk/bsd.own.mk"
426 if [ -f mods/mk/$opsys.bsd.sys.mk ]; then
427 run_cmd "$cpprog mods/mk/$opsys.bsd.sys.mk $prefix/share/mk/bsd.sys.mk"
431 NetBSD) run_cmd "$cpprog mods/bmake/Makefile.in bmake/Makefile.in"
435 if [ "$need_bsd_install" = "yes" ]; then
436 echo_msg "Installing BSD compatible install script"
437 run_cmd "(cd files; $shprog ./install-sh -c -o $user -g $group -m 755 install-sh $prefix/bin/install-sh)"
438 BSTRAP_ENV="INSTALL='$prefix/bin/install-sh -c' $BSTRAP_ENV"
441 if [ "$need_fixed_strip" = "yes" ] ; then
442 echo_msg "Installing fixed strip script"
443 run_cmd "(cd files; $shprog ./install-sh -c -o $user -g $group -m 755 strip-sh $prefix/bin/strip)"
446 echo_msg "Installing bmake"
447 run_cmd "(cd bmake; $shprog ./configure --prefix=$prefix --with-default-sys-path=$prefix/share/mk $configargs && make -f makefile.boot bootstrap && env BINDIR=$prefix/bin MANDIR=$prefix/man $BSTRAP_ENV ./bmake -f Makefile install)"
450 echo_msg "Building libnbcompat"
451 run_cmd "(cd libnbcompat; $shprog ./configure -C --prefix=$prefix && $prefix/bin/bmake)"
459 echo_msg "Installing tnftp"
460 run_cmd "(cd tnftp; env $BSTRAP_ENV $shprog ./configure --prefix=$prefix && make && (cd src && make install))"
461 pkg_install_args="$pkg_install_args --with-ftp=$prefix/bin/ftp"
463 FETCH_CMD=$prefix/bin/ftp
465 echo "FETCH_CMD=$prefix/bin/ftp" >> mk.conf.example
468 echo_msg "Installing digest"
469 run_cmd "(cd digest; env $BSTRAP_ENV $shprog ./configure -C --prefix=$prefix && make && make install)"
471 # create the digest package's meta files
472 digestversion=digest-`$awkprog -F "'" '/^PACKAGE_VERSION=/ {print $2}' digest/configure`
473 $lsprog -ld $prefix/bin/digest | $awkprog '{ print $5 }' > digest/.size
474 env DIGESTPROG=$prefix/bin/digest PKG_DIGEST=md5 PKG_DBDIR=$pkgdbdir \
475 $shprog ./pkg.sh create -d digest/DESCR -O \
476 -c '-Message digest wrapper utility' -l -p $prefix \
477 -f digest/PLIST -s digest/.size -S digest/.size $digestversion
479 # we often need NetBSD's pax as well, nowadays, to make binary packages
481 yes) echo_msg "Installing pax"
482 run_cmd "(cd pax; env $BSTRAP_ENV CPPFLAGS='-I../libnbcompat' LDFLAGS='-L../libnbcompat' LIBS='-lnbcompat' $shprog ./configure -C --prefix=$prefix && $prefix/bin/bmake && $prefix/bin/bmake install)"
483 echo "PAX=$prefix/bin/pax" >> mk.conf.example
484 pkg_install_args="$pkg_install_args --with-pax=$prefix/bin/pax --with-tar=$prefix/bin/tar"
487 pkg_install_args="$pkg_install_args --with-pax=$paxprog --with-tar=$tarprog"
491 # bootstrap mtree if necessary
492 case "$need_mtree" in
493 yes) echo_msg "Installing mtree"
494 run_cmd "(cd mtree; env $BSTRAP_ENV CPPFLAGS='-I../libnbcompat' LDFLAGS='-L../libnbcompat' LIBS='-lnbcompat' $shprog ./configure -C --prefix=$prefix && $prefix/bin/bmake && $prefix/bin/bmake install)"
495 pkg_install_args="$pkg_install_args --with-mtree=$prefix/sbin/mtree"
497 *) pkg_install_args="$pkg_install_args --with-mtree=$mtreeprog"
501 # bootstrap sed if necessary
503 yes) echo_msg "Installing sed"
504 run_cmd "(cd sed; env $BSTRAP_ENV $shprog ./configure -C --prefix=$prefix && make && make install)"
505 echo "SED=$prefix/bin/nbsed" >> mk.conf.example
509 # bootstrap pkg_install
510 echo_msg "Installing pkgtools"
511 pkg_install_mandir="$prefix/man"
512 if [ "$prefix" = "/usr" ]; then
513 pkg_install_mandir="$prefix/share/man"
515 run_cmd "(cd pkg_install; env $BSTRAP_ENV CPPFLAGS='-I../libnbcompat -I../../libnbcompat' LDFLAGS='-L../libnbcompat -L../../libnbcompat' LIBS='-lnbcompat' $shprog ./configure -C --prefix=$prefix --with-pkgdbdir=$pkgdbdir --mandir=$pkg_install_mandir $pkg_install_args && $prefix/bin/bmake && $prefix/bin/bmake install)"
517 # all's ready, install the man page
518 echo_msg "Installing packages(7) man page"
519 (cd files; run_cmd "$shprog ./install-sh -c -m 444 packages.cat7 $prefix/man/cat7/packages.0")
521 # opsys specific fiddling
524 echo "" >> mk.conf.example
525 echo ".endif # end pkgsrc settings" >> mk.conf.example
527 echo "Please remember to add $prefix/bin to your PATH environment variable."
528 echo "If necessary, please remember to add $prefix/man to your MANPATH environment variable."
529 echo "Please remember to set FETCH_CMD in /etc/mk.conf to $prefix/bin/ftp"
531 echo "An example mk.conf file has been created for you in mk.conf.example"
532 echo "with the settings you provided to bootstrap pkgsrc."
534 echo "You can find extensive documentation of the NetBSD Packages Collection"
535 echo "in $pkgsrcdir/Packages.txt and packages(7)."
537 echo "Hopefully everything is now complete."
540 echo_msg "bootstrap started: $build_start"
541 echo_msg "bootstrap ended: `date`"