Allow building of crosstools and world with different compilers.
[dragonfly.git] / Makefile.inc1
1 #
2 # $FreeBSD: src/Makefile.inc1,v 1.141.2.62 2003/04/06 19:54:00 dwmalone Exp $
3 # $DragonFly: src/Makefile.inc1,v 1.118 2008/06/24 20:22:30 thomas Exp $
4 #
5 # Build-time options are documented in make.conf(5).
6 #
7 # The intended user-driven targets are:
8 #
9 # buildworld  - rebuild *everything*, including glue to help do upgrades
10 # quickworld  - skip the glue and do a depend+build on the meat
11 # realquickworld - skip the glue and depend stages and just build the meat
12 # crossworld  - only build the glue (particularly the cross-build environment)
13 # installworld- install everything built by "buildworld"
14 # most        - build user commands, no libraries or include files
15 # installmost - install user commands, no libraries or include files
16 #
17 # Standard targets (not defined here) are documented in the makefiles in
18 # /usr/share/mk.  These include:
19 #               obj depend all install clean cleandepend cleanobj
20
21 # Put initial settings here.
22 SUBDIR=
23
24 # We must do share/info early so that installation of info `dir'
25 # entries works correctly.  Do it first since it is less likely to
26 # grow dependencies on include and lib than vice versa.
27 .if exists(${.CURDIR}/share/info)
28 SUBDIR+= share/info
29 .endif
30
31 # We must do include and lib early so that the perl *.ph generation
32 # works correctly as it uses the header files installed by this.
33 .if exists(${.CURDIR}/include)
34 SUBDIR+= include
35 .endif
36 .if exists(${.CURDIR}/lib)
37 SUBDIR+= lib
38 .endif
39 # This exists simply to ensure that the obj dir hierarchy is
40 # intact for nrelease, allowing the nrelease Makefile's to 
41 # reference ${.OBJDIR}.
42 #
43 .if exists(${.CURDIR}/nrelease)
44 SUBDIR+= nrelease
45 .endif
46
47 .if exists(${.CURDIR}/bin)
48 SUBDIR+= bin
49 .endif
50 .if exists(${.CURDIR}/games) && !defined(NO_GAMES)
51 SUBDIR+= games
52 .endif
53 .if exists(${.CURDIR}/gnu)
54 SUBDIR+= gnu
55 .endif
56 .if exists(${.CURDIR}/kerberos5) && exists(${.CURDIR}/crypto) && \
57     !defined(NO_CRYPT) && !defined(NO_OPENSSL) && defined(WANT_KERBEROS)
58 SUBDIR+= kerberos5
59 .endif
60 .if exists(${.CURDIR}/libexec)
61 SUBDIR+= libexec
62 .endif
63 .if exists(${.CURDIR}/sbin)
64 SUBDIR+= sbin
65 .endif
66 .if exists(${.CURDIR}/secure) && !defined(NO_CRYPT)
67 SUBDIR+= secure
68 .endif
69 .if exists(${.CURDIR}/share) && !defined(NO_SHARE)
70 SUBDIR+= share
71 .endif
72 .if exists(${.CURDIR}/sys)
73 SUBDIR+= sys
74 .endif
75 .if exists(${.CURDIR}/usr.bin)
76 SUBDIR+= usr.bin
77 .endif
78 .if exists(${.CURDIR}/usr.sbin)
79 SUBDIR+= usr.sbin
80 .endif
81
82 # etc must be last for "distribute" to work
83 .if exists(${.CURDIR}/etc)
84 SUBDIR+= etc
85 .endif
86
87 # These are last, since it is nice to at least get the base system
88 # rebuilt before you do them.
89 .if defined(LOCAL_DIRS)
90 .for _DIR in ${LOCAL_DIRS}
91 .if exists(${.CURDIR}/${_DIR}) & exists(${.CURDIR}/${_DIR}/Makefile)
92 SUBDIR+= ${_DIR}
93 .endif
94 .endfor
95 .endif
96
97 .if defined(SUBDIR_OVERRIDE)
98 SUBDIR=         ${SUBDIR_OVERRIDE}
99 .endif
100
101 .if defined(NOCLEANDIR)
102 CLEANDIR=       clean cleandepend
103 .else
104 CLEANDIR=       cleandir
105 .endif
106
107 .if defined(NO_CLEAN)
108 NOCLEAN=        # defined
109 .endif
110
111 # Object directory base in primary make.  Note that when we rerun make
112 # from inside this file we change MAKEOBJDIRPREFIX to the appropriate
113 # subdirectory because the rest of the build system needs it that way.
114 # The original object directory base is saved in OBJTREE.
115 #
116 MAKEOBJDIRPREFIX?=      /usr/obj
117 OBJTREE?=               ${MAKEOBJDIRPREFIX}
118
119 # Used for stage installs and pathing
120 #
121 DESTDIRBASE?=           ${OBJTREE}${.CURDIR}
122
123 # Remove DESTDIR from MAKEFLAGS.  It is present in the environment
124 # anyhow, and we need to be able to override it for stage installs
125 .MAKEFLAGS:=    ${.MAKEFLAGS:NDESTDIR=*}
126
127 WORLD_CCVER?=   ${CCVER}
128
129 TARGET_ARCH?=   ${MACHINE_ARCH}
130 .if ${TARGET_ARCH} == ${MACHINE_ARCH}
131 TARGET?=        ${MACHINE}
132 .else
133 TARGET?=        ${TARGET_ARCH}
134 .endif
135 .if make(buildworld)
136 BUILD_ARCH!=    sysctl -n hw.machine_arch
137 .if ${MACHINE_ARCH} != ${BUILD_ARCH}
138 .error To cross-build, set TARGET_ARCH.
139 .endif
140 .endif
141
142 # Backwards compatibility with older make's or older sys.mk's.  make
143 # is expected to define MACHINE_PLATFORM.
144 #
145 .if !defined(MACHINE_PLATFORM)
146 MACHINE_PLATFORM= pc32
147 .endif
148
149 # XXX this is ugly and we need to come up with a nicer solution
150 .if !defined(TARGET_PLATFORM)
151 .if ${TARGET_ARCH} == "i386"
152 TARGET_PLATFORM= pc32
153 .elif ${TARGET_ARCH} == "amd64"
154 TARGET_PLATFORM= pc64
155 .else
156 .error Unknown target architecture.
157 .endif
158 .endif
159
160 THREAD_LIB?=    thread_xu
161 .if ${THREAD_LIB} == "c_r"
162 .if defined(NO_LIBC_R)
163 .error libc_r is chosen as the default thread library, but NO_LIBC_R is defined
164 .endif
165 .endif
166
167 # BTOOLS        (Natively built) All non-cross-development tools that the
168 #               main build needs.  This includes things like 'mkdir' and 'rm'.
169 #               We will not use the native system's exec path once we start
170 #               on WORLD.  (bootstrap-tools and build-tools or BTOOLS)
171 #
172 # CTOOLS        (Natively built) Cross development tools which are specific
173 #               to the target architecture.
174 #
175 # WORLD         (Cross built) Our ultimate buildworld, using only BTOOLS and
176 #               CTOOLS.
177 #
178 # MACHINE_PLATFORM Platform Architecture we are building on
179 # MACHINE       Machine Architecture (usually the same as MACHINE_ARCH)
180 # MACHINE_ARCH  Cpu Architecture we are building on
181 #
182 # TARGET_PLATFORM Platform Architecture we are building for
183 # TARGET        Machine Architecture we are building for
184 # TARGET_ARCH   Cpu Architecture we are building for
185 #
186 BTOOLSDEST=     ${DESTDIRBASE}/btools_${MACHINE_ARCH}
187 CTOOLSDEST=     ${DESTDIRBASE}/ctools_${MACHINE_ARCH}_${TARGET_ARCH}
188 WORLDDEST=      ${DESTDIRBASE}/world_${TARGET_ARCH}
189
190 # The bootstrap-tools path is used by the bootstrap-tools, build-tools, and
191 # cross-tools stages to augment the existing command path to access newer
192 # versions of certain utilities such as 'patch' that the cross-tools stage
193 # might expect.
194 #
195 BTOOLSPATH= ${BTOOLSDEST}/usr/sbin:${BTOOLSDEST}/usr/bin:${BTOOLSDEST}/bin:${BTOOLSDEST}/usr/games
196
197 # The strict temporary command path contains all binaries required
198 # by the buildworld system after the cross-tools stage.
199 #
200 STRICTTMPPATH=  ${CTOOLSDEST}/usr/sbin:${CTOOLSDEST}/usr/bin:${CTOOLSDEST}/bin:${CTOOLSDEST}/usr/games:${BTOOLSDEST}/usr/sbin:${BTOOLSDEST}/usr/bin:${BTOOLSDEST}/bin:${BTOOLSDEST}/usr/games
201
202 TMPDIR?=        /tmp
203 TMPPID!=        echo $$$$
204
205 #
206 # Building a world goes through the following stages
207 #
208 # 1. bootstrap-tool stage [BMAKE]
209 #       This stage is responsible for creating programs that
210 #       are needed for backward compatibility reasons. They
211 #       are not built as cross-tools.
212 # 2. build-tool stage [TMAKE]
213 #       This stage is responsible for creating the object
214 #       tree and building any tools that are needed during
215 #       the build process.
216 # 3. cross-tool stage [XMAKE]
217 #       This stage is responsible for creating any tools that
218 #       are needed for cross-builds. A cross-compiler is one
219 #       of them.
220 # 4. world stage [WMAKE]
221 #       This stage actually builds the world.
222 # 5. install stage (optional) [IMAKE]
223 #       This stage installs a previously built world.
224 #
225
226 # bootstrap-tool stage
227 #
228 BMAKEENV=       MAKEOBJDIRPREFIX=${BTOOLSDEST} \
229                 OBJTREE=${OBJTREE} \
230                 DESTDIR=${BTOOLSDEST} \
231                 PATH=${BTOOLSPATH}:${PATH} \
232                 INSTALL="sh ${.CURDIR}/tools/install.sh"
233
234 BMAKE=          ${BMAKEENV} ${MAKE} -f Makefile.inc1 -DBOOTSTRAPPING \
235                 -DNOINFO -DNOMAN -DNOPIC -DNOPROFILE -DNOSHARED \
236                 -DNO_WERROR -DNO_NLS
237
238 # build-tool stage
239 #
240 TMAKEENV=       MAKEOBJDIRPREFIX=${BTOOLSDEST} \
241                 OBJTREE=${OBJTREE} \
242                 DESTDIR= \
243                 PATH=${BTOOLSPATH}:${PATH} \
244                 INSTALL="sh ${.CURDIR}/tools/install.sh"
245
246 TMAKE=          ${TMAKEENV} ${MAKE} -f Makefile.inc1 -DBOOTSTRAPPING \
247                 -DNO_FORTRAN -DNOSHARED
248
249 # cross-tool stage
250 #
251 # note: TOOLS_PREFIX points to the obj root holding the cross
252 #       compiler binaries, while USRDATA_PREFIX points to the obj root 
253 #       holding the target environment (and also determines where cross-built
254 #       libraries, crt*.o, and include files are installed).
255 #
256 XMAKEENV=       MAKEOBJDIRPREFIX=${CTOOLSDEST} \
257                 OBJTREE=${OBJTREE} \
258                 DESTDIR=${CTOOLSDEST} \
259                 INSTALL="sh ${.CURDIR}/tools/install.sh" \
260                 TOOLS_PREFIX=${CTOOLSDEST} \
261                 USRDATA_PREFIX=${WORLDDEST} \
262                 PATH=${BTOOLSPATH}:${PATH}
263
264 XMAKE=          ${XMAKEENV} ${MAKE} -f Makefile.inc1 -DNO_FORTRAN -DNO_GDB \
265                 -DBOOTSTRAPPING -DNOSHARED
266
267 # world stage, note the strict path and note that TOOLS_PREFIX is left
268 # unset and USRDATA_PREFIX (which defaults to TOOLS_PREFIX) is set to empty,
269 # which is primarily for the compiler so it targets / (e.g. /usr/<blah>)
270 # for both binary and library paths, even though it is being compiled to
271 # WORLDDEST.  None of the programs in the world stage are ever actually
272 # executed during the buildworld/installworld.
273 #
274 CROSSENV=       MAKEOBJDIRPREFIX=${WORLDDEST} \
275                 OBJTREE=${OBJTREE} \
276                 MACHINE_ARCH=${TARGET_ARCH} \
277                 MACHINE=${TARGET} \
278                 MACHINE_PLATFORM=${TARGET_PLATFORM} \
279                 OBJFORMAT_PATH=${CTOOLSDEST} \
280                 CCVER=${WORLD_CCVER}
281
282 WMAKEENV=       ${CROSSENV} \
283                 DESTDIR=${WORLDDEST} \
284                 INSTALL="sh ${.CURDIR}/tools/install.sh" \
285                 PATH=${STRICTTMPPATH}
286
287 WMAKE=          ${WMAKEENV} ${MAKE} -f Makefile.inc1
288
289 # install stage
290 #
291 IMAKEENV=       ${CROSSENV} \
292                 PATH=${STRICTTMPPATH}
293 IMAKE=          ${IMAKEENV} ${MAKE} -f Makefile.inc1
294
295 # kernel stage
296 #
297 KMAKEENV=       ${WMAKEENV}
298
299 # buildworld
300 #
301 # Attempt to rebuild the entire system, with reasonable chance of
302 # success, regardless of how old your existing system is.
303 #
304 _worldtmp:
305         @echo
306         @echo "--------------------------------------------------------------"
307         @echo ">>> Rebuilding the temporary build tree"
308         @echo "--------------------------------------------------------------"
309 .if !defined(NOCLEAN)
310         rm -rf ${BTOOLSDEST} ${CTOOLSDEST} ${WORLDDEST}
311 .else
312         # XXX - These two can depend on any header file.
313         rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
314         rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
315 .endif
316         mkdir -p ${DESTDIRBASE} ${BTOOLSDEST} ${CTOOLSDEST} ${WORLDDEST}
317 .for _dir in ${WORLDDEST} ${BTOOLSDEST} ${CTOOLSDEST}
318         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist        \
319                 -p ${_dir}/  > /dev/null
320         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist         \
321                 -p ${_dir}/usr > /dev/null
322 .endfor
323         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist     \
324                 -p ${WORLDDEST}/usr/include > /dev/null
325         ${LN} -sf ${.CURDIR}/sys ${WORLDDEST}
326
327 _bootstrap-tools:
328         @echo
329         @echo "--------------------------------------------------------------"
330         @echo ">>> stage 1: bootstrap tools"
331         @echo "--------------------------------------------------------------"
332         cd ${.CURDIR}; ${BMAKE} bootstrap-tools
333 _cleanobj:
334         @echo
335         @echo "--------------------------------------------------------------"
336         @echo ">>> stage 2a: cleaning up the object tree"
337         @echo "--------------------------------------------------------------"
338         cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
339 _obj:
340         @echo
341         @echo "--------------------------------------------------------------"
342         @echo ">>> stage 2b: rebuilding the object tree"
343         @echo "--------------------------------------------------------------"
344         cd ${.CURDIR}; ${WMAKE} par-obj
345 _build-tools:
346         @echo
347         @echo "--------------------------------------------------------------"
348         @echo ">>> stage 2c: build tools"
349         @echo "--------------------------------------------------------------"
350         cd ${.CURDIR}; ${TMAKE} build-tools
351 _cross-tools:
352         @echo
353         @echo "--------------------------------------------------------------"
354         @echo ">>> stage 3: cross tools"
355         @echo "--------------------------------------------------------------"
356         cd ${.CURDIR}; ${XMAKE} cross-tools
357 _includes:
358         @echo
359         @echo "--------------------------------------------------------------"
360         @echo ">>> stage 4a: populating ${WORLDDEST}/usr/include"
361         @echo "--------------------------------------------------------------"
362         cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
363 _libraries:
364         @echo
365         @echo "--------------------------------------------------------------"
366         @echo ">>> stage 4b: building libraries"
367         @echo "--------------------------------------------------------------"
368         cd ${.CURDIR}; ${WMAKE} -DNOHTML -DNOINFO -DNOMAN -DNOFSCHG libraries
369 _depend:
370         @echo
371         @echo "--------------------------------------------------------------"
372         @echo ">>> stage 4c: make dependencies"
373         @echo "--------------------------------------------------------------"
374         cd ${.CURDIR}; ${WMAKE} par-depend
375 everything:
376         @echo
377         @echo "--------------------------------------------------------------"
378         @echo ">>> stage 4d: building everything.."
379         @echo "--------------------------------------------------------------"
380         cd ${.CURDIR}; ${WMAKE} all
381
382 # note: buildworld no longer depends on _cleanobj because we rm -rf the
383 # entire object tree and built the bootstrap tools in a different location.
384 #
385 # buildworld    - build everything from scratch
386 # quickworld    - skip the bootstrap, build, and cross-build steps
387 # realquickworld - skip the bootstrap, build, crossbuild, and depend step.
388 #
389 # note: we include _obj in realquickworld to prevent accidental creation
390 # of files in /usr/src.
391
392 WMAKE_TGTS=
393 .if !defined(SUBDIR_OVERRIDE)
394 WMAKE_TGTS+=    _worldtmp _bootstrap-tools
395 .endif
396 WMAKE_TGTS+=    _obj _build-tools
397 .if !defined(SUBDIR_OVERRIDE)
398 WMAKE_TGTS+=    _cross-tools
399 .endif
400 WMAKE_TGTS+=    _includes _libraries _depend everything
401
402 buildworld: ${WMAKE_TGTS}
403
404 quickworld: _obj _includes _libraries _depend everything
405
406 realquickworld: _obj _includes _libraries everything
407
408 crossworld: _worldtmp _bootstrap-tools _obj _build-tools _cross-tools
409
410 .ORDER: ${WMAKE_TGTS}
411
412 #
413 # installcheck
414 #
415 # Checks to be sure system is ready for installworld
416 #
417 installcheck:
418 .if !defined(NO_SENDMAIL)
419         @pw usershow smmsp || (echo "You may need to run 'make preupgrade' first"; exit 1)
420         @pw groupshow smmsp || (echo "You may need to run 'make preupgrade' first"; exit 1)
421 .endif
422         @pw usershow _pflogd || (echo "You may need to run 'make preupgrade' first"; exit 1)
423         @pw groupshow authpf || (echo "You may need to run 'make preupgrade' first"; exit 1)
424         @pw groupshow _pflogd || (echo "You may need to run 'make preupgrade' first"; exit 1)
425 .if !defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/"
426         @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" ; exit 1;; esac
427 .endif
428 # distributeworld
429 #
430 # Distributes everything compiled by a `buildworld'.
431 #
432 # installworld
433 #
434 # Installs everything compiled by a 'buildworld'.
435 #
436 distributeworld installworld: installcheck
437         cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}
438         ${INSTALL} -o root -g wheel -m 644 ${.CURDIR}/Makefile_upgrade.inc ${DESTDIR}/etc/upgrade/
439
440 #
441 # reinstall
442 #
443 # If you have a build server, you can NFS mount the source and obj directories
444 # and do a 'make reinstall' on the *client* to install new binaries from the
445 # most recent server build.
446 #
447 reinstall:
448         @echo "--------------------------------------------------------------"
449         @echo ">>> Making hierarchy"
450         @echo "--------------------------------------------------------------"
451         cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 hierarchy
452         @echo
453         @echo "--------------------------------------------------------------"
454         @echo ">>> Installing everything.."
455         @echo "--------------------------------------------------------------"
456         cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
457 .if !defined(NOMAN) && !defined(NO_MAKEDB_RUN)
458         @echo
459         @echo "--------------------------------------------------------------"
460         @echo ">>> Rebuilding man page indices"
461         @echo "--------------------------------------------------------------"
462         cd ${.CURDIR}/share/man; ${MAKE} makedb
463 .endif
464
465 redistribute:
466         @echo "--------------------------------------------------------------"
467         @echo ">>> Distributing everything.."
468         @echo "--------------------------------------------------------------"
469         cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
470
471 #
472 # buildkernel, nativekernel, quickkernel, and installkernel
473 #
474 # Which kernels to build and/or install is specified by setting
475 # KERNCONF. If not defined a GENERIC kernel is built/installed.
476 # Only the existing (depending TARGET) config files are used
477 # for building kernels and only the first of these is designated
478 # as the one being installed.
479 #
480 # You can specify INSTALLSTRIPPED=1 if you wish the installed 
481 # kernel and modules to be stripped of its debug info (required
482 # symbols are left intact).  You can specify INSTALLSTRIPPEDMODULES
483 # if you only want to strip the modules of their debug info.  These
484 # only apply if you have DEBUG=-g in your kernel config or make line.
485 #
486 # Note that we have to use TARGET instead of TARGET_ARCH when
487 # we're in kernel-land. Since only TARGET_ARCH is (expected) to
488 # be set to cross-build, we have to make sure TARGET is set
489 # properly.
490
491 .if !defined(KERNCONF) && defined(KERNEL)
492 KERNCONF=       ${KERNEL}
493 KERNWARN=       yes
494 .else
495 KERNCONF?=      GENERIC
496 .endif
497 INSTKERNNAME?=  kernel
498
499 KRNLSRCDIR=     ${.CURDIR}/sys
500 KRNLCONFDIR=    ${KRNLSRCDIR}/config
501 KRNLOBJDIR=     ${OBJTREE}${KRNLSRCDIR}
502 KERNCONFDIR?=   ${KRNLCONFDIR}
503
504 BUILDKERNELS=
505 INSTALLKERNEL=
506 .for _kernel in ${KERNCONF}
507 .if exists(${KERNCONFDIR}/${_kernel})
508 BUILDKERNELS+=  ${_kernel}
509 .if empty(INSTALLKERNEL)
510 INSTALLKERNEL= ${_kernel}
511 .endif
512 .endif
513 .endfor
514
515 # kernel version numbers survive rm -rf
516 #
517 .for _kernel in ${BUILDKERNELS}
518 .if exists(${KRNLOBJDIR}/${_kernel}/version)
519 KERNEL_VERSION_${_kernel} != cat ${KRNLOBJDIR}/${_kernel}/version
520 .endif
521 .endfor
522
523 #
524 # buildkernel
525 #
526 # Builds all kernels defined by BUILDKERNELS.
527 #
528 bk_tools:
529         @if [ ! -f ${WORLDDEST}/.libraries_done ]; then \
530             echo "You must buildworld before buildkernel.  If you wish"; \
531             echo "to build a kernel using native tools, config it manually"; \
532             echo "or use the nativekernel target if you are in a rush"; \
533             exit 1; \
534         fi
535
536 maybe_bk_tools:
537 .for _kernel in ${BUILDKERNELS}
538         @if [ ! -f ${KRNLOBJDIR}/${_kernel}/.nativekernel_run ]; then \
539             if [ ! -f ${WORLDDEST}/.libraries_done ]; then \
540                 echo "The kernel was build using buildworld tools which no" ; \
541                 echo "longer appear to exist, quickkernel failed!" ; \
542                 exit 1; \
543             fi; \
544         fi
545 .endfor
546
547 bk_build_list:
548 .if empty(BUILDKERNELS)
549         @echo ">>> ERROR: Missing kernel configuration file(s) (${KERNCONF})."
550         @echo ">>> Did you move your kernel configs from i386/conf to config/?"
551         @false
552 .endif
553
554 bk_kernwarn:
555 .if defined(KERNWARN)
556         @echo "--------------------------------------------------------------"
557         @echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF="
558         @echo "--------------------------------------------------------------"
559         @sleep 3
560 .endif
561         @echo
562
563 # The buildkernel target rebuilds the specified kernels from scratch
564 # using the crossbuild tools generated by the last buildworld.  It is
565 # the safest (but also the most time consuming) way to build a new kernel.
566 #
567 buildkernel:    bk_tools bk_build_list bk_kernwarn
568 .for _kernel in ${BUILDKERNELS}
569         @echo "--------------------------------------------------------------"
570         @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
571         @echo "--------------------------------------------------------------"
572         @echo "===> ${_kernel}"
573 .if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN)
574         rm -rf ${KRNLOBJDIR}/${_kernel}
575 .else
576         @if [ -f ${KRNLOBJDIR}/${_kernel}/.nativekernel_run ]; then \
577                 echo "YOU ARE REBUILDING WITH BUILDKERNEL, REMOVING OLD NATIVEKERNEL BUILD"; \
578                 rm -rf ${KRNLOBJDIR}/${_kernel}; fi
579 .endif
580         mkdir -p ${KRNLOBJDIR}
581 .if !defined(NO_KERNELCONFIG)
582         cd ${KRNLCONFDIR}; \
583                 PATH=${STRICTTMPPATH} \
584                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
585                         ${KERNCONFDIR}/${_kernel}
586 .endif
587 .if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN) && defined(KERNEL_VERSION_${_kernel})
588         echo ${KERNEL_VERSION_${_kernel}} > ${KRNLOBJDIR}/${_kernel}/version
589 .endif
590         touch ${KRNLOBJDIR}/${_kernel}/.buildkernel_run
591         cd ${KRNLOBJDIR}/${_kernel}; \
592             MAKESRCPATH=${KRNLSRCDIR}/dev/disk/aic7xxx/aicasm \
593             ${MAKE} -DBOOTSTRAPPING -f ${KRNLSRCDIR}/dev/disk/aic7xxx/aicasm/Makefile
594 .if !defined(NO_KERNELDEPEND)
595         cd ${KRNLOBJDIR}/${_kernel}; \
596             ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} depend
597 .endif
598         cd ${KRNLOBJDIR}/${_kernel}; \
599             ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} all
600         @echo "--------------------------------------------------------------"
601         @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
602         @echo "--------------------------------------------------------------"
603 .endfor
604
605 # The nativekernel target rebuilds the specified kernels from scratch
606 # using the system's standard compiler rather than using the crossbuild
607 # tools generated by the last buildworld.  This is fairly safe if your
608 # system is reasonable up-to-date.
609 #
610 nativekernel:   bk_build_list bk_kernwarn
611 .for _kernel in ${BUILDKERNELS}
612         @echo "--------------------------------------------------------------"
613         @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
614         @echo "--------------------------------------------------------------"
615         @echo "===> ${_kernel}"
616 .if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN)
617         rm -rf ${KRNLOBJDIR}/${_kernel}
618 .else
619         @if [ -f ${KRNLOBJDIR}/${_kernel}/.buildkernel_run ]; then \
620                 echo "YOU ARE REBUILDING WITH NATIVEKERNEL, REMOVING OLD BUILDKERNEL BUILD"; \
621                 rm -rf ${KRNLOBJDIR}/${_kernel}; fi
622 .endif
623         mkdir -p ${KRNLOBJDIR}
624 .if !defined(NO_KERNELCONFIG)
625         cd ${KRNLCONFDIR}; \
626                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
627                         ${KERNCONFDIR}/${_kernel}
628 .endif
629 .if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN) && defined(KERNEL_VERSION_${_kernel})
630         echo ${KERNEL_VERSION_${_kernel}} > ${KRNLOBJDIR}/${_kernel}/version
631 .endif
632         touch ${KRNLOBJDIR}/${_kernel}/.nativekernel_run
633         cd ${KRNLOBJDIR}/${_kernel}; \
634             MAKESRCPATH=${KRNLSRCDIR}/dev/disk/aic7xxx/aicasm \
635             ${MAKE} -DBOOTSTRAPPING -f ${KRNLSRCDIR}/dev/disk/aic7xxx/aicasm/Makefile
636 .if !defined(NO_KERNELDEPEND)
637         cd ${KRNLOBJDIR}/${_kernel}; \
638             ${MAKE} KERNEL=${INSTKERNNAME} depend
639 .endif
640         cd ${KRNLOBJDIR}/${_kernel}; \
641             ${MAKE} KERNEL=${INSTKERNNAME} all
642         @echo "--------------------------------------------------------------"
643         @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
644         @echo "--------------------------------------------------------------"
645 .endfor
646
647 # The quickkernel target rebuilds the specified kernels as quickly
648 # as possible.  It will use the native tools or the buildworld cross tools
649 # based on whether the kernel was originally generated via buildkernel or
650 # nativekernel.  Config is rerun but the object hierarchy is not rebuilt,
651 # nor is the make depend step run.
652 #
653 quickkernel:    maybe_bk_tools bk_build_list bk_kernwarn
654 .for _kernel in ${BUILDKERNELS}
655         @echo "--------------------------------------------------------------"
656         @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
657         @echo "--------------------------------------------------------------"
658         @echo "===> ${_kernel}"
659 .if exists(${KRNLOBJDIR}/${_kernel}/.buildkernel_run)
660 .if !defined(NO_KERNELCONFIG)
661         cd ${KRNLCONFDIR}; \
662                 PATH=${STRICTTMPPATH} \
663                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
664                         ${KERNCONFDIR}/${_kernel}
665 .endif
666         cd ${KRNLOBJDIR}/${_kernel}; \
667             ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} all
668 .else
669 .if !defined(NO_KERNELCONFIG)
670         cd ${KRNLCONFDIR}; \
671             config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
672                 ${KERNCONFDIR}/${_kernel}
673 .endif
674         cd ${KRNLOBJDIR}/${_kernel}; \
675             ${MAKE} KERNEL=${INSTKERNNAME} all
676 .endif
677         @echo "--------------------------------------------------------------"
678         @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
679         @echo "--------------------------------------------------------------"
680 .endfor
681
682
683 # installkernel
684 #
685 # Install the kernel defined by INSTALLKERNEL
686 #
687 installkernel reinstallkernel:
688 .if exists(${KRNLOBJDIR}/${_kernel}/.buildkernel_run)
689         cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
690             ${CROSSENV} ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//}
691 .else
692         cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
693             ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//}
694 .endif
695
696 #
697 # most
698 #
699 # Build most of the user binaries on the existing system libs and includes.
700 #
701 most:
702         @echo "--------------------------------------------------------------"
703         @echo ">>> Building programs only"
704         @echo "--------------------------------------------------------------"
705 .for _dir in bin sbin libexec usr.bin usr.sbin gnu/libexec gnu/usr.bin gnu/usr.sbin
706         cd ${.CURDIR}/${_dir};          ${MAKE} DIRPRFX=${_dir}/ all
707 .endfor
708
709 #
710 # installmost
711 #
712 # Install the binaries built by the 'most' target.  This does not include
713 # libraries or include files.
714 #
715 installmost:
716         @echo "--------------------------------------------------------------"
717         @echo ">>> Installing programs only"
718         @echo "--------------------------------------------------------------"
719 .for _dir in bin sbin libexec usr.bin usr.sbin gnu/libexec gnu/usr.bin gnu/usr.sbin
720         cd ${.CURDIR}/${_dir};          ${MAKE} DIRPRFX=${_dir}/ install
721 .endfor
722
723 #
724 # ------------------------------------------------------------------------
725 #
726 # From here onwards are utility targets used by the 'make world' and
727 # related targets.  If your 'world' breaks, you may like to try to fix
728 # the problem and manually run the following targets to attempt to
729 # complete the build.  Beware, this is *not* guaranteed to work, you
730 # need to have a pretty good grip on the current state of the system
731 # to attempt to manually finish it.  If in doubt, 'make world' again.
732 #
733
734 # bootstrap-tools: Build all tools required to build all tools.  Note that
735 # order is important in a number of cases and also note that the bootstrap
736 # and build tools stages have access to earlier binaries they themselves
737 # had generated.
738 #
739 # patch:        older patch's do not have -i.  This program must be built
740 #               first so other bootstrap tools that need to apply patches
741 #               can use it.
742 # [x]install:   dependancies on various new install features
743 # rpcgen:       old rpcgen used a hardwired cpp path, newer OBJFORMAT_PATH
744 #               envs are not compatible with older objformat binaries.
745 #
746 .if exists(${.CURDIR}/games) && !defined(NO_GAMES)
747 _strfile=       games/fortune/strfile
748 .endif
749
750 bootstrap-tools:
751         ${LN} -fs /bin/date ${BTOOLSDEST}/bin/date
752 .for _tool in ${_strfile} \
753     usr.bin/patch \
754     bin/chmod bin/cp bin/cpdup bin/dd bin/mkdir bin/rm bin/echo bin/test \
755     bin/cat bin/ln bin/mv bin/csh bin/expr bin/sh \
756     bin/hostname bin/kill \
757     usr.bin/yacc usr.bin/colldef usr.bin/uudecode usr.bin/xinstall \
758     usr.bin/m4 usr.bin/rpcgen usr.bin/make usr.bin/awk usr.bin/stat \
759     usr.bin/find usr.bin/lex usr.bin/sed usr.bin/uname usr.bin/touch \
760     usr.bin/mkdep usr.bin/mktemp usr.bin/lorder usr.bin/file2c \
761     usr.bin/tsort usr.bin/tr usr.bin/join usr.bin/wc usr.bin/basename \
762     usr.bin/gencat usr.bin/chflags usr.bin/expand usr.bin/paste \
763     usr.bin/mklocale usr.bin/uuencode usr.bin/compile_et usr.bin/hexdump \
764     usr.bin/cap_mkdb usr.bin/true usr.bin/false \
765     usr.bin/cmp usr.bin/xargs usr.bin/id usr.bin/env usr.bin/dirname \
766     usr.bin/tail \
767     usr.sbin/chown usr.sbin/mtree usr.sbin/config \
768     usr.sbin/btxld usr.sbin/zic usr.sbin/makewhatis \
769     gnu/usr.bin/texinfo gnu/usr.bin/grep gnu/usr.bin/sort \
770     usr.bin/gzip usr.bin/bzip2 usr.bin/mkcsmapper usr.bin/mkesdb
771         ${ECHODIR} "===> ${_tool} (bootstrap-tools)"; \
772                 cd ${.CURDIR}/${_tool}; \
773                 ${MAKE} DIRPRFX=${_tool}/ obj; \
774                 ${MAKE} DIRPRFX=${_tool}/ depend; \
775                 ${MAKE} DIRPRFX=${_tool}/ all; \
776                 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${BTOOLSDEST} install
777 .endfor
778         touch ${BTOOLSDEST}/.bootstrap_done
779
780 # build-tools: Build special purpose build tools.
781 #
782 # XXX we may be able to remove or consolidate this into bootstrap-tools
783 # now that we have the native helper (.nx/.no) infrastructure.
784 #
785 .if exists(${.CURDIR}/share) && !defined(NO_SHARE)
786 _share= share/syscons/scrnmaps
787 .endif
788
789 .if !defined(NO_GCC34)
790 _gcc34_cross= gnu/usr.bin/cc34
791 _gcc34_tools= gnu/usr.bin/cc34/cc_prep gnu/usr.bin/cc34/cc_tools
792 .endif
793 _gcc41_cross= gnu/usr.bin/cc41
794 _gcc41_tools= gnu/usr.bin/cc41/cc_prep gnu/usr.bin/cc41/cc_tools
795 _binutils= gnu/usr.bin/binutils217
796
797 .if exists(${.CURDIR}/kerberos5) && exists(${.CURDIR}/crypto) && \
798     !defined(NO_CRYPT) && defined(WANT_KERBEROS)
799 _libkrb5= kerberos5/tools kerberos5/lib/libroken kerberos5/lib/libvers \
800     kerberos5/lib/libasn1 kerberos5/lib/libhdb kerberos5/lib/libsl
801 .endif
802
803 build-tools:
804 .for _tool in ${_gcc34_tools} ${_gcc41_tools} ${_libkrb5} ${_share}
805         ${ECHODIR} "===> ${_tool} (build-tools)"; \
806                 cd ${.CURDIR}/${_tool}; \
807                 ${MAKE} DIRPRFX=${_tool}/ obj; \
808                 ${MAKE} DIRPRFX=${_tool}/ depend; \
809                 ${MAKE} DIRPRFX=${_tool}/ all; \
810                 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${BTOOLSDEST} install
811 .endfor
812         touch ${BTOOLSDEST}/.build_done
813
814 #
815 # cross-tools: Build cross-building tools
816 #
817 .if ${TARGET_ARCH} == "i386" && ${MACHINE_ARCH} != "i386"
818 _btxld= usr.sbin/btxld
819 .endif
820
821 cross-tools:
822 .for _tool in ${_btxld} ${_binutils} \
823               usr.bin/objformat usr.sbin/crunch/crunchide \
824               ${_gcc34_cross} ${_gcc41_cross}
825         ${ECHODIR} "===> ${_tool} (cross-tools)"; \
826                 cd ${.CURDIR}/${_tool}; \
827                 ${MAKE} DIRPRFX=${_tool}/ obj; \
828                 ${MAKE} DIRPRFX=${_tool}/ depend; \
829                 ${MAKE} DIRPRFX=${_tool}/ all; \
830                 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${CTOOLSDEST} install
831 .endfor
832         touch ${CTOOLSDEST}/.cross_done
833
834 #
835 # hierarchy - ensure that all the needed directories are present
836 #
837 hierarchy:
838         cd ${.CURDIR}/etc;              ${MAKE} distrib-dirs
839
840 #
841 # libraries - build all libraries, and install them under ${DESTDIR}.
842 #
843 # The list of libraries with dependents (${_prebuild_libs}) and their
844 # interdependencies (__L) are built automatically by the
845 # ${.CURDIR}/tools/make_libdeps.sh script.
846 #
847 # .makeenv does not work when bootstrapping from 4.x, so we must be sure
848 # to specify the correct CCVER or 'cc' will not exec the correct compiler.
849 #
850 libraries:
851 .if !defined(NO_GCC34)
852         cd ${.CURDIR}; \
853             HOST_CCVER=${HOST_CCVER} CCVER=gcc34 \
854                 ${MAKE} -f Makefile.inc1 _startup_libs34;
855 .endif
856         cd ${.CURDIR}; \
857             HOST_CCVER=${HOST_CCVER} CCVER=gcc41 \
858                 ${MAKE} -f Makefile.inc1 _startup_libs41;
859         cd ${.CURDIR}; \
860             ${MAKE} -f Makefile.inc1 _startup_libs; \
861             ${MAKE} -f Makefile.inc1 _prebuild_libs; \
862             ${MAKE} -f Makefile.inc1 _generic_libs;
863         touch ${WORLDDEST}/.libraries_done
864
865 # These dependencies are not automatically generated:
866 #
867 # gnu/lib/${CCVER}/libgcc and gnu/lib/${CCVER}/csu must be built before all
868 # shared libraries for ELF.  The target for _startup_libs34 is
869 # specifically built using gcc34.  Same goes for _startup_libs41.
870 #
871 _startup_libs34=        gnu/lib/gcc34/csu gnu/lib/gcc34/libgcc
872 _startup_libs41=        gnu/lib/gcc41/csu gnu/lib/gcc41/libgcc
873 _startup_libs=          lib/libc lib/libc_rtld
874
875 _prebuild_libs=         lib/libbz2 lib/libz lib/libarchive
876 _prebuild_libs+=        lib/libutil
877
878 _generic_libs=  gnu/lib
879
880 .if !defined(NO_CRYPT) && defined(WANT_KERBEROS)
881 _prebuild_libs+=        kerberos5/tools
882 _prebuild_libs+=        kerberos5/lib/libasn1
883 _prebuild_libs+=        kerberos5/lib/libgssapi
884 _prebuild_libs+=        kerberos5/lib/libkrb5
885 _prebuild_libs+=        kerberos5/lib/libroken
886 _generic_libs+= kerberos5/lib
887 .endif
888
889 _prebuild_libs+= lib/libcom_err lib/libcrypt lib/libmd \
890                 lib/libncurses/libncurses lib/libopie lib/libradius \
891                 lib/libsbuf lib/libskey lib/libtacplus lib/libm \
892                 lib/libpam lib/lib${THREAD_LIB}
893
894 lib/libopie__L lib/libradius__L lib/libtacplus__L: lib/libmd__L
895 lib/libskey__L: lib/libcrypt__L lib/libmd__L
896
897 _generic_libs+= lib
898
899 .if !defined(NO_CRYPT)
900 .if !defined(NO_OPENSSL)
901 _prebuild_libs+=        secure/lib/libcrypto secure/lib/libssl
902 .if !defined(NO_OPENSSH)
903 _prebuild_libs+=        secure/lib/libssh
904 secure/lib/libssh__L: secure/lib/libcrypto__L lib/libz__L
905 .endif
906 .endif
907 _generic_libs+= secure/lib
908 .endif
909
910 _generic_libs+= usr.bin/lex/lib
911
912 .for _lib in ${_startup_libs34} ${_startup_libs41} \
913                 ${_startup_libs} ${_prebuild_libs} ${_generic_libs}
914 ${_lib}__L: .PHONY
915 .if exists(${.CURDIR}/${_lib})
916         ${ECHODIR} "===> ${_lib}"; \
917                 cd ${.CURDIR}/${_lib}; \
918                 ${MAKE} DIRPRFX=${_lib}/ depend; \
919                 ${MAKE} DIRPRFX=${_lib}/ all; \
920                 ${MAKE} DIRPRFX=${_lib}/ install
921 .endif
922 .endfor
923
924 _startup_libs: ${_startup_libs:S/$/__L/}
925 _startup_libs34: ${_startup_libs34:S/$/__L/}
926 _startup_libs41: ${_startup_libs41:S/$/__L/}
927 _prebuild_libs: ${_prebuild_libs:S/$/__L/}
928 _generic_libs: ${_generic_libs:S/$/__L/}
929
930 # library targets must be ordered because there are inter-library
931 # races (e.g. generation of tconfig.h)
932 #
933 .ORDER: ${_startup_libs34:S/$/__L/}
934 .ORDER: ${_startup_libs41:S/$/__L/}
935 .ORDER: ${_startup_libs:S/$/__L/}
936 .ORDER: ${_prebuild_libs:S/$/__L/}
937 .ORDER: ${_generic_libs:S/$/__L/}
938
939 .for __target in clean cleandepend cleandir obj depend includes
940 .for entry in ${SUBDIR}
941 ${entry}.${__target}__D: .PHONY
942         @if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
943                 ${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH}"; \
944                 edir=${entry}.${MACHINE_ARCH}; \
945                 cd ${.CURDIR}/$${edir}; \
946         else \
947                 ${ECHODIR} "===> ${DIRPRFX}${entry}"; \
948                 edir=${entry}; \
949                 cd ${.CURDIR}/$${edir}; \
950         fi; \
951         ${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
952 .endfor
953 par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
954 .ORDER: ${SUBDIR:S/$/.${__target}__D/}
955 .endfor
956 .ORDER: par-clean par-cleandepend par-cleandir par-obj par-depend par-includes
957
958 # The wmake target is used by /usr/bin/wmake to run make in a
959 # world build environment.
960 #
961 wmake:
962         @echo '${WMAKEENV} ${MAKE} -m ${.CURDIR}/share/mk ${WMAKE_ARGS}'
963
964 wmakeenv:
965         @echo '${WMAKEENV} /bin/sh'
966
967 bmake:
968         @echo '${BMAKEENV} ${MAKE} -m ${.CURDIR}/share/mk ${BMAKE_ARGS}'
969
970 bmakeenv:
971         @echo '${BMAKEENV} /bin/sh'
972
973 tmake:
974         @echo '${TMAKEENV} ${MAKE} -m ${.CURDIR}/share/mk ${TMAKE_ARGS}'
975
976 tmakeenv:
977         @echo '${TMAKEENV} /bin/sh'
978
979 .include <bsd.subdir.mk>
980