3 # $NetBSD: bootstrap,v 1.148 2009/06/27 22:30:50 ahoka 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 # the following environment variables are honored:
39 # compiler/linker flags: CFLAGS, CPPFLAGS, LDFLAGS
40 # tools: CP, GREP, ID, MKDIR, SH, TEST, TOUCH, XARGS
43 BOOTSTRAP_VERSION=20060721
45 # Don't let the bootstrap program get confused by a pre-existing mk.conf
55 # where the building takes place
56 bootstrapdir=`dirname "$0"`
57 bootstrapdir=`cd "${bootstrapdir}" && pwd`
58 pkgsrcdir=`dirname "${bootstrapdir}"`
62 [ --workdir <workdir> ]
64 [ --pkgdbdir <pkgdbdir> ]
65 [ --pkgmandir <pkgmandir> ]
66 [ --sysconfdir <sysconfdir> ]
67 [ --varbase <varbase> ]
68 [ --fetch-cmd <ftp command> ]
69 [ --ignore-case-check ]
70 [ --unprivileged | --ignore-user-check ]
72 [ --compiler <compiler> ]
74 [ --mk-fragment <mk.conf> ]
75 [ --binary-kit <tarball> ]
76 [ --gzip-binary-kit <tarball> ]
77 [ --binary-macpkg <pkg> ]
82 # this replicates some of the logic in bsd.prefs.mk. until
83 # bootstrap-pkgsrc is merged into pkgsrc, we need to determine the
84 # right value for OPSYS and MACHINE_ARCH.
86 # strip / for BSD/OS, strip - for HP-UX
87 opsys=`uname -s | tr -d /-`
92 macdestdir=${wrkdir}/macpkg-destdir
93 rm -rf ${macdestdir} || die "cleanup destdir"
95 mkdir -p ${macdestdir}${prefix} || die "mkdir destprefix"
96 rmdir ${macdestdir}${prefix} || die "rmdir destprefix"
97 cp -Rp ${prefix} ${macdestdir}${prefix} || die "copy prefix"
99 if [ ! -d ${macdestdir}${pkgdbdir} ]; then
100 mkdir -p ${macdestdir}${pkgdbdir} || die "mkdir destdbdir"
101 rmdir ${macdestdir}${pkgdbdir} || die "rmdir destdbdir"
102 cp -Rp ${pkgdbdir} ${macdestdir}${pkgdbdir} || die "copy dbdir"
105 ${sedprog} -e "s|%WRKDIR%|${wrkdir}|g" \
106 -e "s|%TARGETDIR%|${targetdir}|g" -e "s|%DATE%|${date}|g" \
107 < macpkg.pmproj.in > ${wrkdir}/macpkg.pmproj
108 ${packagemaker} -build -proj ${wrkdir}/macpkg.pmproj -p "${binary_macpkg}"
113 # in case tar was built by bootstrap
114 PATH="$prefix/bin:$PATH"; export PATH
115 cd / && tar -hcf "${binary_kit}" .$prefix .$pkgdbdir .$etc_mk_conf
120 # in case tar was built by bootstrap
121 PATH="$prefix/bin:$PATH"; export PATH
122 cd / && tar -hzcf "${binary_gzip_kit}" .$prefix .$pkgdbdir .$etc_mk_conf
136 # see if we're using gcc. If so, set $compiler_is_gnu to '1'.
140 # normally, we'd just use 'cc', but certain configure tools look
141 # for gcc specifically, so we have to see if that comes first
142 if [ -z "${testcc}" ]; then
145 for dir in ${PATH}; do
146 test -z "$dir" && dir=.
147 if [ -x "$dir/gcc" ]; then
155 cat >${wrkdir}/$$.c <<EOF
160 compiler_is_gnu=`${testcc:-cc} -E ${wrkdir}/$$.c 2>/dev/null | grep -c indeed`
168 if [ -n "$abi" ]; then
169 die "ERROR: $abi_opsys has special ABI handling, --abi not supported (yet)."
174 if [ `uname -r` -ge 6 ]; then
175 abi=`sed -e 's/.*\(abi=\)\([on]*[36][24]\).*/\2/' /etc/compiler.defaults`
176 isa=`sed -e 's/.*\(isa=mips\)\([1234]\).*/\2/' /etc/compiler.defaults`
179 imakeopts="-DBuildO32 -DSgiISAo32=$isa"
182 n32) imakeopts="-DBuildN32 -DSgiISA32=$isa"
186 imakeopts="-DBuild64bit -DSgiISA64=$isa"
197 get_machine_arch_aix()
199 _cpuid=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
200 if /usr/sbin/lsattr -El $_cpuid | grep ' POWER' >/dev/null 2>&1; then
209 _var="$1"; _name="$2"
211 eval _tmp=\"\$$_var\"
212 if [ "x$_tmp" != "x" ]; then
213 # Variable is already set (by the user, for example)
217 for _d in `echo $PATH | tr ':' ' '`; do
218 if [ -f "$_d/$_name" ] && [ -x "$_d/$_name" ]; then
220 eval $_var=\""$_d/$_name"\"
225 die "$_name not found in path."
232 if [ ! -z "$imakeopts" ]; then
233 echo "IMAKEOPTS+= $imakeopts" >> ${TARGET_MKCONF}
235 if [ `uname -r` -lt 6 ]; then
236 echo_msg "Installing fake ldd script"
237 run_cmd "$install_sh -c -o $user -g $group -m 755 $pkgsrcdir/pkgtools/bootstrap-extras/files/fakeldd $prefix/sbin"
239 echo "LDD= $prefix/sbin/fakeldd" >> ${TARGET_MKCONF}
247 if [ `uname -s` = "IRIX" ]; then
248 if [ `uname -r` -lt 6 -a -z "$ID" ]; then
249 # older version of IRIX have an id command with limited features
250 if [ "`$idprog`" != "uid=0(root) gid=0(sys)" ]; then
256 if [ `$idprog -u` != 0 ]; then
262 # run a command, abort if it fails
265 echo_msg "running: $@"
268 if [ $ret -ne 0 ]; then
269 echo_msg "exited with status $ret"
274 # Some versions of mkdir (notably SunOS) bail out too easily, so use the
275 # install-sh wrapper instead.
279 run_cmd "$install_sh -d -o $user -g $group $dir"
285 [ -d "$1" ] && return 0
286 mkdir -p "$1" 2> /dev/null && return 0
287 parent=`dirname "$1"`
288 mkdir_p_early "$parent"
289 if [ ! -d "$1" ] && mkdir "$1"; then
290 echo_msg "mkdir $1 exited with status $?"
299 if [ ! -d $wrkdir/$_dst ]; then
300 mkdir_p $wrkdir/$_dst
302 $cpprog -r $_src/* $wrkdir/$_dst
307 expr "x$1" : "x[^=]*=\\(.*\\)"
310 checkarg_sane_absolute_path() {
312 "") ;; # the default value will be used.
314 die "ERROR: Invalid characters in path $1 (from $2)." ;;
316 *) die "ERROR: The argument to $2 must be an absolute path." ;;
320 checkarg_sane_relative_path() {
322 "") ;; # the default value will be used.
324 die "ERROR: Invalid characters in path $1 (from $2)." ;;
325 /*) die "ERROR: The argument to $2 must be a relative path." ;;
330 bootstrap_sh=${SH-/bin/sh}
331 bootstrap_sh_set=${SH+set}
333 # On some newer Ubuntu installations, /bin/sh is a symlink to /bin/dash,
334 # whose echo(1) is not BSD-compatible.
335 dash_echo_test=`$bootstrap_sh -c 'echo "\\100"'`
336 if [ "$dash_echo_test" = "@" ]; then
337 { echo "ERROR: Your shell's echo command is not BSD-compatible."
338 echo "ERROR: Please select another shell by setting the environment"
339 echo "ERROR: variable SH."
344 if [ -n "$PKG_PATH" ]; then
345 echo "ERROR: Please unset PKG_PATH before running bootstrap." 1>&2
350 echo_msg "bootstrap command: $0 $@"
351 echo_msg "bootstrap started: $build_start"
353 # ensure system locations are empty; we will set them later when we know
354 # whether they will be system wide or user specific
366 while [ $# -gt 0 ]; do
368 --workdir=*) wrkdir=`get_optarg "$1"` ;;
369 --workdir) wrkdir="$2"; shift ;;
370 --prefix=*) prefix=`get_optarg "$1"` ;;
371 --prefix) prefix="$2"; shift ;;
372 --pkgdbdir=*) pkgdbdir=`get_optarg "$1"` ;;
373 --pkgdbdir) pkgdbdir="$2"; shift ;;
374 --pkgmandir=*) pkgmandir=`get_optarg "$1"` ;;
375 --pkgmandir) pkgmandir="$2"; shift ;;
376 --sysconfdir=*) sysconfdir=`get_optarg "$1"` ;;
377 --sysconfdir) sysconfdir="$2"; shift ;;
378 --varbase=*) varbase=`get_optarg "$1"` ;;
379 --varbase) varbase="$2"; shift ;;
380 --fetch-cmd=*) fetch_cmd=`get_optarg "$1"` ;;
381 --fetch-cmd) fetch_cmd="$2"; shift ;;
382 --compiler=*) compiler=`get_optarg "$1"` ;;
383 --compiler) compiler="$2"; shift ;;
384 --abi=*) abi=`get_optarg "$1"` ;;
385 --abi) abi="$2"; shift ;;
386 --ignore-case-check) ignorecasecheck=yes ;;
387 --unprivileged | --ignore-user-check) unprivileged=yes ;;
388 --preserve-path) preserve_path=yes ;;
390 mk_fragment=`get_optarg "$1"` ;;
392 mk_fragment="$2"; shift ;;
395 binary_kit=`get_optarg "$1"` ;;
397 binary_kit="$2"; shift ;;
399 binary_gzip_kit=`get_optarg "$1"` ;;
401 binary_gzip_kit="$2"; shift ;;
403 binary_macpkg=`get_optarg "$1"` ;;
405 binary_macpkg="$2"; shift ;;
407 --quiet) quiet=yes ;;
408 --help) echo "$usage"; exit ;;
409 -h) echo "$usage"; exit ;;
410 --*) echo "$usage"; exit 1 ;;
415 checkarg_sane_absolute_path "$wrkdir" "--workdir"
416 checkarg_sane_absolute_path "$prefix" "--prefix"
417 checkarg_sane_absolute_path "$pkgdbdir" "--pkgdbdir"
418 checkarg_sane_absolute_path "$sysconfdir" "--sysconfdir"
419 checkarg_sane_absolute_path "$varbase" "--varbase"
420 checkarg_sane_relative_path "$pkgmandir" "--pkgmandir"
422 # set defaults for system locations if not already set by the user
423 wrkobjdir=${wrkdir}/pkgsrc
424 if [ "$unprivileged" = "yes" ]; then
425 [ -z "$prefix" ] && prefix=${HOME}/pkg
426 elif [ -z "$prefix" -o "$prefix" = "/usr/pkg" ]; then
428 [ -z "$varbase" ] && varbase=/var
431 [ -z "$varbase" ] && varbase=${prefix}/var
432 [ -z "$pkgdbdir" ] && pkgdbdir=${varbase}/db/pkg
434 if [ "$prefix" = "/usr" ]; then
435 [ -z "$pkgmandir" ] && pkgmandir=share/man
437 [ -z "$pkgmandir" ] && pkgmandir=man
439 mandir=${prefix}/${pkgmandir}
440 [ -z "$sysconfdir" ] && sysconfdir=${prefix}/etc
442 if [ "x$preserve_path" != "xyes" ]; then
443 PATH="$PATH:/sbin:/usr/sbin"
458 [ -z "$fetch_cmd" ] && fetch_cmd="/usr/bin/ftp"
459 machine_arch=`uname -p`
460 CC="gcc -isystem /usr/include"; export CC
462 macosx_version=`echo $osrev | awk -F . '{ print "10."$1-4; }'`
463 case "$macosx_version" in
465 packagemaker=/Developer/Tools/packagemaker
468 packagemaker=/Developer/usr/bin/packagemaker
471 unset osrev macosx_version
479 check_prog tarprog tar
480 machine_arch=`uname -p`
483 [ -z "$fetch_cmd" ] && fetch_cmd="/usr/bin/ftp"
485 1.0* | 1.1 | 1.2.* | 1.3.*)
488 [ -z "$fetch_cmd" ] && fetch_cmd="/usr/bin/ftp"
498 machine_arch=`uname -p`
506 machine_arch=`uname -m | sed 's/^9000.*$/hppa/'`
509 if [ -d "/usr/freeware/bin" ]; then
510 overpath="/usr/freeware/bin:$overpath"
512 if [ -d "/usr/bsd/bin" ]; then
513 overpath="/usr/bsd/bin:$overpath"
523 bmakexargs="MACHINE_ARCH=$machine_arch"
524 bmakexenv="MAKE=pmake"
526 if [ `uname -r` -lt 6 ]; then
527 # IRIX 5's mkdir bails out with an error when trying to create with the -p
528 # option an already existing directory
533 if [ -f /etc/debian_version ]; then
541 machine_arch=`uname -m | sed -e 's/i.86/i386/'`
549 machine_arch=`uname -p`
557 machine_arch=`uname -m`
560 if [ -d "/usr/xpg4/bin" ]; then
561 overpath="/usr/xpg4/bin:$overpath"
569 groupsprog="/usr/xpg4/bin/id -gn"
570 whoamiprog="/usr/xpg4/bin/id -un"
571 machine_arch=`uname -p | sed -e 's/i86pc/i386/'`
581 machine_arch=`get_machine_arch_aix`
585 if id -G | grep -q 131616; then
591 mkdir -p "$@" # allows umask to take effect
593 default_install_mode=0775
601 # only used for unprivileged builds
603 # for bootstrap only; pkgsrc uses CPPFLAGS
604 CC="gcc -D_ALL_SOURCE"; export CC
605 ac_cv_header_poll_h=no; export ac_cv_header_poll_h
606 ac_cv_func_poll=no; export ac_cv_func_poll
611 BSTRAP_ENV="INSTALL=/usr/ucb/install $BSTRAP_ENV"
615 whoamiprog=/usr/ucb/whoami
617 CC="gcc -DUNIXWARE"; export CC
633 fetch_cmd="/usr/bin/ftp"
634 machine_arch=`uname -p | sed -e 's/x86/i386/'`
637 echo "This platform ($opsys) is untried - good luck, and thanks for using pkgsrc"
646 # If "--full" is specified, then install all of the platform-independent
647 # bootstrap software.
660 configure_quiet_flags="--quiet"
661 make_quiet_flags="-s"
664 configure_quiet_flags=""
668 # export OPSYS and MACHINE_ARCH for pkg_install. we only set
669 # MACHINE_ARCH on platforms where we override bmake's value.
672 if [ "${machine_arch}" != "" ]; then
673 MACHINE_ARCH=${machine_arch}
677 if [ "x$preserve_path" != "xyes" ]; then
678 PATH="$overpath:$PATH"
681 check_prog awkprog awk
682 check_prog chmodprog chmod
683 if [ -n "$CP" ]; then
688 if [ -n "$ID" ]; then
693 check_prog groupsprog groups
696 check_prog rmdirprog rmdir
697 check_prog sedprog sed
699 check_prog whoamiprog whoami
701 if [ -d "${wrkdir}" ] || [ -f "${wrkdir}" ]; then
702 echo "\"${wrkdir}\" already exists, please remove it or use --workdir.";
706 mkdir_p_early ${wrkdir}
707 if touch ${wrkdir}/.writeable; then
710 echo "\"${wrkdir}\" is not writeable. Try $0 -h.";
713 echo "Working directory is: ${wrkdir}"
715 if [ "$compiler" = "" ] && [ x"$check_compiler" = x"yes" ]; then
717 if [ $compiler_is_gnu -gt 0 ]; then
722 if [ `uname -r` -ge 6 ]; then
727 test -n "$CC" || CC=cc
729 SunOS) compiler="sunpro"
730 test -n "$CC" || CC=cc
736 mkdir_p_early ${wrkdir}/bin
739 run_cmd "$sedprog -e 's|@DEFAULT_INSTALL_MODE@|'${default_install_mode-0755}'|' $pkgsrcdir/sysutils/install-sh/files/install-sh.in > $wrkdir/bin/install-sh"
740 run_cmd "$chmodprog +x $wrkdir/bin/install-sh"
741 install_sh="$shprog $wrkdir/bin/install-sh"
748 if [ $unprivileged = "no" ]; then
749 die "You must be either root to install bootstrap-pkgsrc or use the --unprivileged option."
753 group=`$groupsprog | $awkprog '{print $1}'`
754 echo_msg "building as unprivileged user $user/$group"
756 # force bmake install target to use $user and $group
762 MANGRP=$group" > ${wrkdir}/Makefile.inc
765 # make sure we're using a case-sensitive file system
766 if [ $ignorecasecheck = "no" ]; then
769 echo_msg "Testing file system case sensitivity"
770 for fs in "$prefix"; do
771 testdir="pkgsrc-REQUIRES-case-SENSITIVE-filesystem"
772 testdir_mangled="PKGSRC-requires-CASE-sensitive-FILESYSTEM"
773 mkdir_p "$fs/$testdir" || die "can't verify filesystem ($fs) case-sensitivity"
774 if [ -d "$fs/$testdir_mangled" ]; then
775 $rmdirprog "$fs/$testdir"
776 die "\"$fs\" needs to be on a case-sensitive filesystem (see README.$opsys)"
778 $rmdirprog "$fs/$testdir"
784 # export the proper environment
785 PATH=$prefix/bin:$prefix/sbin:${PATH}; export PATH
786 if [ -d /usr/ccs/bin -a -x /usr/ccs/bin/make ]; then
787 PATH=${PATH}:/usr/ccs/bin; export PATH
789 PKG_DBDIR=$pkgdbdir; export PKG_DBDIR
790 LOCALBASE=$prefix; export LOCALBASE
791 VARBASE=$varbase; export VARBASE
793 # set up an example mk.conf file
794 TARGET_MKCONF=${wrkdir}/mk.conf.example
795 echo_msg "Creating default mk.conf. in ${wrkdir}"
796 echo "# Example ${sysconfdir}/mk.conf file produced by bootstrap-pkgsrc" > ${TARGET_MKCONF}
797 echo "# `date`" >> ${TARGET_MKCONF}
798 echo "" >> ${TARGET_MKCONF}
799 echo ".ifdef BSD_PKG_MK # begin pkgsrc settings" >> ${TARGET_MKCONF}
800 echo "" >> ${TARGET_MKCONF}
802 # IRIX64 needs to be set to IRIX, for example
803 if [ "$set_opsys" = "yes" ]; then
804 echo "OPSYS= $opsys" >> ${TARGET_MKCONF}
807 if [ ! -z "$abi" ]; then
808 echo "ABI= $abi" >> ${TARGET_MKCONF}
810 if [ "$compiler" != "" ]; then
811 echo "PKGSRC_COMPILER= $compiler" >> ${TARGET_MKCONF}
815 echo "CC= cc" >> ${TARGET_MKCONF}
816 echo "CXX= CC" >> ${TARGET_MKCONF}
817 echo "CPP= \${CC} -E" >> ${TARGET_MKCONF}
820 if [ -n "$SUNWSPROBASE" ]; then
821 echo "SUNWSPROBASE= $SUNWSPROBASE" >> ${TARGET_MKCONF}
823 echo "" >> ${TARGET_MKCONF}
825 # enable unprivileged builds if not root
826 if [ "$unprivileged" = "yes" ]; then
827 echo "UNPRIVILEGED= yes" >> ${TARGET_MKCONF}
830 # save environment in example mk.conf
831 echo "PKG_DBDIR= $pkgdbdir" >> ${TARGET_MKCONF}
832 echo "LOCALBASE= $prefix" >> ${TARGET_MKCONF}
833 echo "VARBASE= $varbase" >> ${TARGET_MKCONF}
834 if [ "${sysconfdir}" != "${prefix}/etc" ]; then
835 echo "PKG_SYSCONFBASE= $sysconfdir" >> ${TARGET_MKCONF}
837 echo "PKG_TOOLS_BIN= $prefix/sbin" >> ${TARGET_MKCONF}
838 echo "PKGMANDIR= $pkgmandir" >> ${TARGET_MKCONF}
839 echo "" >> ${TARGET_MKCONF}
841 BOOTSTRAP_MKCONF=${wrkdir}/mk.conf
842 cp ${TARGET_MKCONF} ${BOOTSTRAP_MKCONF}
844 # sbin is used by pkg_install, share/mk by bootstrap-mk-files
845 mkdir_p $wrkdir/sbin $wrkdir/share/mk
846 mkdir_p_early ${wrkdir}
848 if [ "$need_bsd_install" = "yes" ]; then
849 BSTRAP_ENV="INSTALL='$prefix/bin/install-sh -c' $BSTRAP_ENV"
850 echo "TOOLS_PLATFORM.install?= $prefix/bin/install-sh" >> ${TARGET_MKCONF}
851 echo "TOOLS_PLATFORM.install?= $wrkdir/bin/install-sh" >> ${BOOTSTRAP_MKCONF}
854 if [ "$need_fixed_strip" = "yes" ] ; then
855 echo_msg "Installing fixed strip script"
856 run_cmd "$install_sh -c -o $user -g $group -m 755 $pkgsrcdir/pkgtools/bootstrap-extras/files/strip-sh $wrkdir/bin/strip"
857 echo "TOOLS_PLATFORM.strip?= $prefix/bin/strip" >> ${TARGET_MKCONF}
858 echo "TOOLS_PLATFORM.strip?= $wrkdir/bin/strip" >> ${BOOTSTRAP_MKCONF}
862 if [ "$need_mkdir" = "yes" -a -z "$MKDIR" ]; then
863 echo_msg "Installing fixed mkdir script \"mkdir-sh\""
864 run_cmd "$install_sh -c -o $user -g $group -m 755 $pkgsrcdir/pkgtools/bootstrap-extras/files/mkdir-sh $wrkdir/bin/mkdir-sh"
865 echo "TOOLS_PLATFORM.mkdir?= $prefix/bin/mkdir-sh -p" >> ${TARGET_MKCONF}
866 echo "TOOLS_PLATFORM.mkdir?= $wrkdir/bin/mkdir-sh -p" >> ${BOOTSTRAP_MKCONF}
870 if [ "$need_xargs" = "yes" ]; then
871 echo_msg "Installing fixed xargs script"
872 run_cmd "$install_sh -c -o $user -g $group -m 755 $pkgsrcdir/pkgtools/bootstrap-extras/files/xargs-sh $wrkdir/bin/xargs"
873 echo "TOOLS_PLATFORM.xargs?= $prefix/bin/xargs" >> ${TARGET_MKCONF}
874 echo "TOOLS_PLATFORM.xargs?= $wrkdir/bin/xargs" >> ${BOOTSTRAP_MKCONF}
878 echo_msg "Bootstrapping mk-files"
879 run_cmd "(cd ${pkgsrcdir}/pkgtools/bootstrap-mk-files/files && env CP=${cpprog} \
880 OPSYS=${opsys} MK_DST=${wrkdir}/share/mk ROOT_GROUP=${root_group} \
881 ROOT_USER=${root_user} SED=${sedprog} SYSCONFDIR=${sysconfdir} \
882 $shprog ./bootstrap.sh)"
885 echo_msg "Bootstrapping bmake"
886 copy_src $pkgsrcdir/devel/bmake/files bmake
887 run_cmd "(cd $wrkdir/bmake && env $bmakexenv $shprog ./boot-strap $configure_quiet_flags -q -o $opsys --prefix=$wrkdir --sysconfdir=$wrkdir --mksrc none --with-default-sys-path="$wrkdir/share/mk" $bmakexargs)"
888 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/bmake/$opsys/bmake $wrkdir/bin/bmake"
892 bmake="$wrkdir/bin/bmake $make_quiet_flags"
895 echo_msg "Building libnbcompat"
896 copy_src $pkgsrcdir/pkgtools/libnbcompat/files libnbcompat
897 run_cmd "(cd $wrkdir/libnbcompat; $shprog ./configure $configure_quiet_flags -C --prefix=$prefix --mandir=$mandir --sysconfdir=$sysconfdir --enable-bsd-getopt --enable-db && $bmake $make_quiet_flags)"
899 # bootstrap ksh if necessary
901 yes) echo_msg "Bootstrapping ksh"
902 copy_src $pkgsrcdir/shells/pdksh/files ksh
903 test -n "$CC" || CC=gcc # default to gcc if no compiler is specified
904 run_cmd "(cd $wrkdir/ksh && env $BSTRAP_ENV $shprog ./configure $configure_quiet_flags --prefix=$prefix --mandir=$mandir --sysconfdir=$sysconfdir && $bmake)"
905 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/ksh/ksh $wrkdir/bin/pdksh"
906 echo "TOOLS_PLATFORM.sh?= $prefix/bin/pdksh" >> ${TARGET_MKCONF}
907 echo "TOOLS_PLATFORM.sh?= $wrkdir/bin/pdksh" >> ${BOOTSTRAP_MKCONF}
908 echo "TOOLS_PLATFORM.ksh?= $prefix/bin/pdksh" >> ${TARGET_MKCONF}
909 echo "TOOLS_PLATFORM.ksh?= $wrkdir/bin/pdksh" >> ${BOOTSTRAP_MKCONF}
910 # Now rebootstrap bmake for ksh
911 echo_msg "Rebootstrapping bmake for ksh"
912 bmakexargs="$bmakexargs --with-defshell=$wrkdir/bin/pdksh"
917 # bootstrap awk if necessary
919 yes) echo_msg "Bootstrapping awk"
920 copy_src $pkgsrcdir/lang/nawk/files awk
921 test -n "$CC" || CC=gcc # default to gcc if no compiler is specified
922 run_cmd "(cd $wrkdir/awk && $bmake -f Makefile CC=\"${CC}\" CFLAGS=\"${CFLAGS}\")"
923 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/awk/a.out $wrkdir/bin/nawk"
924 echo "TOOLS_PLATFORM.awk?= $prefix/bin/nawk" >> ${TARGET_MKCONF}
925 echo "TOOLS_PLATFORM.awk?= $wrkdir/bin/nawk" >> ${BOOTSTRAP_MKCONF}
929 # bootstrap sed if necessary
931 yes) echo_msg "Bootstrapping sed"
932 copy_src $pkgsrcdir/textproc/nbsed/files sed
933 run_cmd "(cd $wrkdir/sed; env $BSTRAP_ENV CPPFLAGS='$CPPFLAGS -I../libnbcompat' LDFLAGS='$LDFLAGS -L../libnbcompat' LIBS='-lnbcompat' $shprog ./configure $configure_quiet_flags -C --prefix=$prefix --mandir=$mandir --sysconfdir=$sysconfdir --program-transform-name='s,sed,nbsed,' && $bmake)"
934 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/sed/sed $wrkdir/bin/sed"
935 echo "TOOLS_PLATFORM.sed?= $prefix/bin/nbsed" >> ${TARGET_MKCONF}
936 echo "TOOLS_PLATFORM.sed?= $wrkdir/bin/sed" >> ${BOOTSTRAP_MKCONF}
940 # bootstrap pkg_install
941 echo_msg "Bootstrapping pkgtools"
942 copy_src $pkgsrcdir/pkgtools/pkg_install/files pkg_install
943 run_cmd "(cd $wrkdir/pkg_install; env $BSTRAP_ENV \
944 CPPFLAGS='$CPPFLAGS -I../libnbcompat -I../../libnbcompat' \
945 LDFLAGS='$LDFLAGS -L../libnbcompat -L../../libnbcompat' \
946 LIBS='-lnbcompat' $shprog ./configure $configure_quiet_flags -C \
947 --enable-bootstrap --prefix=$prefix --sysconfdir=$sysconfdir \
948 --with-pkgdbdir=$pkgdbdir --mandir=$mandir $pkg_install_args && $bmake)"
949 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/pkg_install/admin/pkg_admin $wrkdir/sbin/pkg_admin"
950 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/pkg_install/create/pkg_create $wrkdir/sbin/pkg_create"
951 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/pkg_install/info/pkg_info $wrkdir/sbin/pkg_info"
952 echo "PKG_ADMIN_CMD?= $wrkdir/sbin/pkg_admin" >> ${BOOTSTRAP_MKCONF}
953 echo "PKG_CREATE_CMD?= $wrkdir/sbin/pkg_create" >> ${BOOTSTRAP_MKCONF}
954 echo "PKG_INFO_CMD?= $wrkdir/sbin/pkg_info" >> ${BOOTSTRAP_MKCONF}
956 if [ -n "${fetch_cmd}" ]; then
957 echo "FETCH_CMD= $fetch_cmd" >> ${TARGET_MKCONF}
960 MAKECONF=$wrkdir/mk.conf
963 if [ "$bootstrap_sh_set" = "set" ]; then
964 echo "TOOLS_PLATFORM.sh?= ${bootstrap_sh}" >> ${TARGET_MKCONF}
965 echo "TOOLS_PLATFORM.sh?= ${bootstrap_sh}" >> ${BOOTSTRAP_MKCONF}
968 # preserve compiler and tool environment variables settings
969 if test -n "$CP"; then
970 echo "TOOLS_PLATFORM.cp?= $CP" >> ${TARGET_MKCONF}
971 echo "TOOLS_PLATFORM.cp?= $CP" >> ${BOOTSTRAP_MKCONF}
973 if test -n "$GREP"; then
974 echo "TOOLS_PLATFORM.grep?= $GREP" >> ${TARGET_MKCONF}
975 echo "TOOLS_PLATFORM.grep?= $GREP" >> ${BOOTSTRAP_MKCONF}
977 if test -n "$ID"; then
978 echo "TOOLS_PLATFORM.id?= $ID" >> ${TARGET_MKCONF}
979 echo "TOOLS_PLATFORM.id?= $ID" >> ${BOOTSTRAP_MKCONF}
981 if test -n "$MKDIR"; then
982 echo "TOOLS_PLATFORM.mkdir?= $MKDIR" >> ${TARGET_MKCONF}
983 echo "TOOLS_PLATFORM.mkdir?= $MKDIR" >> ${BOOTSTRAP_MKCONF}
985 if test -n "$TEST"; then
986 echo "TOOLS_PLATFORM.test?= $TEST" >> ${TARGET_MKCONF}
987 echo "TOOLS_PLATFORM.test?= $TEST" >> ${BOOTSTRAP_MKCONF}
989 if test -n "$TOUCH"; then
990 echo "TOOLS_PLATFORM.touch?= $TOUCH" >> ${TARGET_MKCONF}
991 echo "TOOLS_PLATFORM.touch?= $TOUCH" >> ${BOOTSTRAP_MKCONF}
993 if test -n "$XARGS"; then
994 echo "TOOLS_PLATFORM.xargs?= $XARGS" >> ${TARGET_MKCONF}
995 echo "TOOLS_PLATFORM.xargs?= $XARGS" >> ${BOOTSTRAP_MKCONF}
997 if test -n "$CFLAGS"; then
998 echo "CFLAGS+= $CFLAGS" >> ${TARGET_MKCONF}
999 echo "DBG= # prevent DBG from adding default optimizer flags" >> ${TARGET_MKCONF}
1000 echo "DBG= # prevent DBG from adding default optimizer flags" >> ${BOOTSTRAP_MKCONF}
1002 if test -n "$CPPFLAGS"; then
1003 echo "CPPFLAGS+= $CPPFLAGS" >> ${TARGET_MKCONF}
1005 if test -n "$LDFLAGS"; then
1006 echo "LDFLAGS+= $LDFLAGS" >> ${TARGET_MKCONF}
1009 # opsys specific fiddling
1012 echo "WRKOBJDIR= ${wrkdir}/wrk" >> ${BOOTSTRAP_MKCONF}
1014 echo "" >> ${TARGET_MKCONF}
1015 echo "" >> ${BOOTSTRAP_MKCONF}
1016 if test -n "${mk_fragment}"; then
1017 cat "${mk_fragment}" >> ${TARGET_MKCONF}
1018 echo "" >> ${TARGET_MKCONF}
1020 echo ".endif # end pkgsrc settings" >> ${TARGET_MKCONF}
1021 echo ".endif # end pkgsrc settings" >> ${BOOTSTRAP_MKCONF}
1024 # usage: register_package <packagedirectory> [additional arguments]
1026 run_cmd "(cd $pkgsrcdir/$1 && $bmake -DPKG_PRESERVE MAKECONF=${BOOTSTRAP_MKCONF} install)"
1030 # Please make sure that the following packages and
1031 # only the following packages set BOOTSTRAP_PKG=yes.
1033 echo_msg "Installing packages"
1034 build_package "pkgtools/bootstrap-mk-files"
1035 case "$need_bsd_install" in
1036 yes) build_package "sysutils/install-sh";;
1039 yes) build_package "shells/pdksh";;
1041 build_package "devel/bmake"
1043 yes) build_package "lang/nawk";;
1046 yes) build_package "textproc/nbsed";;
1048 case "$need_extras" in
1049 yes) build_package "pkgtools/bootstrap-extras";;
1051 build_package "pkgtools/pkg_install"
1053 etc_mk_conf="$sysconfdir/mk.conf"
1055 # Install the example mk.conf so that it is used, but only if it doesn't
1056 # exist yet. This can happen with non-default sysconfdir settings.
1057 mkdir_p "$sysconfdir"
1058 if [ ! -f "$etc_mk_conf" ]; then
1059 cp "$TARGET_MKCONF" "$etc_mk_conf"
1060 TARGET_MKCONF="$etc_mk_conf"
1063 hline="==========================================================================="
1067 echo "Please remember to add $prefix/bin to your PATH environment variable"
1068 echo "and $mandir to your MANPATH environment variable, if necessary."
1070 echo "An example mk.conf file with the settings you provided to \"bootstrap\""
1071 echo "has been created for you. It can be found in:"
1073 echo " ${TARGET_MKCONF}"
1075 if [ "$TARGET_MKCONF" != "$etc_mk_conf" ]; then
1076 echo "Please copy it to $etc_mk_conf to use it."
1079 echo "You can find extensive documentation of the NetBSD Packages Collection"
1080 echo "in $pkgsrcdir/doc/pkgsrc.txt."
1082 echo "Hopefully everything is now complete."
1088 [ ! -z "${binary_kit}" ] && mkbinarykit_tar
1089 [ ! -z "${binary_gzip_kit}" ] && mkbinarykit_tgz
1090 [ ! -z "${binary_macpkg}" ] && mkbinarykit_macpkg
1092 echo_msg "bootstrap started: $build_start"
1093 echo_msg "bootstrap ended: `date`"