3 # $NetBSD: bootstrap,v 1.179 2012/07/24 13:18:00 jperkin Exp $
5 # Copyright (c) 2001-2011 Alistair Crooks <agc@NetBSD.org>
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.
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 # the following environment variables are honored:
31 # compiler/linker flags: CFLAGS, CPPFLAGS, LDFLAGS, LIBS
32 # tools: CP, GREP, ID, MKDIR, SH, TEST, TOUCH, XARGS
35 BOOTSTRAP_VERSION=20060721
37 # Don't let the bootstrap program get confused by a pre-existing mk.conf
42 # No vulnerability checks since there might be an incompatible checker installed
43 NO_PKGTOOLS_REQD_CHECK=yes
44 export NO_PKGTOOLS_REQD_CHECK
50 # where the building takes place
51 bootstrapdir=`dirname "$0"`
52 bootstrapdir=`cd "${bootstrapdir}" && pwd`
53 pkgsrcdir=`dirname "${bootstrapdir}"`
58 [ --binary-kit <tarball> ]
59 [ --binary-macpkg <pkg> ]
60 [ --compiler <compiler> ]
62 [ --gzip-binary-kit <tarball> ]
64 [ --mk-fragment <mk.conf> ]
65 [ --pkgdbdir <pkgdbdir> ]
66 [ --pkgmandir <pkgmandir> ]
67 [ --prefer-pkgsrc <list|yes|no> ]
71 [ --sysconfdir <sysconfdir> ]
72 [ --unprivileged | --ignore-user-check ]
73 [ --varbase <varbase> ]
74 [ --workdir <workdir> ]
77 # this replicates some of the logic in bsd.prefs.mk. until
78 # bootstrap-pkgsrc is merged into pkgsrc, we need to determine the
79 # right value for OPSYS and MACHINE_ARCH.
81 # strip / for BSD/OS, strip - for HP-UX
82 opsys=`uname -s | tr -d /-`
87 macdestdir=${wrkdir}/macpkg-destdir
88 rm -rf ${macdestdir} || die "cleanup destdir"
90 mkdir -p ${macdestdir}${prefix} || die "mkdir destprefix"
91 rmdir ${macdestdir}${prefix} || die "rmdir destprefix"
92 cp -Rp ${prefix} ${macdestdir}${prefix} || die "copy prefix"
94 if [ ! -d ${macdestdir}${pkgdbdir} ]; then
95 mkdir -p ${macdestdir}${pkgdbdir} || die "mkdir destdbdir"
96 rmdir ${macdestdir}${pkgdbdir} || die "rmdir destdbdir"
97 cp -Rp ${pkgdbdir} ${macdestdir}${pkgdbdir} || die "copy dbdir"
100 ${sedprog} -e "s|%WRKDIR%|${wrkdir}|g" \
101 -e "s|%TARGETDIR%|${targetdir}|g" -e "s|%DATE%|${date}|g" \
102 < macpkg.pmproj.in > ${wrkdir}/macpkg.pmproj
103 ${packagemaker} -build -proj ${wrkdir}/macpkg.pmproj -p "${binary_macpkg}"
108 # in case tar was built by bootstrap
109 PATH="$prefix/bin:$PATH"; export PATH
110 cd / && tar -hcf "${binary_kit}" .$prefix .$pkgdbdir .$etc_mk_conf
115 # in case tar was built by bootstrap
116 PATH="$prefix/bin:$PATH"; export PATH
117 cd / && tar -hcf - .$prefix .$pkgdbdir .$etc_mk_conf | gzip > "${binary_gzip_kit}"
131 # see if we're using gcc. If so, set $compiler_is_gnu to '1'.
135 # normally, we'd just use 'cc', but certain configure tools look
136 # for gcc specifically, so we have to see if that comes first
137 if [ -z "${testcc}" ]; then
140 for dir in ${PATH}; do
141 test -z "$dir" && dir=.
142 if [ -x "$dir/gcc" ]; then
150 cat >${wrkdir}/$$.c <<EOF
155 compiler_is_gnu=`${testcc:-cc} -E ${wrkdir}/$$.c 2>/dev/null | grep -c indeed`
163 if [ -n "$abi" ]; then
164 die "ERROR: $abi_opsys has special ABI handling, --abi not supported (yet)."
169 if [ `uname -r` -ge 6 ]; then
170 abi=`sed -e 's/.*\(abi=\)\([on]*[36][24]\).*/\2/' /etc/compiler.defaults`
171 isa=`sed -e 's/.*\(isa=mips\)\([1234]\).*/\2/' /etc/compiler.defaults`
174 imakeopts="-DBuildO32 -DSgiISAo32=$isa"
177 n32) imakeopts="-DBuildN32 -DSgiISA32=$isa"
181 imakeopts="-DBuild64bit -DSgiISA64=$isa"
192 get_machine_arch_aix()
194 _cpuid=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
195 if /usr/sbin/lsattr -El $_cpuid | grep ' POWER' >/dev/null 2>&1; then
204 _var="$1"; _name="$2"
206 eval _tmp=\"\$$_var\"
207 if [ "x$_tmp" != "x" ]; then
208 # Variable is already set (by the user, for example)
212 for _d in `echo $PATH | tr ':' ' '`; do
213 if [ -f "$_d/$_name" ] && [ -x "$_d/$_name" ]; then
215 eval $_var=\""$_d/$_name"\"
220 die "$_name not found in path."
227 if [ -n "$imakeopts" ]; then
228 echo "IMAKEOPTS+= $imakeopts" >> ${TARGET_MKCONF}
230 if [ `uname -r` -lt 6 ]; then
231 echo_msg "Installing fake ldd script"
232 run_cmd "$install_sh -c -o $user -g $group -m 755 $pkgsrcdir/pkgtools/bootstrap-extras/files/fakeldd $prefix/sbin"
234 echo "LDD= $prefix/sbin/fakeldd" >> ${TARGET_MKCONF}
239 echo "LDD= $prefix/sbin/fakeldd" >> ${TARGET_MKCONF}
246 if [ `uname -s` = "IRIX" ]; then
247 if [ `uname -r` -lt 6 -a -z "$ID" ]; then
248 # older version of IRIX have an id command with limited features
249 if [ "`$idprog`" != "uid=0(root) gid=0(sys)" ]; then
255 if [ `$idprog -u` != 0 ]; then
261 # run a command, abort if it fails
264 echo_msg "running: $@"
267 if [ $ret -ne 0 ]; then
268 echo_msg "exited with status $ret"
273 # Some versions of mkdir (notably SunOS) bail out too easily, so use the
274 # install-sh wrapper instead.
278 run_cmd "$install_sh -d -o $user -g $group $dir"
284 [ -d "$1" ] && return 0
285 mkdir -p "$1" 2> /dev/null && return 0
286 parent=`dirname "$1"`
287 mkdir_p_early "$parent"
288 if [ ! -d "$1" ] && mkdir "$1"; then
289 echo_msg "mkdir $1 exited with status $?"
298 if [ ! -d $wrkdir/$_dst ]; then
299 mkdir_p $wrkdir/$_dst
301 $cpprog -r $_src/* $wrkdir/$_dst
306 expr "x$1" : "x[^=]*=\\(.*\\)"
309 checkarg_sane_absolute_path() {
311 "") ;; # the default value will be used.
313 die "ERROR: Invalid characters in path $1 (from $2)." ;;
314 */) die "ERROR: The argument to $2 must not end in /." ;;
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 case "$bootstrap_sh" in
337 echo "ERROR: The variable SH must contain an absolute path" 1>&2
342 # On some newer Ubuntu installations, /bin/sh is a symlink to /bin/dash,
343 # whose echo(1) is not BSD-compatible.
344 dash_echo_test=`$bootstrap_sh -c 'echo "\\100"'`
345 if [ "$dash_echo_test" = "@" ]; then
346 { echo "ERROR: Your shell's echo command is not BSD-compatible."
347 echo "ERROR: Please select another shell by setting the environment"
348 echo "ERROR: variable SH."
353 if [ -n "$PKG_PATH" ]; then
354 echo "ERROR: Please unset PKG_PATH before running bootstrap." 1>&2
359 echo_msg "bootstrap command: $0 $@"
360 echo_msg "bootstrap started: $build_start"
362 # ensure system locations are empty; we will set them later when we know
363 # whether they will be system wide or user specific
375 while [ $# -gt 0 ]; do
377 --workdir=*) wrkdir=`get_optarg "$1"` ;;
378 --workdir) wrkdir="$2"; shift ;;
379 --prefix=*) prefix=`get_optarg "$1"` ;;
380 --prefix) prefix="$2"; shift ;;
381 --pkgdbdir=*) pkgdbdir=`get_optarg "$1"` ;;
382 --pkgdbdir) pkgdbdir="$2"; shift ;;
383 --pkgmandir=*) pkgmandir=`get_optarg "$1"` ;;
384 --pkgmandir) pkgmandir="$2"; shift ;;
385 --sysconfdir=*) sysconfdir=`get_optarg "$1"` ;;
386 --sysconfdir) sysconfdir="$2"; shift ;;
387 --varbase=*) varbase=`get_optarg "$1"` ;;
388 --varbase) varbase="$2"; shift ;;
389 --compiler=*) compiler=`get_optarg "$1"` ;;
390 --compiler) compiler="$2"; shift ;;
391 --abi=*) abi=`get_optarg "$1"` ;;
392 --abi) abi="$2"; shift ;;
393 --unprivileged | --ignore-user-check) unprivileged=yes ;;
395 prefer_pkgsrc=`get_optarg "$1"` ;;
397 prefer_pkgsrc="$2"; shift ;;
398 --preserve-path) preserve_path=yes ;;
400 mk_fragment=`get_optarg "$1"` ;;
402 mk_fragment="$2"; shift ;;
404 binary_kit=`get_optarg "$1"` ;;
406 binary_kit="$2"; shift ;;
408 binary_gzip_kit=`get_optarg "$1"` ;;
410 binary_gzip_kit="$2"; shift ;;
412 binary_macpkg=`get_optarg "$1"` ;;
414 binary_macpkg="$2"; shift ;;
416 --quiet) quiet=yes ;;
417 --help) echo "$usage"; exit ;;
418 -h) echo "$usage"; exit ;;
419 --*) echo "$usage"; exit 1 ;;
424 checkarg_sane_absolute_path "$wrkdir" "--workdir"
425 checkarg_sane_absolute_path "$prefix" "--prefix"
426 checkarg_sane_absolute_path "$pkgdbdir" "--pkgdbdir"
427 checkarg_sane_absolute_path "$sysconfdir" "--sysconfdir"
428 checkarg_sane_absolute_path "$varbase" "--varbase"
429 checkarg_sane_relative_path "$pkgmandir" "--pkgmandir"
431 # set defaults for system locations if not already set by the user
432 wrkobjdir=${wrkdir}/pkgsrc
433 if [ "$unprivileged" = "yes" ]; then
434 [ -z "$prefix" ] && prefix=${HOME}/pkg
435 elif [ -z "$prefix" -o "$prefix" = "/usr/pkg" ]; then
437 [ -z "$varbase" ] && varbase=/var
440 [ -z "$varbase" ] && varbase=${prefix}/var
441 [ -z "$pkgdbdir" ] && pkgdbdir=${varbase}/db/pkg
443 if [ "$prefix" = "/usr" ]; then
444 [ -z "$pkgmandir" ] && pkgmandir=share/man
446 [ -z "$pkgmandir" ] && pkgmandir=man
448 mandir=${prefix}/${pkgmandir}
449 [ -z "$sysconfdir" ] && sysconfdir=${prefix}/etc
451 if [ "x$preserve_path" != "xyes" ]; then
452 PATH="$PATH:/sbin:/usr/sbin"
468 machine_arch=`get_machine_arch_aix`
476 machine_arch=`uname -p`
477 CC=${CC:-"gcc -isystem /usr/include"}; export CC
479 macosx_version=`echo $osrev | awk -F . '{ print "10."$1-4; }'`
480 case "$macosx_version" in
482 packagemaker=/Developer/Tools/packagemaker
485 packagemaker=/Developer/usr/bin/packagemaker
488 unset osrev macosx_version
496 check_prog tarprog tar
497 machine_arch=`uname -p`
505 machine_arch=`uname -p`
522 machine_arch=`uname -p`
532 machine_arch=`uname -m | sed 's/^9000.*$/hppa/'`
536 if id -G | grep -q 131616; then
542 mkdir -p "$@" # allows umask to take effect
544 default_install_mode=0775
563 # only used for unprivileged builds
565 # for bootstrap only; pkgsrc uses CPPFLAGS
566 CC="gcc -D_ALL_SOURCE"; export CC
567 ac_cv_header_poll_h=no; export ac_cv_header_poll_h
568 ac_cv_func_poll=no; export ac_cv_func_poll
571 if [ -d "/usr/freeware/bin" ]; then
572 overpath="/usr/freeware/bin:$overpath"
574 if [ -d "/usr/bsd" ]; then
575 overpath="/usr/bsd:$overpath"
577 if [ -d "/usr/bsd/bin" ]; then
578 overpath="/usr/bsd/bin:$overpath"
588 bmakexargs="MACHINE_ARCH=$machine_arch"
589 bmakexenv="MAKE=pmake"
591 if [ `uname -r` -lt 6 ]; then
592 # IRIX 5's mkdir bails out with an error when trying to create with the -p
593 # option an already existing directory
598 if [ -f /etc/ssdlinux_version ]; then
607 machine_arch=`uname -m | sed -e 's/i.86/i386/'`
617 check_prog mtreeprog mtree
618 machine_arch=`arch -s`
619 # there is no /usr/bin/cc, so use mgcc if unset
620 test -n "$CC" || { CC=mgcc; export CC; }
621 # get some variables from the native make if unset
622 for var in CFLAGS CPPFLAGS LDFLAGS; do
623 # check if variable is already set
625 [ "x$_tmp" != x ] && continue
626 # ask the native make (EXPERIMENTAL = don't add -Werror)
627 # the -I${.CURDIR} dance is to prevent junk in CPPFLAGS
628 _tmp=`printf '%s\nall:\n\t@%s %%s %s=${%s:M*:Q:Q}\n%s\n%s\n' \
629 $var'+=-I${.CURDIR}' printf $var $var':S/-I${.CURDIR}//' \
630 EXPERIMENTAL=yes '.include <bsd.prog.mk>' | \
631 (unset MAKECONF; /usr/bin/make -f - all 2>/dev/null) | \
643 machine_arch=`uname -p`
651 machine_arch=`uname -m`
669 machine_arch=`uname -p | sed -e 's/x86/i386/'`
674 if [ -x "/usr/gnu/bin/awk" ]; then
679 if [ -x "/usr/gnu/bin/sed" ]; then
684 if [ "`uname -r`" = "5.11" ]; then
687 bootstrap_sh=${SH:-/usr/bin/bash}
691 bootstrap_sh=${SH:-/bin/ksh}
699 idprog="/usr/xpg4/bin/id"
700 groupsprog="${idprog} -gn"
701 whoamiprog="${idprog} -un"
702 machine_arch=`uname -p | sed -e 's/i86pc/i386/'`
708 BSTRAP_ENV="INSTALL=/usr/ucb/install $BSTRAP_ENV"
712 whoamiprog=/usr/ucb/whoami
714 CC="gcc -DUNIXWARE"; export CC
717 echo "This platform ($opsys) is untried - good luck, and thanks for using pkgsrc"
726 # If "--full" is specified, then install all of the platform-independent
727 # bootstrap software.
740 configure_quiet_flags="--quiet"
741 make_quiet_flags="-s"
744 configure_quiet_flags=""
748 # export OPSYS and MACHINE_ARCH for pkg_install. we only set
749 # MACHINE_ARCH on platforms where we override bmake's value.
752 if [ "${machine_arch}" != "" ]; then
753 MACHINE_ARCH=${machine_arch}
757 if [ "x$preserve_path" != "xyes" ]; then
758 PATH="$overpath:$PATH"
761 check_prog awkprog awk
762 check_prog chmodprog chmod
763 if [ -n "$CP" ]; then
768 if [ -n "$ID" ]; then
773 check_prog groupsprog groups
776 check_prog rmdirprog rmdir
777 check_prog sedprog sed
779 check_prog whoamiprog whoami
781 if [ -d "${wrkdir}" ] || [ -f "${wrkdir}" ]; then
782 echo "\"${wrkdir}\" already exists, please remove it or use --workdir.";
786 mkdir_p_early ${wrkdir}
787 if touch ${wrkdir}/.writeable; then
790 echo "\"${wrkdir}\" is not writeable. Try $0 -h.";
793 echo "Working directory is: ${wrkdir}"
795 if [ "$compiler" = "" ] && [ x"$check_compiler" = x"yes" ]; then
797 if [ $compiler_is_gnu -gt 0 ]; then
802 if [ `uname -r` -ge 6 ]; then
807 test -n "$CC" || CC=cc
809 SunOS) compiler="sunpro"
810 test -n "$CC" || CC=cc
816 mkdir_p_early ${wrkdir}/bin
819 run_cmd "$sedprog -e 's|@DEFAULT_INSTALL_MODE@|'${default_install_mode-0755}'|' $pkgsrcdir/sysutils/install-sh/files/install-sh.in > $wrkdir/bin/install-sh"
820 run_cmd "$chmodprog +x $wrkdir/bin/install-sh"
821 install_sh="$shprog $wrkdir/bin/install-sh"
828 if [ $unprivileged = "no" ]; then
829 die "You must be either root to install bootstrap-pkgsrc or use the --unprivileged option."
833 group=`$groupsprog | $awkprog '{print $1}'`
834 echo_msg "building as unprivileged user $user/$group"
836 # force bmake install target to use $user and $group
842 MANGRP=$group" > ${wrkdir}/Makefile.inc
845 # export the proper environment
846 PATH=$prefix/bin:$prefix/sbin:${PATH}; export PATH
847 if [ -d /usr/ccs/bin -a -x /usr/ccs/bin/make ]; then
848 PATH=${PATH}:/usr/ccs/bin; export PATH
850 PKG_DBDIR=$pkgdbdir; export PKG_DBDIR
851 LOCALBASE=$prefix; export LOCALBASE
852 VARBASE=$varbase; export VARBASE
854 # set up an example mk.conf file
855 TARGET_MKCONF=${wrkdir}/mk.conf.example
856 echo_msg "Creating default mk.conf in ${wrkdir}"
857 echo "# Example ${sysconfdir}/mk.conf file produced by bootstrap-pkgsrc" > ${TARGET_MKCONF}
858 echo "# `date`" >> ${TARGET_MKCONF}
859 echo "" >> ${TARGET_MKCONF}
860 echo ".ifdef BSD_PKG_MK # begin pkgsrc settings" >> ${TARGET_MKCONF}
861 echo "" >> ${TARGET_MKCONF}
863 # IRIX64 needs to be set to IRIX, for example
864 if [ "$set_opsys" = "yes" ]; then
865 echo "OPSYS= $opsys" >> ${TARGET_MKCONF}
868 if [ -n "$abi" ]; then
869 echo "ABI= $abi" >> ${TARGET_MKCONF}
871 if [ "$compiler" != "" ]; then
872 echo "PKGSRC_COMPILER= $compiler" >> ${TARGET_MKCONF}
876 echo "CC= cc" >> ${TARGET_MKCONF}
877 echo "CXX= CC" >> ${TARGET_MKCONF}
878 echo "CPP= \${CC} -E" >> ${TARGET_MKCONF}
881 if [ -n "$GCCBASE" ]; then
882 echo "GCCBASE= $GCCBASE" >> ${TARGET_MKCONF}
884 if [ -n "$SUNWSPROBASE" ]; then
885 echo "SUNWSPROBASE= $SUNWSPROBASE" >> ${TARGET_MKCONF}
887 echo "" >> ${TARGET_MKCONF}
889 # enable unprivileged builds if not root
890 if [ "$unprivileged" = "yes" ]; then
891 echo "UNPRIVILEGED= yes" >> ${TARGET_MKCONF}
894 # save environment in example mk.conf
895 echo "PKG_DBDIR= $pkgdbdir" >> ${TARGET_MKCONF}
896 echo "LOCALBASE= $prefix" >> ${TARGET_MKCONF}
897 echo "VARBASE= $varbase" >> ${TARGET_MKCONF}
898 if [ "${sysconfdir}" != "${prefix}/etc" ]; then
899 echo "PKG_SYSCONFBASE= $sysconfdir" >> ${TARGET_MKCONF}
901 echo "PKG_TOOLS_BIN= $prefix/sbin" >> ${TARGET_MKCONF}
902 echo "PKGMANDIR= $pkgmandir" >> ${TARGET_MKCONF}
903 echo "" >> ${TARGET_MKCONF}
905 if [ -n "$prefer_pkgsrc" ]; then
906 echo "PREFER_PKGSRC= $prefer_pkgsrc" >> ${TARGET_MKCONF}
907 echo "" >> ${TARGET_MKCONF}
910 BOOTSTRAP_MKCONF=${wrkdir}/mk.conf
911 cp ${TARGET_MKCONF} ${BOOTSTRAP_MKCONF}
913 # sbin is used by pkg_install, share/mk by bootstrap-mk-files
914 mkdir_p $wrkdir/sbin $wrkdir/share/mk
915 mkdir_p_early ${wrkdir}
917 if [ "$need_bsd_install" = "yes" ]; then
918 BSTRAP_ENV="INSTALL='$prefix/bin/install-sh -c' $BSTRAP_ENV"
919 echo "TOOLS_PLATFORM.install?= $prefix/bin/install-sh" >> ${TARGET_MKCONF}
920 echo "TOOLS_PLATFORM.install?= $wrkdir/bin/install-sh" >> ${BOOTSTRAP_MKCONF}
923 if [ "$need_fixed_strip" = "yes" ] ; then
924 echo_msg "Installing fixed strip script"
925 run_cmd "$install_sh -c -o $user -g $group -m 755 $pkgsrcdir/pkgtools/bootstrap-extras/files/strip-sh $wrkdir/bin/strip"
926 echo "TOOLS_PLATFORM.strip?= $prefix/bin/strip" >> ${TARGET_MKCONF}
927 echo "TOOLS_PLATFORM.strip?= $wrkdir/bin/strip" >> ${BOOTSTRAP_MKCONF}
931 if [ "$need_mkdir" = "yes" -a -z "$MKDIR" ]; then
932 echo_msg "Installing fixed mkdir script \"mkdir-sh\""
933 run_cmd "$install_sh -c -o $user -g $group -m 755 $pkgsrcdir/pkgtools/bootstrap-extras/files/mkdir-sh $wrkdir/bin/mkdir-sh"
934 echo "TOOLS_PLATFORM.mkdir?= $prefix/bin/mkdir-sh -p" >> ${TARGET_MKCONF}
935 echo "TOOLS_PLATFORM.mkdir?= $wrkdir/bin/mkdir-sh -p" >> ${BOOTSTRAP_MKCONF}
939 if [ "$need_xargs" = "yes" ]; then
940 echo_msg "Installing fixed xargs script"
941 run_cmd "$install_sh -c -o $user -g $group -m 755 $pkgsrcdir/pkgtools/bootstrap-extras/files/xargs-sh $wrkdir/bin/xargs"
942 echo "TOOLS_PLATFORM.xargs?= $prefix/bin/xargs" >> ${TARGET_MKCONF}
943 echo "TOOLS_PLATFORM.xargs?= $wrkdir/bin/xargs" >> ${BOOTSTRAP_MKCONF}
947 echo_msg "Bootstrapping mk-files"
948 run_cmd "(cd ${pkgsrcdir}/pkgtools/bootstrap-mk-files/files && env CP=${cpprog} \
949 OPSYS=${opsys} MK_DST=${wrkdir}/share/mk ROOT_GROUP=${root_group} \
950 ROOT_USER=${root_user} SED=${sedprog} SYSCONFDIR=${sysconfdir} \
951 $shprog ./bootstrap.sh)"
954 echo_msg "Bootstrapping bmake"
955 copy_src $pkgsrcdir/devel/bmake/files bmake
956 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)"
957 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/bmake/$opsys/bmake $wrkdir/bin/bmake"
961 bmake="$wrkdir/bin/bmake $make_quiet_flags"
964 echo_msg "Building libnbcompat"
965 copy_src $pkgsrcdir/pkgtools/libnbcompat/files libnbcompat
966 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)"
968 # bootstrap ksh if necessary
970 yes) echo_msg "Bootstrapping ksh"
971 copy_src $pkgsrcdir/shells/pdksh/files ksh
972 test -n "$CC" || CC=gcc # default to gcc if no compiler is specified
973 run_cmd "(cd $wrkdir/ksh && env $BSTRAP_ENV $shprog ./configure $configure_quiet_flags --prefix=$prefix --mandir=$mandir --sysconfdir=$sysconfdir && $bmake)"
974 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/ksh/ksh $wrkdir/bin/pdksh"
975 echo "TOOLS_PLATFORM.sh?= $prefix/bin/pdksh" >> ${TARGET_MKCONF}
976 echo "TOOLS_PLATFORM.sh?= $wrkdir/bin/pdksh" >> ${BOOTSTRAP_MKCONF}
977 echo "TOOLS_PLATFORM.ksh?= $prefix/bin/pdksh" >> ${TARGET_MKCONF}
978 echo "TOOLS_PLATFORM.ksh?= $wrkdir/bin/pdksh" >> ${BOOTSTRAP_MKCONF}
979 # Now rebootstrap bmake for ksh
980 echo_msg "Rebootstrapping bmake for ksh"
981 bmakexargs="$bmakexargs --with-defshell=$wrkdir/bin/pdksh"
986 # bootstrap awk if necessary
988 yes) echo_msg "Bootstrapping awk"
989 copy_src $pkgsrcdir/lang/nawk/files awk
990 test -n "$CC" || CC=gcc # default to gcc if no compiler is specified
991 run_cmd "(cd $wrkdir/awk && $bmake -f Makefile CC=\"${CC}\" CFLAGS=\"${CFLAGS}\")"
992 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/awk/a.out $wrkdir/bin/nawk"
993 echo "TOOLS_PLATFORM.awk?= $prefix/bin/nawk" >> ${TARGET_MKCONF}
994 echo "TOOLS_PLATFORM.awk?= $wrkdir/bin/nawk" >> ${BOOTSTRAP_MKCONF}
998 # bootstrap sed if necessary
1000 yes) echo_msg "Bootstrapping sed"
1001 copy_src $pkgsrcdir/textproc/nbsed/files sed
1002 run_cmd "(cd $wrkdir/sed; env $BSTRAP_ENV CPPFLAGS='$CPPFLAGS -I../libnbcompat' LDFLAGS='$LDFLAGS -L../libnbcompat' LIBS='$LIBS -lnbcompat' $shprog ./configure $configure_quiet_flags -C --prefix=$prefix --mandir=$mandir --sysconfdir=$sysconfdir --program-transform-name='s,sed,nbsed,' && $bmake)"
1003 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/sed/sed $wrkdir/bin/sed"
1004 echo "TOOLS_PLATFORM.sed?= $prefix/bin/nbsed" >> ${TARGET_MKCONF}
1005 echo "TOOLS_PLATFORM.sed?= $wrkdir/bin/sed" >> ${BOOTSTRAP_MKCONF}
1009 # bootstrap pkg_install
1010 echo_msg "Bootstrapping pkgtools"
1011 copy_src $pkgsrcdir/pkgtools/pkg_install/files pkg_install
1012 run_cmd "(cd $wrkdir/pkg_install; env $BSTRAP_ENV \
1013 CPPFLAGS='$CPPFLAGS -I../libnbcompat -I../../libnbcompat' \
1014 LDFLAGS='$LDFLAGS -L../libnbcompat -L../../libnbcompat' \
1015 LIBS='$LIBS -lnbcompat' $shprog ./configure $configure_quiet_flags -C \
1016 --enable-bootstrap --prefix=$prefix --sysconfdir=$sysconfdir \
1017 --with-pkgdbdir=$pkgdbdir --mandir=$mandir $pkg_install_args && $bmake)"
1018 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/pkg_install/admin/pkg_admin $wrkdir/sbin/pkg_admin"
1019 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/pkg_install/create/pkg_create $wrkdir/sbin/pkg_create"
1020 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/pkg_install/info/pkg_info $wrkdir/sbin/pkg_info"
1021 echo "PKG_ADMIN_CMD?= $wrkdir/sbin/pkg_admin" >> ${BOOTSTRAP_MKCONF}
1022 echo "PKG_CREATE_CMD?= $wrkdir/sbin/pkg_create" >> ${BOOTSTRAP_MKCONF}
1023 echo "PKG_INFO_CMD?= $wrkdir/sbin/pkg_info" >> ${BOOTSTRAP_MKCONF}
1025 MAKECONF=$wrkdir/mk.conf
1028 if [ "$bootstrap_sh_set" = "set" ]; then
1029 echo "TOOLS_PLATFORM.sh?= ${bootstrap_sh}" >> ${TARGET_MKCONF}
1030 echo "TOOLS_PLATFORM.sh?= ${bootstrap_sh}" >> ${BOOTSTRAP_MKCONF}
1033 # preserve compiler and tool environment variables settings
1034 if test -n "$CP"; then
1035 echo "TOOLS_PLATFORM.cp?= $CP" >> ${TARGET_MKCONF}
1036 echo "TOOLS_PLATFORM.cp?= $CP" >> ${BOOTSTRAP_MKCONF}
1038 if test -n "$GREP"; then
1039 echo "TOOLS_PLATFORM.grep?= $GREP" >> ${TARGET_MKCONF}
1040 echo "TOOLS_PLATFORM.grep?= $GREP" >> ${BOOTSTRAP_MKCONF}
1042 if test -n "$ID"; then
1043 echo "TOOLS_PLATFORM.id?= $ID" >> ${TARGET_MKCONF}
1044 echo "TOOLS_PLATFORM.id?= $ID" >> ${BOOTSTRAP_MKCONF}
1046 if test -n "$MKDIR"; then
1047 echo "TOOLS_PLATFORM.mkdir?= $MKDIR" >> ${TARGET_MKCONF}
1048 echo "TOOLS_PLATFORM.mkdir?= $MKDIR" >> ${BOOTSTRAP_MKCONF}
1050 if test -n "$TEST"; then
1051 echo "TOOLS_PLATFORM.test?= $TEST" >> ${TARGET_MKCONF}
1052 echo "TOOLS_PLATFORM.test?= $TEST" >> ${BOOTSTRAP_MKCONF}
1054 if test -n "$TOUCH"; then
1055 echo "TOOLS_PLATFORM.touch?= $TOUCH" >> ${TARGET_MKCONF}
1056 echo "TOOLS_PLATFORM.touch?= $TOUCH" >> ${BOOTSTRAP_MKCONF}
1058 if test -n "$XARGS"; then
1059 echo "TOOLS_PLATFORM.xargs?= $XARGS" >> ${TARGET_MKCONF}
1060 echo "TOOLS_PLATFORM.xargs?= $XARGS" >> ${BOOTSTRAP_MKCONF}
1062 if test -n "$CFLAGS"; then
1063 echo "CFLAGS+= $CFLAGS" >> ${TARGET_MKCONF}
1064 echo "DBG= # prevent DBG from adding default optimizer flags" >> ${TARGET_MKCONF}
1065 echo "DBG= # prevent DBG from adding default optimizer flags" >> ${BOOTSTRAP_MKCONF}
1067 if test -n "$CPPFLAGS"; then
1068 echo "CPPFLAGS+= $CPPFLAGS" >> ${TARGET_MKCONF}
1070 if test -n "$LDFLAGS"; then
1071 echo "LDFLAGS+= $LDFLAGS" >> ${TARGET_MKCONF}
1073 if test -n "$LIBS"; then
1074 echo "LIBS+= $LIBS" >> ${TARGET_MKCONF}
1077 # opsys specific fiddling
1080 echo "WRKOBJDIR= ${wrkdir}/wrk" >> ${BOOTSTRAP_MKCONF}
1082 echo "" >> ${TARGET_MKCONF}
1083 echo "" >> ${BOOTSTRAP_MKCONF}
1084 if test -n "${mk_fragment}"; then
1085 cat "${mk_fragment}" >> ${TARGET_MKCONF}
1086 echo "" >> ${TARGET_MKCONF}
1088 echo ".endif # end pkgsrc settings" >> ${TARGET_MKCONF}
1089 echo ".endif # end pkgsrc settings" >> ${BOOTSTRAP_MKCONF}
1092 # usage: register_package <packagedirectory> [additional arguments]
1094 run_cmd "(cd $pkgsrcdir/$1 && $bmake USE_DESTDIR=no -DPKG_PRESERVE MAKECONF=${BOOTSTRAP_MKCONF} install)"
1098 # Please make sure that the following packages and
1099 # only the following packages set BOOTSTRAP_PKG=yes.
1101 echo_msg "Installing packages"
1102 build_package "pkgtools/bootstrap-mk-files"
1103 case "$need_bsd_install" in
1104 yes) build_package "sysutils/install-sh";;
1107 yes) build_package "shells/pdksh";;
1109 build_package "devel/bmake"
1111 yes) build_package "lang/nawk";;
1114 yes) build_package "textproc/nbsed";;
1116 case "$need_extras" in
1117 yes) build_package "pkgtools/bootstrap-extras";;
1119 build_package "pkgtools/pkg_install"
1121 etc_mk_conf="$sysconfdir/mk.conf"
1123 # Install the example mk.conf so that it is used, but only if it doesn't
1124 # exist yet. This can happen with non-default sysconfdir settings.
1125 mkdir_p "$sysconfdir"
1126 if [ ! -f "$etc_mk_conf" ]; then
1127 cp "$TARGET_MKCONF" "$etc_mk_conf"
1128 TARGET_MKCONF="$etc_mk_conf"
1131 hline="==========================================================================="
1135 echo "Please remember to add $prefix/bin to your PATH environment variable"
1136 echo "and $mandir to your MANPATH environment variable, if necessary."
1138 echo "An example mk.conf file with the settings you provided to \"bootstrap\""
1139 echo "has been created for you. It can be found in:"
1141 echo " ${TARGET_MKCONF}"
1143 if [ "$TARGET_MKCONF" != "$etc_mk_conf" ]; then
1144 echo "Please copy it to $etc_mk_conf to use it."
1147 echo "You can find extensive documentation of the NetBSD Packages Collection"
1148 echo "in $pkgsrcdir/doc/pkgsrc.txt."
1150 echo "Hopefully everything is now complete."
1151 echo "Thank you for using pkgsrc!"
1156 [ -n "${binary_kit}" ] && mkbinarykit_tar
1157 [ -n "${binary_gzip_kit}" ] && mkbinarykit_tgz
1158 [ -n "${binary_macpkg}" ] && mkbinarykit_macpkg
1160 echo_msg "bootstrap started: $build_start"
1161 echo_msg "bootstrap ended: `date`"