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