Makefile revision 36408
1#
2#	$Id: Makefile,v 1.181 1998/05/26 20:12:43 sos Exp $
3#
4# While porting to the another architecture include the bootstrap instead
5# of the normal build.
6#
7.if exists(${.CURDIR}/Makefile.${MACHINE}) && defined(BOOTSTRAP_WORLD)
8.include "${.CURDIR}/Makefile.${MACHINE}"
9.else
10#
11# Make command line options:
12#	-DCLOBBER will remove /usr/include
13#	-DMAKE_KERBEROS4 to build KerberosIV
14#	-DALLLANG to build documentation for all languages
15#	  (where available -- see share/doc/Makefile)
16#
17#	-DNOCLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
18#	-DNOCLEAN do not clean at all
19#	-DNOTOOLS do not rebuild any tools first
20#	-DNOCRYPT will prevent building of crypt versions
21#	-DNOLKM do not build loadable kernel modules
22#	-DNOOBJDIR do not run ``${MAKE} obj''
23#	-DNOPROFILE do not build profiled libraries
24#	-DNOSECURE do not go into secure subdir
25#	-DNOGAMES do not go into games subdir
26#	-DNOSHARE do not go into share subdir
27#	-DNOINFO do not make or install info files
28#	-DNOLIBC_R do not build libc_r.
29#	LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
30
31#
32# The intended user-driven targets are:
33# buildworld  - rebuild *everything*, including glue to help do upgrades
34# installworld- install everything built by "buildworld"
35# world       - buildworld + installworld
36# update      - convenient way to update your source tree (eg: sup/cvs)
37# most        - build user commands, no libraries or include files
38# installmost - install user commands, no libraries or include files
39#
40# Standard targets (not defined here) are documented in the makefiles in
41# /usr/share/mk.  These include:
42#		obj depend all install clean cleandepend cleanobj
43
44.if (!make(world)) && (!make(buildworld)) && (!make(installworld))
45.MAKEFLAGS:=	-m ${.CURDIR}/share/mk ${.MAKEFLAGS}
46.endif
47
48# Put initial settings here.
49SUBDIR=
50
51# We must do share/info early so that installation of info `dir'
52# entries works correctly.  Do it first since it is less likely to
53# grow dependencies on include and lib than vice versa.
54.if exists(share/info)
55SUBDIR+= share/info
56.endif
57
58# We must do include and lib early so that the perl *.ph generation
59# works correctly as it uses the header files installed by this.
60.if exists(include)
61SUBDIR+= include
62.endif
63.if exists(lib)
64SUBDIR+= lib
65.endif
66
67.if exists(bin)
68SUBDIR+= bin
69.endif
70.if exists(games) && !defined(NOGAMES)
71SUBDIR+= games
72.endif
73.if exists(gnu)
74SUBDIR+= gnu
75.endif
76.if exists(kerberosIV) && exists(crypto) && !defined(NOCRYPT) && \
77    defined(MAKE_KERBEROS4)
78SUBDIR+= kerberosIV
79.endif
80.if exists(libexec)
81SUBDIR+= libexec
82.endif
83.if exists(sbin)
84SUBDIR+= sbin
85.endif
86.if exists(share) && !defined(NOSHARE)
87SUBDIR+= share
88.endif
89.if exists(sys)
90SUBDIR+= sys
91.endif
92.if exists(usr.bin)
93SUBDIR+= usr.bin
94.endif
95.if exists(usr.sbin)
96SUBDIR+= usr.sbin
97.endif
98.if exists(secure) && !defined(NOCRYPT) && !defined(NOSECURE)
99SUBDIR+= secure
100.endif
101.if exists(lkm) && !defined(NOLKM)
102SUBDIR+= lkm
103.endif
104
105# etc must be last for "distribute" to work
106.if exists(etc) && make(distribute)
107SUBDIR+= etc
108.endif
109
110# These are last, since it is nice to at least get the base system
111# rebuilt before you do them.
112.if defined(LOCAL_DIRS)
113.for _DIR in ${LOCAL_DIRS}
114.if exists(${_DIR}) & exists(${_DIR}/Makefile)
115SUBDIR+= ${_DIR}
116.endif
117.endfor
118.endif
119
120# Handle -DNOOBJDIR, -DNOCLEAN and -DNOCLEANDIR
121.if defined(NOOBJDIR)
122OBJDIR=
123.else
124OBJDIR=		obj
125.endif
126
127.if defined(NOCLEAN)
128CLEANDIR=
129.else
130.if defined(NOCLEANDIR)
131CLEANDIR=	clean cleandepend
132.else
133CLEANDIR=	cleandir
134.endif
135.endif
136
137.if !defined(NOCLEAN) && ${.MAKEFLAGS:M-j} == ""
138_NODEPEND=	true
139.endif
140.if defined(_NODEPEND)
141_DEPEND=	cleandepend
142.else
143_DEPEND=	depend
144.endif
145
146SUP?=		cvsup
147SUPFLAGS?=	-g -L 2 -P -
148
149#
150# While building tools for bootstrapping, we don't need to waste time on
151# shared or profiled libraries, shared linkage, or documentation, except
152# when the tools won't get cleaned we must use the defaults for shared
153# libraries and shared linkage (and this doesn't waste time).
154# XXX actually, we do need to waste time building shared libraries.
155#
156.if defined(NOCLEAN)
157MK_FLAGS=	-DNOINFO -DNOMAN         -DNOPROFILE
158.else
159MK_FLAGS=	-DNOINFO -DNOMAN -DNOPIC -DNOPROFILE -DNOSHARED
160.endif
161
162#
163# world
164#
165# Attempt to rebuild and reinstall *everything*, with reasonable chance of
166# success, regardless of how old your existing system is.
167#
168# >> Beware, it overwrites the local build environment! <<
169#
170world:
171	@echo "--------------------------------------------------------------"
172	@echo "make world started on `LC_TIME=C date`"
173	@echo "--------------------------------------------------------------"
174.if target(pre-world)
175	@echo
176	@echo "--------------------------------------------------------------"
177	@echo " Making 'pre-world' target"
178	@echo "--------------------------------------------------------------"
179	cd ${.CURDIR}; ${MAKE} pre-world
180.endif
181	cd ${.CURDIR}; ${MAKE} buildworld
182	cd ${.CURDIR}; ${MAKE} -B installworld
183.if target(post-world)
184	@echo
185	@echo "--------------------------------------------------------------"
186	@echo " Making 'post-world' target"
187	@echo "--------------------------------------------------------------"
188	cd ${.CURDIR}; ${MAKE} post-world
189.endif
190	@echo
191	@echo "--------------------------------------------------------------"
192	@echo "make world completed on `LC_TIME=C date`"
193	@echo "--------------------------------------------------------------"
194
195.if defined(MAKEOBJDIRPREFIX)
196WORLDTMP=	${MAKEOBJDIRPREFIX}${.CURDIR}/tmp
197.else
198WORLDTMP=	/usr/obj${.CURDIR}/tmp
199.endif
200STRICTTMPPATH=	${WORLDTMP}/sbin:${WORLDTMP}/usr/sbin:${WORLDTMP}/bin:${WORLDTMP}/usr/bin
201TMPPATH=	${STRICTTMPPATH}:${PATH}
202
203# XXX COMPILER_PATH is needed for finding cc1, ld and as
204# XXX GCC_EXEC_PREFIX is for *crt.o.  It is probably unnecssary now
205#	tbat LIBRARY_PATH is set.  We still can't use -nostdlib, since gcc
206#	wouldn't link *crt.o or libgcc if it were used.
207# XXX LD_LIBRARY_PATH is for ld.so.  It is also used by ld, although we don't
208#	want that - all compile-time library paths should be resolved by gcc.
209#	It fails for set[ug]id executables (are any used?).
210COMPILER_ENV=	BISON_SIMPLE=${WORLDTMP}/usr/share/misc/bison.simple \
211		OBJFORMAT_PATH=${WORLDTMP}/usr/libexec \
212		COMPILER_PATH=${WORLDTMP}/usr/libexec:${WORLDTMP}/usr/bin \
213		GCC_EXEC_PREFIX=${WORLDTMP}${SHLIBDIR}:${WORLDTMP}/usr/lib/ \
214		LD_LIBRARY_PATH=${WORLDTMP}${SHLIBDIR} \
215		LIBRARY_PATH=${WORLDTMP}${SHLIBDIR}:${WORLDTMP}/usr/lib
216
217BMAKEENV=	PATH=${TMPPATH} ${COMPILER_ENV} NOEXTRADEPEND=t
218XMAKEENV=	PATH=${STRICTTMPPATH} ${COMPILER_ENV} \
219		CFLAGS="-nostdinc ${CFLAGS}"	# XXX -nostdlib
220
221# used to compile and install 'make' in temporary build tree
222MAKETMP=	${WORLDTMP}/make
223IBMAKE=	${BMAKEENV} MAKEOBJDIR=${MAKETMP} ${MAKE} DESTDIR=${WORLDTMP}
224# bootstrap make
225BMAKE=	${BMAKEENV} ${WORLDTMP}/usr/bin/make DESTDIR=${WORLDTMP}
226# cross make used for compilation
227XMAKE=	${XMAKEENV} ${WORLDTMP}/usr/bin/make DESTDIR=${WORLDTMP}
228# cross make used for final installation
229IXMAKE=	${XMAKEENV} ${WORLDTMP}/usr/bin/make
230
231#
232# buildworld
233#
234# Attempt to rebuild the entire system, with reasonable chance of
235# success, regardless of how old your existing system is.
236#
237buildworld:
238.if !defined(NOCLEAN)
239	@echo
240	@echo "--------------------------------------------------------------"
241	@echo " Cleaning up the temporary build tree"
242	@echo "--------------------------------------------------------------"
243	mkdir -p ${WORLDTMP}
244	chflags -R noschg ${WORLDTMP}/
245	rm -rf ${WORLDTMP}
246.endif
247.if !defined(NOTOOLS)
248	@echo
249	@echo "--------------------------------------------------------------"
250	@echo " Making make"
251	@echo "--------------------------------------------------------------"
252	mkdir -p ${WORLDTMP}/usr/bin ${MAKETMP}
253	( \
254	cd ${.CURDIR}/usr.bin/make; \
255		MAKEOBJDIRPREFIX=""; unset MAKEOBJDIRPREFIX; \
256		${IBMAKE} -I${.CURDIR}/share/mk ${MK_FLAGS} all; \
257		${IBMAKE} -I${.CURDIR}/share/mk ${MK_FLAGS} install; \
258		${IBMAKE} -I${.CURDIR}/share/mk ${MK_FLAGS} clean \
259	)
260.endif
261	@echo
262	@echo "--------------------------------------------------------------"
263	@echo " Making hierarchy"
264	@echo "--------------------------------------------------------------"
265	cd ${.CURDIR}; ${BMAKE} hierarchy
266.if !defined(NOCLEAN)
267	@echo
268	@echo "--------------------------------------------------------------"
269	@echo " Cleaning up the obj tree"
270	@echo "--------------------------------------------------------------"
271	cd ${.CURDIR}; ${BMAKE} ${CLEANDIR:S/^/par-/}
272.endif
273.if !defined(NOOBJDIR)
274	@echo
275	@echo "--------------------------------------------------------------"
276	@echo " Rebuilding the obj tree"
277	@echo "--------------------------------------------------------------"
278	cd ${.CURDIR}; ${BMAKE} par-${OBJDIR}
279.endif
280.if !defined(NOTOOLS)
281	@echo
282	@echo "--------------------------------------------------------------"
283	@echo " Rebuilding bootstrap tools"
284	@echo "--------------------------------------------------------------"
285	cd ${.CURDIR}; ${BMAKE} bootstrap
286	@echo
287	@echo "--------------------------------------------------------------"
288	@echo " Rebuilding tools necessary to build the include files"
289	@echo "--------------------------------------------------------------"
290	cd ${.CURDIR}; ${BMAKE} include-tools
291.endif
292	@echo
293	@echo "--------------------------------------------------------------"
294	@echo " Rebuilding ${DESTDIR}/usr/include"
295	@echo "--------------------------------------------------------------"
296	cd ${.CURDIR}; SHARED=symlinks ${BMAKE} includes
297	@echo
298	@echo "--------------------------------------------------------------"
299	@echo " Rebuilding bootstrap libraries"
300	@echo "--------------------------------------------------------------"
301	cd ${.CURDIR}; ${BMAKE} bootstrap-libraries
302.if !defined(NOTOOLS)
303	@echo
304	@echo "--------------------------------------------------------------"
305	@echo " Rebuilding tools needed to build libraries"
306	@echo "--------------------------------------------------------------"
307	cd ${.CURDIR}; ${BMAKE} lib-tools
308.endif
309.if !defined(NOTOOLS)
310	@echo
311	@echo "--------------------------------------------------------------"
312	@echo " Rebuilding all other tools needed to build the world"
313	@echo "--------------------------------------------------------------"
314	cd ${.CURDIR}; ${BMAKE} build-tools
315.endif
316.if !defined(_NODEPEND)
317	@echo
318	@echo "--------------------------------------------------------------"
319	@echo " Rebuilding dependencies"
320	@echo "--------------------------------------------------------------"
321	cd ${.CURDIR}; ${XMAKE} par-depend
322.endif
323	@echo
324	@echo "--------------------------------------------------------------"
325	@echo " Building libraries"
326	@echo "--------------------------------------------------------------"
327	cd ${.CURDIR}; ${XMAKE} -DNOINFO -DNOMAN libraries
328	@echo
329	@echo "--------------------------------------------------------------"
330	@echo " Building everything.."
331	@echo "--------------------------------------------------------------"
332	cd ${.CURDIR}; ${XMAKE} all
333
334#
335# installworld
336#
337# Installs everything compiled by a 'buildworld'.
338#
339installworld:
340	cd ${.CURDIR}; ${IXMAKE} reinstall
341
342#
343# reinstall
344#
345# If you have a build server, you can NFS mount the source and obj directories
346# and do a 'make reinstall' on the *client* to install new binaries from the
347# most recent server build.
348#
349reinstall:
350	@echo "--------------------------------------------------------------"
351	@echo " Making hierarchy"
352	@echo "--------------------------------------------------------------"
353	cd ${.CURDIR}; ${MAKE} hierarchy
354	@echo
355	@echo "--------------------------------------------------------------"
356	@echo " Installing everything.."
357	@echo "--------------------------------------------------------------"
358	cd ${.CURDIR}; ${MAKE} install
359	@echo
360	@echo "--------------------------------------------------------------"
361	@echo " Re-scanning the shared libraries.."
362	@echo "--------------------------------------------------------------"
363	cd ${.CURDIR}; ldconfig -R
364	@echo
365	@echo "--------------------------------------------------------------"
366	@echo " Rebuilding man page indexes"
367	@echo "--------------------------------------------------------------"
368	cd ${.CURDIR}/share/man; ${MAKE} makedb
369
370#
371# update
372#
373# Update the source tree, by running sup and/or running cvs to update to the
374# latest copy.
375#
376update:
377.if defined(SUP_UPDATE)
378	@echo "--------------------------------------------------------------"
379	@echo "Running ${SUP}"
380	@echo "--------------------------------------------------------------"
381	@${SUP} ${SUPFLAGS} ${SUPFILE}
382.if defined(SUPFILE1)
383	@${SUP} ${SUPFLAGS} ${SUPFILE1}
384.endif
385.if defined(SUPFILE2)
386	@${SUP} ${SUPFLAGS} ${SUPFILE2}
387.endif
388.endif
389.if defined(CVS_UPDATE)
390	@echo "--------------------------------------------------------------"
391	@echo "Updating /usr/src from cvs repository" ${CVSROOT}
392	@echo "--------------------------------------------------------------"
393	cd ${.CURDIR}; cvs -q update -P -d
394.endif
395
396#
397# most
398#
399# Build most of the user binaries on the existing system libs and includes.
400#
401most:
402	@echo "--------------------------------------------------------------"
403	@echo " Building programs only"
404	@echo "--------------------------------------------------------------"
405	cd ${.CURDIR}/bin;		${MAKE} all
406	cd ${.CURDIR}/sbin;		${MAKE} all
407	cd ${.CURDIR}/libexec;		${MAKE} all
408	cd ${.CURDIR}/usr.bin;		${MAKE} all
409	cd ${.CURDIR}/usr.sbin;		${MAKE} all
410	cd ${.CURDIR}/gnu/libexec;	${MAKE} all
411	cd ${.CURDIR}/gnu/usr.bin;	${MAKE} all
412	cd ${.CURDIR}/gnu/usr.sbin;	${MAKE} all
413#.if defined(MAKE_KERBEROS4) && !defined(NOCRYPT)
414#	cd ${.CURDIR}/kerberosIV;	${MAKE} most
415#.endif
416#.if !defined(NOSECURE) && !defined(NOCRYPT)
417#	cd ${.CURDIR}/secure;		${MAKE} most
418#.endif
419
420#
421# installmost
422#
423# Install the binaries built by the 'most' target.  This does not include
424# libraries or include files.
425#
426installmost:
427	@echo "--------------------------------------------------------------"
428	@echo " Installing programs only"
429	@echo "--------------------------------------------------------------"
430	cd ${.CURDIR}/bin;		${MAKE} install
431	cd ${.CURDIR}/sbin;		${MAKE} install
432	cd ${.CURDIR}/libexec;		${MAKE} install
433	cd ${.CURDIR}/usr.bin;		${MAKE} install
434	cd ${.CURDIR}/usr.sbin;		${MAKE} install
435	cd ${.CURDIR}/gnu/libexec;	${MAKE} install
436	cd ${.CURDIR}/gnu/usr.bin;	${MAKE} install
437	cd ${.CURDIR}/gnu/usr.sbin;	${MAKE} install
438#.if defined(MAKE_KERBEROS4) && !defined(NOCRYPT)
439#	cd ${.CURDIR}/kerberosIV;	${MAKE} installmost
440#.endif
441#.if !defined(NOSECURE) && !defined(NOCRYPT)
442#	cd ${.CURDIR}/secure;		${MAKE} installmost
443#.endif
444
445#
446# ------------------------------------------------------------------------
447#
448# From here onwards are utility targets used by the 'make world' and
449# related targets.  If your 'world' breaks, you may like to try to fix
450# the problem and manually run the following targets to attempt to
451# complete the build.  Beware, this is *not* guaranteed to work, you
452# need to have a pretty good grip on the current state of the system
453# to attempt to manually finish it.  If in doubt, 'make world' again.
454#
455
456#
457# heirarchy - ensure that all the needed directories are present
458#
459hierarchy:
460	cd ${.CURDIR}/etc;		${MAKE} distrib-dirs
461
462#
463# bootstrap - [re]build tools needed to run the actual build, this includes
464# tools needed by 'make depend', as some tools are needed to generate source
465# for the dependency information to be gathered from.
466#
467bootstrap:
468.if defined(DESTDIR)
469	rm -f ${DESTDIR}/usr/src/sys
470	ln -s ${.CURDIR}/sys ${DESTDIR}/usr/src
471	cd ${.CURDIR}/include; find -dx . | cpio -dump ${DESTDIR}/usr/include
472	cd ${.CURDIR}/include; ${MAKE} symlinks
473.endif
474	cd ${.CURDIR}/usr.bin/make; ${MAKE} ${MK_FLAGS} ${_DEPEND}; \
475		${MAKE} ${MK_FLAGS} all; \
476		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
477	cd ${.CURDIR}/usr.bin/xinstall; ${MAKE} ${MK_FLAGS} ${_DEPEND}; \
478		${MAKE} ${MK_FLAGS} all; \
479		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
480	cd ${.CURDIR}/usr.bin/lex; ${MAKE} bootstrap; \
481		${MAKE} ${MK_FLAGS} ${_DEPEND}; \
482		${MAKE} ${MK_FLAGS} -DNOLIB all; \
483		${MAKE} ${MK_FLAGS} -DNOLIB -B install ${CLEANDIR}
484.if !defined(NOOBJDIR)
485	cd ${.CURDIR}/usr.bin/lex; ${MAKE} ${OBJDIR}
486.endif
487
488#
489# include-tools - generally the same as 'bootstrap', except that it's for
490# things that are specifically needed to generate include files.
491#
492# XXX should be merged with bootstrap, it's not worth keeeping them separate.
493# Well, maybe it is now.  We force 'cleandepend' here to avoid dependencies
494# on cleaned away headers in ${WORLDTMP}.
495#
496include-tools:
497.for d in usr.bin/compile_et usr.bin/rpcgen
498	cd ${.CURDIR}/$d; ${MAKE} cleandepend; \
499		${MAKE} ${MK_FLAGS} ${_DEPEND}; \
500		${MAKE} ${MK_FLAGS} all; \
501		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
502.endfor
503
504#
505# includes - possibly generate and install the include files.
506#
507includes:
508.if defined(CLOBBER)
509	rm -rf ${DESTDIR}/usr/include/*
510	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
511		-p ${DESTDIR}/usr/include
512.endif
513	cd ${.CURDIR}/include;			${MAKE} -B all install
514	cd ${.CURDIR}/gnu/include;		${MAKE} install
515	cd ${.CURDIR}/gnu/lib/libmp;		${MAKE} beforeinstall
516	cd ${.CURDIR}/gnu/lib/libobjc;		${MAKE} beforeinstall
517	cd ${.CURDIR}/gnu/lib/libreadline;	${MAKE} beforeinstall
518	cd ${.CURDIR}/gnu/lib/libregex;		${MAKE} beforeinstall
519	cd ${.CURDIR}/gnu/lib/libstdc++;	${MAKE} beforeinstall
520	cd ${.CURDIR}/gnu/lib/libg++;		${MAKE} beforeinstall
521	cd ${.CURDIR}/gnu/lib/libdialog;	${MAKE} beforeinstall
522	cd ${.CURDIR}/gnu/lib/libgmp;		${MAKE} beforeinstall
523.if exists(secure) && !defined(NOCRYPT)
524	cd ${.CURDIR}/secure/lib/libdes;	${MAKE} beforeinstall
525.endif
526.if exists(kerberosIV) && !defined(NOCRYPT) && defined(MAKE_KERBEROS4)
527	cd ${.CURDIR}/kerberosIV/lib/libacl;	${MAKE} beforeinstall
528	cd ${.CURDIR}/kerberosIV/lib/libkadm;	${MAKE} beforeinstall
529	cd ${.CURDIR}/kerberosIV/lib/libkafs;	${MAKE} beforeinstall
530	cd ${.CURDIR}/kerberosIV/lib/libkdb;	${MAKE} beforeinstall
531	cd ${.CURDIR}/kerberosIV/lib/libkrb;	${MAKE} beforeinstall
532	cd ${.CURDIR}/kerberosIV/lib/libtelnet; ${MAKE} beforeinstall
533.else
534	cd ${.CURDIR}/lib/libtelnet;		${MAKE} beforeinstall
535.endif
536.if exists(${.CURDIR}/lib/csu/${MACHINE})
537	cd ${.CURDIR}/lib/csu/${MACHINE};	${MAKE} beforeinstall
538.endif
539	cd ${.CURDIR}/lib/libalias;		${MAKE} beforeinstall
540	cd ${.CURDIR}/lib/libc;			${MAKE} beforeinstall
541	cd ${.CURDIR}/lib/libcalendar;		${MAKE} beforeinstall
542	cd ${.CURDIR}/lib/libcurses;		${MAKE} beforeinstall
543	cd ${.CURDIR}/lib/libdisk;		${MAKE} beforeinstall
544	cd ${.CURDIR}/lib/libedit;		${MAKE} beforeinstall
545	cd ${.CURDIR}/lib/libftpio;		${MAKE} beforeinstall
546	cd ${.CURDIR}/lib/libmd;		${MAKE} beforeinstall
547	cd ${.CURDIR}/lib/libmytinfo;		${MAKE} beforeinstall
548	cd ${.CURDIR}/lib/libncurses;		${MAKE} beforeinstall
549.if !defined(WANT_CSRG_LIBM)
550	cd ${.CURDIR}/lib/msun;			${MAKE} beforeinstall
551.endif
552	cd ${.CURDIR}/lib/libopie;		${MAKE} beforeinstall
553	cd ${.CURDIR}/lib/libpcap;		${MAKE} beforeinstall
554	cd ${.CURDIR}/lib/librpcsvc;		${MAKE} beforeinstall
555	cd ${.CURDIR}/lib/libskey;		${MAKE} beforeinstall
556.if !defined(NOTCL) && exists (${.CURDIR}/contrib/tcl) && \
557	exists(${.CURDIR}/usr.bin/tclsh) && exists (${.CURDIR}/lib/libtcl)
558	cd ${.CURDIR}/lib/libtcl;		${MAKE} installhdrs
559.endif
560	cd ${.CURDIR}/lib/libtermcap;		${MAKE} beforeinstall
561	cd ${.CURDIR}/lib/libcom_err;		${MAKE} beforeinstall
562	cd ${.CURDIR}/lib/libss;		${MAKE} -B hdrs beforeinstall
563	cd ${.CURDIR}/lib/libscsi;		${MAKE} beforeinstall
564	cd ${.CURDIR}/lib/libutil;		${MAKE} beforeinstall
565	cd ${.CURDIR}/lib/libvgl;		${MAKE} beforeinstall
566	cd ${.CURDIR}/lib/libz;			${MAKE} beforeinstall
567	cd ${.CURDIR}/usr.bin/f2c;		${MAKE} beforeinstall
568	cd ${.CURDIR}/usr.bin/lex;		${MAKE} beforeinstall
569
570#
571# lib-tools - build tools to compile and install the libraries.
572#
573# XXX gperf is required for cc
574# XXX a new ld and tsort is required for cc
575lib-tools:
576.for d in				\
577		gnu/usr.bin/gperf	\
578		gnu/usr.bin/ld		\
579		usr.bin/tsort		\
580		gnu/usr.bin/as		\
581		gnu/usr.bin/bison	\
582		gnu/usr.bin/cc		\
583		usr.bin/ar		\
584		usr.bin/lex/lib		\
585		usr.bin/mk_cmds		\
586		usr.bin/nm		\
587		usr.bin/ranlib		\
588		usr.bin/strip		\
589		usr.bin/objformat	\
590		usr.bin/env		\
591		gnu/usr.bin/binutils	\
592		usr.bin/uudecode
593	cd ${.CURDIR}/$d; ${MAKE} ${MK_FLAGS} ${_DEPEND}; \
594		${MAKE} ${MK_FLAGS} all; \
595		${MAKE} ${MK_FLAGS} -B install; \
596		${MAKE} ${MK_FLAGS:S/-DNOPIC//} -B ${CLEANDIR} ${OBJDIR}
597.endfor
598
599#
600# We have to know too much about ordering and subdirs in the lib trees:
601#
602# To satisfy shared library linkage when only the libraries being built
603# are visible:
604#
605# libcom_err must be built before libss.
606# libcrypt and libmd must be built before libskey.
607# libm must be built before libtcl.
608# libmytinfo must be built before libdialog and libncurses.
609# libncurses must be built before libdialog.
610# libtermcap must be built before libcurses, libedit and libreadline.
611#
612# Some libraries are built conditionally and/or are in inconsistently
613# named directories:
614#
615.if exists(lib/csu/${MACHINE}.pcc)
616_csu=lib/csu/${MACHINE}.pcc
617.else
618_csu=lib/csu/${MACHINE}
619.endif
620
621_libcrypt=	lib/libcrypt
622.if !defined(NOSECURE) && !defined(NOCRYPT)
623_libcrypt+=	secure/lib/libcrypt
624.endif
625
626.if defined(WANT_CSRG_LIBM)
627_libm=	lib/libm
628.else
629_libm=	lib/msun
630.endif
631
632#
633# bootstrap-libraries - build just enough libraries for the bootstrap
634# tools, and install them under ${WORLDTMP}.
635#
636# Build csu and libgcc early so that some tools get linked to the new
637# versions (too late for the main tools, however).  Then build the
638# necessary prerequisite libraries (libtermcap just needs to be before
639# libcurses, and this only matters for the NOCLEAN case when NOPIC is
640# not set).
641#
642# This is mostly wrong.  The build tools must run on the host system,
643# so they should use host libraries.  We depend on the target being
644# similar enough to the host for new target libraries to work on the
645# host.
646#
647bootstrap-libraries:
648.for _lib in ${_csu} gnu/usr.bin/cc/libgcc lib/libtermcap \
649    gnu/lib/libregex gnu/lib/libreadline lib/libc \
650    lib/libcrypt lib/libcurses lib/libedit ${_libm} \
651    lib/libmd lib/libutil lib/libz usr.bin/lex/lib
652.if exists(${.CURDIR}/${_lib})
653	cd ${.CURDIR}/${_lib}; \
654		${MAKE} ${MK_FLAGS} ${_DEPEND}; \
655		${MAKE} ${MK_FLAGS} all; \
656		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
657.endif
658.endfor
659
660#
661# libraries - build all libraries, and install them under ${DESTDIR}.
662#
663# The ordering is not as special as for bootstrap-libraries.  Build
664# the prerequisites first, then build almost everything else in
665# alphabetical order.
666#
667libraries:
668.for _lib in lib/libcom_err ${_libcrypt} ${_libm} lib/libmytinfo \
669    lib/libncurses lib/libtermcap \
670    gnu/lib gnu/usr.bin/cc/libgcc lib usr.bin/lex/lib usr.sbin/pcvt/keycap
671.if exists(${.CURDIR}/${_lib})
672	cd ${.CURDIR}/${_lib}; ${MAKE} all; ${MAKE} -B install
673.endif
674.endfor
675.if exists(${.CURDIR}/secure/lib) && !defined(NOCRYPT) && !defined(NOSECURE)
676	cd ${.CURDIR}/secure/lib; ${MAKE} all; ${MAKE} -B install
677.endif
678.if exists(${.CURDIR}/kerberosIV/lib) && !defined(NOCRYPT) && \
679    defined(MAKE_KERBEROS4)
680	cd ${.CURDIR}/kerberosIV/lib; ${MAKE} all; ${MAKE} -B install
681.endif
682
683#
684# build-tools - build and install any other tools needed to complete the
685# compile and install.
686# ifdef stale
687# bc and cpp are required to build groff.  Otherwise, the order here is
688# mostly historical, i.e., bogus.
689# chmod is used to build gcc's tmpmultilib[2] at obscure times.
690# endif stale
691# XXX uname is a bug - the target should not depend on the host.
692#
693build-tools:
694.for d in				\
695		bin/cat 		\
696		bin/chmod		\
697		bin/cp 			\
698		bin/date		\
699		bin/dd			\
700		bin/echo		\
701		bin/expr		\
702		bin/hostname		\
703		bin/ln			\
704		bin/ls			\
705		bin/mkdir		\
706		bin/mv			\
707		bin/rm			\
708		bin/sh			\
709		bin/test		\
710		gnu/usr.bin/awk		\
711		gnu/usr.bin/bc		\
712		gnu/usr.bin/grep	\
713		gnu/usr.bin/groff	\
714		gnu/usr.bin/gzip	\
715		gnu/usr.bin/man/makewhatis	\
716		gnu/usr.bin/patch	\
717		gnu/usr.bin/perl/perl	\
718		gnu/usr.bin/sort	\
719		gnu/usr.bin/texinfo	\
720		usr.bin/basename	\
721		usr.bin/cap_mkdb	\
722		usr.bin/chflags		\
723		usr.bin/cmp		\
724		usr.bin/col		\
725		usr.bin/cpp		\
726		usr.bin/expand		\
727		usr.bin/file2c		\
728		usr.bin/find		\
729		usr.bin/gencat		\
730		usr.bin/lorder		\
731		usr.bin/m4		\
732		usr.bin/mkdep		\
733		usr.bin/paste		\
734		usr.bin/sed		\
735		usr.bin/size		\
736		usr.bin/soelim		\
737		usr.bin/strip		\
738		usr.bin/symorder	\
739		usr.bin/touch		\
740		usr.bin/tr		\
741		usr.bin/true		\
742		usr.bin/uname		\
743		usr.bin/uuencode	\
744		usr.bin/vgrind		\
745		usr.bin/vi		\
746		usr.bin/wc		\
747		usr.bin/xargs		\
748		usr.bin/yacc		\
749		usr.sbin/chown		\
750		usr.sbin/mtree		\
751		usr.sbin/zic
752	cd ${.CURDIR}/$d; ${MAKE} ${MK_FLAGS} ${_DEPEND}; \
753		${MAKE} ${MK_FLAGS} all; \
754		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
755.endfor
756
757.for __target in clean cleandepend cleandir depend obj
758.for entry in ${SUBDIR}
759${entry}.${__target}__D: .PHONY
760	@if test -d ${.CURDIR}/${entry}.${MACHINE}; then \
761		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE}"; \
762		edir=${entry}.${MACHINE}; \
763		cd ${.CURDIR}/$${edir}; \
764	else \
765		${ECHODIR} "===> ${DIRPRFX}${entry}"; \
766		edir=${entry}; \
767		cd ${.CURDIR}/$${edir}; \
768	fi; \
769	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
770.endfor
771par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
772.endfor
773
774.endif
775
776.include <bsd.subdir.mk>
777