1a868f3c093e618cbc0749b53c909f2370fbc400
[dragonfly.git] / Makefile.inc1
1 #
2 # $FreeBSD: src/Makefile.inc1,v 1.141.2.62 2003/04/06 19:54:00 dwmalone Exp $
3 #
4 # This file defines the user-driven targets.
5 #
6 # Standard targets are documented in the makefiles in /usr/share/mk and include:
7 #       obj depend all install clean cleandepend cleanobj
8 #
9 # Build-time options are documented in make.conf(5).
10 #
11
12 # Put initial settings here.
13 SUBDIR=
14
15 # /libexec/ld-elf.so.2 needs to be installed first
16 # Otherwise, install(1) beeing a dynamically linked binary will fail
17 # during the first upgrade from a static to a dynamic world
18 .if exists(${.CURDIR}/libexec)
19 SUBDIR+= libexec
20 .endif
21
22 # We need to do include and lib early.
23 #
24 .if exists(${.CURDIR}/include)
25 SUBDIR+= include
26 .endif
27 .if exists(${.CURDIR}/lib)
28 SUBDIR+= lib
29 .endif
30 # This exists simply to ensure that the obj dir hierarchy is
31 # intact for nrelease, allowing the nrelease Makefile's to
32 # reference ${.OBJDIR}.
33 #
34 .if exists(${.CURDIR}/nrelease)
35 SUBDIR+= nrelease
36 .endif
37
38 .if exists(${.CURDIR}/bin)
39 SUBDIR+= bin
40 .endif
41 .if exists(${.CURDIR}/games) && !defined(NO_GAMES)
42 SUBDIR+= games
43 .endif
44 .if exists(${.CURDIR}/gnu)
45 SUBDIR+= gnu
46 .endif
47 .if exists(${.CURDIR}/sbin)
48 SUBDIR+= sbin
49 .endif
50 .if exists(${.CURDIR}/share) && !defined(NO_SHARE)
51 SUBDIR+= share
52 .endif
53 .if exists(${.CURDIR}/sys)
54 SUBDIR+= sys
55 .endif
56 .if exists(${.CURDIR}/usr.bin)
57 SUBDIR+= usr.bin
58 .endif
59 .if exists(${.CURDIR}/usr.sbin)
60 SUBDIR+= usr.sbin
61 .endif
62 #.if exists(${.CURDIR}/llvm_clang)
63 #SUBDIR+= llvm_clang
64 #.endif
65
66 .if exists(${.CURDIR}/etc)
67 SUBDIR+= etc
68 .endif
69
70 # These are last, since it is nice to at least get the base system
71 # rebuilt before you do them.
72 .if defined(LOCAL_DIRS)
73 .for _DIR in ${LOCAL_DIRS}
74 .if exists(${.CURDIR}/${_DIR}) & exists(${.CURDIR}/${_DIR}/Makefile)
75 SUBDIR+= ${_DIR}
76 .endif
77 .endfor
78 .endif
79
80 .if defined(SUBDIR_OVERRIDE)
81 SUBDIR=         ${SUBDIR_OVERRIDE}
82 .endif
83
84 .if defined(NOCLEANDIR)
85 CLEANDIR=       clean cleandepend
86 .else
87 CLEANDIR=       cleandir
88 .endif
89
90 .if defined(NO_CLEAN)
91 NOCLEAN=        # defined
92 .endif
93
94 # Object directory base in primary make.  Note that when we rerun make
95 # from inside this file we change MAKEOBJDIRPREFIX to the appropriate
96 # subdirectory because the rest of the build system needs it that way.
97 # The original object directory base is saved in OBJTREE.
98 #
99 MAKEOBJDIRPREFIX?=      /usr/obj
100 OBJTREE?=               ${MAKEOBJDIRPREFIX}
101
102 # Used for stage installs and pathing
103 #
104 DESTDIRBASE:=           ${OBJTREE}${.CURDIR}
105
106 # Remove DESTDIR from MAKEFLAGS.  It is present in the environment
107 # anyhow, and we need to be able to override it for stage installs
108 .MAKEFLAGS:=    ${.MAKEFLAGS:NDESTDIR=*}
109
110 # This section sets the tools used to build the world/kernel
111 WORLD_CCVER?=           gcc50
112 WORLD_LDVER?=           ld.gold
113 WORLD_BINUTILSVER?=     binutils227
114
115 # Set the backup parameters if they are not already defined
116 #
117 WORLD_BACKUP?=          /var/backups/world_backup
118 AUTO_BACKUP?=           ${OBJTREE}/world_backup/${DESTDIR}
119
120 TARGET_ARCH?=   ${MACHINE_ARCH}
121 .if ${TARGET_ARCH} == ${MACHINE_ARCH}
122 TARGET?=        ${MACHINE}
123 .else
124 TARGET?=        ${TARGET_ARCH}
125 .endif
126 .if make(buildworld)
127 BUILD_ARCH!=    sysctl -n hw.machine_arch
128
129 # temporary until everybody has converted to x86_64
130 .if ${BUILD_ARCH} == "amd64"
131 BUILD_ARCH=     x86_64
132 .endif
133
134 .if ${MACHINE_ARCH} != ${BUILD_ARCH}
135 .error To cross-build, set TARGET_ARCH.
136 .endif
137 .endif
138
139 # XXX this is ugly and we need to come up with a nicer solution
140 .if !defined(TARGET_PLATFORM)
141 .if ${TARGET_ARCH} == "x86_64"
142 TARGET_PLATFORM= pc64
143 .else
144 .error Unknown target architecture.
145 .endif
146 .endif
147
148 THREAD_LIB?=    thread_xu
149 .if ${THREAD_LIB} == "c_r"
150 .if defined(NO_LIBC_R)
151 .error libc_r is chosen as the default thread library, but NO_LIBC_R is defined
152 .endif
153 .endif
154
155 # BTOOLS        (Natively built) All non-cross-development tools that the
156 #               main build needs.  This includes things like 'mkdir' and 'rm'.
157 #               We will not use the native system's exec path once we start
158 #               on WORLD.  (bootstrap-tools and build-tools or BTOOLS)
159 #
160 # CTOOLS        (Natively built) Cross development tools which are specific
161 #               to the target architecture.
162 #
163 # WORLD         (Cross built) Our ultimate buildworld, using only BTOOLS and
164 #               CTOOLS.
165 #
166 # MACHINE_PLATFORM      Platform Architecture we are building on
167 # MACHINE               Machine Architecture (usually the same as MACHINE_ARCH)
168 # MACHINE_ARCH          CPU Architecture we are building on
169 #
170 # TARGET_PLATFORM       Platform Architecture we are building for
171 # TARGET                Machine Architecture we are building for
172 # TARGET_ARCH           CPU Architecture we are building for
173 #
174 BTOOLSDEST=     ${DESTDIRBASE}/btools_${MACHINE_ARCH}
175 CTOOLSDEST=     ${DESTDIRBASE}/ctools_${MACHINE_ARCH}_${TARGET_ARCH}
176 WORLDDEST=      ${DESTDIRBASE}/world_${TARGET_ARCH}
177
178 # The bootstrap-tools path is used by the bootstrap-tools, build-tools, and
179 # cross-tools stages to augment the existing command path to access newer
180 # versions of certain utilities such as 'patch' that the cross-tools stage
181 # might expect.
182 #
183 BTOOLSPATH= ${BTOOLSDEST}/usr/sbin:${BTOOLSDEST}/usr/bin:${BTOOLSDEST}/sbin:${BTOOLSDEST}/bin
184
185 # The cross-tools path containing the cross-tools to cross build the
186 # ultimate world.
187 #
188 CTOOLSPATH= ${CTOOLSDEST}/usr/sbin:${CTOOLSDEST}/usr/bin:${CTOOLSDEST}/sbin:${CTOOLSDEST}/bin
189
190 # The strict temporary command path contains all binaries required
191 # by the buildworld system after the cross-tools stage.
192 #
193 # NOTE: Append '/usr/local/bin:/usr/pkg/bin' to support external compilers.
194 #       See compilers.conf(5) man page for more info.
195 #
196 STRICTTMPPATH= ${CTOOLSPATH}:${BTOOLSPATH}:/usr/local/bin:/usr/pkg/bin
197
198 TMPDIR?=        /tmp
199 TMPPID!=        echo $$$$
200
201 #
202 # Building a world goes through the following stages
203 #
204 # 1. bootstrap-tool stage [BMAKE]
205 #       This stage is responsible for creating programs that
206 #       are needed for backward compatibility reasons. They
207 #       are not built as cross-tools.
208 # 2. build-tool stage [TMAKE]
209 #       This stage is responsible for creating the object
210 #       tree and building any tools that are needed during
211 #       the build process.
212 # 3. cross-tool stage [XMAKE]
213 #       This stage is responsible for creating any tools that
214 #       are needed for cross-builds. A cross-compiler is one
215 #       of them.
216 # 4. world stage [WMAKE]
217 #       This stage actually builds the world.
218 # 5. install stage (optional) [IMAKE]
219 #       This stage installs a previously built world.
220 #
221 # In all cases we must carefully adjust the environment so the proper
222 # tools and header files are used.
223 #
224 # NOTE: The M4 environment variable is used by the [f]lex binary to
225 #       override the location of the 'm4' binary.  The override is
226 #       needed for certain buildworld version transitions, specifically
227 #       past a certain point in 3.3 because the older /usr/bin/m4 will
228 #       generate output that will blow up the newer [f]lex/yacc/bison
229 #       utilities.
230 #
231
232 # bootstrap-tool stage
233 #
234 BMAKEENV=       MAKEOBJDIRPREFIX=${BTOOLSDEST} \
235                 OBJTREE=${OBJTREE} \
236                 DESTDIR=${BTOOLSDEST} \
237                 LC_ALL=C \
238                 PATH=${BTOOLSPATH}:${PATH} \
239                 M4=${BTOOLSDEST}/usr/bin/m4 \
240                 INSTALL="sh ${.CURDIR}/tools/install.sh"
241
242 BMAKE=          ${BMAKEENV} make -f Makefile.inc1 -DBOOTSTRAPPING \
243                 -DNOMAN -DNOPIC -DNOPROFILE -DNOSHARED \
244                 -DNO_WERROR -DNO_NLS -DSYSBUILD
245
246 # build-tool stage
247 #
248 TMAKEENV=       MAKEOBJDIRPREFIX=${BTOOLSDEST} \
249                 OBJTREE=${OBJTREE} \
250                 DESTDIR= \
251                 LC_ALL=C \
252                 PATH=${BTOOLSPATH}:${PATH} \
253                 M4=${BTOOLSDEST}/usr/bin/m4 \
254                 INSTALL="sh ${.CURDIR}/tools/install.sh"
255
256 TMAKE=          ${TMAKEENV} make -f Makefile.inc1 -DBOOTSTRAPPING \
257                 -DNOSHARED -DSYSBUILD
258
259 # cross-tool stage
260 #
261 # note: TOOLS_PREFIX points to the obj root holding the cross
262 #       compiler binaries, while USRDATA_PREFIX points to the obj root
263 #       holding the target environment (and also determines where cross-built
264 #       libraries, crt*.o, and include files are installed).
265 #
266 XMAKEENV=       MAKEOBJDIRPREFIX=${CTOOLSDEST} \
267                 OBJTREE=${OBJTREE} \
268                 DESTDIR=${CTOOLSDEST} \
269                 LC_ALL=C \
270                 _SHLIBDIRPREFIX=${CTOOLSDEST} \
271                 INSTALL="sh ${.CURDIR}/tools/install.sh" \
272                 TOOLS_PREFIX=${CTOOLSDEST} \
273                 USRDATA_PREFIX=${WORLDDEST} \
274                 SELECT_LINKER=${WORLD_LDVER} \
275                 M4=${BTOOLSDEST}/usr/bin/m4 \
276                 PATH=${BTOOLSPATH}:${PATH}
277
278 XMAKE=          ${XMAKEENV} make -f Makefile.inc1 -DNO_GDB \
279                 -DBOOTSTRAPPING -DNOSHARED -DSYSBUILD
280
281 # world stage, note the strict path and note that TOOLS_PREFIX is left
282 # unset and USRDATA_PREFIX (which defaults to TOOLS_PREFIX) is set to empty,
283 # which is primarily for the compiler so it targets / (e.g. /usr/<blah>)
284 # for both binary and library paths, even though it is being compiled to
285 # WORLDDEST.  None of the programs in the world stage are ever actually
286 # executed during the buildworld/installworld.
287 #
288 CROSSENV=       MAKEOBJDIRPREFIX=${WORLDDEST} \
289                 OBJTREE=${OBJTREE} \
290                 MACHINE_ARCH=${TARGET_ARCH} \
291                 MACHINE=${TARGET} \
292                 MACHINE_PLATFORM=${TARGET_PLATFORM} \
293                 LC_ALL=C \
294                 OBJFORMAT_PATH=${CTOOLSDEST} \
295                 HOST_CCVER=${HOST_CCVER} \
296                 CCVER=${WORLD_CCVER} \
297                 LDVER=${WORLD_LDVER} \
298                 BINUTILSVER=${WORLD_BINUTILSVER}
299
300 WMAKEENV=       ${CROSSENV} \
301                 DESTDIR=${WORLDDEST} \
302                 _SHLIBDIRPREFIX=${WORLDDEST} \
303                 INSTALL="sh ${.CURDIR}/tools/install.sh" \
304                 M4=${BTOOLSDEST}/usr/bin/m4 \
305                 PATH=${STRICTTMPPATH}
306
307 WMAKE=          ${WMAKEENV} make -f Makefile.inc1 -DSYSBUILD
308
309 # install stage
310 #
311 IMAKEENV=       ${CROSSENV} \
312                 PATH=${STRICTTMPPATH}
313 IMAKE=          ${IMAKEENV} make -f Makefile.inc1 -DSYSBUILD
314
315 # kernel stage
316 #
317 KMAKEENV=       ${WMAKEENV}
318
319 # buildworld
320 #
321 # Attempt to rebuild the entire system, with reasonable chance of
322 # success, regardless of how old your existing system is.
323 #
324 _worldtmp: _cleantmp _mtreetmp
325 .ORDER: _cleantmp _mtreetmp
326
327 _cleantmp:
328         @echo
329         @echo "--------------------------------------------------------------"
330         @echo ">>> Rebuilding the temporary build tree"
331         @echo "--------------------------------------------------------------"
332 .if !defined(NOCLEAN)
333         rm -rf ${BTOOLSDEST} ${CTOOLSDEST} ${WORLDDEST}
334 .else
335         # XXX - These two can depend on any header file.
336         rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
337         rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
338 .endif
339
340 _mtreetmp:
341         mkdir -p ${DESTDIRBASE} ${BTOOLSDEST} ${CTOOLSDEST} ${WORLDDEST}
342 .for _dir in ${WORLDDEST} ${BTOOLSDEST} ${CTOOLSDEST}
343         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist        \
344                 -p ${_dir}/  > /dev/null
345         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist         \
346                 -p ${_dir}/usr > /dev/null
347 .endfor
348         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist     \
349                 -p ${WORLDDEST}/usr/include > /dev/null
350         ${LN} -sf ${.CURDIR}/sys ${WORLDDEST}
351
352 _bootstrap-tools:
353         @echo
354         @echo "--------------------------------------------------------------"
355         @echo ">>> stage 1: bootstrap tools"
356         @echo "--------------------------------------------------------------"
357         cd ${.CURDIR}; ${BMAKE} bootstrap-tools
358 _cleanobj:
359         @echo
360         @echo "--------------------------------------------------------------"
361         @echo ">>> stage 2a: cleaning up the object tree"
362         @echo "--------------------------------------------------------------"
363         cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
364 _obj:
365         @echo
366         @echo "--------------------------------------------------------------"
367         @echo ">>> stage 2b: rebuilding the object tree"
368         @echo "--------------------------------------------------------------"
369         cd ${.CURDIR}; ${WMAKE} par-obj
370 _build-tools:
371         @echo
372         @echo "--------------------------------------------------------------"
373         @echo ">>> stage 2c: build tools"
374         @echo "--------------------------------------------------------------"
375         cd ${.CURDIR}; ${TMAKE} build-tools
376 _cross-tools:
377         @echo
378         @echo "--------------------------------------------------------------"
379         @echo ">>> stage 3: cross tools"
380         @echo "--------------------------------------------------------------"
381         cd ${.CURDIR}; ${XMAKE} cross-tools
382 _includes:
383         @echo
384         @echo "--------------------------------------------------------------"
385         @echo ">>> stage 4a: populating ${WORLDDEST}/usr/include"
386         @echo "--------------------------------------------------------------"
387         cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
388 _libraries:
389         @echo
390         @echo "--------------------------------------------------------------"
391         @echo ">>> stage 4b: building libraries"
392         @echo "--------------------------------------------------------------"
393         cd ${.CURDIR}; ${WMAKE} -DNOHTML -DNOMAN -DNOFSCHG libraries
394 _depend:
395         @echo
396         @echo "--------------------------------------------------------------"
397         @echo ">>> stage 4c: make dependencies"
398         @echo "--------------------------------------------------------------"
399         cd ${.CURDIR}; ${WMAKE} par-depend
400 everything:
401         @echo
402         @echo "--------------------------------------------------------------"
403         @echo ">>> stage 4d: building everything.."
404         @echo "--------------------------------------------------------------"
405         cd ${.CURDIR}; ${WMAKE} all
406 _bwinit:
407         @echo "--------------------------------------------------------------"
408         @echo ">>> starting buildworld target"
409         @echo "--------------------------------------------------------------"
410 _bwdone:
411         @echo "--------------------------------------------------------------"
412         @echo ">>> buildworld target complete"
413         @echo "--------------------------------------------------------------"
414 _qwinit:
415         @echo "--------------------------------------------------------------"
416         @echo ">>> starting quickworld target"
417         @echo "--------------------------------------------------------------"
418 _qwdone:
419         @echo "--------------------------------------------------------------"
420         @echo ">>> quickworld target complete"
421         @echo "--------------------------------------------------------------"
422 _iwinit:
423         @echo "--------------------------------------------------------------"
424         @echo ">>> starting installworld target"
425         @echo "--------------------------------------------------------------"
426
427 # note: buildworld no longer depends on _cleanobj because we rm -rf the
428 # entire object tree and built the bootstrap tools in a different location.
429 #
430 # buildworld    - build everything from scratch
431 # quickworld    - skip the bootstrap, build, and cross-build steps
432 # realquickworld - skip the bootstrap, build, crossbuild, and depend step.
433 #
434 # note: we include _obj in realquickworld to prevent accidental creation
435 # of files in /usr/src.
436
437 WMAKE_TGTS=
438 .if !defined(SUBDIR_OVERRIDE)
439 WMAKE_TGTS+=    _worldtmp _bootstrap-tools
440 .endif
441 WMAKE_TGTS+=    _obj _build-tools
442 .if !defined(SUBDIR_OVERRIDE)
443 WMAKE_TGTS+=    _cross-tools
444 .endif
445 WMAKE_TGTS+=    _includes _libraries _depend everything
446
447 buildworld: _bwinit ${WMAKE_TGTS} _bwdone
448
449 quickworld: _qwinit _mtreetmp _obj _includes _libraries _depend everything _qwdone
450
451 realquickworld: _qwinit _mtreetmp _obj _includes _libraries everything _qwdone
452
453 crossworld: _worldtmp _bootstrap-tools _obj _build-tools _cross-tools
454
455 .ORDER: _bwinit ${WMAKE_TGTS} _bwdone
456 .ORDER: _obj _includes
457 .ORDER: _qwinit _mtreetmp _obj
458 .ORDER: installcheck backupworld-auto
459 .ORDER: everything _qwdone
460
461 #
462 # installcheck
463 #
464 # Checks to be sure system is ready for installworld
465 #
466 installcheck: _iwinit
467         @pw usershow _pflogd || (echo "You may need to run 'make preupgrade' first"; /usr/bin/false)
468         @pw groupshow authpf || (echo "You may need to run 'make preupgrade' first"; /usr/bin/false)
469         @pw groupshow _pflogd || (echo "You may need to run 'make preupgrade' first"; /usr/bin/false)
470 .if !defined(OVERRIDE_CHECKS)
471 .if !defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/"
472         @case `uname -r` in 1.2*|1.3-*|1.3.*|1.4.*|1.5.0-*|1.5.1-*|1.5.2-*|1.5.3-*) echo "You must upgrade your kernel to at least 1.5.4 and reboot before you can safely installworld, due to libc/system call ABI changes" ; /usr/bin/false ; esac
473         @case `uname -r` in 1.*|2.*|3.0*|3.1*|3.2*|3.3*|3.4*|3.5*|3.6*) echo "Base is too old for a normal installworld, you need to use installworld-force" ; /usr/bin/false ; esac
474 .endif
475 .endif
476
477 #
478 # installworld
479 #
480 # Backs up the current world if ${AUTO_BACKUP} is writable.
481 # Installs everything compiled by a 'buildworld'.
482 #
483 installworld: installcheck
484         -@mkdir -p ${AUTO_BACKUP} > /dev/null 2>&1
485         @cd ${.CURDIR}; \
486             (touch ${AUTO_BACKUP}/.updating > /dev/null 2>&1 && \
487              ${IMAKE} backupworld-auto) || \
488             echo "Cannot write to ${AUTO_BACKUP} - world not backed up"
489
490         cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}
491         ${INSTALL} -o root -g wheel -m 644 ${.CURDIR}/Makefile_upgrade.inc ${DESTDIR}/etc/upgrade/
492         sync
493         @echo "--------------------------------------------------------------"
494         @echo ">>> installworld target complete"
495         @echo "--------------------------------------------------------------"
496         @echo "If things work as expected after a full reboot, consider updating the rescue"
497         @echo "image with 'make rescue'.  Do not do it until after rebooting."
498
499 installworld-force:
500         @echo "Doing a forced installworld.  This will install to a temporary directory,"
501         @echo "then copy the main binaries and libraries with a static cpdup to ${DESTDIR}/"
502         @echo "and finally will issue a normal installworld.  Starting in 5 seconds.".
503         @echo "^C to abort."
504         sleep 1
505         rm -rf /usr/obj/temp > /dev/null 2>& 1 || chflags -R noschg /usr/obj/temp
506         rm -rf /usr/obj/temp
507         mkdir -p /usr/obj/temp/cpdup/bin
508         (cd ${.CURDIR}/bin/cpdup; make clean && make obj && make clean && make CFLAGS=-static all install DESTDIR=/usr/obj/temp/cpdup NOMAN=TRUE)
509         @echo "XXXXXXXXX Installing to temporary XXXXXXXXX"
510         @sleep 1
511         (cd ${.CURDIR}; ${MAKE} installworld DESTDIR=/usr/obj/temp > /dev/null 2>&1)
512         @echo "XXXXXXXXX Blasting binaries and libraries XXXXXXXXX"
513         @sleep 1
514         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/bin /bin
515         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/sbin /sbin
516         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/lib /lib
517         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/bin /usr/bin
518         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/sbin /usr/sbin
519         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/lib /usr/lib
520         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/libexec /libexec
521         /usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/libexec /usr/libexec
522         @echo "XXXXXXXXX Doing final installworld XXXXXXXX"
523         sleep 5
524         (cd ${.CURDIR}; ${MAKE} installworld OVERRIDE_CHECKS=TRUE)
525         (cd ${.CURDIR}; ${MAKE} upgrade OVERRIDE_CHECKS=TRUE)
526
527 # Create a rescue image.  We no longer do this automatically for several
528 # reasons, primarily that users have had serious issue with mismatched 'vn'
529 # vs the kldload image that can crash the system.  But also, the rescue image
530 # is intended to be a rescue image, it is a bad idea to update it at the
531 # same time the world is installed.
532 #
533 rescue:
534         mkinitrd -b ${DESTDIR}/boot
535
536 #
537 # reinstall
538 #
539 # If you have a build server, you can NFS mount the source and obj directories
540 # and do a 'make reinstall' on the *client* to install new binaries from the
541 # most recent server build.
542 #
543 reinstall:
544         @echo "--------------------------------------------------------------"
545         @echo ">>> Making hierarchy"
546         @echo "--------------------------------------------------------------"
547         cd ${.CURDIR}; make -f Makefile.inc1 hierarchy
548         @echo
549         @echo "--------------------------------------------------------------"
550         @echo ">>> Installing everything.."
551         @echo "--------------------------------------------------------------"
552         cd ${.CURDIR}; make -f Makefile.inc1 install
553
554 #
555 # buildkernel, nativekernel, quickkernel, realquickkernel, and installkernel
556 #
557 # Which kernels to build and/or install is specified by setting
558 # KERNCONF. If not defined an X86_64_GENERIC kernel is built/installed.
559 # Only the existing (depending TARGET) config files are used
560 # for building kernels and only the first of these is designated
561 # as the one being installed.
562 #
563 # You can specify INSTALLSTRIPPED=1 if you wish the installed
564 # kernel and modules to be stripped of its debug info (required
565 # symbols are left intact).  You can specify INSTALLSTRIPPEDMODULES
566 # if you only want to strip the modules of their debug info.  These
567 # only apply if you have DEBUG=-g in your kernel config or make line.
568 #
569 # Note that we have to use TARGET instead of TARGET_ARCH when
570 # we're in kernel-land. Since only TARGET_ARCH is (expected) to
571 # be set to cross-build, we have to make sure TARGET is set
572 # properly.
573
574 .if !defined(KERNCONF) && defined(KERNEL)
575 KERNCONF=       ${KERNEL}
576 KERNWARN=       yes
577 .else
578 # XXX makeshift fix to build the right kernel for the (target) architecture
579 # We should configure this in the platform files somehow
580 .if ${TARGET_ARCH} == "x86_64"
581 KERNCONF?=      X86_64_GENERIC
582 .endif
583 .endif
584 INSTKERNNAME?=  kernel
585
586 KRNLSRCDIR=     ${.CURDIR}/sys
587 KRNLCONFDIR=    ${KRNLSRCDIR}/config
588 KRNLOBJDIR=     ${OBJTREE}${KRNLSRCDIR}
589 KERNCONFDIR?=   ${KRNLCONFDIR}
590
591 BUILDKERNELS=
592 INSTALLKERNEL=
593 .for _kernel in ${KERNCONF}
594 .if exists(${KERNCONFDIR}/${_kernel})
595 BUILDKERNELS+=  ${_kernel}
596 .if empty(INSTALLKERNEL)
597 INSTALLKERNEL= ${_kernel}
598 .endif
599 .endif
600 .endfor
601
602 # kernel version numbers survive rm -rf
603 #
604 .for _kernel in ${BUILDKERNELS}
605 .if exists(${KRNLOBJDIR}/${_kernel}/version)
606 KERNEL_VERSION_${_kernel} != cat ${KRNLOBJDIR}/${_kernel}/version
607 .endif
608 .endfor
609
610 #
611 # buildkernel
612 #
613 # Builds all kernels defined by BUILDKERNELS.
614 #
615 bk_tools:
616         @if [ ! -f ${WORLDDEST}/.libraries_done ]; then \
617             echo "You must buildworld before buildkernel.  If you wish"; \
618             echo "to build a kernel using native tools, config it manually"; \
619             echo "or use the nativekernel target if you are in a rush"; \
620             /usr/bin/false; \
621         fi
622
623 maybe_bk_tools:
624 .for _kernel in ${BUILDKERNELS}
625         @if [ ! -f ${KRNLOBJDIR}/${_kernel}/.nativekernel_run ]; then \
626             if [ ! -f ${WORLDDEST}/.libraries_done ]; then \
627                 echo "The kernel was build using buildworld tools which no" ; \
628                 echo "longer appear to exist, (real)quickkernel failed!" ; \
629                 /usr/bin/false; \
630             fi; \
631         fi
632 .endfor
633
634 bk_build_list:
635 .if empty(BUILDKERNELS)
636         @echo ">>> ERROR: Missing kernel configuration file(s)."
637         @echo ">>> ${KERNCONF} not found in ${KERNCONFDIR}."
638         @false
639 .endif
640
641 bk_kernwarn:
642 .if defined(KERNWARN)
643         @echo "--------------------------------------------------------------"
644         @echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF="
645         @echo "--------------------------------------------------------------"
646         @sleep 3
647 .endif
648         @echo
649
650 # The buildkernel target rebuilds the specified kernels from scratch
651 # using the crossbuild tools generated by the last buildworld.  It is
652 # the safest (but also the most time consuming) way to build a new kernel.
653 #
654 buildkernel:    bk_tools bk_build_list bk_kernwarn
655 .for _kernel in ${BUILDKERNELS}
656         @echo "--------------------------------------------------------------"
657         @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
658         @echo "--------------------------------------------------------------"
659         @echo "===> ${_kernel}"
660 .if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN)
661         rm -rf ${KRNLOBJDIR}/${_kernel}
662 .else
663         @if [ -f ${KRNLOBJDIR}/${_kernel}/.nativekernel_run ]; then \
664                 echo "YOU ARE REBUILDING WITH BUILDKERNEL, REMOVING OLD NATIVEKERNEL BUILD"; \
665                 rm -rf ${KRNLOBJDIR}/${_kernel}; fi
666 .endif
667         mkdir -p ${KRNLOBJDIR}
668 .if !defined(NO_KERNELCONFIG)
669         cd ${KRNLCONFDIR}; \
670                 PATH=${STRICTTMPPATH} \
671                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
672                         ${KERNCONFDIR}/${_kernel}
673 .endif
674 .if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN) && defined(KERNEL_VERSION_${_kernel})
675         echo ${KERNEL_VERSION_${_kernel}} > ${KRNLOBJDIR}/${_kernel}/version
676 .endif
677         touch ${KRNLOBJDIR}/${_kernel}/.buildkernel_run
678 .if !defined(NO_KERNELDEPEND)
679         cd ${KRNLOBJDIR}/${_kernel}; \
680             ${KMAKEENV} make KERNEL=${INSTKERNNAME} depend
681 .endif
682         cd ${KRNLOBJDIR}/${_kernel}; \
683             ${KMAKEENV} make KERNEL=${INSTKERNNAME} all
684         @echo "--------------------------------------------------------------"
685         @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
686         @echo "--------------------------------------------------------------"
687 .endfor
688
689 # The nativekernel target rebuilds the specified kernels from scratch
690 # using the system's standard compiler rather than using the crossbuild
691 # tools generated by the last buildworld.  This is fairly safe if your
692 # system is reasonable up-to-date.
693 #
694 nativekernel:   bk_build_list bk_kernwarn
695 .for _kernel in ${BUILDKERNELS}
696         @echo "--------------------------------------------------------------"
697         @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
698         @echo "--------------------------------------------------------------"
699         @echo "===> ${_kernel}"
700 .if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN)
701         rm -rf ${KRNLOBJDIR}/${_kernel}
702 .else
703         @if [ -f ${KRNLOBJDIR}/${_kernel}/.buildkernel_run ]; then \
704                 echo "YOU ARE REBUILDING WITH NATIVEKERNEL, REMOVING OLD BUILDKERNEL BUILD"; \
705                 rm -rf ${KRNLOBJDIR}/${_kernel}; fi
706 .endif
707         mkdir -p ${KRNLOBJDIR}
708 .if !defined(NO_KERNELCONFIG)
709         cd ${KRNLCONFDIR}; \
710                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
711                         ${KERNCONFDIR}/${_kernel}
712 .endif
713 .if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN) && defined(KERNEL_VERSION_${_kernel})
714         echo ${KERNEL_VERSION_${_kernel}} > ${KRNLOBJDIR}/${_kernel}/version
715 .endif
716         touch ${KRNLOBJDIR}/${_kernel}/.nativekernel_run
717 .if !defined(NO_KERNELDEPEND)
718         cd ${KRNLOBJDIR}/${_kernel}; \
719             make KERNEL=${INSTKERNNAME} depend
720 .endif
721         cd ${KRNLOBJDIR}/${_kernel}; \
722             make KERNEL=${INSTKERNNAME} all
723         @echo "--------------------------------------------------------------"
724         @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
725         @echo "--------------------------------------------------------------"
726 .endfor
727
728 # The (real)quickkernel target rebuilds the specified kernels as quickly
729 # as possible.  It will use the native tools or the buildworld cross tools
730 # based on whether the kernel was originally generated via buildkernel or
731 # nativekernel.  Config is rerun but the object hierarchy is not rebuilt.
732 # realquickkernel skips the depend step (analogous to realquickworld).
733 #
734 quickkernel realquickkernel:    maybe_bk_tools bk_build_list bk_kernwarn
735 .for _kernel in ${BUILDKERNELS}
736         @echo "--------------------------------------------------------------"
737         @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
738         @echo "--------------------------------------------------------------"
739         @echo "===> ${_kernel}"
740 .if exists(${KRNLOBJDIR}/${_kernel}/.buildkernel_run)
741 .if !defined(NO_KERNELCONFIG)
742         cd ${KRNLCONFDIR}; \
743                 PATH=${STRICTTMPPATH} \
744                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
745                         ${KERNCONFDIR}/${_kernel}
746 .endif
747 .if !defined(NO_KERNELDEPEND) && !make(realquickkernel)
748         cd ${KRNLOBJDIR}/${_kernel}; \
749             ${KMAKEENV} make KERNEL=${INSTKERNNAME} depend
750 .endif
751         cd ${KRNLOBJDIR}/${_kernel}; \
752             ${KMAKEENV} make KERNEL=${INSTKERNNAME} all
753 .else
754 .if !defined(NO_KERNELCONFIG)
755         cd ${KRNLCONFDIR}; \
756             config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
757                 ${KERNCONFDIR}/${_kernel}
758 .endif
759 .if !defined(NO_KERNELDEPEND) && !make(realquickkernel)
760         cd ${KRNLOBJDIR}/${_kernel}; \
761             make KERNEL=${INSTKERNNAME} depend
762 .endif
763         cd ${KRNLOBJDIR}/${_kernel}; \
764             make KERNEL=${INSTKERNNAME} all
765 .endif
766         @echo "--------------------------------------------------------------"
767         @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
768         @echo "--------------------------------------------------------------"
769 .endfor
770
771
772 # installkernel
773 #
774 # Install the kernel defined by INSTALLKERNEL
775 #
776 installkernel reinstallkernel:
777         @echo "--------------------------------------------------------------"
778         @echo ">>> Kernel install for ${INSTALLKERNEL} started on `LC_ALL=C date`"
779         @echo "--------------------------------------------------------------"
780 .if exists(${KRNLOBJDIR}/${INSTALLKERNEL}/.buildkernel_run)
781         cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
782             ${IMAKEENV} make KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//}
783 .else
784         cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
785             make KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//}
786 .endif
787         @echo "--------------------------------------------------------------"
788         @echo ">>> Kernel install for ${INSTALLKERNEL} completed on `LC_ALL=C date`"
789         @echo "--------------------------------------------------------------"
790
791 #
792 # most
793 #
794 # Build most of the user binaries on the existing system libs and includes.
795 #
796 most:
797         @echo "--------------------------------------------------------------"
798         @echo ">>> Building programs only"
799         @echo "--------------------------------------------------------------"
800 .for _dir in bin sbin libexec usr.bin usr.sbin gnu/libexec gnu/usr.bin gnu/usr.sbin
801         cd ${.CURDIR}/${_dir};          make DIRPRFX=${_dir}/ all
802 .endfor
803
804 #
805 # installmost
806 #
807 # Install the binaries built by the 'most' target.  This does not include
808 # libraries or include files.
809 #
810 installmost:
811         @echo "--------------------------------------------------------------"
812         @echo ">>> Installing programs only"
813         @echo "--------------------------------------------------------------"
814 .for _dir in bin sbin libexec usr.bin usr.sbin gnu/libexec gnu/usr.bin gnu/usr.sbin
815         cd ${.CURDIR}/${_dir};          make DIRPRFX=${_dir}/ install
816 .endfor
817
818 #
819 # ------------------------------------------------------------------------
820 #
821 # From here onwards are utility targets used by the 'make world' and
822 # related targets.  If your 'world' breaks, you may like to try to fix
823 # the problem and manually run the following targets to attempt to
824 # complete the build.  Beware, this is *not* guaranteed to work, you
825 # need to have a pretty good grip on the current state of the system
826 # to attempt to manually finish it.  If in doubt, 'make world' again.
827 #
828
829 # bootstrap-tools: Build all tools required to build all tools.  Note that
830 # order is important in a number of cases and also note that the bootstrap
831 # and build tools stages have access to earlier binaries they themselves
832 # had generated.
833 #
834 # patch:        older patch's do not have -i.  This program must be built
835 #               first so other bootstrap tools that need to apply patches
836 #               can use it.
837 # [x]install:   dependancies on various new install features
838 # rpcgen:       old rpcgen used a hardwired cpp path, newer OBJFORMAT_PATH
839 #               envs are not compatible with older objformat binaries.
840 #
841
842 # BSTRAPDIRS1 - must be built in strict order, no parallelism
843 #
844 # order is very important. yacc before m4 before flex.  flex exec's m4,
845 # m4's parser file needs the latest byacc (insanity!).
846 #
847 BSTRAPDIRS1= \
848         usr.bin/patch \
849         bin/chmod bin/cp bin/cpdup bin/dd bin/mkdir bin/rm bin/echo \
850         bin/test bin/cat bin/ln bin/mv bin/expr bin/sh \
851         bin/hostname bin/kill \
852         usr.bin/yacc usr.bin/m4 usr.bin/localedef \
853         usr.bin/uudecode usr.bin/xinstall \
854         usr.bin/rpcgen usr.bin/bmake usr.bin/awk usr.bin/stat \
855         usr.bin/find usr.bin/flex
856
857 # BSTRAPDIRS2 - may built in parallel
858 #
859 BSTRAPDIRS2= \
860         usr.bin/sed usr.bin/uname usr.bin/touch \
861         usr.bin/mkdep usr.bin/mktemp usr.bin/lorder usr.bin/file2c \
862         usr.bin/tsort usr.bin/tr usr.bin/join usr.bin/wc usr.bin/basename \
863         usr.bin/gencat usr.bin/chflags usr.bin/expand usr.bin/paste \
864         usr.bin/uuencode usr.bin/cap_mkdb usr.bin/true usr.bin/false \
865         usr.bin/cmp usr.bin/xargs usr.bin/id usr.bin/env usr.bin/dirname \
866         usr.bin/tail usr.bin/unifdef \
867         usr.sbin/chown usr.sbin/mtree usr.sbin/config \
868         usr.sbin/zic usr.sbin/makewhatis \
869         gnu/usr.bin/grep usr.bin/sort usr.bin/gzip \
870         usr.bin/mkcsmapper usr.bin/mkesdb usr.bin/crunch
871
872 bootstrap-tools: bootstrap-tools-before bootstrap-tools-targets1 bootstrap-tools-targets2
873         touch ${BTOOLSDEST}/.bootstrap_done
874
875 bootstrap-tools-before:
876         ${LN} -fs /bin/date ${BTOOLSDEST}/bin/date
877
878 bootstrap-tools-targets1: ${BSTRAPDIRS1:S/^/bstrap-/}
879
880 bootstrap-tools-targets2: ${BSTRAPDIRS2:S/^/bstrap-/}
881
882 .ORDER: bootstrap-tools-before bootstrap-tools-targets1 bootstrap-tools-targets2
883
884 .ORDER: ${BSTRAPDIRS1:S/^/bstrap-/}
885
886 .for _tool in ${BSTRAPDIRS1} ${BSTRAPDIRS2}
887 bstrap-${_tool}!
888         ${ECHODIR} "===> ${_tool} (bootstrap-tools)"; \
889                 cd ${.CURDIR}/${_tool}; \
890                 make DIRPRFX=${_tool}/ obj && \
891                 make DIRPRFX=${_tool}/ depend && \
892                 make DIRPRFX=${_tool}/ all && \
893                 make DIRPRFX=${_tool}/ DESTDIR=${BTOOLSDEST} install
894 .endfor
895
896 # build-tools: Build special purpose build tools.
897 #
898 # XXX we may be able to remove or consolidate this into bootstrap-tools
899 # now that we have the native helper (.nx/.no) infrastructure.
900 #
901 # XXX we should separate this into new Makefile.inc2.
902 # Just to prepare for reduction of ORDER: that slows down parallel crossworld.
903
904 # Make sure Makefile.inc1 logic is intact.
905 .if !defined(WORLD_ALTCOMPILER)
906 .warning undefined WORLD_ALTCOMPILER
907 .endif
908
909 _gcc_common_cross= lib/libz gnu/usr.bin/gmp gnu/usr.bin/mpfr gnu/usr.bin/mpc
910 _gcc50_cross= gnu/usr.bin/cc50
911 _gcc50_tools= gnu/usr.bin/cc50/cc_prep gnu/usr.bin/cc50/cc_tools
912 .if !defined(NO_ALTCOMPILER)
913 . if defined(WORLD_ALTCOMPILER) && (${WORLD_ALTCOMPILER} == "all" || ${WORLD_ALTCOMPILER:Mgcc47})
914 _gcc47_cross= gnu/usr.bin/cc47
915 _gcc47_tools= gnu/usr.bin/cc47/cc_prep gnu/usr.bin/cc47/cc_tools
916 _altcompiler_cross+= ${_gcc47_cross}
917 _altcompiler_tools+= _gcc47_tools
918 . endif
919 . if defined(WORLD_ALTCOMPILER) && (${WORLD_ALTCOMPILER} == "all" || ${WORLD_ALTCOMPILER:Mgcc80})
920 _gcc80_cross= gnu/usr.bin/cc80
921 _gcc80_tools= gnu/usr.bin/cc80/cc_prep gnu/usr.bin/cc80/cc_tools
922 _altcompiler_cross+= ${_gcc80_cross}
923 _altcompiler_tools+= _gcc80_tools
924 . endif
925 .endif
926 _custom_cross= libexec/customcc
927 _binutils= gnu/usr.bin/${WORLD_BINUTILSVER}
928
929 # XXX obsolete
930 .if 0
931 .for _atools in ${_altcompiler_tools}
932 BTOOLSDIRS+=    ${${_atools}}
933 .endfor
934 BTOOLSDIRS+=    ${_gcc50_tools}
935 .endif
936
937 build-tools: build-tools-targets
938         touch ${BTOOLSDEST}/.build_done
939
940 build-tools-targets: ${BTOOLSDIRS:S/^/btools-/}
941
942 .if 0
943 .for _atools in ${_altcompiler_tools}
944 .ORDER: ${${_atools}:C/^/btools-/}
945 .endfor
946 .ORDER: ${_gcc50_tools:S/^/btools-/}
947
948 .for _tool in ${BTOOLSDIRS}
949 btools-${_tool}!
950         ${ECHODIR} "===> ${_tool} (build-tools)"; \
951                 cd ${.CURDIR}/${_tool}; \
952                 make DIRPRFX=${_tool}/ obj && \
953                 make DIRPRFX=${_tool}/ depend && \
954                 make DIRPRFX=${_tool}/ all && \
955                 make DIRPRFX=${_tool}/ DESTDIR=${BTOOLSDEST} install
956 .endfor
957 .endif
958
959 #
960 # cross-tools: Build cross-building tools
961 #
962
963 CTOOLSDIRS= usr.bin/objformat usr.bin/crunch/crunchide
964
965 CTOOLSDIRS+=    ${_binutils} \
966                 ${_gcc_common_cross} \
967                 ${_altcompiler_cross} \
968                 ${_gcc50_cross} ${_custom_cross}
969
970 cross-tools: cross-tools-targets
971         touch ${CTOOLSDEST}/.cross_done
972
973 cross-tools-targets: ${CTOOLSDIRS:S/^/ctools-/}
974
975 .for _tool in ${CTOOLSDIRS}
976 ctools-${_tool}!
977         ${ECHODIR} "===> ${_tool} (cross-tools)"; \
978                 cd ${.CURDIR}/${_tool}; \
979                 make DIRPRFX=${_tool}/ obj && \
980                 make DIRPRFX=${_tool}/ depend && \
981                 make DIRPRFX=${_tool}/ all && \
982                 make DIRPRFX=${_tool}/ DESTDIR=${CTOOLSDEST} install
983 .endfor
984
985 #
986 # hierarchy - ensure that all the needed directories are present
987 #
988 hierarchy:
989         cd ${.CURDIR}/etc;              make distrib-dirs
990
991 #
992 # libraries - build all libraries, and install them under ${DESTDIR}.
993 #
994 # The list of libraries with dependents (${_prebuild_libs}) and their
995 # interdependencies (__L) are built automatically by the
996 # ${.CURDIR}/tools/make_libdeps.sh script.
997 #
998 # .makeenv does not work when bootstrapping from 4.x, so we must be sure
999 # to specify the correct CCVER or 'cc' will not exec the correct compiler.
1000 #
1001 libraries:
1002         cd ${.CURDIR}; \
1003             HOST_CCVER=${HOST_CCVER} CCVER=gcc50 \
1004                 make -f Makefile.inc1 _startup_libs50 -DSYSBUILD -DLIBGCC_ONLY;
1005 .if !defined(NO_ALTCOMPILER)
1006 . if defined(WORLD_ALTCOMPILER) && (${WORLD_ALTCOMPILER} == "all" || ${WORLD_ALTCOMPILER:Mgcc47})
1007         cd ${.CURDIR}; \
1008             HOST_CCVER=${HOST_CCVER} CCVER=gcc47 \
1009                 make -f Makefile.inc1 _startup_libs47 -DSYSBUILD -DLIBGCC_ONLY;
1010 . endif
1011 . if defined(WORLD_ALTCOMPILER) && (${WORLD_ALTCOMPILER} == "all" || ${WORLD_ALTCOMPILER:Mgcc80})
1012         cd ${.CURDIR}; \
1013             HOST_CCVER=${HOST_CCVER} CCVER=gcc80 \
1014                 make -f Makefile.inc1 _startup_libs80 -DSYSBUILD -DLIBGCC_ONLY;
1015 . endif
1016 .endif
1017         cd ${.CURDIR}; \
1018             make -f Makefile.inc1 _startup_libs -DSYSBUILD && \
1019             make -f Makefile.inc1 _prebuild_libs -DSYSBUILD && \
1020             make -f Makefile.inc1 _generic_libs -DSYSBUILD && \
1021             touch ${WORLDDEST}/.libraries_done
1022
1023 # These dependencies are not automatically generated:
1024 #
1025 # gnu/lib/${CCVER}/libgcc and gnu/lib/${CCVER}/csu must be built before all
1026 # shared libraries for ELF.  The target for _startup_libsXX is
1027 # specifically built using gccXX.
1028 #
1029 .if !defined(NO_ALTCOMPILER)
1030 _startup_libs47=        gnu/usr.bin/cc47/cc_prep \
1031                         gnu/usr.bin/cc47/cc_tools \
1032                         gnu/lib/gcc47/csu \
1033                         gnu/lib/gcc47/libgcc \
1034                         gnu/lib/gcc47/libgcc_eh \
1035                         gnu/lib/gcc47/libgcc_pic
1036 . if defined(WORLD_ALTCOMPILER) && (${WORLD_ALTCOMPILER} == "all" || ${WORLD_ALTCOMPILER:Mgcc47})
1037 _startup_libs_alt+=     _startup_libs47
1038 . endif
1039 .endif
1040 _startup_libs50=        gnu/usr.bin/cc50/cc_prep \
1041                         gnu/usr.bin/cc50/cc_tools \
1042                         gnu/lib/gcc50/csu \
1043                         gnu/lib/gcc50/libgcc \
1044                         gnu/lib/gcc50/libgcc_eh \
1045                         gnu/lib/gcc50/libgcc_pic
1046 _startup_libs80=        gnu/usr.bin/cc80/cc_prep \
1047                         gnu/usr.bin/cc80/cc_tools \
1048                         gnu/lib/gcc80/csu \
1049                         gnu/lib/gcc80/libgcc \
1050                         gnu/lib/gcc80/libgcc_eh \
1051                         gnu/lib/gcc80/libgcc_pic
1052 .if !defined(NO_ALTCOMPILER)
1053 . if defined(WORLD_ALTCOMPILER) && (${WORLD_ALTCOMPILER} == "all" || ${WORLD_ALTCOMPILER:Mgcc80})
1054 _startup_libs_alt+=     _startup_libs80
1055 . endif
1056 .endif
1057
1058 _startup_libs=          lib/csu lib/libc lib/libc_rtld
1059 lib/libc__L: lib/csu__L
1060
1061 _prebuild_libs=         lib/libbz2 lib/libz
1062 _prebuild_libs+=        lib/libutil
1063
1064 _prebuild_libs+=        lib/libelf
1065 _prebuild_libs+=        lib/libpcap
1066
1067 _generic_libs=  gnu/lib
1068
1069 _prebuild_libs+= lib/libcrypt lib/libmd \
1070                 lib/libncurses/libncurses
1071
1072 lib/libopie__L lib/libtacplus__L: lib/libmd__L
1073
1074 _generic_libs+= lib
1075
1076 _prebuild_libs+=        lib/librecrypto lib/libressl
1077 lib/libressl__L: lib/librecrypto__L
1078
1079 _prebuild_libs+=        lib/libssh
1080 lib/libssh__L: lib/librecrypto__L lib/libz__L
1081
1082 _prebuild_libs+=        lib/libradius lib/libopie
1083 lib/libradius__L: lib/librecrypto__L
1084 lib/libopie__L: lib/librecrypto__L
1085
1086 _prebuild_libs+= lib/libsbuf lib/libtacplus lib/libm \
1087                 lib/libpam/libpam lib/libypclnt lib/lib${THREAD_LIB} \
1088                 lib/libpthread lib/liblzma lib/libprop lib/libdevattr
1089 lib/liblzma__L: lib/libpthread__L
1090 lib/libdevattr__L: lib/libprop__L
1091
1092 _generic_libs+= usr.bin/flex/lib
1093
1094 .for _alib in ${_startup_libs_alt}
1095 __startup_alibs+= ${${_alib}}
1096 .endfor
1097
1098 .for _lib in ${__startup_alibs} ${_startup_libs50} \
1099                 ${_startup_libs} ${_prebuild_libs} ${_generic_libs}
1100 ${_lib}__L: .PHONY
1101 .if exists(${.CURDIR}/${_lib})
1102         @${ECHODIR} "===> ${_lib}"; \
1103                 cd ${.CURDIR}/${_lib}; \
1104                 echo "STEP DEP ${_lib}" && \
1105                 make DIRPRFX=${_lib}/ depend && \
1106                 echo "STEP ALL ${_lib}" && \
1107                 make DIRPRFX=${_lib}/ all && \
1108                 echo "STEP INSTALL ${_lib}" && \
1109                 make DIRPRFX=${_lib}/ install && \
1110                 echo "STEP DONE ${_lib}";
1111 .else
1112 .warning missing ${.CURDIR}/${_lib} directory.
1113 .endif
1114 .endfor
1115
1116 _startup_libs: ${_startup_libs:S/$/__L/}
1117 .for _alib in ${_startup_libs_alt}
1118 ${_alib}: ${${_alib}:C/$/__L/}
1119 .endfor
1120 _startup_libs50: ${_startup_libs50:S/$/__L/}
1121 _prebuild_libs: ${_prebuild_libs:S/$/__L/}
1122 _generic_libs: ${_generic_libs:S/$/__L/}
1123
1124 # library targets must be ordered because there are inter-library
1125 # races (e.g. generation of tconfig.h)
1126 #
1127 .for _alib in ${_startup_libs_alt}
1128 .ORDER: ${${_alib}:C/$/__L/}
1129 .endfor
1130 .ORDER: ${_startup_libs50:S/$/__L/}
1131 #.ORDER: ${_startup_libs:S/$/__L/}
1132
1133 # uncomment if there are missing dependencies
1134 .if 0
1135 .ORDER: ${_prebuild_libs:S/$/__L/}
1136 # we can disable this one, no lib/* depend on libstdc++
1137 .ORDER: ${_generic_libs:S/$/__L/}
1138 .endif
1139
1140 .for __target in clean cleandepend cleandir obj depend includes
1141 .for entry in ${SUBDIR}
1142 ${entry}.${__target}__D: .PHONY
1143         @if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1144                 ${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH}"; \
1145                 edir=${entry}.${MACHINE_ARCH}; \
1146                 cd ${.CURDIR}/$${edir}; \
1147         else \
1148                 ${ECHODIR} "===> ${DIRPRFX}${entry}"; \
1149                 edir=${entry}; \
1150                 cd ${.CURDIR}/$${edir}; \
1151         fi; \
1152         make ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1153 .endfor
1154 par-${__target}: ${SUBDIR:C/$/.${__target}__D/}
1155 .ORDER: ${SUBDIR:C/$/.${__target}__D/}
1156 .endfor
1157 .ORDER: par-clean par-cleandepend par-cleandir par-obj par-depend par-includes
1158
1159 # The wmake target is used by /usr/bin/wmake to run make in a
1160 # world build environment.
1161 #
1162 wmake:
1163         @echo '${WMAKEENV} make ${WMAKE_ARGS} -DSYSBUILD'
1164
1165 wmakeenv:
1166         @echo '${WMAKEENV} /bin/sh'
1167
1168 bmake:
1169         @echo '${BMAKEENV} make ${BMAKE_ARGS} -DSYSBUILD'
1170
1171 bmakeenv:
1172         @echo '${BMAKEENV} /bin/sh'
1173
1174 tmake:
1175         @echo '${TMAKEENV} make ${TMAKE_ARGS} -DSYSBUILD'
1176
1177 tmakeenv:
1178         @echo '${TMAKEENV} /bin/sh'
1179
1180 xmake:
1181         @echo '${XMAKEENV} make ${XMAKE_ARGS} -DSYSBUILD'
1182
1183 xmakeenv:
1184         @echo '${XMAKEENV} /bin/sh'
1185
1186 backupworld: backup-clean
1187         @mkdir -p ${WORLD_BACKUP}
1188 .if (exists(${DESTDIR}/sbin) && exists(${DESTDIR}/bin) && \
1189      exists(${DESTDIR}/usr/sbin) && exists(${DESTDIR}/usr/bin) && \
1190      exists(${DESTDIR}/usr/lib) && exists(${DESTDIR}/usr/libexec))
1191         tar -czf ${WORLD_BACKUP}/binaries.tar.gz -C ${DESTDIR}/ \
1192                 --options gzip:compression-level=1 \
1193                 sbin bin usr/sbin usr/bin usr/lib usr/libexec
1194 .endif
1195
1196 backupworld-auto:
1197 .if !defined(NO_BACKUP)
1198         rm -f ${AUTO_BACKUP}/binaries.tar.gz
1199         @mkdir -p ${AUTO_BACKUP}
1200 .if (exists(${DESTDIR}/sbin) && exists(${DESTDIR}/bin) && \
1201      exists(${DESTDIR}/usr/sbin) && exists(${DESTDIR}/usr/bin) && \
1202      exists(${DESTDIR}/usr/lib) && exists(${DESTDIR}/usr/libexec))
1203         /usr/bin/tar -czf ${AUTO_BACKUP}/binaries.tar.gz -C ${DESTDIR}/ \
1204                 --options gzip:compression-level=1 \
1205                 sbin bin usr/sbin usr/bin usr/lib usr/libexec
1206 .endif
1207 .endif
1208
1209 backup-auto-clean:
1210         rm -f ${AUTO_BACKUP}/binaries.tar.gz
1211
1212 backup-clean:
1213         rm -f ${WORLD_BACKUP}/binaries.tar.gz
1214
1215 restoreworld:
1216 .if !exists(${WORLD_BACKUP}/binaries.tar.gz)
1217         @echo "There does not seem to be a valid archive present."
1218 .else
1219         @echo "Restoring system binaries from manual backup archive..."
1220         @chflags -R noschg ${DESTDIR}/sbin ${DESTDIR}/bin \
1221                 ${DESTDIR}/usr/sbin ${DESTDIR}/usr/bin \
1222                 ${DESTDIR}/usr/lib ${DESTDIR}/usr/libexec
1223         tar -xzf ${WORLD_BACKUP}/binaries.tar.gz -C ${DESTDIR}/
1224 .endif
1225
1226 restoreworld-auto:
1227 .if !exists(${AUTO_BACKUP}/binaries.tar.gz)
1228         @echo "There does not seem to be a valid archive present."
1229 .else
1230         @echo "Restoring system binaries from auto-backup archive..."
1231         @chflags -R noschg ${DESTDIR}/sbin ${DESTDIR}/bin \
1232                 ${DESTDIR}/usr/sbin ${DESTDIR}/usr/bin \
1233                 ${DESTDIR}/usr/lib ${DESTDIR}/usr/libexec
1234         tar -xzf ${AUTO_BACKUP}/binaries.tar.gz -C ${DESTDIR}/
1235 .endif
1236
1237 # Take advantage of bmake error response
1238 #
1239 MAKE_PRINT_VAR_ON_ERROR= \
1240         .CURDIR \
1241         .OBJDIR \
1242         LD_LIBRARY_PATH \
1243         MACHINE_ARCH \
1244         MACHINE \
1245         MAKEFILE \
1246         WORLD_ALTCOMPILER \
1247         .TARGETS \
1248         .ERROR_TARGET \
1249         .MAKE.LEVEL
1250
1251 .include <bsd.subdir.mk>