Merge from vendor branch TNF:
[pkgsrcv2.git] / bootstrap / bootstrap
1 #! /bin/sh
2
3 # $NetBSD: bootstrap,v 1.39 2005/05/29 17:15:25 jmmv Exp $
4 #
5 #
6 # Copyright (c) 2001-2002 Alistair G. Crooks.  All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
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
22 #    permission.
23 #
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.
35 #
36 #set -x
37
38 BOOTSTRAP_VERSION=20050419
39
40 ignorecasecheck=no
41 ignoreusercheck=no
42
43 preserve_path=no
44
45 # where the building takes place
46 wrkdir=work # default: relative to pkgsrc/bootstrap
47 bootstrapdir=`pwd`
48 pkgsrcdir=`dirname $bootstrapdir`
49
50 usage="Usage: $0 "'
51     [ --workdir <workdir> ]
52     [ --prefix <prefix> ]
53     [ --pkgdbdir <pkgdbdir> ]
54     [ --sysconfdir <sysconfdir> ]
55     [ --varbase <varbase> ]
56     [ --ignore-case-check ]
57     [ --ignore-user-check ]
58     [ --preserve-path ]
59     [ --help ]'
60
61 # this replicates some of the logic in bsd.prefs.mk. until
62 # bootstrap-pkgsrc is merged into pkgsrc, we need to determine the
63 # right value for OPSYS and MACHINE_ARCH.
64
65 # strip / for BSD/OS
66 opsys=`uname -s | tr -d /`
67
68 die()
69 {
70         echo >&2 "$@"
71         exit 1
72 }
73
74 echo_msg()
75 {
76         echo "===> $@"
77 }
78
79 # see if we're using gcc.  If so, set $compiler_is_gnu to '1'.
80 get_compiler()
81 {
82         testcc="${CC}"
83         # normally, we'd just use 'cc', but certain configure tools look
84         # for gcc specifically, so we have to see if that comes first
85         if [ -z "${testcc}" ]; then
86                 save_IFS="${IFS}"
87                 IFS=':'
88                 for dir in ${PATH}; do
89                         test -z "$dir" && dir=.
90                         if [ -x "$dir/gcc" ]; then
91                                 testcc="$dir/gcc"
92                                 break
93                         fi
94                 done
95                 IFS="${save_IFS}"
96         fi
97
98         cat >${wrkdir}/$$.c <<EOF
99 #ifdef __GNUC__
100 indeed
101 #endif
102 EOF
103         compiler_is_gnu=`${testcc:-cc} -E ${wrkdir}/$$.c 2>/dev/null | grep -c indeed`
104         rm -f ${wrkdir}/$$.c
105
106 }
107 get_abi()
108 {
109         abi_opsys=$@
110         case "$abi_opsys" in
111         IRIX)
112                 abi=`sed -e 's/.*\(abi=\)\([on]*[36][24]\).*/\2/' /etc/compiler.defaults`
113                 isa=`sed -e 's/.*\(isa=mips\)\([1234]\).*/\2/' /etc/compiler.defaults`
114                 case "$abi" in
115                 o32)
116                         imakeopts="-DBuildO32 -DSgiISAo32=$isa"
117                         abi=""
118                         ;;
119                 n32)    imakeopts="-DBuildN32 -DSgiISA32=$isa"
120                         abi="32"
121                         ;;
122                 64 | n64)
123                         imakeopts="-DBuild64bit -DSgiISA64=$isa"
124                         abi="64"
125                         ;;
126                 esac
127
128
129                 ;;
130         esac
131 }
132
133 get_machine_arch_aix()
134 {
135         _cpuid=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
136         if /usr/sbin/lsattr -El $_cpuid | grep ' POWER' >/dev/null 2>&1; then
137                 echo rs6000
138         else
139                 echo powerpc
140         fi
141 }
142
143 check_prog()
144 {
145         _var="$1"; _name="$2"
146
147         eval _tmp=\"\$$_var\"
148         if [ "x$_tmp" != "x" ]; then
149                 # Variable is already set (by the user, for example)
150                 return 0
151         fi
152
153         for _d in `echo $PATH | tr ':' ' '`; do
154                 if [ -x "$_d/$_name" ]; then
155                         # Program found
156                         eval $_var=\""$_d/$_name"\"
157                         return 1
158                 fi
159         done
160
161         die "$_name not found in path."
162 }
163
164 opsys_finish()
165 {
166         case "$opsys" in
167         IRIX)
168                 # setting X11BASE to /usr breaks buildlink
169                 if [ ! -e /usr/X11R6 ]; then
170                         ln -sf /usr /usr/X11R6
171                 fi
172                 if [ ! -z $imakeopts ]; then
173                         echo "IMAKEOPTS+=$imakeopts" >> ${MKCONF_EXAMPLE}
174                 fi
175                 patch -d / --forward --quiet -E -p0 \
176                         < files/irix.patch 2>/dev/null || true
177                 ;;
178         OSF1)
179                 if [ ! -e /usr/X11R6 ]; then
180                         ln -sf /usr /usr/X11R6
181                 fi
182                 ;;
183         esac
184 }
185
186 is_root()
187 {
188         if [ `$idprog -u` != 0 ]; then
189                 return 0
190         fi
191         return 1
192 }
193
194 # run a command, abort if it fails
195 run_cmd()
196 {
197         echo_msg "running: $@"
198         eval "$@"
199         ret=$?
200         if [ $ret -ne 0 ]; then
201                 echo_msg "exited with status $ret"
202                 die "aborted."
203         fi
204 }
205
206 # Some versions of mkdir (notably SunOS) bail out too easily, so use the
207 # install-sh wrapper instead.
208 mkdir_p()
209 {
210         for dir in $@; do
211                 run_cmd "$shprog $wrkdir/install-sh -d -o $user -g $group $dir"
212         done
213 }
214
215 copy_src()
216 {
217         _src="$1"; _dst="$2"
218         if [ ! -d $wrkdir/$_dst ]; then
219                 mkdir_p $wrkdir/$_dst
220         fi
221         $cpprog -R $_src/* $wrkdir/$_dst
222 }
223
224 get_optarg()
225 {
226         expr "x$1" : "x[^=]*=\\(.*\\)"
227 }
228
229 build_start=`date`
230 echo_msg "bootstrap command: $0 $@"
231 echo_msg "bootstrap started: $build_start"
232
233 # ensure system locations are empty; we will set them later when we know
234 # whether they will be system wide or user specific
235 prefix=
236 pkgdbdir=
237 sysconfdir=
238 varbase=
239
240 while [ $# -gt 0 ]; do
241         case $1 in
242         --workdir=*)    wrkdir=`get_optarg "$1"` ;;
243         --workdir)      wrkdir="$2"; shift ;;
244         --prefix=*)     prefix=`get_optarg "$1"`;
245                         sysconfdir=${prefix}/etc ;;
246         --prefix)       prefix="$2"; shift;
247                         sysconfdir=${prefix}/etc ;;
248         --pkgdbdir=*)   pkgdbdir=`get_optarg "$1"` ;;
249         --pkgdbdir)     pkgdbdir="$2"; shift ;;
250         --sysconfdir=*) sysconfdir=`get_optarg "$1"` ;;
251         --sysconfdir)   sysconfdir="$2"; shift ;;
252         --varbase=*)    varbase=`get_optarg "$1"` ;;
253         --varbase)      varbase="$2"; shift ;;
254         --ignore-case-check) ignorecasecheck=yes ;;
255         --ignore-user-check) ignoreusercheck=yes ;;
256         --preserve-path) preserve_path=yes ;;
257         --help)         echo "$usage"; exit ;;
258         -h)             echo "$usage"; exit ;;
259         --*)            echo "$usage"; exit 1 ;;
260         esac
261         shift
262 done
263
264 # set defaults for system locations if not already set by the user
265 if [ "$ignoreusercheck" = "yes" ]; then
266         [ -z "$prefix" ] && prefix=${HOME}/pkg
267         [ -z "$pkgdbdir" ] && pkgdbdir=${prefix}/var/db/pkg
268         [ -z "$sysconfdir" ] && sysconfdir=${prefix}/etc
269         [ -z "$varbase" ] && varbase=${prefix}/var
270 else
271         [ -z "$prefix" ] && prefix=/usr/pkg
272         [ -z "$pkgdbdir" ] && pkgdbdir=/var/db/pkg
273         [ -z "$sysconfdir" ] && sysconfdir=${prefix}/etc
274         [ -z "$varbase" ] && varbase=/var
275 fi
276
277 if [ "x$preserve_path" != "xyes" ]; then
278         PATH="$PATH:/sbin:/usr/sbin"
279 fi
280
281 overpath=""
282 root_user=root
283 case "$opsys" in
284 Darwin)
285         root_group=wheel
286         need_pax=yes
287         need_mtree=no
288         need_bsd_install=no
289         need_sed=no
290         set_opsys=no
291         check_prog mtreeprog mtree
292         machine_arch=`uname -p`
293         ;;
294 DragonFly)
295         root_group=wheel
296         need_pax=yes
297         need_mtree=no
298         need_bsd_install=no
299         need_sed=no
300         set_opsys=no
301         check_prog tarprog tar
302         check_prog mtreeprog mtree
303         machine_arch=`uname -p`
304         ;;
305 FreeBSD)
306         root_group=wheel
307         need_pax=yes
308         need_mtree=yes
309         need_bsd_install=no
310         need_sed=no
311         set_opsys=no
312         machine_arch=`uname -p`
313         ;;
314 HP-UX)
315         root_group=root
316         need_pax=yes
317         need_mtree=yes
318         need_bsd_install=yes
319         need_sed=yes
320         set_opsys=no
321         ;;
322 IRIX*)
323         if [ -d "/usr/freeware/bin" ]; then
324                 overpath="/usr/freeware/bin:$overpath"
325         fi
326         if [ -d "/usr/bsd/bin" ]; then
327                 overpath="/usr/bsd/bin:$overpath"
328         fi
329         root_group=sys
330         need_mtree=yes
331         need_bsd_install=yes
332         need_pax=yes
333         configargs="--with-machine_arch=mipseb"
334         get_abi "IRIX"
335         opsys=IRIX
336         need_sed=yes
337         set_opsys=yes
338         machine_arch=mipseb
339         check_compiler=yes
340         ;;
341 Linux)
342         if [ -f /etc/debian_version ]; then
343                 DEBIAN=yes
344         fi
345         root_group=root
346         need_pax=yes
347         need_mtree=yes
348         need_bsd_install=no
349         need_sed=no
350         set_opsys=no
351         machine_arch=`uname -m | sed -e 's/i.86/i386/'`
352         ;;
353 NetBSD)
354         root_group=wheel
355         need_pax=no
356         need_mtree=no
357         need_bsd_install=no
358         need_sed=no
359         set_opsys=no
360         check_prog paxprog pax
361         check_prog tarprog tar
362         check_prog mtreeprog mtree
363         machine_arch=`uname -p`
364         ;;
365 OpenBSD)
366         root_group=wheel
367         need_pax=yes
368         need_mtree=no
369         need_bsd_install=no
370         need_sed=no
371         set_opsys=no
372         check_prog mtreeprog mtree
373         machine_arch=`uname -m`
374         ;;
375 SunOS)
376         if [ -d "/usr/xpg4/bin" ]; then
377                 overpath="/usr/xpg4/bin:$overpath"
378         fi
379         root_group=root
380         need_pax=yes
381         need_mtree=yes
382         need_bsd_install=no
383         need_sed=yes
384         set_opsys=no
385         whoamiprog=/usr/ucb/whoami
386         machine_arch=`uname -p | sed -e 's/i86pc/i386/'`
387         ;;
388 AIX)
389         root_group=system
390         need_pax=yes
391         need_mtree=yes
392         need_bsd_install=yes
393         need_sed=yes
394         need_fixed_strip=yes
395         set_opsys=no
396         machine_arch=`get_machine_arch_aix`
397         ;;
398 Interix)
399         is_root () {
400                 if id -G | grep -q 131616; then
401                         return 1
402                 fi
403                 return 0
404         }
405         mkdir_p () {
406                 mkdir -p "$@" # allows umask to take effect
407         }
408         default_install_mode=0775
409         root_user=`id -u`
410         root_group=131616
411         need_pax=yes
412         need_mtree=yes
413         need_bsd_install=yes
414         need_sed=yes
415         set_opsys=no
416         # only used for unprivileged builds
417         groupsprog="id -gn"
418         # for bootstrap only; pkgsrc uses CPPFLAGS
419         CC="gcc -D_ALL_SOURCE"; export CC
420         ac_cv_header_poll_h=no; export ac_cv_header_poll_h
421         ac_cv_func_poll=no; export ac_cv_func_poll
422         ;;
423 UnixWare)
424         root_group=sys
425         need_pax=yes
426         need_mtree=yes
427         need_bsd_install=no
428         BSTRAP_ENV="INSTALL=/usr/ucb/install $BSTRAP_ENV"
429         need_mkdir=yes
430         need_sed=yes
431         whoamiprog=/usr/ucb/whoami
432         set_opsys=no
433         CC="gcc -DUNIXWARE"; export CC
434         ;;
435 OSF1)
436         root_group=system
437         need_pax=yes
438         need_mtree=yes
439         need_bsd_install=yes
440         need_sed=yes
441         set_opsys=no
442         ;;
443 *)
444         echo "This platform ($opsys) is untried - good luck, and thanks for using pkgsrc"
445         root_group=wheel
446         need_pax=yes
447         need_mtree=yes
448         need_bsd_install=yes
449         need_sed=yes
450         set_opsys=no
451         ;;
452 esac
453
454 # export OPSYS and MACHINE_ARCH for pkg_install. we only set
455 # MACHINE_ARCH on platforms where we override bmake's value.
456 OPSYS=${opsys}
457 export OPSYS
458 if [ "${machine_arch}" != "" ]; then
459         MACHINE_ARCH=${machine_arch}
460         export MACHINE_ARCH
461 fi
462
463 if [ "x$preserve_path" != "xyes" ]; then
464         PATH="$overpath:$PATH"
465 fi
466
467 check_prog awkprog awk
468 check_prog chmodprog chmod
469 check_prog cpprog cp
470 check_prog idprog id
471 check_prog groupsprog groups
472 check_prog lsprog ls
473 check_prog rmdirprog rmdir
474 check_prog sedprog sed
475 check_prog shprog sh
476 check_prog whoamiprog whoami
477
478
479 if [ ! -d ${wrkdir} ]; then
480         if mkdir ${wrkdir}; then
481                 :
482         else
483                 echo "Could not create the working directory \"${wrkdir}\". Try $0 -h.";
484                 exit 1
485         fi
486 fi
487 if touch ${wrkdir}/.writeable; then
488         :
489 else
490         echo "\"${wrkdir}\" is not writeable. Try $0 -h.";
491         exit 1
492 fi
493 echo "Working directory is: ${wrkdir}"
494
495 if [ x"$check_compiler" = x"yes" ]; then
496         get_compiler
497         if [ $compiler_is_gnu -gt 0 ]; then
498                 compiler="gcc"
499         else
500                 case "$opsys" in
501                 IRIX)
502                         compiler="mipspro"
503                         ;;
504                 esac
505         fi
506 fi
507
508 if [ ! -x ${wrkdir}/install-sh ]; then
509         run_cmd "$sedprog -e 's|@DEFAULT_INSTALL_MODE@|'${default_install_mode-0755}'|' files/install-sh.in > $wrkdir/install-sh"
510         run_cmd "$chmodprog +x $wrkdir/install-sh"
511 fi
512
513 is_root
514 if [ $? = 1 ]; then
515         user=$root_user
516         group=$root_group
517 else
518         if [ $ignoreusercheck = "no" ]; then
519                 die "You must be root to install bootstrap-pkgsrc."
520         fi
521
522         user=`$whoamiprog`
523         group=`$groupsprog | $awkprog '{print $1}'`
524         echo_msg "building as unprivileged user $user/$group"
525
526         # force bmake install target to use $user and $group
527         echo "BINOWN=$user
528 BINGRP=$group
529 LIBOWN=$user
530 LIBGRP=$group
531 MANOWN=$user
532 MANGRP=$group" > ${wrkdir}/Makefile.inc
533 fi
534
535 # make sure we're using a case-sensitive file system on Darwin
536 if [ $ignorecasecheck = "no" ]; then
537 case "$opsys" in
538 Darwin|Interix)
539         echo_msg "Testing file system case sensitivity"
540         for fs in "$prefix" "$pkgsrcdir"; do
541                 testdir="pkgsrc-REQUIRES-case-SENSITIVE-filesystem"
542                 testdir_mangled="PKGSRC-requires-CASE-sensitive-FILESYSTEM"
543                 mkdir_p "$fs/$testdir" || die "can't verify filesystem ($fs) case-sensitivity"
544                 if [ -d "$fs/$testdir_mangled" ]; then
545                         $rmdirprog "$fs/$testdir"
546                         die "\"$fs\" needs to be on a case-sensitive filesystem (see README.$opsys)"
547                 fi
548                 $rmdirprog "$fs/$testdir"
549         done
550         ;;
551 esac
552 fi
553
554 # export the proper environment
555 PATH=$prefix/bin:$prefix/sbin:${PATH}; export PATH
556 if [ -d /usr/ccs/bin -a -x /usr/ccs/bin/make ]; then
557         PATH=${PATH}:/usr/ccs/bin; export PATH
558 fi
559 PKG_DBDIR=$pkgdbdir; export PKG_DBDIR
560 LOCALBASE=$prefix; export LOCALBASE
561 VARBASE=$varbase; export VARBASE
562
563 # build libnbcompat
564 echo_msg "Building libnbcompat"
565 copy_src ../pkgtools/libnbcompat/files libnbcompat
566 run_cmd "(cd $wrkdir/libnbcompat; $shprog ./configure -C --prefix=$prefix --sysconfdir=$sysconfdir && make)"
567
568 # set up an example mk.conf file
569 MKCONF_EXAMPLE=${wrkdir}/mk.conf.example
570 export MKCONF_EXAMPLE
571 echo_msg "Creating mk.conf.example in ${wrkdir}"
572 echo "# Example ${sysconfdir}/mk.conf file produced by bootstrap-pkgsrc" > ${MKCONF_EXAMPLE}
573 echo "# `date`" >> ${MKCONF_EXAMPLE}
574 echo "" >> ${MKCONF_EXAMPLE}
575 echo ".ifdef BSD_PKG_MK # begin pkgsrc settings" >> ${MKCONF_EXAMPLE}
576 echo "" >> ${MKCONF_EXAMPLE}
577
578 # IRIX64 needs to be set to IRIX, for example
579 if [ "$set_opsys" = "yes" ]; then
580         echo "OPSYS=$opsys" >> ${MKCONF_EXAMPLE}
581 fi
582
583 if [ ! -z "$abi" ]; then
584         echo "ABI=$abi" >> ${MKCONF_EXAMPLE}
585 fi
586 if [ ! -z "$compiler" ]; then
587         echo "PKGSRC_COMPILER=$compiler" >> ${MKCONF_EXAMPLE}
588 fi
589                         
590
591 # enable unprivileged builds if not root
592 if [ "$ignoreusercheck" = "yes" ]; then
593         echo "UNPRIVILEGED=yes" >> ${MKCONF_EXAMPLE}
594 fi
595
596 # save environment in example mk.conf
597 echo "PKG_DBDIR=$pkgdbdir" >> ${MKCONF_EXAMPLE}
598 echo "LOCALBASE=$prefix" >> ${MKCONF_EXAMPLE}
599 echo "VARBASE=$varbase" >> ${MKCONF_EXAMPLE}
600 if [ "${sysconfdir}" != "${prefix}/etc" ]; then
601         echo "PKG_SYSCONFBASE=$sysconfdir" >> ${MKCONF_EXAMPLE}
602 fi
603
604 # create directories
605 mkdir_p $prefix $pkgdbdir $prefix/sbin
606 mkdir_p $prefix/man/man1 $prefix/man/cat1
607 mkdir_p $prefix/man/man8 $prefix/man/cat8
608
609 # bootstrap make and *.mk files
610 mkdir_p $prefix/share/mk $prefix/lib
611 copy_src bmake bmake
612
613 (cd ${wrkdir}/bmake/mk;
614         if [ -f ${bootstrapdir}/mods/mk/$opsys.sys.mk ]; then
615                 run_cmd "$cpprog ${bootstrapdir}/mods/mk/$opsys.sys.mk $prefix/share/mk/sys.mk"
616         else
617                 run_cmd "$cpprog ${bootstrapdir}/mods/mk/generic.sys.mk $prefix/share/mk/sys.mk"
618         fi
619         run_cmd "$cpprog bsd.*.mk $prefix/share/mk")
620
621 if [ -f mods/mk/$opsys.bsd.lib.mk ] ;  then
622         run_cmd "$cpprog mods/mk/$opsys.bsd.lib.mk ${wrkdir}/bmake/mk/bsd.lib.mk"
623         run_cmd "$cpprog mods/mk/$opsys.bsd.lib.mk $prefix/share/mk/bsd.lib.mk"
624 fi
625
626 if [ -f mods/mk/$opsys.bsd.man.mk ] ;  then
627         run_cmd "$cpprog mods/mk/$opsys.bsd.man.mk ${wrkdir}/bmake/mk/bsd.man.mk"
628         run_cmd "$cpprog mods/mk/$opsys.bsd.man.mk $prefix/share/mk/bsd.man.mk"
629 fi
630
631 own_mk=mods/mk/bsd.own.mk.in
632 if [ -f mods/mk/$opsys.bsd.own.mk ] ; then
633         own_mk=mods/mk/$opsys.bsd.own.mk.in
634 fi
635 run_cmd "$sedprog -e 's|@ROOT_GROUP@|'$root_group'|g;s|@ROOT_USER@|'$root_user'|g;s|@SYSCONFDIR@|'$sysconfdir'|g' $own_mk > $prefix/share/mk/bsd.own.mk"
636
637 if [ -f mods/mk/$opsys.bsd.prog.mk ] ; then
638         run_cmd "$cpprog mods/mk/$opsys.bsd.prog.mk $prefix/share/mk/bsd.prog.mk"
639 fi
640
641 if [ -f mods/mk/$opsys.bsd.sys.mk ]; then
642         run_cmd "$cpprog mods/mk/$opsys.bsd.sys.mk $prefix/share/mk/bsd.sys.mk"
643 fi      
644         
645 case "$opsys" in
646 NetBSD) run_cmd "$cpprog mods/bmake/Makefile.in ${wrkdir}/bmake/Makefile.in"
647         ;;
648 esac
649
650 if [ "$need_bsd_install" = "yes" ]; then
651         echo_msg "Installing BSD compatible install script"
652         run_cmd "$shprog $wrkdir/install-sh -c -o $user -g $group -m 755 $wrkdir/install-sh $prefix/bin/install-sh"
653         BSTRAP_ENV="INSTALL='$prefix/bin/install-sh -c' $BSTRAP_ENV"
654         echo "INSTALL=$prefix/bin/install-sh" >> ${MKCONF_EXAMPLE}
655 fi
656
657 if [ "$need_fixed_strip" = "yes" ] ; then
658         echo_msg "Installing fixed strip script"
659         run_cmd "$shprog $wrkdir/install-sh -c -o $user -g $group -m 755 files/strip-sh $prefix/bin/strip"
660 fi
661
662 if [ "$need_mkdir" = "yes" ]; then
663         echo_msg "Installing fixed mkdir script \"mkdir-sh\""
664         run_cmd "$shprog $wrkdir/install-sh -c -o $user -g $group -m 755 files/mkdir-sh $prefix/sbin/mkdir-sh"
665 fi
666
667 echo_msg "Installing bmake"
668 run_cmd "(cd $wrkdir/bmake; env CPPFLAGS='$CPPFLAGS -I../libnbcompat' LDFLAGS='$LDFLAGS -L../libnbcompat' LIBS='-lnbcompat' $shprog ./configure --prefix=$prefix --with-default-sys-path=$prefix/share/mk $configargs && make -f makefile.boot bootstrap && env BINDIR=$prefix/bin MANDIR=$prefix/man $BSTRAP_ENV ./bmake -f Makefile install)"
669
670 # bootstrap tnftp
671 case "$DEBIAN" in
672 yes)
673         LIBS="-lncurses"
674         ;;
675 esac
676 echo_msg "Installing tnftp"
677 copy_src ../net/tnftp/files tnftp
678 run_cmd "(cd $wrkdir/tnftp; env $BSTRAP_ENV $shprog ./configure --prefix=$prefix --sysconfdir=$sysconfdir && make && (cd src && make install))"
679 pkg_install_args="$pkg_install_args --with-ftp=$prefix/bin/ftp"
680
681 FETCH_CMD=$prefix/bin/ftp
682 export FETCH_CMD
683 echo "FETCH_CMD=$prefix/bin/ftp" >> ${MKCONF_EXAMPLE}
684
685 # bootstrap digest
686 echo_msg "Installing digest"
687 copy_src ../pkgtools/digest/files digest
688 run_cmd "(cd $wrkdir/digest; env $BSTRAP_ENV $shprog ./configure -C --prefix=$prefix --sysconfdir=$sysconfdir && make && make install)"
689
690 # create the digest package's meta files
691 digestversion=digest-`$awkprog -F "'" '/^PACKAGE_VERSION=/ {print $2}' $wrkdir/digest/configure`
692 $lsprog -ld $prefix/bin/digest | $awkprog '{ print $5 }' > $wrkdir/digest/.size
693 env DIGESTPROG=$prefix/bin/digest PKG_DIGEST=md5 PKG_DBDIR=$pkgdbdir \
694         $shprog ./pkg.sh create -d $wrkdir/digest/DESCR -O \
695         -c '-Message digest wrapper utility' -l -p $prefix \
696         -f $wrkdir/digest/PLIST -s $wrkdir/digest/.size -S $wrkdir/digest/.size $digestversion
697
698 # we often need NetBSD's pax as well, nowadays, to make binary packages
699 case "$need_pax" in
700 yes)    echo_msg "Installing pax"
701         copy_src ../archivers/pax/files pax
702         run_cmd "(cd $wrkdir/pax; env $BSTRAP_ENV CPPFLAGS='$CPPFLAGS -I../libnbcompat' LDFLAGS='$LDFLAGS -L../libnbcompat' LIBS='-lnbcompat' $shprog ./configure -C --prefix=$prefix --sysconfdir=$sysconfdir && $prefix/bin/bmake && $prefix/bin/bmake install)"
703         echo "PAX=$prefix/bin/pax" >> ${MKCONF_EXAMPLE}
704         pkg_install_args="$pkg_install_args --with-pax=$prefix/bin/pax --with-tar=$prefix/bin/tar"
705         ;;
706 *)
707         pkg_install_args="$pkg_install_args --with-pax=$paxprog --with-tar=$tarprog"
708         ;;
709 esac
710
711 # bootstrap mtree if necessary
712 case "$need_mtree" in
713 yes)    echo_msg "Installing mtree"
714         copy_src ../pkgtools/mtree/files mtree
715         run_cmd "(cd $wrkdir/mtree; env $BSTRAP_ENV CPPFLAGS='$CPPFLAGS -I../libnbcompat' LDFLAGS='$LDFLAGS -L../libnbcompat' LIBS='-lnbcompat' $shprog ./configure -C --prefix=$prefix --sysconfdir=$sysconfdir && $prefix/bin/bmake && $prefix/bin/bmake install)"
716         pkg_install_args="$pkg_install_args --with-mtree=$prefix/sbin/mtree"
717         ;;
718 *)      pkg_install_args="$pkg_install_args --with-mtree=$mtreeprog"
719         ;;
720 esac
721
722 # bootstrap sed if necessary
723 case "$need_sed" in
724 yes)    echo_msg "Installing sed"
725         copy_src ../textproc/nbsed/files sed
726         run_cmd "(cd $wrkdir/sed; env $BSTRAP_ENV CPPFLAGS='$CPPFLAGS -I../libnbcompat' LDFLAGS='$LDFLAGS -L../libnbcompat' LIBS='-lnbcompat' $shprog ./configure -C --prefix=$prefix --sysconfdir=$sysconfdir --program-transform-name='s,sed,nbsed,' && make && make install)"
727         echo "SED=$prefix/bin/nbsed" >> ${MKCONF_EXAMPLE}
728         BSTRAP_ENV="SED=\"$prefix/bin/nbsed\" $BSTRAP_ENV"
729         ;;
730 esac
731
732 # bootstrap pkg_install
733 echo_msg "Installing pkgtools"
734 copy_src ../pkgtools/pkg_install/files pkg_install
735 pkg_install_mandir="$prefix/man"
736 if [ "$prefix" = "/usr" ]; then
737         pkg_install_mandir="$prefix/share/man"
738 fi
739 run_cmd "(cd $wrkdir/pkg_install; env $BSTRAP_ENV CPPFLAGS='$CPPFLAGS -I../libnbcompat -I../../libnbcompat' LDFLAGS='$LDFLAGS -L../libnbcompat -L../../libnbcompat' LIBS='-lnbcompat' $shprog ./configure -C --prefix=$prefix --sysconfdir=$sysconfdir --with-pkgdbdir=$pkgdbdir --mandir=$pkg_install_mandir $pkg_install_args && $prefix/bin/bmake && $prefix/bin/bmake install)"
740
741 # all's ready, install the man page
742 echo_msg "Installing packages(7) man page"
743 run_cmd "$shprog $wrkdir/install-sh -c -m 444 files/packages.cat7 $prefix/man/cat7/packages.0"
744
745 # opsys specific fiddling
746 opsys_finish
747
748 echo "" >> ${MKCONF_EXAMPLE}
749 echo ".endif                    # end pkgsrc settings" >> ${MKCONF_EXAMPLE}
750
751 echo ""
752 echo "Please remember to add $prefix/bin to your PATH environment variable"
753 echo "and $prefix/man to your MANPATH environment variable, if necessary."
754 echo ""
755 echo "An example mk.conf file \"${MKCONF_EXAMPLE}\" with the settings you"
756 echo "provided to \"bootstrap\" has been created for you."
757 echo "Please copy ${MKCONF_EXAMPLE} to ${sysconfdir}/mk.conf."
758 echo ""
759 echo "You can find extensive documentation of the NetBSD Packages Collection"
760 echo "in $pkgsrcdir/doc/pkgsrc.txt and packages(7)."
761 echo ""
762 echo "Hopefully everything is now complete."
763 echo "Thank you"
764
765 echo_msg "bootstrap started: $build_start"
766 echo_msg "bootstrap ended:   `date`"
767
768 exit 0