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