3 # $NetBSD: bootstrap,v 1.163 2011/01/23 19:07:25 agc 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, LIBS
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 [ -n "$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}
244 echo "LDD= $prefix/sbin/fakeldd" >> ${TARGET_MKCONF}
251 if [ `uname -s` = "IRIX" ]; then
252 if [ `uname -r` -lt 6 -a -z "$ID" ]; then
253 # older version of IRIX have an id command with limited features
254 if [ "`$idprog`" != "uid=0(root) gid=0(sys)" ]; then
260 if [ `$idprog -u` != 0 ]; then
266 # run a command, abort if it fails
269 echo_msg "running: $@"
272 if [ $ret -ne 0 ]; then
273 echo_msg "exited with status $ret"
278 # Some versions of mkdir (notably SunOS) bail out too easily, so use the
279 # install-sh wrapper instead.
283 run_cmd "$install_sh -d -o $user -g $group $dir"
289 [ -d "$1" ] && return 0
290 mkdir -p "$1" 2> /dev/null && return 0
291 parent=`dirname "$1"`
292 mkdir_p_early "$parent"
293 if [ ! -d "$1" ] && mkdir "$1"; then
294 echo_msg "mkdir $1 exited with status $?"
303 if [ ! -d $wrkdir/$_dst ]; then
304 mkdir_p $wrkdir/$_dst
306 $cpprog -r $_src/* $wrkdir/$_dst
311 expr "x$1" : "x[^=]*=\\(.*\\)"
314 checkarg_sane_absolute_path() {
316 "") ;; # the default value will be used.
318 die "ERROR: Invalid characters in path $1 (from $2)." ;;
319 */) die "ERROR: The argument to $2 must not end in /." ;;
321 *) die "ERROR: The argument to $2 must be an absolute path." ;;
325 checkarg_sane_relative_path() {
327 "") ;; # the default value will be used.
329 die "ERROR: Invalid characters in path $1 (from $2)." ;;
330 /*) die "ERROR: The argument to $2 must be a relative path." ;;
335 bootstrap_sh=${SH-/bin/sh}
336 bootstrap_sh_set=${SH+set}
338 case "$bootstrap_sh" in
342 echo "ERROR: The variable SH must contain an absolute path" 1>&2
347 # On some newer Ubuntu installations, /bin/sh is a symlink to /bin/dash,
348 # whose echo(1) is not BSD-compatible.
349 dash_echo_test=`$bootstrap_sh -c 'echo "\\100"'`
350 if [ "$dash_echo_test" = "@" ]; then
351 { echo "ERROR: Your shell's echo command is not BSD-compatible."
352 echo "ERROR: Please select another shell by setting the environment"
353 echo "ERROR: variable SH."
358 if [ -n "$PKG_PATH" ]; then
359 echo "ERROR: Please unset PKG_PATH before running bootstrap." 1>&2
364 echo_msg "bootstrap command: $0 $@"
365 echo_msg "bootstrap started: $build_start"
367 # ensure system locations are empty; we will set them later when we know
368 # whether they will be system wide or user specific
380 while [ $# -gt 0 ]; do
382 --workdir=*) wrkdir=`get_optarg "$1"` ;;
383 --workdir) wrkdir="$2"; shift ;;
384 --prefix=*) prefix=`get_optarg "$1"` ;;
385 --prefix) prefix="$2"; shift ;;
386 --pkgdbdir=*) pkgdbdir=`get_optarg "$1"` ;;
387 --pkgdbdir) pkgdbdir="$2"; shift ;;
388 --pkgmandir=*) pkgmandir=`get_optarg "$1"` ;;
389 --pkgmandir) pkgmandir="$2"; shift ;;
390 --sysconfdir=*) sysconfdir=`get_optarg "$1"` ;;
391 --sysconfdir) sysconfdir="$2"; shift ;;
392 --varbase=*) varbase=`get_optarg "$1"` ;;
393 --varbase) varbase="$2"; shift ;;
394 --fetch-cmd=*) fetch_cmd=`get_optarg "$1"` ;;
395 --fetch-cmd) fetch_cmd="$2"; shift ;;
396 --compiler=*) compiler=`get_optarg "$1"` ;;
397 --compiler) compiler="$2"; shift ;;
398 --abi=*) abi=`get_optarg "$1"` ;;
399 --abi) abi="$2"; shift ;;
400 --ignore-case-check) ignorecasecheck=yes ;;
401 --unprivileged | --ignore-user-check) unprivileged=yes ;;
402 --preserve-path) preserve_path=yes ;;
404 mk_fragment=`get_optarg "$1"` ;;
406 mk_fragment="$2"; shift ;;
409 binary_kit=`get_optarg "$1"` ;;
411 binary_kit="$2"; shift ;;
413 binary_gzip_kit=`get_optarg "$1"` ;;
415 binary_gzip_kit="$2"; shift ;;
417 binary_macpkg=`get_optarg "$1"` ;;
419 binary_macpkg="$2"; shift ;;
421 --quiet) quiet=yes ;;
422 --help) echo "$usage"; exit ;;
423 -h) echo "$usage"; exit ;;
424 --*) echo "$usage"; exit 1 ;;
429 checkarg_sane_absolute_path "$wrkdir" "--workdir"
430 checkarg_sane_absolute_path "$prefix" "--prefix"
431 checkarg_sane_absolute_path "$pkgdbdir" "--pkgdbdir"
432 checkarg_sane_absolute_path "$sysconfdir" "--sysconfdir"
433 checkarg_sane_absolute_path "$varbase" "--varbase"
434 checkarg_sane_relative_path "$pkgmandir" "--pkgmandir"
436 # set defaults for system locations if not already set by the user
437 wrkobjdir=${wrkdir}/pkgsrc
438 if [ "$unprivileged" = "yes" ]; then
439 [ -z "$prefix" ] && prefix=${HOME}/pkg
440 elif [ -z "$prefix" -o "$prefix" = "/usr/pkg" ]; then
442 [ -z "$varbase" ] && varbase=/var
445 [ -z "$varbase" ] && varbase=${prefix}/var
446 [ -z "$pkgdbdir" ] && pkgdbdir=${varbase}/db/pkg
448 if [ "$prefix" = "/usr" ]; then
449 [ -z "$pkgmandir" ] && pkgmandir=share/man
451 [ -z "$pkgmandir" ] && pkgmandir=man
453 mandir=${prefix}/${pkgmandir}
454 [ -z "$sysconfdir" ] && sysconfdir=${prefix}/etc
456 if [ "x$preserve_path" != "xyes" ]; then
457 PATH="$PATH:/sbin:/usr/sbin"
473 machine_arch=`get_machine_arch_aix`
481 [ -z "$fetch_cmd" ] && fetch_cmd="/usr/bin/ftp"
482 machine_arch=`uname -p`
483 CC=${CC:-"gcc -isystem /usr/include"}; export CC
485 macosx_version=`echo $osrev | awk -F . '{ print "10."$1-4; }'`
486 case "$macosx_version" in
488 packagemaker=/Developer/Tools/packagemaker
491 packagemaker=/Developer/usr/bin/packagemaker
494 unset osrev macosx_version
502 check_prog tarprog tar
503 machine_arch=`uname -p`
506 [ -z "$fetch_cmd" ] && fetch_cmd="/usr/bin/ftp"
508 1.0* | 1.1 | 1.2.* | 1.3.*)
511 [ -z "$fetch_cmd" ] && fetch_cmd="/usr/bin/ftp"
521 machine_arch=`uname -p`
538 machine_arch=`uname -p`
548 machine_arch=`uname -m | sed 's/^9000.*$/hppa/'`
552 if id -G | grep -q 131616; then
558 mkdir -p "$@" # allows umask to take effect
560 default_install_mode=0775
579 # only used for unprivileged builds
581 # for bootstrap only; pkgsrc uses CPPFLAGS
582 CC="gcc -D_ALL_SOURCE"; export CC
583 ac_cv_header_poll_h=no; export ac_cv_header_poll_h
584 ac_cv_func_poll=no; export ac_cv_func_poll
587 if [ -d "/usr/freeware/bin" ]; then
588 overpath="/usr/freeware/bin:$overpath"
590 if [ -d "/usr/bsd" ]; then
591 overpath="/usr/bsd:$overpath"
593 if [ -d "/usr/bsd/bin" ]; then
594 overpath="/usr/bsd/bin:$overpath"
604 bmakexargs="MACHINE_ARCH=$machine_arch"
605 bmakexenv="MAKE=pmake"
607 if [ `uname -r` -lt 6 ]; then
608 # IRIX 5's mkdir bails out with an error when trying to create with the -p
609 # option an already existing directory
614 if [ -f /etc/ssdlinux_version ]; then
623 machine_arch=`uname -m | sed -e 's/i.86/i386/'`
633 check_prog mtreeprog mtree
634 machine_arch=`arch -s`
635 [ -z "$fetch_cmd" ] && fetch_cmd=/usr/bin/ftp
636 # there is no /usr/bin/cc, so use mgcc if unset
637 test -n "$CC" || { CC=mgcc; export CC; }
638 # get some variables from the native make if unset
639 for var in CFLAGS CPPFLAGS LDFLAGS; do
640 # check if variable is already set
642 [ "x$_tmp" != x ] && continue
643 # ask the native make (EXPERIMENTAL = don't add -Werror)
644 # the -I${.CURDIR} dance is to prevent junk in CPPFLAGS
645 _tmp=`printf '%s\nall:\n\t@%s %%s %s=${%s:M*:Q:Q}\n%s\n%s\n' \
646 $var'+=-I${.CURDIR}' printf $var $var':S/-I${.CURDIR}//' \
647 EXPERIMENTAL=yes '.include <bsd.prog.mk>' | \
648 (unset MAKECONF; /usr/bin/make -f - all 2>/dev/null) | \
660 machine_arch=`uname -p`
668 machine_arch=`uname -m`
686 fetch_cmd="/usr/bin/ftp"
687 machine_arch=`uname -p | sed -e 's/x86/i386/'`
690 if [ -d "/usr/xpg4/bin" ]; then
691 overpath="/usr/xpg4/bin:$overpath"
699 groupsprog="/usr/xpg4/bin/id -gn"
700 whoamiprog="/usr/xpg4/bin/id -un"
701 machine_arch=`uname -p | sed -e 's/i86pc/i386/'`
707 BSTRAP_ENV="INSTALL=/usr/ucb/install $BSTRAP_ENV"
711 whoamiprog=/usr/ucb/whoami
713 CC="gcc -DUNIXWARE"; export CC
716 echo "This platform ($opsys) is untried - good luck, and thanks for using pkgsrc"
725 # If "--full" is specified, then install all of the platform-independent
726 # bootstrap software.
739 configure_quiet_flags="--quiet"
740 make_quiet_flags="-s"
743 configure_quiet_flags=""
747 # export OPSYS and MACHINE_ARCH for pkg_install. we only set
748 # MACHINE_ARCH on platforms where we override bmake's value.
751 if [ "${machine_arch}" != "" ]; then
752 MACHINE_ARCH=${machine_arch}
756 if [ "x$preserve_path" != "xyes" ]; then
757 PATH="$overpath:$PATH"
760 check_prog awkprog awk
761 check_prog chmodprog chmod
762 if [ -n "$CP" ]; then
767 if [ -n "$ID" ]; then
772 check_prog groupsprog groups
775 check_prog rmdirprog rmdir
776 check_prog sedprog sed
778 check_prog whoamiprog whoami
780 if [ -d "${wrkdir}" ] || [ -f "${wrkdir}" ]; then
781 echo "\"${wrkdir}\" already exists, please remove it or use --workdir.";
785 mkdir_p_early ${wrkdir}
786 if touch ${wrkdir}/.writeable; then
789 echo "\"${wrkdir}\" is not writeable. Try $0 -h.";
792 echo "Working directory is: ${wrkdir}"
794 if [ "$compiler" = "" ] && [ x"$check_compiler" = x"yes" ]; then
796 if [ $compiler_is_gnu -gt 0 ]; then
801 if [ `uname -r` -ge 6 ]; then
806 test -n "$CC" || CC=cc
808 SunOS) compiler="sunpro"
809 test -n "$CC" || CC=cc
815 mkdir_p_early ${wrkdir}/bin
818 run_cmd "$sedprog -e 's|@DEFAULT_INSTALL_MODE@|'${default_install_mode-0755}'|' $pkgsrcdir/sysutils/install-sh/files/install-sh.in > $wrkdir/bin/install-sh"
819 run_cmd "$chmodprog +x $wrkdir/bin/install-sh"
820 install_sh="$shprog $wrkdir/bin/install-sh"
827 if [ $unprivileged = "no" ]; then
828 die "You must be either root to install bootstrap-pkgsrc or use the --unprivileged option."
832 group=`$groupsprog | $awkprog '{print $1}'`
833 echo_msg "building as unprivileged user $user/$group"
835 # force bmake install target to use $user and $group
841 MANGRP=$group" > ${wrkdir}/Makefile.inc
844 # make sure we're using a case-sensitive file system
845 if [ $ignorecasecheck = "no" ]; then
848 echo_msg "Testing file system case sensitivity"
849 for fs in "$prefix"; do
850 testdir="pkgsrc-REQUIRES-case-SENSITIVE-filesystem"
851 testdir_mangled="PKGSRC-requires-CASE-sensitive-FILESYSTEM"
852 mkdir_p "$fs/$testdir" || die "can't verify filesystem ($fs) case-sensitivity"
853 if [ -d "$fs/$testdir_mangled" ]; then
854 $rmdirprog "$fs/$testdir"
855 die "\"$fs\" needs to be on a case-sensitive filesystem (see README.$opsys)"
857 $rmdirprog "$fs/$testdir"
863 # export the proper environment
864 PATH=$prefix/bin:$prefix/sbin:${PATH}; export PATH
865 if [ -d /usr/ccs/bin -a -x /usr/ccs/bin/make ]; then
866 PATH=${PATH}:/usr/ccs/bin; export PATH
868 PKG_DBDIR=$pkgdbdir; export PKG_DBDIR
869 LOCALBASE=$prefix; export LOCALBASE
870 VARBASE=$varbase; export VARBASE
872 # set up an example mk.conf file
873 TARGET_MKCONF=${wrkdir}/mk.conf.example
874 echo_msg "Creating default mk.conf in ${wrkdir}"
875 echo "# Example ${sysconfdir}/mk.conf file produced by bootstrap-pkgsrc" > ${TARGET_MKCONF}
876 echo "# `date`" >> ${TARGET_MKCONF}
877 echo "" >> ${TARGET_MKCONF}
878 echo ".ifdef BSD_PKG_MK # begin pkgsrc settings" >> ${TARGET_MKCONF}
879 echo "" >> ${TARGET_MKCONF}
881 # IRIX64 needs to be set to IRIX, for example
882 if [ "$set_opsys" = "yes" ]; then
883 echo "OPSYS= $opsys" >> ${TARGET_MKCONF}
886 if [ -n "$abi" ]; then
887 echo "ABI= $abi" >> ${TARGET_MKCONF}
889 if [ "$compiler" != "" ]; then
890 echo "PKGSRC_COMPILER= $compiler" >> ${TARGET_MKCONF}
894 echo "CC= cc" >> ${TARGET_MKCONF}
895 echo "CXX= CC" >> ${TARGET_MKCONF}
896 echo "CPP= \${CC} -E" >> ${TARGET_MKCONF}
899 if [ -n "$SUNWSPROBASE" ]; then
900 echo "SUNWSPROBASE= $SUNWSPROBASE" >> ${TARGET_MKCONF}
902 echo "" >> ${TARGET_MKCONF}
904 # enable unprivileged builds if not root
905 if [ "$unprivileged" = "yes" ]; then
906 echo "UNPRIVILEGED= yes" >> ${TARGET_MKCONF}
909 # save environment in example mk.conf
910 echo "PKG_DBDIR= $pkgdbdir" >> ${TARGET_MKCONF}
911 echo "LOCALBASE= $prefix" >> ${TARGET_MKCONF}
912 echo "VARBASE= $varbase" >> ${TARGET_MKCONF}
913 if [ "${sysconfdir}" != "${prefix}/etc" ]; then
914 echo "PKG_SYSCONFBASE= $sysconfdir" >> ${TARGET_MKCONF}
916 echo "PKG_TOOLS_BIN= $prefix/sbin" >> ${TARGET_MKCONF}
917 echo "PKGMANDIR= $pkgmandir" >> ${TARGET_MKCONF}
918 echo "" >> ${TARGET_MKCONF}
920 BOOTSTRAP_MKCONF=${wrkdir}/mk.conf
921 cp ${TARGET_MKCONF} ${BOOTSTRAP_MKCONF}
923 # sbin is used by pkg_install, share/mk by bootstrap-mk-files
924 mkdir_p $wrkdir/sbin $wrkdir/share/mk
925 mkdir_p_early ${wrkdir}
927 if [ "$need_bsd_install" = "yes" ]; then
928 BSTRAP_ENV="INSTALL='$prefix/bin/install-sh -c' $BSTRAP_ENV"
929 echo "TOOLS_PLATFORM.install?= $prefix/bin/install-sh" >> ${TARGET_MKCONF}
930 echo "TOOLS_PLATFORM.install?= $wrkdir/bin/install-sh" >> ${BOOTSTRAP_MKCONF}
933 if [ "$need_fixed_strip" = "yes" ] ; then
934 echo_msg "Installing fixed strip script"
935 run_cmd "$install_sh -c -o $user -g $group -m 755 $pkgsrcdir/pkgtools/bootstrap-extras/files/strip-sh $wrkdir/bin/strip"
936 echo "TOOLS_PLATFORM.strip?= $prefix/bin/strip" >> ${TARGET_MKCONF}
937 echo "TOOLS_PLATFORM.strip?= $wrkdir/bin/strip" >> ${BOOTSTRAP_MKCONF}
941 if [ "$need_mkdir" = "yes" -a -z "$MKDIR" ]; then
942 echo_msg "Installing fixed mkdir script \"mkdir-sh\""
943 run_cmd "$install_sh -c -o $user -g $group -m 755 $pkgsrcdir/pkgtools/bootstrap-extras/files/mkdir-sh $wrkdir/bin/mkdir-sh"
944 echo "TOOLS_PLATFORM.mkdir?= $prefix/bin/mkdir-sh -p" >> ${TARGET_MKCONF}
945 echo "TOOLS_PLATFORM.mkdir?= $wrkdir/bin/mkdir-sh -p" >> ${BOOTSTRAP_MKCONF}
949 if [ "$need_xargs" = "yes" ]; then
950 echo_msg "Installing fixed xargs script"
951 run_cmd "$install_sh -c -o $user -g $group -m 755 $pkgsrcdir/pkgtools/bootstrap-extras/files/xargs-sh $wrkdir/bin/xargs"
952 echo "TOOLS_PLATFORM.xargs?= $prefix/bin/xargs" >> ${TARGET_MKCONF}
953 echo "TOOLS_PLATFORM.xargs?= $wrkdir/bin/xargs" >> ${BOOTSTRAP_MKCONF}
957 echo_msg "Bootstrapping mk-files"
958 run_cmd "(cd ${pkgsrcdir}/pkgtools/bootstrap-mk-files/files && env CP=${cpprog} \
959 OPSYS=${opsys} MK_DST=${wrkdir}/share/mk ROOT_GROUP=${root_group} \
960 ROOT_USER=${root_user} SED=${sedprog} SYSCONFDIR=${sysconfdir} \
961 $shprog ./bootstrap.sh)"
964 echo_msg "Bootstrapping bmake"
965 copy_src $pkgsrcdir/devel/bmake/files bmake
966 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)"
967 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/bmake/$opsys/bmake $wrkdir/bin/bmake"
971 bmake="$wrkdir/bin/bmake $make_quiet_flags"
974 echo_msg "Building libnbcompat"
975 copy_src $pkgsrcdir/pkgtools/libnbcompat/files libnbcompat
976 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)"
978 # bootstrap ksh if necessary
980 yes) echo_msg "Bootstrapping ksh"
981 copy_src $pkgsrcdir/shells/pdksh/files ksh
982 test -n "$CC" || CC=gcc # default to gcc if no compiler is specified
983 run_cmd "(cd $wrkdir/ksh && env $BSTRAP_ENV $shprog ./configure $configure_quiet_flags --prefix=$prefix --mandir=$mandir --sysconfdir=$sysconfdir && $bmake)"
984 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/ksh/ksh $wrkdir/bin/pdksh"
985 echo "TOOLS_PLATFORM.sh?= $prefix/bin/pdksh" >> ${TARGET_MKCONF}
986 echo "TOOLS_PLATFORM.sh?= $wrkdir/bin/pdksh" >> ${BOOTSTRAP_MKCONF}
987 echo "TOOLS_PLATFORM.ksh?= $prefix/bin/pdksh" >> ${TARGET_MKCONF}
988 echo "TOOLS_PLATFORM.ksh?= $wrkdir/bin/pdksh" >> ${BOOTSTRAP_MKCONF}
989 # Now rebootstrap bmake for ksh
990 echo_msg "Rebootstrapping bmake for ksh"
991 bmakexargs="$bmakexargs --with-defshell=$wrkdir/bin/pdksh"
996 # bootstrap awk if necessary
998 yes) echo_msg "Bootstrapping awk"
999 copy_src $pkgsrcdir/lang/nawk/files awk
1000 test -n "$CC" || CC=gcc # default to gcc if no compiler is specified
1001 run_cmd "(cd $wrkdir/awk && $bmake -f Makefile CC=\"${CC}\" CFLAGS=\"${CFLAGS}\")"
1002 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/awk/a.out $wrkdir/bin/nawk"
1003 echo "TOOLS_PLATFORM.awk?= $prefix/bin/nawk" >> ${TARGET_MKCONF}
1004 echo "TOOLS_PLATFORM.awk?= $wrkdir/bin/nawk" >> ${BOOTSTRAP_MKCONF}
1008 # bootstrap sed if necessary
1010 yes) echo_msg "Bootstrapping sed"
1011 copy_src $pkgsrcdir/textproc/nbsed/files sed
1012 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)"
1013 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/sed/sed $wrkdir/bin/sed"
1014 echo "TOOLS_PLATFORM.sed?= $prefix/bin/nbsed" >> ${TARGET_MKCONF}
1015 echo "TOOLS_PLATFORM.sed?= $wrkdir/bin/sed" >> ${BOOTSTRAP_MKCONF}
1019 # bootstrap pkg_install
1020 echo_msg "Bootstrapping pkgtools"
1021 copy_src $pkgsrcdir/pkgtools/pkg_install/files pkg_install
1022 run_cmd "(cd $wrkdir/pkg_install; env $BSTRAP_ENV \
1023 CPPFLAGS='$CPPFLAGS -I../libnbcompat -I../../libnbcompat' \
1024 LDFLAGS='$LDFLAGS -L../libnbcompat -L../../libnbcompat' \
1025 LIBS='$LIBS -lnbcompat' $shprog ./configure $configure_quiet_flags -C \
1026 --enable-bootstrap --prefix=$prefix --sysconfdir=$sysconfdir \
1027 --with-pkgdbdir=$pkgdbdir --mandir=$mandir $pkg_install_args && $bmake)"
1028 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/pkg_install/admin/pkg_admin $wrkdir/sbin/pkg_admin"
1029 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/pkg_install/create/pkg_create $wrkdir/sbin/pkg_create"
1030 run_cmd "$install_sh -c -o $user -g $group -m 755 $wrkdir/pkg_install/info/pkg_info $wrkdir/sbin/pkg_info"
1031 echo "PKG_ADMIN_CMD?= $wrkdir/sbin/pkg_admin" >> ${BOOTSTRAP_MKCONF}
1032 echo "PKG_CREATE_CMD?= $wrkdir/sbin/pkg_create" >> ${BOOTSTRAP_MKCONF}
1033 echo "PKG_INFO_CMD?= $wrkdir/sbin/pkg_info" >> ${BOOTSTRAP_MKCONF}
1035 if [ -n "${fetch_cmd}" ]; then
1036 echo "FETCH_CMD= $fetch_cmd" >> ${TARGET_MKCONF}
1039 MAKECONF=$wrkdir/mk.conf
1042 if [ "$bootstrap_sh_set" = "set" ]; then
1043 echo "TOOLS_PLATFORM.sh?= ${bootstrap_sh}" >> ${TARGET_MKCONF}
1044 echo "TOOLS_PLATFORM.sh?= ${bootstrap_sh}" >> ${BOOTSTRAP_MKCONF}
1047 # preserve compiler and tool environment variables settings
1048 if test -n "$CP"; then
1049 echo "TOOLS_PLATFORM.cp?= $CP" >> ${TARGET_MKCONF}
1050 echo "TOOLS_PLATFORM.cp?= $CP" >> ${BOOTSTRAP_MKCONF}
1052 if test -n "$GREP"; then
1053 echo "TOOLS_PLATFORM.grep?= $GREP" >> ${TARGET_MKCONF}
1054 echo "TOOLS_PLATFORM.grep?= $GREP" >> ${BOOTSTRAP_MKCONF}
1056 if test -n "$ID"; then
1057 echo "TOOLS_PLATFORM.id?= $ID" >> ${TARGET_MKCONF}
1058 echo "TOOLS_PLATFORM.id?= $ID" >> ${BOOTSTRAP_MKCONF}
1060 if test -n "$MKDIR"; then
1061 echo "TOOLS_PLATFORM.mkdir?= $MKDIR" >> ${TARGET_MKCONF}
1062 echo "TOOLS_PLATFORM.mkdir?= $MKDIR" >> ${BOOTSTRAP_MKCONF}
1064 if test -n "$TEST"; then
1065 echo "TOOLS_PLATFORM.test?= $TEST" >> ${TARGET_MKCONF}
1066 echo "TOOLS_PLATFORM.test?= $TEST" >> ${BOOTSTRAP_MKCONF}
1068 if test -n "$TOUCH"; then
1069 echo "TOOLS_PLATFORM.touch?= $TOUCH" >> ${TARGET_MKCONF}
1070 echo "TOOLS_PLATFORM.touch?= $TOUCH" >> ${BOOTSTRAP_MKCONF}
1072 if test -n "$XARGS"; then
1073 echo "TOOLS_PLATFORM.xargs?= $XARGS" >> ${TARGET_MKCONF}
1074 echo "TOOLS_PLATFORM.xargs?= $XARGS" >> ${BOOTSTRAP_MKCONF}
1076 if test -n "$CFLAGS"; then
1077 echo "CFLAGS+= $CFLAGS" >> ${TARGET_MKCONF}
1078 echo "DBG= # prevent DBG from adding default optimizer flags" >> ${TARGET_MKCONF}
1079 echo "DBG= # prevent DBG from adding default optimizer flags" >> ${BOOTSTRAP_MKCONF}
1081 if test -n "$CPPFLAGS"; then
1082 echo "CPPFLAGS+= $CPPFLAGS" >> ${TARGET_MKCONF}
1084 if test -n "$LDFLAGS"; then
1085 echo "LDFLAGS+= $LDFLAGS" >> ${TARGET_MKCONF}
1087 if test -n "$LIBS"; then
1088 echo "LIBS+= $LIBS" >> ${TARGET_MKCONF}
1091 # opsys specific fiddling
1094 echo "WRKOBJDIR= ${wrkdir}/wrk" >> ${BOOTSTRAP_MKCONF}
1096 echo "" >> ${TARGET_MKCONF}
1097 echo "" >> ${BOOTSTRAP_MKCONF}
1098 if test -n "${mk_fragment}"; then
1099 cat "${mk_fragment}" >> ${TARGET_MKCONF}
1100 echo "" >> ${TARGET_MKCONF}
1102 echo ".endif # end pkgsrc settings" >> ${TARGET_MKCONF}
1103 echo ".endif # end pkgsrc settings" >> ${BOOTSTRAP_MKCONF}
1106 # usage: register_package <packagedirectory> [additional arguments]
1108 run_cmd "(cd $pkgsrcdir/$1 && $bmake -DPKG_PRESERVE MAKECONF=${BOOTSTRAP_MKCONF} install)"
1112 # Please make sure that the following packages and
1113 # only the following packages set BOOTSTRAP_PKG=yes.
1115 echo_msg "Installing packages"
1116 build_package "pkgtools/bootstrap-mk-files"
1117 case "$need_bsd_install" in
1118 yes) build_package "sysutils/install-sh";;
1121 yes) build_package "shells/pdksh";;
1123 build_package "devel/bmake"
1125 yes) build_package "lang/nawk";;
1128 yes) build_package "textproc/nbsed";;
1130 case "$need_extras" in
1131 yes) build_package "pkgtools/bootstrap-extras";;
1133 build_package "pkgtools/pkg_install"
1135 etc_mk_conf="$sysconfdir/mk.conf"
1137 # Install the example mk.conf so that it is used, but only if it doesn't
1138 # exist yet. This can happen with non-default sysconfdir settings.
1139 mkdir_p "$sysconfdir"
1140 if [ ! -f "$etc_mk_conf" ]; then
1141 cp "$TARGET_MKCONF" "$etc_mk_conf"
1142 TARGET_MKCONF="$etc_mk_conf"
1145 hline="==========================================================================="
1149 echo "Please remember to add $prefix/bin to your PATH environment variable"
1150 echo "and $mandir to your MANPATH environment variable, if necessary."
1152 echo "An example mk.conf file with the settings you provided to \"bootstrap\""
1153 echo "has been created for you. It can be found in:"
1155 echo " ${TARGET_MKCONF}"
1157 if [ "$TARGET_MKCONF" != "$etc_mk_conf" ]; then
1158 echo "Please copy it to $etc_mk_conf to use it."
1161 echo "You can find extensive documentation of the NetBSD Packages Collection"
1162 echo "in $pkgsrcdir/doc/pkgsrc.txt."
1164 echo "Hopefully everything is now complete."
1170 [ -n "${binary_kit}" ] && mkbinarykit_tar
1171 [ -n "${binary_gzip_kit}" ] && mkbinarykit_tgz
1172 [ -n "${binary_macpkg}" ] && mkbinarykit_macpkg
1174 echo_msg "bootstrap started: $build_start"
1175 echo_msg "bootstrap ended: `date`"