3 # $NetBSD: bootstrap,v 1.176 2012/06/08 12:15:29 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> ]
70 [ --sysconfdir <sysconfdir> ]
71 [ --unprivileged | --ignore-user-check ]
72 [ --varbase <varbase> ]
73 [ --workdir <workdir> ]
76 # this replicates some of the logic in bsd.prefs.mk. until
77 # bootstrap-pkgsrc is merged into pkgsrc, we need to determine the
78 # right value for OPSYS and MACHINE_ARCH.
80 # strip / for BSD/OS, strip - for HP-UX
81 opsys=`uname -s | tr -d /-`
86 macdestdir=${wrkdir}/macpkg-destdir
87 rm -rf ${macdestdir} || die "cleanup destdir"
89 mkdir -p ${macdestdir}${prefix} || die "mkdir destprefix"
90 rmdir ${macdestdir}${prefix} || die "rmdir destprefix"
91 cp -Rp ${prefix} ${macdestdir}${prefix} || die "copy prefix"
93 if [ ! -d ${macdestdir}${pkgdbdir} ]; then
94 mkdir -p ${macdestdir}${pkgdbdir} || die "mkdir destdbdir"
95 rmdir ${macdestdir}${pkgdbdir} || die "rmdir destdbdir"
96 cp -Rp ${pkgdbdir} ${macdestdir}${pkgdbdir} || die "copy dbdir"
99 ${sedprog} -e "s|%WRKDIR%|${wrkdir}|g" \
100 -e "s|%TARGETDIR%|${targetdir}|g" -e "s|%DATE%|${date}|g" \
101 < macpkg.pmproj.in > ${wrkdir}/macpkg.pmproj
102 ${packagemaker} -build -proj ${wrkdir}/macpkg.pmproj -p "${binary_macpkg}"
107 # in case tar was built by bootstrap
108 PATH="$prefix/bin:$PATH"; export PATH
109 cd / && tar -hcf "${binary_kit}" .$prefix .$pkgdbdir .$etc_mk_conf
114 # in case tar was built by bootstrap
115 PATH="$prefix/bin:$PATH"; export PATH
116 cd / && tar -hcf - .$prefix .$pkgdbdir .$etc_mk_conf | gzip > "${binary_gzip_kit}"
130 # see if we're using gcc. If so, set $compiler_is_gnu to '1'.
134 # normally, we'd just use 'cc', but certain configure tools look
135 # for gcc specifically, so we have to see if that comes first
136 if [ -z "${testcc}" ]; then
139 for dir in ${PATH}; do
140 test -z "$dir" && dir=.
141 if [ -x "$dir/gcc" ]; then
149 cat >${wrkdir}/$$.c <<EOF
154 compiler_is_gnu=`${testcc:-cc} -E ${wrkdir}/$$.c 2>/dev/null | grep -c indeed`
162 if [ -n "$abi" ]; then
163 die "ERROR: $abi_opsys has special ABI handling, --abi not supported (yet)."
168 if [ `uname -r` -ge 6 ]; then
169 abi=`sed -e 's/.*\(abi=\)\([on]*[36][24]\).*/\2/' /etc/compiler.defaults`
170 isa=`sed -e 's/.*\(isa=mips\)\([1234]\).*/\2/' /etc/compiler.defaults`
173 imakeopts="-DBuildO32 -DSgiISAo32=$isa"
176 n32) imakeopts="-DBuildN32 -DSgiISA32=$isa"
180 imakeopts="-DBuild64bit -DSgiISA64=$isa"
191 get_machine_arch_aix()
193 _cpuid=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
194 if /usr/sbin/lsattr -El $_cpuid | grep ' POWER' >/dev/null 2>&1; then
203 _var="$1"; _name="$2"
205 eval _tmp=\"\$$_var\"
206 if [ "x$_tmp" != "x" ]; then
207 # Variable is already set (by the user, for example)
211 for _d in `echo $PATH | tr ':' ' '`; do
212 if [ -f "$_d/$_name" ] && [ -x "$_d/$_name" ]; then
214 eval $_var=\""$_d/$_name"\"
219 die "$_name not found in path."
226 if [ -n "$imakeopts" ]; then
227 echo "IMAKEOPTS+= $imakeopts" >> ${TARGET_MKCONF}
229 if [ `uname -r` -lt 6 ]; then
230 echo_msg "Installing fake ldd script"
231 run_cmd "$install_sh -c -o $user -g $group -m 755 $pkgsrcdir/pkgtools/bootstrap-extras/files/fakeldd $prefix/sbin"
233 echo "LDD= $prefix/sbin/fakeldd" >> ${TARGET_MKCONF}
238 echo "LDD= $prefix/sbin/fakeldd" >> ${TARGET_MKCONF}
245 if [ `uname -s` = "IRIX" ]; then
246 if [ `uname -r` -lt 6 -a -z "$ID" ]; then
247 # older version of IRIX have an id command with limited features
248 if [ "`$idprog`" != "uid=0(root) gid=0(sys)" ]; then
254 if [ `$idprog -u` != 0 ]; then
260 # run a command, abort if it fails
263 echo_msg "running: $@"
266 if [ $ret -ne 0 ]; then
267 echo_msg "exited with status $ret"
272 # Some versions of mkdir (notably SunOS) bail out too easily, so use the
273 # install-sh wrapper instead.
277 run_cmd "$install_sh -d -o $user -g $group $dir"
283 [ -d "$1" ] && return 0
284 mkdir -p "$1" 2> /dev/null && return 0
285 parent=`dirname "$1"`
286 mkdir_p_early "$parent"
287 if [ ! -d "$1" ] && mkdir "$1"; then
288 echo_msg "mkdir $1 exited with status $?"
297 if [ ! -d $wrkdir/$_dst ]; then
298 mkdir_p $wrkdir/$_dst
300 $cpprog -r $_src/* $wrkdir/$_dst
305 expr "x$1" : "x[^=]*=\\(.*\\)"
308 checkarg_sane_absolute_path() {
310 "") ;; # the default value will be used.
312 die "ERROR: Invalid characters in path $1 (from $2)." ;;
313 */) die "ERROR: The argument to $2 must not end in /." ;;
315 *) die "ERROR: The argument to $2 must be an absolute path." ;;
319 checkarg_sane_relative_path() {
321 "") ;; # the default value will be used.
323 die "ERROR: Invalid characters in path $1 (from $2)." ;;
324 /*) die "ERROR: The argument to $2 must be a relative path." ;;
329 bootstrap_sh=${SH-/bin/sh}
330 bootstrap_sh_set=${SH+set}
332 case "$bootstrap_sh" in
336 echo "ERROR: The variable SH must contain an absolute path" 1>&2
341 # On some newer Ubuntu installations, /bin/sh is a symlink to /bin/dash,
342 # whose echo(1) is not BSD-compatible.
343 dash_echo_test=`$bootstrap_sh -c 'echo "\\100"'`
344 if [ "$dash_echo_test" = "@" ]; then
345 { echo "ERROR: Your shell's echo command is not BSD-compatible."
346 echo "ERROR: Please select another shell by setting the environment"
347 echo "ERROR: variable SH."
352 if [ -n "$PKG_PATH" ]; then
353 echo "ERROR: Please unset PKG_PATH before running bootstrap." 1>&2
358 echo_msg "bootstrap command: $0 $@"
359 echo_msg "bootstrap started: $build_start"
361 # ensure system locations are empty; we will set them later when we know
362 # whether they will be system wide or user specific
374 while [ $# -gt 0 ]; do
376 --workdir=*) wrkdir=`get_optarg "$1"` ;;
377 --workdir) wrkdir="$2"; shift ;;
378 --prefix=*) prefix=`get_optarg "$1"` ;;
379 --prefix) prefix="$2"; shift ;;
380 --pkgdbdir=*) pkgdbdir=`get_optarg "$1"` ;;
381 --pkgdbdir) pkgdbdir="$2"; shift ;;
382 --pkgmandir=*) pkgmandir=`get_optarg "$1"` ;;
383 --pkgmandir) pkgmandir="$2"; shift ;;
384 --sysconfdir=*) sysconfdir=`get_optarg "$1"` ;;
385 --sysconfdir) sysconfdir="$2"; shift ;;
386 --varbase=*) varbase=`get_optarg "$1"` ;;
387 --varbase) varbase="$2"; shift ;;
388 --compiler=*) compiler=`get_optarg "$1"` ;;
389 --compiler) compiler="$2"; shift ;;
390 --abi=*) abi=`get_optarg "$1"` ;;
391 --abi) abi="$2"; shift ;;
392 --unprivileged | --ignore-user-check) unprivileged=yes ;;
393 --preserve-path) preserve_path=yes ;;
395 mk_fragment=`get_optarg "$1"` ;;
397 mk_fragment="$2"; shift ;;
400 binary_kit=`get_optarg "$1"` ;;
402 binary_kit="$2"; shift ;;
404 binary_gzip_kit=`get_optarg "$1"` ;;
406 binary_gzip_kit="$2"; shift ;;
408 binary_macpkg=`get_optarg "$1"` ;;
410 binary_macpkg="$2"; shift ;;
412 --quiet) quiet=yes ;;
413 --help) echo "$usage"; exit ;;
414 -h) echo "$usage"; exit ;;
415 --*) echo "$usage"; exit 1 ;;
420 checkarg_sane_absolute_path "$wrkdir" "--workdir"
421 checkarg_sane_absolute_path "$prefix" "--prefix"
422 checkarg_sane_absolute_path "$pkgdbdir" "--pkgdbdir"
423 checkarg_sane_absolute_path "$sysconfdir" "--sysconfdir"
424 checkarg_sane_absolute_path "$varbase" "--varbase"
425 checkarg_sane_relative_path "$pkgmandir" "--pkgmandir"
427 # set defaults for system locations if not already set by the user
428 wrkobjdir=${wrkdir}/pkgsrc
429 if [ "$unprivileged" = "yes" ]; then
430 [ -z "$prefix" ] && prefix=${HOME}/pkg
431 elif [ -z "$prefix" -o "$prefix" = "/usr/pkg" ]; then
433 [ -z "$varbase" ] && varbase=/var
436 [ -z "$varbase" ] && varbase=${prefix}/var
437 [ -z "$pkgdbdir" ] && pkgdbdir=${varbase}/db/pkg
439 if [ "$prefix" = "/usr" ]; then
440 [ -z "$pkgmandir" ] && pkgmandir=share/man
442 [ -z "$pkgmandir" ] && pkgmandir=man
444 mandir=${prefix}/${pkgmandir}
445 [ -z "$sysconfdir" ] && sysconfdir=${prefix}/etc
447 if [ "x$preserve_path" != "xyes" ]; then
448 PATH="$PATH:/sbin:/usr/sbin"
464 machine_arch=`get_machine_arch_aix`
472 machine_arch=`uname -p`
473 CC=${CC:-"gcc -isystem /usr/include"}; export CC
475 macosx_version=`echo $osrev | awk -F . '{ print "10."$1-4; }'`
476 case "$macosx_version" in
478 packagemaker=/Developer/Tools/packagemaker
481 packagemaker=/Developer/usr/bin/packagemaker
484 unset osrev macosx_version
492 check_prog tarprog tar
493 machine_arch=`uname -p`
501 machine_arch=`uname -p`
518 machine_arch=`uname -p`
528 machine_arch=`uname -m | sed 's/^9000.*$/hppa/'`
532 if id -G | grep -q 131616; then
538 mkdir -p "$@" # allows umask to take effect
540 default_install_mode=0775
559 # only used for unprivileged builds
561 # for bootstrap only; pkgsrc uses CPPFLAGS
562 CC="gcc -D_ALL_SOURCE"; export CC
563 ac_cv_header_poll_h=no; export ac_cv_header_poll_h
564 ac_cv_func_poll=no; export ac_cv_func_poll
567 if [ -d "/usr/freeware/bin" ]; then
568 overpath="/usr/freeware/bin:$overpath"
570 if [ -d "/usr/bsd" ]; then
571 overpath="/usr/bsd:$overpath"
573 if [ -d "/usr/bsd/bin" ]; then
574 overpath="/usr/bsd/bin:$overpath"
584 bmakexargs="MACHINE_ARCH=$machine_arch"
585 bmakexenv="MAKE=pmake"
587 if [ `uname -r` -lt 6 ]; then
588 # IRIX 5's mkdir bails out with an error when trying to create with the -p
589 # option an already existing directory
594 if [ -f /etc/ssdlinux_version ]; then
603 machine_arch=`uname -m | sed -e 's/i.86/i386/'`
613 check_prog mtreeprog mtree
614 machine_arch=`arch -s`
615 # there is no /usr/bin/cc, so use mgcc if unset
616 test -n "$CC" || { CC=mgcc; export CC; }
617 # get some variables from the native make if unset
618 for var in CFLAGS CPPFLAGS LDFLAGS; do
619 # check if variable is already set
621 [ "x$_tmp" != x ] && continue
622 # ask the native make (EXPERIMENTAL = don't add -Werror)
623 # the -I${.CURDIR} dance is to prevent junk in CPPFLAGS
624 _tmp=`printf '%s\nall:\n\t@%s %%s %s=${%s:M*:Q:Q}\n%s\n%s\n' \
625 $var'+=-I${.CURDIR}' printf $var $var':S/-I${.CURDIR}//' \
626 EXPERIMENTAL=yes '.include <bsd.prog.mk>' | \
627 (unset MAKECONF; /usr/bin/make -f - all 2>/dev/null) | \
639 machine_arch=`uname -p`
647 machine_arch=`uname -m`
665 machine_arch=`uname -p | sed -e 's/x86/i386/'`
670 if [ -x "/usr/gnu/bin/awk" ]; then
675 if [ -x "/usr/gnu/bin/sed" ]; then
680 if [ "`uname -r`" = "5.11" ]; then
681 bootstrap_sh=${SH:-/bin/ksh}
687 idprog="/usr/xpg4/bin/id"
688 groupsprog="${idprog} -gn"
689 whoamiprog="${idprog} -un"
690 machine_arch=`uname -p | sed -e 's/i86pc/i386/'`
696 BSTRAP_ENV="INSTALL=/usr/ucb/install $BSTRAP_ENV"
700 whoamiprog=/usr/ucb/whoami
702 CC="gcc -DUNIXWARE"; export CC
705 echo "This platform ($opsys) is untried - good luck, and thanks for using pkgsrc"
714 # If "--full" is specified, then install all of the platform-independent
715 # bootstrap software.
728 configure_quiet_flags="--quiet"
729 make_quiet_flags="-s"
732 configure_quiet_flags=""
736 # export OPSYS and MACHINE_ARCH for pkg_install. we only set
737 # MACHINE_ARCH on platforms where we override bmake's value.
740 if [ "${machine_arch}" != "" ]; then
741 MACHINE_ARCH=${machine_arch}
745 if [ "x$preserve_path" != "xyes" ]; then
746 PATH="$overpath:$PATH"
749 check_prog awkprog awk
750 check_prog chmodprog chmod
751 if [ -n "$CP" ]; then
756 if [ -n "$ID" ]; then
761 check_prog groupsprog groups
764 check_prog rmdirprog rmdir
765 check_prog sedprog sed
767 check_prog whoamiprog whoami
769 if [ -d "${wrkdir}" ] || [ -f "${wrkdir}" ]; then
770 echo "\"${wrkdir}\" already exists, please remove it or use --workdir.";
774 mkdir_p_early ${wrkdir}
775 if touch ${wrkdir}/.writeable; then
778 echo "\"${wrkdir}\" is not writeable. Try $0 -h.";
781 echo "Working directory is: ${wrkdir}"
783 if [ "$compiler" = "" ] && [ x"$check_compiler" = x"yes" ]; then
785 if [ $compiler_is_gnu -gt 0 ]; then
790 if [ `uname -r` -ge 6 ]; then
795 test -n "$CC" || CC=cc
797 SunOS) compiler="sunpro"
798 test -n "$CC" || CC=cc
804 mkdir_p_early ${wrkdir}/bin
807 run_cmd "$sedprog -e 's|@DEFAULT_INSTALL_MODE@|'${default_install_mode-0755}'|' $pkgsrcdir/sysutils/install-sh/files/install-sh.in > $wrkdir/bin/install-sh"
808 run_cmd "$chmodprog +x $wrkdir/bin/install-sh"
809 install_sh="$shprog $wrkdir/bin/install-sh"
816 if [ $unprivileged = "no" ]; then
817 die "You must be either root to install bootstrap-pkgsrc or use the --unprivileged option."
821 group=`$groupsprog | $awkprog '{print $1}'`
822 echo_msg "building as unprivileged user $user/$group"
824 # force bmake install target to use $user and $group
830 MANGRP=$group" > ${wrkdir}/Makefile.inc
833 # export the proper environment
834 PATH=$prefix/bin:$prefix/sbin:${PATH}; export PATH
835 if [ -d /usr/ccs/bin -a -x /usr/ccs/bin/make ]; then
836 PATH=${PATH}:/usr/ccs/bin; export PATH
838 PKG_DBDIR=$pkgdbdir; export PKG_DBDIR
839 LOCALBASE=$prefix; export LOCALBASE
840 VARBASE=$varbase; export VARBASE
842 # set up an example mk.conf file
843 TARGET_MKCONF=${wrkdir}/mk.conf.example
844 echo_msg "Creating default mk.conf in ${wrkdir}"
845 echo "# Example ${sysconfdir}/mk.conf file produced by bootstrap-pkgsrc" > ${TARGET_MKCONF}
846 echo "# `date`" >> ${TARGET_MKCONF}
847 echo "" >> ${TARGET_MKCONF}
848 echo ".ifdef BSD_PKG_MK # begin pkgsrc settings" >> ${TARGET_MKCONF}
849 echo "" >> ${TARGET_MKCONF}
851 # IRIX64 needs to be set to IRIX, for example
852 if [ "$set_opsys" = "yes" ]; then
853 echo "OPSYS= $opsys" >> ${TARGET_MKCONF}
856 if [ -n "$abi" ]; then
857 echo "ABI= $abi" >> ${TARGET_MKCONF}
859 if [ "$compiler" != "" ]; then
860 echo "PKGSRC_COMPILER= $compiler" >> ${TARGET_MKCONF}
864 echo "CC= cc" >> ${TARGET_MKCONF}
865 echo "CXX= CC" >> ${TARGET_MKCONF}
866 echo "CPP= \${CC} -E" >> ${TARGET_MKCONF}
869 if [ -n "$SUNWSPROBASE" ]; then
870 echo "SUNWSPROBASE= $SUNWSPROBASE" >> ${TARGET_MKCONF}
872 echo "" >> ${TARGET_MKCONF}
874 # enable unprivileged builds if not root
875 if [ "$unprivileged" = "yes" ]; then
876 echo "UNPRIVILEGED= yes" >> ${TARGET_MKCONF}
879 # save environment in example mk.conf
880 echo "PKG_DBDIR= $pkgdbdir" >> ${TARGET_MKCONF}
881 echo "LOCALBASE= $prefix" >> ${TARGET_MKCONF}
882 echo "VARBASE= $varbase" >> ${TARGET_MKCONF}
883 if [ "${sysconfdir}" != "${prefix}/etc" ]; then
884 echo "PKG_SYSCONFBASE= $sysconfdir" >> ${TARGET_MKCONF}
886 echo "PKG_TOOLS_BIN= $prefix/sbin" >> ${TARGET_MKCONF}
887 echo "PKGMANDIR= $pkgmandir" >> ${TARGET_MKCONF}
888 echo "" >> ${TARGET_MKCONF}
890 BOOTSTRAP_MKCONF=${wrkdir}/mk.conf
891 cp ${TARGET_MKCONF} ${BOOTSTRAP_MKCONF}
893 # sbin is used by pkg_install, share/mk by bootstrap-mk-files
894 mkdir_p $wrkdir/sbin $wrkdir/share/mk
895 mkdir_p_early ${wrkdir}
897 if [ "$need_bsd_install" = "yes" ]; then
898 BSTRAP_ENV="INSTALL='$prefix/bin/install-sh -c' $BSTRAP_ENV"
899 echo "TOOLS_PLATFORM.install?= $prefix/bin/install-sh" >> ${TARGET_MKCONF}
900 echo "TOOLS_PLATFORM.install?= $wrkdir/bin/install-sh" >> ${BOOTSTRAP_MKCONF}
903 if [ "$need_fixed_strip" = "yes" ] ; then
904 echo_msg "Installing fixed strip script"
905 run_cmd "$install_sh -c -o $user -g $group -m 755 $pkgsrcdir/pkgtools/bootstrap-extras/files/strip-sh $wrkdir/bin/strip"
906 echo "TOOLS_PLATFORM.strip?= $prefix/bin/strip" >> ${TARGET_MKCONF}
907 echo "TOOLS_PLATFORM.strip?= $wrkdir/bin/strip" >> ${BOOTSTRAP_MKCONF}
911 if [ "$need_mkdir" = "yes" -a -z "$MKDIR" ]; then
912 echo_msg "Installing fixed mkdir script \"mkdir-sh\""
913 run_cmd "$install_sh -c -o $user -g $group -m 755 $pkgsrcdir/pkgtools/bootstrap-extras/files/mkdir-sh $wrkdir/bin/mkdir-sh"
914 echo "TOOLS_PLATFORM.mkdir?= $prefix/bin/mkdir-sh -p" >> ${TARGET_MKCONF}
915 echo "TOOLS_PLATFORM.mkdir?= $wrkdir/bin/mkdir-sh -p" >> ${BOOTSTRAP_MKCONF}
919 if [ "$need_xargs" = "yes" ]; then
920 echo_msg "Installing fixed xargs script"
921 run_cmd "$install_sh -c -o $user -g $group -m 755 $pkgsrcdir/pkgtools/bootstrap-extras/files/xargs-sh $wrkdir/bin/xargs"
922 echo "TOOLS_PLATFORM.xargs?= $prefix/bin/xargs" >> ${TARGET_MKCONF}
923 echo "TOOLS_PLATFORM.xargs?= $wrkdir/bin/xargs" >> ${BOOTSTRAP_MKCONF}
927 echo_msg "Bootstrapping mk-files"
928 run_cmd "(cd ${pkgsrcdir}/pkgtools/bootstrap-mk-files/files && env CP=${cpprog} \
929 OPSYS=${opsys} MK_DST=${wrkdir}/share/mk ROOT_GROUP=${root_group} \
930 ROOT_USER=${root_user} SED=${sedprog} SYSCONFDIR=${sysconfdir} \
931 $shprog ./bootstrap.sh)"
934 echo_msg "Bootstrapping bmake"
935 copy_src $pkgsrcdir/devel/bmake/files bmake
936 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)"
937 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/bmake/$opsys/bmake $wrkdir/bin/bmake"
941 bmake="$wrkdir/bin/bmake $make_quiet_flags"
944 echo_msg "Building libnbcompat"
945 copy_src $pkgsrcdir/pkgtools/libnbcompat/files libnbcompat
946 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)"
948 # bootstrap ksh if necessary
950 yes) echo_msg "Bootstrapping ksh"
951 copy_src $pkgsrcdir/shells/pdksh/files ksh
952 test -n "$CC" || CC=gcc # default to gcc if no compiler is specified
953 run_cmd "(cd $wrkdir/ksh && env $BSTRAP_ENV $shprog ./configure $configure_quiet_flags --prefix=$prefix --mandir=$mandir --sysconfdir=$sysconfdir && $bmake)"
954 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/ksh/ksh $wrkdir/bin/pdksh"
955 echo "TOOLS_PLATFORM.sh?= $prefix/bin/pdksh" >> ${TARGET_MKCONF}
956 echo "TOOLS_PLATFORM.sh?= $wrkdir/bin/pdksh" >> ${BOOTSTRAP_MKCONF}
957 echo "TOOLS_PLATFORM.ksh?= $prefix/bin/pdksh" >> ${TARGET_MKCONF}
958 echo "TOOLS_PLATFORM.ksh?= $wrkdir/bin/pdksh" >> ${BOOTSTRAP_MKCONF}
959 # Now rebootstrap bmake for ksh
960 echo_msg "Rebootstrapping bmake for ksh"
961 bmakexargs="$bmakexargs --with-defshell=$wrkdir/bin/pdksh"
966 # bootstrap awk if necessary
968 yes) echo_msg "Bootstrapping awk"
969 copy_src $pkgsrcdir/lang/nawk/files awk
970 test -n "$CC" || CC=gcc # default to gcc if no compiler is specified
971 run_cmd "(cd $wrkdir/awk && $bmake -f Makefile CC=\"${CC}\" CFLAGS=\"${CFLAGS}\")"
972 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/awk/a.out $wrkdir/bin/nawk"
973 echo "TOOLS_PLATFORM.awk?= $prefix/bin/nawk" >> ${TARGET_MKCONF}
974 echo "TOOLS_PLATFORM.awk?= $wrkdir/bin/nawk" >> ${BOOTSTRAP_MKCONF}
978 # bootstrap sed if necessary
980 yes) echo_msg "Bootstrapping sed"
981 copy_src $pkgsrcdir/textproc/nbsed/files sed
982 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)"
983 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/sed/sed $wrkdir/bin/sed"
984 echo "TOOLS_PLATFORM.sed?= $prefix/bin/nbsed" >> ${TARGET_MKCONF}
985 echo "TOOLS_PLATFORM.sed?= $wrkdir/bin/sed" >> ${BOOTSTRAP_MKCONF}
989 # bootstrap pkg_install
990 echo_msg "Bootstrapping pkgtools"
991 copy_src $pkgsrcdir/pkgtools/pkg_install/files pkg_install
992 run_cmd "(cd $wrkdir/pkg_install; env $BSTRAP_ENV \
993 CPPFLAGS='$CPPFLAGS -I../libnbcompat -I../../libnbcompat' \
994 LDFLAGS='$LDFLAGS -L../libnbcompat -L../../libnbcompat' \
995 LIBS='$LIBS -lnbcompat' $shprog ./configure $configure_quiet_flags -C \
996 --enable-bootstrap --prefix=$prefix --sysconfdir=$sysconfdir \
997 --with-pkgdbdir=$pkgdbdir --mandir=$mandir $pkg_install_args && $bmake)"
998 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/pkg_install/admin/pkg_admin $wrkdir/sbin/pkg_admin"
999 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/pkg_install/create/pkg_create $wrkdir/sbin/pkg_create"
1000 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/pkg_install/info/pkg_info $wrkdir/sbin/pkg_info"
1001 echo "PKG_ADMIN_CMD?= $wrkdir/sbin/pkg_admin" >> ${BOOTSTRAP_MKCONF}
1002 echo "PKG_CREATE_CMD?= $wrkdir/sbin/pkg_create" >> ${BOOTSTRAP_MKCONF}
1003 echo "PKG_INFO_CMD?= $wrkdir/sbin/pkg_info" >> ${BOOTSTRAP_MKCONF}
1005 MAKECONF=$wrkdir/mk.conf
1008 if [ "$bootstrap_sh_set" = "set" ]; then
1009 echo "TOOLS_PLATFORM.sh?= ${bootstrap_sh}" >> ${TARGET_MKCONF}
1010 echo "TOOLS_PLATFORM.sh?= ${bootstrap_sh}" >> ${BOOTSTRAP_MKCONF}
1013 # preserve compiler and tool environment variables settings
1014 if test -n "$CP"; then
1015 echo "TOOLS_PLATFORM.cp?= $CP" >> ${TARGET_MKCONF}
1016 echo "TOOLS_PLATFORM.cp?= $CP" >> ${BOOTSTRAP_MKCONF}
1018 if test -n "$GREP"; then
1019 echo "TOOLS_PLATFORM.grep?= $GREP" >> ${TARGET_MKCONF}
1020 echo "TOOLS_PLATFORM.grep?= $GREP" >> ${BOOTSTRAP_MKCONF}
1022 if test -n "$ID"; then
1023 echo "TOOLS_PLATFORM.id?= $ID" >> ${TARGET_MKCONF}
1024 echo "TOOLS_PLATFORM.id?= $ID" >> ${BOOTSTRAP_MKCONF}
1026 if test -n "$MKDIR"; then
1027 echo "TOOLS_PLATFORM.mkdir?= $MKDIR" >> ${TARGET_MKCONF}
1028 echo "TOOLS_PLATFORM.mkdir?= $MKDIR" >> ${BOOTSTRAP_MKCONF}
1030 if test -n "$TEST"; then
1031 echo "TOOLS_PLATFORM.test?= $TEST" >> ${TARGET_MKCONF}
1032 echo "TOOLS_PLATFORM.test?= $TEST" >> ${BOOTSTRAP_MKCONF}
1034 if test -n "$TOUCH"; then
1035 echo "TOOLS_PLATFORM.touch?= $TOUCH" >> ${TARGET_MKCONF}
1036 echo "TOOLS_PLATFORM.touch?= $TOUCH" >> ${BOOTSTRAP_MKCONF}
1038 if test -n "$XARGS"; then
1039 echo "TOOLS_PLATFORM.xargs?= $XARGS" >> ${TARGET_MKCONF}
1040 echo "TOOLS_PLATFORM.xargs?= $XARGS" >> ${BOOTSTRAP_MKCONF}
1042 if test -n "$CFLAGS"; then
1043 echo "CFLAGS+= $CFLAGS" >> ${TARGET_MKCONF}
1044 echo "DBG= # prevent DBG from adding default optimizer flags" >> ${TARGET_MKCONF}
1045 echo "DBG= # prevent DBG from adding default optimizer flags" >> ${BOOTSTRAP_MKCONF}
1047 if test -n "$CPPFLAGS"; then
1048 echo "CPPFLAGS+= $CPPFLAGS" >> ${TARGET_MKCONF}
1050 if test -n "$LDFLAGS"; then
1051 echo "LDFLAGS+= $LDFLAGS" >> ${TARGET_MKCONF}
1053 if test -n "$LIBS"; then
1054 echo "LIBS+= $LIBS" >> ${TARGET_MKCONF}
1057 # opsys specific fiddling
1060 echo "WRKOBJDIR= ${wrkdir}/wrk" >> ${BOOTSTRAP_MKCONF}
1062 echo "" >> ${TARGET_MKCONF}
1063 echo "" >> ${BOOTSTRAP_MKCONF}
1064 if test -n "${mk_fragment}"; then
1065 cat "${mk_fragment}" >> ${TARGET_MKCONF}
1066 echo "" >> ${TARGET_MKCONF}
1068 echo ".endif # end pkgsrc settings" >> ${TARGET_MKCONF}
1069 echo ".endif # end pkgsrc settings" >> ${BOOTSTRAP_MKCONF}
1072 # usage: register_package <packagedirectory> [additional arguments]
1074 run_cmd "(cd $pkgsrcdir/$1 && $bmake USE_DESTDIR=no -DPKG_PRESERVE MAKECONF=${BOOTSTRAP_MKCONF} install)"
1078 # Please make sure that the following packages and
1079 # only the following packages set BOOTSTRAP_PKG=yes.
1081 echo_msg "Installing packages"
1082 build_package "pkgtools/bootstrap-mk-files"
1083 case "$need_bsd_install" in
1084 yes) build_package "sysutils/install-sh";;
1087 yes) build_package "shells/pdksh";;
1089 build_package "devel/bmake"
1091 yes) build_package "lang/nawk";;
1094 yes) build_package "textproc/nbsed";;
1096 case "$need_extras" in
1097 yes) build_package "pkgtools/bootstrap-extras";;
1099 build_package "pkgtools/pkg_install"
1101 etc_mk_conf="$sysconfdir/mk.conf"
1103 # Install the example mk.conf so that it is used, but only if it doesn't
1104 # exist yet. This can happen with non-default sysconfdir settings.
1105 mkdir_p "$sysconfdir"
1106 if [ ! -f "$etc_mk_conf" ]; then
1107 cp "$TARGET_MKCONF" "$etc_mk_conf"
1108 TARGET_MKCONF="$etc_mk_conf"
1111 hline="==========================================================================="
1115 echo "Please remember to add $prefix/bin to your PATH environment variable"
1116 echo "and $mandir to your MANPATH environment variable, if necessary."
1118 echo "An example mk.conf file with the settings you provided to \"bootstrap\""
1119 echo "has been created for you. It can be found in:"
1121 echo " ${TARGET_MKCONF}"
1123 if [ "$TARGET_MKCONF" != "$etc_mk_conf" ]; then
1124 echo "Please copy it to $etc_mk_conf to use it."
1127 echo "You can find extensive documentation of the NetBSD Packages Collection"
1128 echo "in $pkgsrcdir/doc/pkgsrc.txt."
1130 echo "Hopefully everything is now complete."
1131 echo "Thank you for using pkgsrc!"
1136 [ -n "${binary_kit}" ] && mkbinarykit_tar
1137 [ -n "${binary_gzip_kit}" ] && mkbinarykit_tgz
1138 [ -n "${binary_macpkg}" ] && mkbinarykit_macpkg
1140 echo_msg "bootstrap started: $build_start"
1141 echo_msg "bootstrap ended: `date`"