]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - Makefile.inc1
Plug memory leak to silent Coverity. Error is still not really handled.
[FreeBSD/FreeBSD.git] / Makefile.inc1
1 #
2 # $FreeBSD$
3 #
4 # Make command line options:
5 #       -DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
6 #       -DNO_CLEAN do not clean at all
7 #       -DNO_SHARE do not go into share subdir
8 #       -DKERNFAST define NO_KERNEL{CONFIG,CLEAN,DEPEND,OBJ}
9 #       -DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
10 #       -DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
11 #       -DNO_KERNELDEPEND do not run ${MAKE} depend in ${MAKE} buildkernel
12 #       -DNO_KERNELOBJ do not run ${MAKE} obj in ${MAKE} buildkernel
13 #       -DNO_PORTSUPDATE do not update ports in ${MAKE} update
14 #       -DNO_DOCUPDATE do not update doc in ${MAKE} update
15 #       -DNO_CTF do not run the DTrace CTF conversion tools on built objects
16 #       LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
17 #       TARGET="machine" to crossbuild world for a different machine type
18 #       TARGET_ARCH= may be required when a TARGET supports multiple endians
19
20 #
21 # The intended user-driven targets are:
22 # buildworld  - rebuild *everything*, including glue to help do upgrades
23 # installworld- install everything built by "buildworld"
24 # doxygen     - build API documentation of the kernel
25 # update      - convenient way to update your source tree (eg: cvsup/cvs)
26 #
27 # Standard targets (not defined here) are documented in the makefiles in
28 # /usr/share/mk.  These include:
29 #               obj depend all install clean cleandepend cleanobj
30
31 .include <bsd.own.mk>
32
33 .if ${MACHINE_ARCH} == "mips"
34 MK_RESCUE=no    # not yet
35 .endif
36
37 # We must do share/info early so that installation of info `dir'
38 # entries works correctly.  Do it first since it is less likely to
39 # grow dependencies on include and lib than vice versa.
40 #
41 # We must do lib/ and libexec/ before bin/, because if installworld
42 # installs a new /bin/sh, the 'make' command will *immediately*
43 # use that new version.  And the new (dynamically-linked) /bin/sh
44 # will expect to find appropriate libraries in /lib and /libexec.
45 #
46 SUBDIR= share/info lib libexec
47 SUBDIR+=bin
48 .if ${MK_GAMES} != "no"
49 SUBDIR+=games
50 .endif
51 .if ${MK_CDDL} != "no"
52 SUBDIR+=cddl
53 .else
54 NO_CTF=1
55 .endif
56 SUBDIR+=gnu include
57 .if ${MK_KERBEROS} != "no"
58 SUBDIR+=kerberos5
59 .endif
60 .if ${MK_RESCUE} != "no"
61 SUBDIR+=rescue
62 .endif
63 SUBDIR+=sbin
64 .if ${MK_CRYPT} != "no"
65 SUBDIR+=secure
66 .endif
67 .if !defined(NO_SHARE)
68 SUBDIR+=share
69 .endif
70 SUBDIR+=sys usr.bin usr.sbin
71 #
72 # We must do etc/ last for install/distribute to work.
73 #
74 SUBDIR+=etc
75
76 # These are last, since it is nice to at least get the base system
77 # rebuilt before you do them.
78 .for _DIR in ${LOCAL_DIRS}
79 .if exists(${.CURDIR}/${_DIR}/Makefile)
80 SUBDIR+= ${_DIR}
81 .endif
82 .endfor
83
84 .if defined(SUBDIR_OVERRIDE)
85 SUBDIR=         ${SUBDIR_OVERRIDE}
86 .endif
87
88 .if defined(NOCLEAN)
89 NO_CLEAN=       ${NOCLEAN}
90 .endif
91 .if defined(NO_CLEANDIR)
92 CLEANDIR=       clean cleandepend
93 .else
94 CLEANDIR=       cleandir
95 .endif
96
97 CVS?=           cvs
98 CVSFLAGS?=      -A -P -d -I!
99 SVN?=           svn
100 SVNFLAGS?=      -r HEAD
101 SUP?=           /usr/bin/csup
102 SUPFLAGS?=      -g -L 2
103 .if defined(SUPHOST)
104 SUPFLAGS+=      -h ${SUPHOST}
105 .endif
106
107 MAKEOBJDIRPREFIX?=      /usr/obj
108 .if !defined(OSRELDATE)
109 .if exists(/usr/include/osreldate.h)
110 OSRELDATE!=     awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
111                 /usr/include/osreldate.h
112 .else
113 OSRELDATE=      0
114 .endif
115 .endif
116
117 .if !defined(VERSION)
118 VERSION!=       uname -srp
119 VERSION+=       ${OSRELDATE}
120 .endif
121
122 # Guess machine architecture from machine type, and vice versa.
123 .if !defined(TARGET_ARCH) && defined(TARGET)
124 TARGET_ARCH=    ${TARGET:S/pc98/i386/:S/sun4v/sparc64/}
125 .elif !defined(TARGET) && defined(TARGET_ARCH) && \
126     ${TARGET_ARCH} != ${MACHINE_ARCH}
127 TARGET=         ${TARGET_ARCH}
128 .endif
129 # Otherwise, default to current machine type and architecture.
130 TARGET?=        ${MACHINE}
131 TARGET_ARCH?=   ${MACHINE_ARCH}
132
133 KNOWN_ARCHES?=  amd64 arm i386 i386/pc98 ia64 mips powerpc sparc64 sparc64/sun4v
134 .if ${TARGET} == ${TARGET_ARCH}
135 _t=             ${TARGET}
136 .else
137 _t=             ${TARGET_ARCH}/${TARGET}
138 .endif
139 .for _t in ${_t}
140 .if empty(KNOWN_ARCHES:M${_t})
141 .error Unknown target ${TARGET_ARCH}:${TARGET}.
142 .endif
143 .endfor
144
145 .if ${TARGET} == ${MACHINE}
146 TARGET_CPUTYPE?=${CPUTYPE}
147 .else
148 TARGET_CPUTYPE?=
149 .endif
150
151 .if !empty(TARGET_CPUTYPE)
152 _TARGET_CPUTYPE=${TARGET_CPUTYPE}
153 .else
154 _TARGET_CPUTYPE=dummy
155 .endif
156 _CPUTYPE!=      MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \
157                 -f /dev/null -m ${.CURDIR}/share/mk -V CPUTYPE
158 .if ${_CPUTYPE} != ${_TARGET_CPUTYPE}
159 .error CPUTYPE global should be set with ?=.
160 .endif
161 .if make(buildworld)
162 BUILD_ARCH!=    uname -p
163 .if ${MACHINE_ARCH} != ${BUILD_ARCH}
164 .error To cross-build, set TARGET_ARCH.
165 .endif
166 .endif
167 .if ${MACHINE} == ${TARGET} && !defined(CROSS_BUILD_TESTING)
168 OBJTREE=        ${MAKEOBJDIRPREFIX}
169 .else
170 OBJTREE=        ${MAKEOBJDIRPREFIX}/${TARGET}
171 .endif
172 WORLDTMP=       ${OBJTREE}${.CURDIR}/tmp
173 # /usr/games added for fortune which depend on strfile
174 BPATH=          ${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games
175 XPATH=          ${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin:${WORLDTMP}/usr/games
176 STRICTTMPPATH=  ${BPATH}:${XPATH}
177 TMPPATH=        ${STRICTTMPPATH}:${PATH}
178
179 #
180 # Avoid running mktemp(1) unless actually needed.
181 # It may not be functional, e.g., due to new ABI
182 # when in the middle of installing over this system.
183 #
184 .if make(distributeworld) || make(installworld)
185 INSTALLTMP!=    /usr/bin/mktemp -d -u -t install
186 .endif
187
188 #
189 # Building a world goes through the following stages
190 #
191 # 1. legacy stage [BMAKE]
192 #       This stage is responsible for creating compatibility
193 #       shims that are needed by the bootstrap-tools,
194 #       build-tools and cross-tools stages.
195 # 1. bootstrap-tools stage [BMAKE]
196 #       This stage is responsible for creating programs that
197 #       are needed for backward compatibility reasons. They
198 #       are not built as cross-tools.
199 # 2. build-tools stage [TMAKE]
200 #       This stage is responsible for creating the object
201 #       tree and building any tools that are needed during
202 #       the build process.
203 # 3. cross-tools stage [XMAKE]
204 #       This stage is responsible for creating any tools that
205 #       are needed for cross-builds. A cross-compiler is one
206 #       of them.
207 # 4. world stage [WMAKE]
208 #       This stage actually builds the world.
209 # 5. install stage (optional) [IMAKE]
210 #       This stage installs a previously built world.
211 #
212
213 BOOTSTRAPPING?= 0
214
215 # Common environment for world related stages
216 CROSSENV=       MAKEOBJDIRPREFIX=${OBJTREE} \
217                 MACHINE_ARCH=${TARGET_ARCH} \
218                 MACHINE=${TARGET} \
219                 CPUTYPE=${TARGET_CPUTYPE} \
220                 GROFF_BIN_PATH=${WORLDTMP}/legacy/usr/bin \
221                 GROFF_FONT_PATH=${WORLDTMP}/legacy/usr/share/groff_font \
222                 GROFF_TMAC_PATH=${WORLDTMP}/legacy/usr/share/tmac
223 .if ${OSRELDATE} < 700044
224 CROSSENV+=      AR=gnu-ar RANLIB=gnu-ranlib
225 .endif
226
227 # bootstrap-tools stage
228 BMAKEENV=       INSTALL="sh ${.CURDIR}/tools/install.sh" \
229                 PATH=${BPATH}:${PATH} \
230                 WORLDTMP=${WORLDTMP} \
231                 VERSION="${VERSION}" \
232                 MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
233 BMAKE=          MAKEOBJDIRPREFIX=${WORLDTMP} \
234                 ${BMAKEENV} ${MAKE} -f Makefile.inc1 \
235                 DESTDIR= \
236                 BOOTSTRAPPING=${OSRELDATE} \
237                 SSP_CFLAGS= \
238                 -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT -DWITHOUT_MAN \
239                 -DNO_PIC -DWITHOUT_PROFILE -DNO_SHARED \
240                 -DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF
241
242 # build-tools stage
243 TMAKE=          MAKEOBJDIRPREFIX=${OBJTREE} \
244                 ${BMAKEENV} ${MAKE} -f Makefile.inc1 \
245                 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
246                 DESTDIR= \
247                 SSP_CFLAGS= \
248                 BOOTSTRAPPING=${OSRELDATE} -DNO_LINT -DNO_CPU_CFLAGS \
249                 -DNO_WARNS -DNO_CTF
250
251 # cross-tools stage
252 XMAKE=          TOOLS_PREFIX=${WORLDTMP} ${BMAKE} \
253                 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
254                 -DWITHOUT_GDB
255
256 # world stage
257 WMAKEENV=       ${CROSSENV} \
258                 _SHLIBDIRPREFIX=${WORLDTMP} \
259                 VERSION="${VERSION}" \
260                 INSTALL="sh ${.CURDIR}/tools/install.sh" \
261                 PATH=${TMPPATH}
262 .if ${MK_CDDL} == "no"
263 WMAKEENV+=      NO_CTF=1
264 .endif
265 WMAKE=          ${WMAKEENV} ${MAKE} -f Makefile.inc1 DESTDIR=${WORLDTMP}
266
267 .if ${TARGET_ARCH} == "amd64"
268 # 32 bit world
269 LIB32TMP=       ${OBJTREE}${.CURDIR}/lib32
270
271 .if empty(TARGET_CPUTYPE)
272 LIB32CPUFLAGS=  -march=i686 -mmmx -msse -msse2
273 .else
274 LIB32CPUFLAGS=  -march=${TARGET_CPUTYPE}
275 .endif
276 LIB32FLAGS=     -m32 ${LIB32CPUFLAGS} -mfancy-math-387 -DCOMPAT_32BIT \
277                 -isystem ${LIB32TMP}/usr/include/ \
278                 -L${LIB32TMP}/usr/lib32 \
279                 -B${LIB32TMP}/usr/lib32
280
281 # Yes, the flags are redundant.
282 LIB32WMAKEENV=  MAKEOBJDIRPREFIX=${OBJTREE}/lib32 \
283                 _SHLIBDIRPREFIX=${LIB32TMP} \
284                 VERSION="${VERSION}" \
285                 MACHINE=i386 \
286                 MACHINE_ARCH=i386 \
287                 MACHINE_CPU="i686 mmx sse sse2" \
288                 INSTALL="sh ${.CURDIR}/tools/install.sh" \
289                 PATH=${TMPPATH} \
290                 CC="${CC} ${LIB32FLAGS}" \
291                 CXX="${CXX} ${LIB32FLAGS}" \
292                 OBJC="${OBJC} ${LIB32FLAGS}" \
293                 LD="${LD} -m elf_i386_fbsd -Y P,${LIB32TMP}/usr/lib32" \
294                 AS="${AS} --32" \
295                 LIBDIR=/usr/lib32 \
296                 SHLIBDIR=/usr/lib32
297
298 LIB32WMAKE=     ${LIB32WMAKEENV} ${MAKE} -DNO_CPU_CFLAGS -DCOMPAT_32BIT \
299                 -DWITHOUT_BIND -DWITHOUT_MAN -DWITHOUT_INFO \
300                 -DWITHOUT_HTML -DNO_CTF DESTDIR=${LIB32TMP}
301 LIB32IMAKE=     ${LIB32WMAKE:NINSTALL=*:NDESTDIR=*} -DNO_INCS
302 .endif
303
304 # install stage
305 IMAKEENV=       ${CROSSENV}
306 IMAKE=          ${IMAKEENV} ${MAKE} -f Makefile.inc1
307 .if empty(.MAKEFLAGS:M-n)
308 IMAKEENV+=      PATH=${STRICTTMPPATH}:${INSTALLTMP} \
309                 LD_LIBRARY_PATH=${INSTALLTMP} \
310                 PATH_LOCALE=${INSTALLTMP}/locale
311 IMAKE+=         __MAKE_SHELL=${INSTALLTMP}/sh
312 .else
313 IMAKEENV+=      PATH=${TMPPATH}:${INSTALLTMP}
314 .endif
315
316 # kernel stage
317 KMAKEENV=       ${WMAKEENV}
318 KMAKE=          ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME}
319
320 #
321 # buildworld
322 #
323 # Attempt to rebuild the entire system, with reasonable chance of
324 # success, regardless of how old your existing system is.
325 #
326 _worldtmp:
327 .if ${.CURDIR:C/[^,]//g} != ""
328 #       The m4 build of sendmail files doesn't like it if ',' is used
329 #       anywhere in the path of it's files.
330         @echo
331         @echo "*** Error: path to source tree contains a comma ','"
332         @echo
333         false
334 .endif
335         @echo
336         @echo "--------------------------------------------------------------"
337         @echo ">>> Rebuilding the temporary build tree"
338         @echo "--------------------------------------------------------------"
339 .if !defined(NO_CLEAN)
340         rm -rf ${WORLDTMP}
341 .if ${TARGET_ARCH} == "amd64"
342         rm -rf ${LIB32TMP}
343 .endif
344 .else
345         rm -rf ${WORLDTMP}/legacy/usr/include
346 #       XXX - These three can depend on any header file.
347         rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
348         rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/kdump_subr.c
349         rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
350 .endif
351 .for _dir in \
352     lib usr legacy/usr
353         mkdir -p ${WORLDTMP}/${_dir}
354 .endfor
355         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
356             -p ${WORLDTMP}/legacy/usr >/dev/null
357         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
358             -p ${WORLDTMP}/usr >/dev/null
359         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
360             -p ${WORLDTMP}/usr/include >/dev/null
361         ln -sf ${.CURDIR}/sys ${WORLDTMP}
362 .if ${MK_BIND_LIBS} != "no"
363         mtree -deU -f ${.CURDIR}/etc/mtree/BIND.include.dist \
364             -p ${WORLDTMP}/usr/include >/dev/null
365 .endif
366 _legacy:
367         @echo
368         @echo "--------------------------------------------------------------"
369         @echo ">>> stage 1.1: legacy release compatibility shims"
370         @echo "--------------------------------------------------------------"
371         ${_+_}cd ${.CURDIR}; ${BMAKE} legacy
372 _bootstrap-tools:
373         @echo
374         @echo "--------------------------------------------------------------"
375         @echo ">>> stage 1.2: bootstrap tools"
376         @echo "--------------------------------------------------------------"
377         ${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools
378 _cleanobj:
379 .if !defined(NO_CLEAN)
380         @echo
381         @echo "--------------------------------------------------------------"
382         @echo ">>> stage 2.1: cleaning up the object tree"
383         @echo "--------------------------------------------------------------"
384         ${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
385 .if ${TARGET_ARCH} == "amd64"
386         ${_+_}cd ${.CURDIR}; ${LIB32WMAKE} -f Makefile.inc1 ${CLEANDIR:S/^/par-/}
387 .endif
388 .endif
389 _obj:
390         @echo
391         @echo "--------------------------------------------------------------"
392         @echo ">>> stage 2.2: rebuilding the object tree"
393         @echo "--------------------------------------------------------------"
394         ${_+_}cd ${.CURDIR}; ${WMAKE} par-obj
395 _build-tools:
396         @echo
397         @echo "--------------------------------------------------------------"
398         @echo ">>> stage 2.3: build tools"
399         @echo "--------------------------------------------------------------"
400         ${_+_}cd ${.CURDIR}; ${TMAKE} build-tools
401 _cross-tools:
402         @echo
403         @echo "--------------------------------------------------------------"
404         @echo ">>> stage 3: cross tools"
405         @echo "--------------------------------------------------------------"
406         ${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools
407 _includes:
408         @echo
409         @echo "--------------------------------------------------------------"
410         @echo ">>> stage 4.1: building includes"
411         @echo "--------------------------------------------------------------"
412         ${_+_}cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
413 _libraries:
414         @echo
415         @echo "--------------------------------------------------------------"
416         @echo ">>> stage 4.2: building libraries"
417         @echo "--------------------------------------------------------------"
418         ${_+_}cd ${.CURDIR}; \
419             ${WMAKE} -DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \
420             -DWITHOUT_MAN -DWITHOUT_PROFILE libraries
421 _depend:
422         @echo
423         @echo "--------------------------------------------------------------"
424         @echo ">>> stage 4.3: make dependencies"
425         @echo "--------------------------------------------------------------"
426         ${_+_}cd ${.CURDIR}; ${WMAKE} par-depend
427 everything:
428         @echo
429         @echo "--------------------------------------------------------------"
430         @echo ">>> stage 4.4: building everything"
431         @echo "--------------------------------------------------------------"
432         ${_+_}cd ${.CURDIR}; ${WMAKE} par-all
433 .if ${TARGET_ARCH} == "amd64"
434 build32:
435         @echo
436         @echo "--------------------------------------------------------------"
437         @echo ">>> stage 5.1: building 32 bit shim libraries"
438         @echo "--------------------------------------------------------------"
439         mkdir -p ${LIB32TMP}/usr/lib32
440         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
441             -p ${LIB32TMP}/usr >/dev/null
442         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
443             -p ${LIB32TMP}/usr/include >/dev/null
444         mkdir -p ${WORLDTMP}
445         ln -sf ${.CURDIR}/sys ${WORLDTMP}
446 .if ${MK_KERBEROS} != "no"
447 .for _t in obj depend all
448         cd ${.CURDIR}/kerberos5/tools; \
449             MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} SSP_CFLAGS= DESTDIR= \
450             ${_t}
451 .endfor
452 .endif
453 .for _t in obj includes
454         cd ${.CURDIR}/include; ${LIB32WMAKE} ${_t}
455         cd ${.CURDIR}/lib; ${LIB32WMAKE} ${_t}
456 .if ${MK_CDDL} != "no"
457         cd ${.CURDIR}/cddl/lib; ${LIB32WMAKE} ${_t}
458 .endif
459         cd ${.CURDIR}/gnu/lib; ${LIB32WMAKE} ${_t}
460 .if ${MK_CRYPT} != "no"
461         cd ${.CURDIR}/secure/lib; ${LIB32WMAKE} ${_t}
462 .endif
463 .if ${MK_KERBEROS} != "no"
464         cd ${.CURDIR}/kerberos5/lib; ${LIB32WMAKE} ${_t}
465 .endif
466 .endfor
467 .for _dir in usr.bin/lex/lib
468         cd ${.CURDIR}/${_dir}; ${LIB32WMAKE} obj
469 .endfor
470 .for _dir in lib/ncurses/ncurses lib/ncurses/ncursesw lib/libmagic
471         cd ${.CURDIR}/${_dir}; \
472             MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} SSP_CFLAGS= DESTDIR= \
473             build-tools
474 .endfor
475         cd ${.CURDIR}; \
476             ${LIB32WMAKE} -f Makefile.inc1 libraries
477 .for _t in obj depend all
478         cd ${.CURDIR}/libexec/rtld-elf; PROG=ld-elf32.so.1 ${LIB32WMAKE} ${_t}
479         cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIB32WMAKE} ${_t}
480 .endfor
481
482 distribute32 install32:
483 .if make(distribute32)
484         mkdir -p ${DISTDIR}/${DISTRIBUTION}/usr/lib32   # XXX add to mtree
485         mkdir -p ${DISTDIR}/${DISTRIBUTION}/usr/lib32/dtrace    # XXX add to mtree
486 .else
487         mkdir -p ${DESTDIR}/usr/lib32                   # XXX add to mtree
488         mkdir -p ${DESTDIR}/usr/lib32/dtrace            # XXX add to mtree
489 .endif
490         cd ${.CURDIR}/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
491 .if ${MK_CDDL} != "no"
492         cd ${.CURDIR}/cddl/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
493 .endif
494         cd ${.CURDIR}/gnu/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
495 .if ${MK_CRYPT} != "no"
496         cd ${.CURDIR}/secure/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
497 .endif
498 .if ${MK_KERBEROS} != "no"
499         cd ${.CURDIR}/kerberos5/lib; ${LIB32IMAKE} ${.TARGET:S/32$//}
500 .endif
501         cd ${.CURDIR}/libexec/rtld-elf; \
502             PROG=ld-elf32.so.1 ${LIB32IMAKE} ${.TARGET:S/32$//}
503         cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIB32IMAKE} ${.TARGET:S/32$//}
504 .endif
505
506 WMAKE_TGTS=
507 .if !defined(SUBDIR_OVERRIDE)
508 WMAKE_TGTS+=    _worldtmp _legacy _bootstrap-tools
509 .endif
510 WMAKE_TGTS+=    _cleanobj _obj _build-tools
511 .if !defined(SUBDIR_OVERRIDE)
512 WMAKE_TGTS+=    _cross-tools
513 .endif
514 WMAKE_TGTS+=    _includes _libraries _depend everything
515 .if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
516 WMAKE_TGTS+=    build32
517 .endif
518
519 buildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
520 .ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue
521
522 buildworld_prologue:
523         @echo "--------------------------------------------------------------"
524         @echo ">>> World build started on `LC_ALL=C date`"
525         @echo "--------------------------------------------------------------"
526
527 buildworld_epilogue:
528         @echo
529         @echo "--------------------------------------------------------------"
530         @echo ">>> World build completed on `LC_ALL=C date`"
531         @echo "--------------------------------------------------------------"
532
533 #
534 # We need to have this as a target because the indirection between Makefile
535 # and Makefile.inc1 causes the correct PATH to be used, rather than a
536 # modification of the current environment's PATH.  In addition, we need
537 # to quote multiword values.
538 #
539 buildenvvars:
540         @echo ${WMAKEENV:Q}
541
542 buildenv:
543         @echo Entering world for ${TARGET_ARCH}:${TARGET}
544         @cd ${.CURDIR} && env ${WMAKEENV} sh || true
545
546 TOOLCHAIN_TGTS= ${WMAKE_TGTS:N_depend:Neverything:Nbuild32}
547 toolchain: ${TOOLCHAIN_TGTS}
548 kernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries}
549
550 #
551 # installcheck
552 #
553 # Checks to be sure system is ready for installworld/installkernel.
554 #
555 installcheck:
556
557 #
558 # Require DESTDIR to be set if installing for a different architecture.
559 #
560 .if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE}
561 .if !make(distributeworld)
562 installcheck: installcheck_DESTDIR
563 installcheck_DESTDIR:
564 .if !defined(DESTDIR) || empty(DESTDIR)
565         @echo "ERROR: Please set DESTDIR!"; \
566         false
567 .endif
568 .endif
569 .endif
570
571 #
572 # Check for missing UIDs/GIDs.
573 #
574 CHECK_UIDS=
575 CHECK_GIDS=     audit
576 .if ${MK_SENDMAIL} != "no"
577 CHECK_UIDS+=    smmsp
578 CHECK_GIDS+=    smmsp
579 .endif
580 .if ${MK_PF} != "no"
581 CHECK_UIDS+=    proxy
582 CHECK_GIDS+=    proxy authpf
583 .endif
584 installcheck: installcheck_UGID
585 installcheck_UGID:
586 .for uid in ${CHECK_UIDS}
587         @if ! `id -u ${uid} >/dev/null 2>&1`; then \
588                 echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \
589                 false; \
590         fi
591 .endfor
592 .for gid in ${CHECK_GIDS}
593         @if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \
594                 echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \
595                 false; \
596         fi
597 .endfor
598
599 #
600 # Required install tools to be saved in a scratch dir for safety.
601 #
602 .if ${MK_INFO} != "no"
603 _install-info=  install-info
604 .endif
605 .if ${MK_ZONEINFO} != "no"
606 _zoneinfo=      zic tzsetup
607 .endif
608
609 ITOOLS= [ awk cap_mkdb cat chflags chmod chown \
610         date echo egrep find grep ${_install-info} \
611         ln lockf make mkdir mtree mv pwd_mkdb rm sed sh sysctl \
612         test true uname wc ${_zoneinfo}
613
614 #
615 # distributeworld
616 #
617 # Distributes everything compiled by a `buildworld'.
618 #
619 # installworld
620 #
621 # Installs everything compiled by a 'buildworld'.
622 #
623 distributeworld installworld: installcheck
624         mkdir -p ${INSTALLTMP}
625         progs=$$(for prog in ${ITOOLS}; do \
626                 if progpath=`which $$prog`; then \
627                         echo $$progpath; \
628                 else \
629                         echo "Required tool $$prog not found in PATH." >&2; \
630                         exit 1; \
631                 fi; \
632             done); \
633         libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \
634             while read line; do \
635                 set -- $$line; \
636                 if [ "$$2 $$3" != "not found" ]; then \
637                         echo $$2; \
638                 else \
639                         echo "Required library $$1 not found." >&2; \
640                         exit 1; \
641                 fi; \
642             done); \
643         cp $$libs $$progs ${INSTALLTMP}
644         cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
645         ${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
646             ${IMAKEENV} rm -rf ${INSTALLTMP}
647
648 #
649 # reinstall
650 #
651 # If you have a build server, you can NFS mount the source and obj directories
652 # and do a 'make reinstall' on the *client* to install new binaries from the
653 # most recent server build.
654 #
655 reinstall:
656         @echo "--------------------------------------------------------------"
657         @echo ">>> Making hierarchy"
658         @echo "--------------------------------------------------------------"
659         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 hierarchy
660         @echo
661         @echo "--------------------------------------------------------------"
662         @echo ">>> Installing everything"
663         @echo "--------------------------------------------------------------"
664         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
665 .if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
666         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
667 .endif
668
669 redistribute:
670         @echo "--------------------------------------------------------------"
671         @echo ">>> Distributing everything"
672         @echo "--------------------------------------------------------------"
673         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute
674 .if ${TARGET_ARCH} == "amd64" && ${MK_LIB32} != "no"
675         ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute32 \
676             DISTRIBUTION=lib32
677 .endif
678
679 distrib-dirs distribution:
680         cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} ${.TARGET}
681
682 #
683 # buildkernel and installkernel
684 #
685 # Which kernels to build and/or install is specified by setting
686 # KERNCONF. If not defined a GENERIC kernel is built/installed.
687 # Only the existing (depending TARGET) config files are used
688 # for building kernels and only the first of these is designated
689 # as the one being installed.
690 #
691 # Note that we have to use TARGET instead of TARGET_ARCH when
692 # we're in kernel-land. Since only TARGET_ARCH is (expected) to
693 # be set to cross-build, we have to make sure TARGET is set
694 # properly.
695
696 .if defined(KERNFAST)
697 NO_KERNELCLEAN= t
698 NO_KERNELCONFIG=        t
699 NO_KERNELDEPEND=        t
700 NO_KERNELOBJ=           t
701 # Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah
702 .if !defined(KERNCONF) && ${KERNFAST} != "1"
703 KERNCONF=${KERNFAST}
704 .endif
705 .endif
706 .if !defined(KERNCONF) && defined(KERNEL)
707 KERNCONF=       ${KERNEL}
708 KERNWARN=
709 .else
710 KERNCONF?=      GENERIC
711 .endif
712 INSTKERNNAME?=  kernel
713
714 KERNSRCDIR?=    ${.CURDIR}/sys
715 KRNLCONFDIR=    ${KERNSRCDIR}/${TARGET}/conf
716 KRNLOBJDIR=     ${OBJTREE}${KERNSRCDIR}
717 KERNCONFDIR?=   ${KRNLCONFDIR}
718
719 BUILDKERNELS=
720 INSTALLKERNEL=
721 .for _kernel in ${KERNCONF}
722 .if exists(${KERNCONFDIR}/${_kernel})
723 BUILDKERNELS+=  ${_kernel}
724 .if empty(INSTALLKERNEL)
725 INSTALLKERNEL= ${_kernel}
726 .endif
727 .endif
728 .endfor
729
730 #
731 # buildkernel
732 #
733 # Builds all kernels defined by BUILDKERNELS.
734 #
735 buildkernel:
736 .if empty(BUILDKERNELS)
737         @echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \
738         false
739 .endif
740 .if defined(KERNWARN)
741         @echo "--------------------------------------------------------------"
742         @echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF="
743         @echo "--------------------------------------------------------------"
744         @sleep 3
745 .endif
746         @echo
747 .for _kernel in ${BUILDKERNELS}
748         @echo "--------------------------------------------------------------"
749         @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
750         @echo "--------------------------------------------------------------"
751         @echo "===> ${_kernel}"
752         mkdir -p ${KRNLOBJDIR}
753 .if !defined(NO_KERNELCONFIG)
754         @echo
755         @echo "--------------------------------------------------------------"
756         @echo ">>> stage 1: configuring the kernel"
757         @echo "--------------------------------------------------------------"
758         cd ${KRNLCONFDIR}; \
759                 PATH=${TMPPATH} \
760                     config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
761                         ${KERNCONFDIR}/${_kernel}
762 .endif
763 .if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN)
764         @echo
765         @echo "--------------------------------------------------------------"
766         @echo ">>> stage 2.1: cleaning up the object tree"
767         @echo "--------------------------------------------------------------"
768         cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR}
769 .endif
770 .if !defined(NO_KERNELOBJ)
771         @echo
772         @echo "--------------------------------------------------------------"
773         @echo ">>> stage 2.2: rebuilding the object tree"
774         @echo "--------------------------------------------------------------"
775         cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj
776 .endif
777         @echo
778         @echo "--------------------------------------------------------------"
779         @echo ">>> stage 2.3: build tools"
780         @echo "--------------------------------------------------------------"
781         cd ${KRNLOBJDIR}/${_kernel}; \
782             MAKESRCPATH=${KERNSRCDIR}/dev/aic7xxx/aicasm \
783             ${MAKE} SSP_CFLAGS= -DNO_CPU_CFLAGS \
784             -f ${KERNSRCDIR}/dev/aic7xxx/aicasm/Makefile
785 # XXX - Gratuitously builds aicasm in the ``makeoptions NO_MODULES'' case.
786 .if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists(${KERNSRCDIR}/modules)
787 .for target in obj depend all
788         cd ${KERNSRCDIR}/modules/aic7xxx/aicasm; \
789             MAKEOBJDIRPREFIX=${KRNLOBJDIR}/${_kernel}/modules \
790             ${MAKE} SSP_CFLAGS= -DNO_CPU_CFLAGS -DNO_CTF ${target}
791 .endfor
792 .endif
793 .if !defined(NO_KERNELDEPEND)
794         @echo
795         @echo "--------------------------------------------------------------"
796         @echo ">>> stage 3.1: making dependencies"
797         @echo "--------------------------------------------------------------"
798         cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} depend -DNO_MODULES_OBJ
799 .endif
800         @echo
801         @echo "--------------------------------------------------------------"
802         @echo ">>> stage 3.2: building everything"
803         @echo "--------------------------------------------------------------"
804         cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ
805         @echo "--------------------------------------------------------------"
806         @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
807         @echo "--------------------------------------------------------------"
808 .endfor
809
810 #
811 # installkernel, etc.
812 #
813 # Install the kernel defined by INSTALLKERNEL
814 #
815 installkernel installkernel.debug \
816 reinstallkernel reinstallkernel.debug: installcheck
817 .if empty(INSTALLKERNEL)
818         @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \
819         false
820 .endif
821         @echo "--------------------------------------------------------------"
822         @echo ">>> Installing kernel"
823         @echo "--------------------------------------------------------------"
824         cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
825             ${CROSSENV} PATH=${TMPPATH} \
826             ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
827
828 #
829 # doxygen
830 #
831 # Build the API documentation with doxygen
832 #
833 doxygen:
834         @if [ ! -x `/usr/bin/which doxygen` ]; then \
835                 echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \
836                 exit 1; \
837         fi
838         cd ${.CURDIR}/tools/kerneldoc/subsys && ${MAKE} obj all
839
840 #
841 # update
842 #
843 # Update the source tree, by running cvsup and/or running cvs to update to the
844 # latest copy.
845 #
846 update:
847 .if defined(SUP_UPDATE)
848         @echo "--------------------------------------------------------------"
849         @echo ">>> Running ${SUP}"
850         @echo "--------------------------------------------------------------"
851 .if defined(SUPFILE)
852         @${SUP} ${SUPFLAGS} ${SUPFILE}
853 .endif
854 .if defined(SUPFILE1)
855         @${SUP} ${SUPFLAGS} ${SUPFILE1}
856 .endif
857 .if defined(SUPFILE2)
858         @${SUP} ${SUPFLAGS} ${SUPFILE2}
859 .endif
860 .if defined(PORTSSUPFILE) && !defined(NO_PORTSUPDATE)
861         @${SUP} ${SUPFLAGS} ${PORTSSUPFILE}
862 .endif
863 .if defined(DOCSUPFILE) && !defined(NO_DOCUPDATE)
864         @${SUP} ${SUPFLAGS} ${DOCSUPFILE}
865 .endif
866 .endif
867 .if defined(CVS_UPDATE)
868         @cd ${.CURDIR} ; \
869         if [ -d CVS ] ; then \
870                 echo "--------------------------------------------------------------" ; \
871                 echo ">>> Updating ${.CURDIR} from CVS repository" ${CVSROOT} ; \
872                 echo "--------------------------------------------------------------" ; \
873                 echo ${CVS} -R -q update ${CVSFLAGS} ; \
874                 ${CVS} -R -q update ${CVSFLAGS} ; \
875         fi
876 .endif
877 .if defined(SVN_UPDATE)
878         @cd ${.CURDIR} ; \
879         if [ -d .svn ] ; then \
880                 echo "--------------------------------------------------------------" ; \
881                 echo ">>> Updating ${.CURDIR} using Subversion" ; \
882                 echo "--------------------------------------------------------------" ; \
883                 echo ${SVN} update ${SVNFLAGS} ; \
884                 ${SVN} update ${SVNFLAGS} ; \
885         fi
886 .endif
887
888 #
889 # ------------------------------------------------------------------------
890 #
891 # From here onwards are utility targets used by the 'make world' and
892 # related targets.  If your 'world' breaks, you may like to try to fix
893 # the problem and manually run the following targets to attempt to
894 # complete the build.  Beware, this is *not* guaranteed to work, you
895 # need to have a pretty good grip on the current state of the system
896 # to attempt to manually finish it.  If in doubt, 'make world' again.
897 #
898
899 #
900 # legacy: Build compatibility shims for the next three targets
901 #
902 legacy:
903 .if ${BOOTSTRAPPING} < 600034 && ${BOOTSTRAPPING} != 0
904         @echo "ERROR: Source upgrades from versions prior to 6.0 not supported."; \
905         false
906 .endif
907 .for _tool in tools/build
908         ${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,depend,all,install)"; \
909             cd ${.CURDIR}/${_tool}; \
910             ${MAKE} DIRPRFX=${_tool}/ obj; \
911             ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes; \
912             ${MAKE} DIRPRFX=${_tool}/ depend; \
913             ${MAKE} DIRPRFX=${_tool}/ all; \
914             ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
915 .endfor
916
917 #
918 # bootstrap-tools: Build tools needed for compatibility
919 #
920 .if ${MK_GAMES} != "no"
921 _strfile=       games/fortune/strfile
922 .endif
923
924 .if ${MK_CXX} != "no"
925 _gperf=         gnu/usr.bin/gperf
926 .if ${BOOTSTRAPPING} < 700004
927 _groff=         gnu/usr.bin/groff
928 .else
929 _groff=         gnu/usr.bin/groff/tmac
930 .endif
931 .endif
932
933 .if ${BOOTSTRAPPING} >= 700044 && ${BOOTSTRAPPING} < 800022
934 _ar=            usr.bin/ar
935 .endif
936
937 .if ${BOOTSTRAPPING} < 800013
938 _mklocale=      usr.bin/mklocale
939 .endif
940
941 .if ${BOOTSTRAPPING} < 900002
942 _sed=           usr.bin/sed
943 .endif
944
945 .if ${BOOTSTRAPPING} < 900006
946 _lex=           usr.bin/lex
947 _yacc=          usr.bin/yacc
948 .endif
949
950 .if ${BOOTSTRAPPING} < 700018
951 _gensnmptree=   usr.sbin/bsnmpd/gensnmptree
952 .endif
953
954 .if ${MK_RESCUE} != "no" && \
955     ${BOOTSTRAPPING} < 700026
956 _crunchgen=     usr.sbin/crunch/crunchgen
957 .endif
958
959 .if ${MK_CDDL} != "no"
960 _dtrace_tools= cddl/usr.bin/sgsmsg cddl/lib/libctf lib/libelf \
961     lib/libdwarf cddl/usr.bin/ctfconvert cddl/usr.bin/ctfmerge
962 .endif
963
964 bootstrap-tools:
965 .for _tool in \
966     ${_dtrace_tools} \
967     ${_strfile} \
968     ${_gperf} \
969     ${_groff} \
970     ${_ar} \
971     usr.bin/lorder \
972     usr.bin/makewhatis \
973     ${_mklocale} \
974     usr.bin/rpcgen \
975     ${_sed} \
976     ${_lex} \
977     ${_yacc} \
978     usr.bin/xinstall \
979     ${_gensnmptree} \
980     usr.sbin/config \
981     ${_crunchgen}
982         ${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
983                 cd ${.CURDIR}/${_tool}; \
984                 ${MAKE} DIRPRFX=${_tool}/ obj; \
985                 ${MAKE} DIRPRFX=${_tool}/ depend; \
986                 ${MAKE} DIRPRFX=${_tool}/ all; \
987                 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install
988 .endfor
989
990 #
991 # build-tools: Build special purpose build tools
992 #
993 .if defined(MODULES_WITH_WORLD) && exists(${KERNSRCDIR}/modules)
994 _aicasm= sys/modules/aic7xxx/aicasm
995 .endif
996
997 .if !defined(NO_SHARE)
998 _share= share/syscons/scrnmaps
999 .endif
1000
1001 .if ${MK_KERBEROS} != "no"
1002 _kerberos5_tools= kerberos5/tools
1003 .endif
1004
1005 .if ${MK_RESCUE} != "no"
1006 _rescue= rescue/rescue
1007 .endif
1008
1009 build-tools:
1010 .for _tool in \
1011     bin/csh \
1012     bin/sh \
1013     ${_rescue} \
1014     lib/ncurses/ncurses \
1015     lib/ncurses/ncursesw \
1016     ${_share} \
1017     ${_aicasm} \
1018     usr.bin/awk \
1019     lib/libmagic \
1020     usr.sbin/sysinstall
1021         ${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \
1022                 cd ${.CURDIR}/${_tool}; \
1023                 ${MAKE} DIRPRFX=${_tool}/ obj; \
1024                 ${MAKE} DIRPRFX=${_tool}/ build-tools
1025 .endfor
1026 .for _tool in \
1027     gnu/usr.bin/cc/cc_tools \
1028     ${_kerberos5_tools}
1029         ${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \
1030                 cd ${.CURDIR}/${_tool}; \
1031                 ${MAKE} DIRPRFX=${_tool}/ obj; \
1032                 ${MAKE} DIRPRFX=${_tool}/ depend; \
1033                 ${MAKE} DIRPRFX=${_tool}/ all
1034 .endfor
1035
1036 #
1037 # cross-tools: Build cross-building tools
1038 #
1039 .if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${BOOTSTRAPPING} < 800035
1040 .if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
1041 _btxld=         usr.sbin/btxld
1042 .endif
1043 .endif
1044 .if ${TARGET_ARCH} != ${MACHINE_ARCH}
1045 .if ${MK_RESCUE} != "no" || defined(RELEASEDIR)
1046 _crunchide=     usr.sbin/crunch/crunchide
1047 .endif
1048 .if ${TARGET_ARCH} == "i386" && defined(RELEASEDIR)
1049 _kgzip=         usr.sbin/kgzip
1050 .endif
1051 .endif
1052
1053 cross-tools:
1054 .for _tool in \
1055     gnu/usr.bin/binutils \
1056     gnu/usr.bin/cc \
1057     usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \
1058     ${_btxld} \
1059     ${_crunchide} \
1060     ${_kgzip}
1061         ${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \
1062                 cd ${.CURDIR}/${_tool}; \
1063                 ${MAKE} DIRPRFX=${_tool}/ obj; \
1064                 ${MAKE} DIRPRFX=${_tool}/ depend; \
1065                 ${MAKE} DIRPRFX=${_tool}/ all; \
1066                 ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install
1067 .endfor
1068
1069 #
1070 # hierarchy - ensure that all the needed directories are present
1071 #
1072 hierarchy:
1073         cd ${.CURDIR}/etc;              ${MAKE} distrib-dirs
1074
1075 #
1076 # libraries - build all libraries, and install them under ${DESTDIR}.
1077 #
1078 # The list of libraries with dependents (${_prebuild_libs}) and their
1079 # interdependencies (__L) are built automatically by the
1080 # ${.CURDIR}/tools/make_libdeps.sh script.
1081 #
1082 libraries:
1083         cd ${.CURDIR}; \
1084             ${MAKE} -f Makefile.inc1 _prereq_libs; \
1085             ${MAKE} -f Makefile.inc1 _startup_libs; \
1086             ${MAKE} -f Makefile.inc1 _prebuild_libs; \
1087             ${MAKE} -f Makefile.inc1 _generic_libs;
1088
1089 #
1090 # static libgcc.a prerequisite for shared libc
1091 #
1092 _prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc
1093
1094 # These dependencies are not automatically generated:
1095 #
1096 # gnu/lib/csu, gnu/lib/libgcc, lib/csu and lib/libc must be built before
1097 # all shared libraries for ELF.
1098 #
1099 _startup_libs=  gnu/lib/csu
1100 .if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
1101 _startup_libs+= lib/csu/${MACHINE_ARCH}-elf
1102 .else
1103 _startup_libs+= lib/csu/${MACHINE_ARCH}
1104 .endif
1105 _startup_libs+= gnu/lib/libgcc
1106 _startup_libs+= lib/libc
1107
1108 gnu/lib/libgcc__L: lib/libc__L
1109
1110 _prebuild_libs= ${_kerberos5_lib_libasn1} ${_kerberos5_lib_libheimntlm} \
1111                 ${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \
1112                 ${_kerberos5_lib_libroken} \
1113                 lib/libbz2 lib/libcom_err lib/libcrypt \
1114                 lib/libexpat lib/libfetch \
1115                 ${_lib_libgssapi} ${_lib_libipx} \
1116                 lib/libkiconv lib/libkvm lib/liblzma lib/libmd \
1117                 lib/ncurses/ncurses lib/ncurses/ncursesw \
1118                 lib/libopie lib/libpam ${_lib_libthr} \
1119                 lib/libradius lib/libsbuf lib/libtacplus \
1120                 lib/libutil ${_lib_libypclnt} lib/libz lib/msun \
1121                 ${_secure_lib_libcrypto} ${_secure_lib_libssh} \
1122                 ${_secure_lib_libssl}
1123
1124 .if ${MK_LIBTHR} != "no"
1125 _lib_libthr=    lib/libthr
1126 .endif
1127
1128 _generic_libs=  ${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib
1129
1130 lib/libopie__L lib/libtacplus__L: lib/libmd__L
1131
1132 .if ${MK_CDDL} != "no"
1133 _cddl_lib= cddl/lib
1134 .endif
1135
1136 .if ${MK_CRYPT} != "no"
1137 .if ${MK_OPENSSL} != "no"
1138 _secure_lib_libcrypto= secure/lib/libcrypto
1139 _secure_lib_libssl= secure/lib/libssl
1140 lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L
1141 lib/libfetch__L: secure/lib/libcrypto__L secure/lib/libssl__L lib/libmd__L
1142 .if ${MK_OPENSSH} != "no"
1143 _secure_lib_libssh= secure/lib/libssh
1144 secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L
1145 .if ${MK_KERBEROS_SUPPORT} != "no"
1146 secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \
1147     kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \
1148     lib/libmd__L kerberos5/lib/libroken__L
1149 .endif
1150 .endif
1151 .endif
1152 _secure_lib=    secure/lib
1153 .endif
1154
1155 .if ${MK_GSSAPI} != "no"
1156 _lib_libgssapi= lib/libgssapi
1157 .endif
1158
1159 .if ${MK_IPX} != "no"
1160 _lib_libipx=    lib/libipx
1161 .endif
1162
1163 .if ${MK_KERBEROS} != "no"
1164 _kerberos5_lib= kerberos5/lib
1165 _kerberos5_lib_libasn1= kerberos5/lib/libasn1
1166 _kerberos5_lib_libkrb5= kerberos5/lib/libkrb5
1167 _kerberos5_lib_libhx509= kerberos5/lib/libhx509
1168 _kerberos5_lib_libroken= kerberos5/lib/libroken
1169 _kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm
1170 .endif
1171
1172 .if ${MK_NIS} != "no"
1173 _lib_libypclnt= lib/libypclnt
1174 .endif
1175
1176 .if ${MK_OPENSSL} == "no"
1177 lib/libfetch__L lib/libradius__L: lib/libmd__L
1178 .endif
1179
1180 .for _lib in ${_prereq_libs}
1181 ${_lib}__PL: .PHONY
1182 .if exists(${.CURDIR}/${_lib})
1183         ${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1184                 cd ${.CURDIR}/${_lib}; \
1185                 ${MAKE} DIRPRFX=${_lib}/ obj; \
1186                 ${MAKE} DIRPRFX=${_lib}/ depend; \
1187                 ${MAKE} -DWITHOUT_PROFILE -DNO_PIC DIRPRFX=${_lib}/ all; \
1188                 ${MAKE} -DWITHOUT_PROFILE -DNO_PIC DIRPRFX=${_lib}/ install
1189 .endif
1190 .endfor
1191
1192 .for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs}
1193 ${_lib}__L: .PHONY
1194 .if exists(${.CURDIR}/${_lib})
1195         ${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \
1196                 cd ${.CURDIR}/${_lib}; \
1197                 ${MAKE} DIRPRFX=${_lib}/ obj; \
1198                 ${MAKE} DIRPRFX=${_lib}/ depend; \
1199                 ${MAKE} DIRPRFX=${_lib}/ all; \
1200                 ${MAKE} DIRPRFX=${_lib}/ install
1201 .endif
1202 .endfor
1203
1204 # libpam is special: we need to build static PAM modules before
1205 # static PAM library, and dynamic PAM library before dynamic PAM
1206 # modules.
1207 lib/libpam__L: .PHONY
1208         ${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \
1209                 cd ${.CURDIR}/lib/libpam; \
1210                 ${MAKE} DIRPRFX=lib/libpam/ obj; \
1211                 ${MAKE} DIRPRFX=lib/libpam/ depend; \
1212                 ${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET all; \
1213                 ${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET install
1214
1215 _prereq_libs: ${_prereq_libs:S/$/__PL/}
1216 _startup_libs: ${_startup_libs:S/$/__L/}
1217 _prebuild_libs: ${_prebuild_libs:S/$/__L/}
1218 _generic_libs: ${_generic_libs:S/$/__L/}
1219
1220 .for __target in all clean cleandepend cleandir depend includes obj
1221 .for entry in ${SUBDIR}
1222 ${entry}.${__target}__D: .PHONY
1223         ${_+_}@if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1224                 ${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH} (${__target})"; \
1225                 edir=${entry}.${MACHINE_ARCH}; \
1226                 cd ${.CURDIR}/$${edir}; \
1227         else \
1228                 ${ECHODIR} "===> ${DIRPRFX}${entry} (${__target})"; \
1229                 edir=${entry}; \
1230                 cd ${.CURDIR}/$${edir}; \
1231         fi; \
1232         ${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1233 .endfor
1234 par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
1235 .endfor
1236
1237 .include <bsd.subdir.mk>
1238
1239 .if make(check-old) || make(check-old-dirs) || \
1240     make(check-old-files) || make(check-old-libs) || \
1241     make(delete-old) || make(delete-old-dirs) || \
1242     make(delete-old-files) || make(delete-old-libs)
1243
1244 #
1245 # check for / delete old files section
1246 #
1247
1248 .include "ObsoleteFiles.inc"
1249
1250 OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \
1251 else you can not start such an application. Consult UPDATING for more \
1252 information regarding how to cope with the removal/revision bump of a \
1253 specific library."
1254
1255 .if !defined(BATCH_DELETE_OLD_FILES)
1256 RM_I=-i
1257 .else
1258 RM_I=-v
1259 .endif
1260
1261 delete-old-files:
1262         @echo ">>> Removing old files (only deletes safe to delete libs)"
1263 # Ask for every old file if the user really wants to remove it.
1264 # It's annoying, but better safe than sorry.
1265         @for file in ${OLD_FILES} ${OLD_FILES:Musr/share/*.gz:R}; do \
1266                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1267                         chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1268                         rm ${RM_I} "${DESTDIR}/$${file}"; \
1269                 fi; \
1270         done
1271 # Remove catpages without corresponding manpages.
1272         @exec 3<&0; \
1273         find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1274         sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1275         while read catpage; do \
1276                 read manpage; \
1277                 if [ ! -e "$${manpage}" ]; then \
1278                         rm ${RM_I} $${catpage} <&3 ; \
1279                 fi; \
1280         done
1281         @echo ">>> Old files removed"
1282
1283 check-old-files:
1284         @echo ">>> Checking for old files"
1285         @for file in ${OLD_FILES} ${OLD_FILES:Musr/share/*.gz:R}; do \
1286                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1287                         echo "${DESTDIR}/$${file}"; \
1288                 fi; \
1289         done
1290 # Check for catpages without corresponding manpages.
1291         @find ${DESTDIR}/usr/share/man/cat* ! -type d | \
1292         sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \
1293         while read catpage; do \
1294                 read manpage; \
1295                 if [ ! -e "$${manpage}" ]; then \
1296                         echo $${catpage} ; \
1297                 fi; \
1298         done
1299
1300 delete-old-libs:
1301         @echo ">>> Removing old libraries"
1302         @echo "${OLD_LIBS_MESSAGE}" | fmt
1303         @for file in ${OLD_LIBS}; do \
1304                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1305                         chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \
1306                         rm ${RM_I} "${DESTDIR}/$${file}"; \
1307                 fi; \
1308         done
1309         @echo ">>> Old libraries removed"
1310
1311 check-old-libs:
1312         @echo ">>> Checking for old libraries"
1313         @for file in ${OLD_LIBS}; do \
1314                 if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \
1315                         echo "${DESTDIR}/$${file}"; \
1316                 fi; \
1317         done
1318
1319 delete-old-dirs:
1320         @echo ">>> Removing old directories"
1321         @for dir in ${OLD_DIRS}; do \
1322                 if [ -d "${DESTDIR}/$${dir}" ]; then \
1323                         rmdir -v "${DESTDIR}/$${dir}" || true; \
1324                 elif [ -L "${DESTDIR}/$${dir}" ]; then \
1325                         echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1326                 fi; \
1327         done
1328         @echo ">>> Old directories removed"
1329
1330 check-old-dirs:
1331         @echo ">>> Checking for old directories"
1332         @for dir in ${OLD_DIRS}; do \
1333                 if [ -d "${DESTDIR}/$${dir}" ]; then \
1334                         echo "${DESTDIR}/$${dir}"; \
1335                 elif [ -L "${DESTDIR}/$${dir}" ]; then \
1336                         echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \
1337                 fi; \
1338         done
1339
1340 delete-old: delete-old-files delete-old-dirs
1341         @echo "To remove old libraries run '${MAKE} delete-old-libs'."
1342
1343 check-old: check-old-files check-old-libs check-old-dirs
1344         @echo "To remove old files and directories run '${MAKE} delete-old'."
1345         @echo "To remove old libraries run '${MAKE} delete-old-libs'."
1346
1347 .endif
1348
1349 #
1350 # showconfig - show build configuration.
1351 #
1352 showconfig:
1353         @${MAKE} -n -f bsd.own.mk -V dummy -dg1 | grep ^MK_ | sort
1354
1355
1356 ###############
1357
1358 .if defined(XDEV) && defined(XDEV_ARCH)
1359
1360 NOFUN=-DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \
1361         -DWITHOUT_MAN -DWITHOUT_NLS -DWITHOUT_PROFILE \
1362         -DWITHOUT_KERBEROS -DWITHOUT_RESCUE -DNO_WARNS
1363
1364 XDDIR=${XDEV}-freebsd
1365 XDTP=/usr/${XDDIR}
1366 CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR} \
1367         TARGET=${XDEV} TARGET_ARCH=${XDEV_ARCH}
1368 CDENV= ${CDBENV} \
1369         _SHLIBDIRPREFIX=${XDTP} \
1370         TOOLS_PREFIX=${XDTP}
1371 CD2ENV=${CDENV} \
1372         MACHINE=${XDEV} MACHINE_ARCH=${XDEV_ARCH}
1373
1374 CDTMP=  ${MAKEOBJDIRPREFIX}/${XDEV}/${.CURDIR}/tmp
1375 CDMAKE=${CDENV} ${MAKE} ${NOFUN}
1376 CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDTP}/usr/bin:${PATH} ${MAKE} ${NOFUN}
1377 XDDESTDIR=${DESTDIR}${XDTP}
1378 .if !defined(OSREL)
1379 OSREL!= uname -r | sed -e 's/[-(].*//'
1380 .endif
1381
1382 .ORDER: xdev-build xdev-install
1383 xdev: xdev-build xdev-install
1384
1385 .ORDER: _xb-build-tools _xb-cross-tools
1386 xdev-build: _xb-build-tools _xb-cross-tools
1387
1388 _xb-build-tools:
1389         ${_+_}cd ${.CURDIR}; \
1390         ${CDBENV} ${MAKE} -f Makefile.inc1 ${NOFUN} build-tools
1391
1392 _xb-cross-tools:
1393 .for _tool in \
1394     gnu/usr.bin/binutils \
1395     gnu/usr.bin/cc
1396         ${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,depend,all)"; \
1397         cd ${.CURDIR}/${_tool}; \
1398         ${CDMAKE} DIRPRFX=${_tool}/ obj; \
1399         ${CDMAKE} DIRPRFX=${_tool}/ depend; \
1400         ${CDMAKE} DIRPRFX=${_tool}/ all
1401 .endfor
1402
1403 _xi-mtree:
1404         ${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}"
1405         mkdir -p ${XDDESTDIR}
1406         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \
1407             -p ${XDDESTDIR} >/dev/null
1408         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
1409             -p ${XDDESTDIR}/usr >/dev/null
1410         mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
1411             -p ${XDDESTDIR}/usr/include >/dev/null
1412
1413 .ORDER: _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
1414 xdev-install: _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links
1415
1416 _xi-cross-tools:
1417         @echo "_xi-cross-tools"
1418 .for _tool in \
1419     gnu/usr.bin/binutils \
1420     gnu/usr.bin/cc
1421         ${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \
1422         cd ${.CURDIR}/${_tool}; \
1423         ${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR}
1424 .endfor
1425
1426 _xi-includes:
1427         ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 par-includes \
1428                 DESTDIR=${XDDESTDIR}
1429
1430 _xi-libraries:
1431         ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \
1432                 DESTDIR=${XDDESTDIR}
1433
1434 _xi-links:
1435         ${_+_}cd ${XDDESTDIR}/usr/bin; \
1436                 for i in *; do \
1437                         ln -sf ../../${XDTP}/usr/bin/$$i \
1438                             ../../../../usr/bin/${XDDIR}-$$i; \
1439                         ln -sf ../../${XDTP}/usr/bin/$$i \
1440                             ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \
1441                 done
1442 .endif