xref: /freebsd/Makefile (revision b04a7a0baf6523245034b8ccd06cd0176b8a18cf)
1#
2# $FreeBSD$
3#
4# The user-driven targets are:
5#
6# universe            - *Really* build *everything* (buildworld and
7#                       all kernels on all architectures).
8# tinderbox           - Same as universe, but presents a list of failed build
9#                       targets and exits with an error if there were any.
10# buildworld          - Rebuild *everything*, including glue to help do
11#                       upgrades.
12# installworld        - Install everything built by "buildworld".
13# world               - buildworld + installworld, no kernel.
14# buildkernel         - Rebuild the kernel and the kernel-modules.
15# installkernel       - Install the kernel and the kernel-modules.
16# installkernel.debug
17# reinstallkernel     - Reinstall the kernel and the kernel-modules.
18# reinstallkernel.debug
19# kernel              - buildkernel + installkernel.
20# kernel-toolchain    - Builds the subset of world necessary to build a kernel
21# kernel-toolchains   - Build kernel-toolchain for all universe targets.
22# doxygen             - Build API documentation of the kernel, needs doxygen.
23# update              - Convenient way to update your source tree(s).
24# check-old           - List obsolete directories/files/libraries.
25# check-old-dirs      - List obsolete directories.
26# check-old-files     - List obsolete files.
27# check-old-libs      - List obsolete libraries.
28# delete-old          - Delete obsolete directories/files.
29# delete-old-dirs     - Delete obsolete directories.
30# delete-old-files    - Delete obsolete files.
31# delete-old-libs     - Delete obsolete libraries.
32# targets             - Print a list of supported TARGET/TARGET_ARCH pairs
33#                       for world and kernel targets.
34# toolchains          - Build a toolchain for all world and kernel targets.
35# xdev                - xdev-build + xdev-install for the architecture
36#                       specified with XDEV and XDEV_ARCH.
37# xdev-build          - Build cross-development tools.
38# xdev-install        - Install cross-development tools.
39#
40# "quick" way to test all kernel builds:
41# 	_jflag=`sysctl -n hw.ncpu`
42# 	_jflag=$(($_jflag * 2))
43# 	[ $_jflag -gt 12 ] && _jflag=12
44# 	make universe -DMAKE_JUST_KERNELS JFLAG=-j${_jflag}
45#
46# This makefile is simple by design. The FreeBSD make automatically reads
47# the /usr/share/mk/sys.mk unless the -m argument is specified on the
48# command line. By keeping this makefile simple, it doesn't matter too
49# much how different the installed mk files are from those in the source
50# tree. This makefile executes a child make process, forcing it to use
51# the mk files from the source tree which are supposed to DTRT.
52#
53# Most of the user-driven targets (as listed above) are implemented in
54# Makefile.inc1.  The exceptions are universe, tinderbox and targets.
55#
56# If you want to build your system from source be sure that /usr/obj has
57# at least 1GB of diskspace available.  A complete 'universe' build requires
58# about 15GB of space.
59#
60# For individuals wanting to build from the sources currently on their
61# system, the simple instructions are:
62#
63# 1.  `cd /usr/src'  (or to the directory containing your source tree).
64# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
65# 3.  `make world'
66#
67# For individuals wanting to upgrade their sources (even if only a
68# delta of a few days):
69#
70#  1.  `cd /usr/src'       (or to the directory containing your source tree).
71#  2.  `make buildworld'
72#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
73#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
74#       [steps 3. & 4. can be combined by using the "kernel" target]
75#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
76#  6.  `mergemaster -p'
77#  7.  `make installworld'
78#  8.  `mergemaster'		(you may wish to use -i, along with -U or -F).
79#  9.  `make delete-old'
80# 10.  `reboot'
81# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
82#
83# See src/UPDATING `COMMON ITEMS' for more complete information.
84#
85# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
86# cross build world for other machine types using the buildworld target,
87# and once the world is built you can cross build a kernel using the
88# buildkernel target.
89#
90# Define the user-driven targets. These are listed here in alphabetical
91# order, but that's not important.
92#
93# Targets that begin with underscore are internal targets intended for
94# developer convenience only.  They are intentionally not documented and
95# completely subject to change without notice.
96#
97# For more information, see the build(7) manual page.
98#
99TGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
100	check-old check-old-dirs check-old-files check-old-libs \
101	checkdpadd clean cleandepend cleandir \
102	delete-old delete-old-dirs delete-old-files delete-old-libs \
103	depend distribute distributekernel distributekernel.debug \
104	distributeworld distrib-dirs distribution doxygen \
105	everything hier hierarchy install installcheck installkernel \
106	installkernel.debug packagekernel packageworld \
107	reinstallkernel reinstallkernel.debug \
108	installworld kernel-toolchain libraries lint maninstall \
109	obj objlink regress rerelease showconfig tags toolchain update \
110	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
111	_build-tools _cross-tools _includes _libraries _depend \
112	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
113
114TGTS+=	${SUBDIR_TARGETS}
115
116BITGTS=	files includes
117BITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
118TGTS+=	${BITGTS}
119
120.ORDER: buildworld installworld
121.ORDER: buildworld distributeworld
122.ORDER: buildworld buildkernel
123.ORDER: buildkernel installkernel
124.ORDER: buildkernel installkernel.debug
125.ORDER: buildkernel reinstallkernel
126.ORDER: buildkernel reinstallkernel.debug
127
128PATH=	/sbin:/bin:/usr/sbin:/usr/bin
129MAKEOBJDIRPREFIX?=	/usr/obj
130_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
131    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
132    -f /dev/null -V MAKEOBJDIRPREFIX dummy
133.if !empty(_MAKEOBJDIRPREFIX)
134.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
135	(in make.conf(5)) or command-line variable.
136.endif
137
138# We often need to use the tree's version of make to build it.
139# Choices add to complexity though.
140# We cannot blindly use a make which may not be the one we want
141# so be exlicit - until all choice is removed.
142.if !defined(WITHOUT_BMAKE)
143WANT_MAKE=	bmake
144.else
145WANT_MAKE=	fmake
146.endif
147MYMAKE=		${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}/${WANT_MAKE}
148.if defined(.PARSEDIR)
149HAVE_MAKE=	bmake
150.else
151HAVE_MAKE=	fmake
152.endif
153.if exists(${MYMAKE})
154SUB_MAKE:= ${MYMAKE} -m ${.CURDIR}/share/mk
155.elif ${WANT_MAKE} != ${HAVE_MAKE} || ${WANT_MAKE} != "bmake"
156# It may not exist yet but we may cause it to.
157# In the case of fmake, upgrade_checks may cause a newer version to be built.
158SUB_MAKE= `test -x ${MYMAKE} && echo ${MYMAKE} || echo ${MAKE}` \
159	-m ${.CURDIR}/share/mk
160.else
161SUB_MAKE= ${MAKE} -m ${.CURDIR}/share/mk
162.endif
163
164_MAKE=	PATH=${PATH} ${SUB_MAKE} -f Makefile.inc1 TARGET=${_TARGET} TARGET_ARCH=${_TARGET_ARCH}
165
166# Guess machine architecture from machine type, and vice versa.
167.if !defined(TARGET_ARCH) && defined(TARGET)
168_TARGET_ARCH=	${TARGET:S/pc98/i386/}
169.elif !defined(TARGET) && defined(TARGET_ARCH) && \
170    ${TARGET_ARCH} != ${MACHINE_ARCH}
171_TARGET=		${TARGET_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb|hf)?/arm/}
172.endif
173.if defined(TARGET) && !defined(_TARGET)
174_TARGET=${TARGET}
175.endif
176.if defined(TARGET_ARCH) && !defined(_TARGET_ARCH)
177_TARGET_ARCH=${TARGET_ARCH}
178.endif
179# Otherwise, default to current machine type and architecture.
180_TARGET?=	${MACHINE}
181_TARGET_ARCH?=	${MACHINE_ARCH}
182
183#
184# Make sure we have an up-to-date make(1). Only world and buildworld
185# should do this as those are the initial targets used for upgrades.
186# The user can define ALWAYS_CHECK_MAKE to have this check performed
187# for all targets.
188#
189.if defined(ALWAYS_CHECK_MAKE)
190${TGTS}: upgrade_checks
191.else
192buildworld: upgrade_checks
193.endif
194
195#
196# This 'cleanworld' target is not included in TGTS, because it is not a
197# recursive target.  All of the work for it is done right here.   It is
198# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
199# created by bsd.obj.mk, except that we don't want to .include that file
200# in this makefile.
201#
202# In the following, the first 'rm' in a series will usually remove all
203# files and directories.  If it does not, then there are probably some
204# files with file flags set, so this unsets them and tries the 'rm' a
205# second time.  There are situations where this target will be cleaning
206# some directories via more than one method, but that duplication is
207# needed to correctly handle all the possible situations.  Removing all
208# files without file flags set in the first 'rm' instance saves time,
209# because 'chflags' will need to operate on fewer files afterwards.
210#
211BW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
212cleanworld:
213.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
214.if exists(${BW_CANONICALOBJDIR}/)
215	-rm -rf ${BW_CANONICALOBJDIR}/*
216	-chflags -R 0 ${BW_CANONICALOBJDIR}
217	rm -rf ${BW_CANONICALOBJDIR}/*
218.endif
219	#   To be safe in this case, fall back to a 'make cleandir'
220	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
221.else
222	-rm -rf ${.OBJDIR}/*
223	-chflags -R 0 ${.OBJDIR}
224	rm -rf ${.OBJDIR}/*
225.endif
226
227#
228# Handle the user-driven targets, using the source relative mk files.
229#
230
231.if empty(.MAKEFLAGS:M-n)
232# skip this for -n to avoid changing previous behavior of
233# 'make -n buildworld' etc.
234${TGTS}: .MAKE
235tinderbox toolchains kernel-toolchains: .MAKE
236.endif
237
238${TGTS}:
239	${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET}
240
241# Set a reasonable default
242.MAIN:	all
243
244STARTTIME!= LC_ALL=C date
245CHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0s ; echo
246.if !empty(CHECK_TIME)
247.error check your date/time: ${STARTTIME}
248.endif
249
250.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
251#
252# world
253#
254# Attempt to rebuild and reinstall everything. This target is not to be
255# used for upgrading an existing FreeBSD system, because the kernel is
256# not included. One can argue that this target doesn't build everything
257# then.
258#
259world: upgrade_checks
260	@echo "--------------------------------------------------------------"
261	@echo ">>> make world started on ${STARTTIME}"
262	@echo "--------------------------------------------------------------"
263.if target(pre-world)
264	@echo
265	@echo "--------------------------------------------------------------"
266	@echo ">>> Making 'pre-world' target"
267	@echo "--------------------------------------------------------------"
268	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
269.endif
270	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
271	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
272.if target(post-world)
273	@echo
274	@echo "--------------------------------------------------------------"
275	@echo ">>> Making 'post-world' target"
276	@echo "--------------------------------------------------------------"
277	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
278.endif
279	@echo
280	@echo "--------------------------------------------------------------"
281	@echo ">>> make world completed on `LC_ALL=C date`"
282	@echo "                   (started ${STARTTIME})"
283	@echo "--------------------------------------------------------------"
284.else
285world:
286	@echo "WARNING: make world will overwrite your existing FreeBSD"
287	@echo "installation without also building and installing a new"
288	@echo "kernel.  This can be dangerous.  Please read the handbook,"
289	@echo "'Rebuilding world', for how to upgrade your system."
290	@echo "Define DESTDIR to where you want to install FreeBSD,"
291	@echo "including /, to override this warning and proceed as usual."
292	@echo ""
293	@echo "Bailing out now..."
294	@false
295.endif
296
297#
298# kernel
299#
300# Short hand for `make buildkernel installkernel'
301#
302kernel: buildkernel installkernel
303
304#
305# Perform a few tests to determine if the installed tools are adequate
306# for building the world.
307#
308# Note: if we ever need to care about the version of bmake, simply testing
309# MAKE_VERSION against a required version should suffice.
310#
311upgrade_checks:
312.if ${HAVE_MAKE} != ${WANT_MAKE}
313	@(cd ${.CURDIR} && ${MAKE} ${WANT_MAKE:S,^f,,})
314.elif ${WANT_MAKE} == "fmake"
315	@if ! (cd ${.CURDIR}/tools/build/make_check && \
316	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
317	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
318	then \
319	    (cd ${.CURDIR} && ${MAKE} make); \
320	fi
321.endif
322
323#
324# Upgrade make(1) to the current version using the installed
325# headers, libraries and tools.  Also, allow the location of
326# the system bsdmake-like utility to be overridden.
327#
328MMAKEENV=	MAKEOBJDIRPREFIX=${MYMAKE:H} \
329		DESTDIR= \
330		INSTALL="sh ${.CURDIR}/tools/install.sh"
331MMAKE=		${MMAKEENV} ${MAKE} \
332		-D_UPGRADING -DNO_MAN -DNO_SHARED \
333		-DNO_CPU_CFLAGS -DNO_WERROR \
334		DESTDIR= MK_TESTS=no PROGNAME=${MYMAKE:T}
335
336make bmake: .PHONY
337	@echo
338	@echo "--------------------------------------------------------------"
339	@echo ">>> Building an up-to-date make(1)"
340	@echo "--------------------------------------------------------------"
341	${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \
342		${MMAKE} obj && \
343		${MMAKE} depend && \
344		${MMAKE} all && \
345		${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR=
346
347tinderbox toolchains kernel-toolchains: upgrade_checks
348
349tinderbox:
350	@cd ${.CURDIR} && ${SUB_MAKE} DOING_TINDERBOX=YES universe
351
352toolchains:
353	@cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe
354
355kernel-toolchains:
356	@cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe
357
358#
359# universe
360#
361# Attempt to rebuild *everything* for all supported architectures,
362# with a reasonable chance of success, regardless of how old your
363# existing system is.
364#
365.if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
366TARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64
367TARGET_ARCHES_arm?=	arm armeb armv6 armv6hf
368TARGET_ARCHES_mips?=	mipsel mips mips64el mips64 mipsn32
369TARGET_ARCHES_powerpc?=	powerpc powerpc64
370TARGET_ARCHES_pc98?=	i386
371.for target in ${TARGETS}
372TARGET_ARCHES_${target}?= ${target}
373.endfor
374
375.if defined(UNIVERSE_TARGET)
376MAKE_JUST_WORLDS=	YES
377.else
378UNIVERSE_TARGET?=	buildworld
379.endif
380KERNSRCDIR?=		${.CURDIR}/sys
381
382targets:
383	@echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
384.for target in ${TARGETS}
385.for target_arch in ${TARGET_ARCHES_${target}}
386	@echo "    ${target}/${target_arch}"
387.endfor
388.endfor
389
390.if defined(DOING_TINDERBOX)
391FAILFILE=${.CURDIR}/_.tinderbox.failed
392MAKEFAIL=tee -a ${FAILFILE}
393.else
394MAKEFAIL=cat
395.endif
396
397universe_prologue:  upgrade_checks
398universe: universe_prologue
399universe_prologue:
400	@echo "--------------------------------------------------------------"
401	@echo ">>> make universe started on ${STARTTIME}"
402	@echo "--------------------------------------------------------------"
403.if defined(DOING_TINDERBOX)
404	@rm -f ${FAILFILE}
405.endif
406.for target in ${TARGETS}
407universe: universe_${target}
408universe_epilogue: universe_${target}
409universe_${target}: universe_${target}_prologue
410universe_${target}_prologue: universe_prologue
411	@echo ">> ${target} started on `LC_ALL=C date`"
412.if !defined(MAKE_JUST_KERNELS)
413.for target_arch in ${TARGET_ARCHES_${target}}
414universe_${target}: universe_${target}_${target_arch}
415universe_${target}_${target_arch}: universe_${target}_prologue .MAKE
416	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
417	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
418	    ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
419	    TARGET=${target} \
420	    TARGET_ARCH=${target_arch} \
421	    > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
422	    (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
423	    "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
424	    ${MAKEFAIL}))
425	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
426.endfor
427.endif
428.if !defined(MAKE_JUST_WORLDS)
429# If we are building world and kernels wait for the required worlds to finish
430.if !defined(MAKE_JUST_KERNELS)
431.for target_arch in ${TARGET_ARCHES_${target}}
432universe_${target}_kernels: universe_${target}_${target_arch}
433.endfor
434.endif
435universe_${target}: universe_${target}_kernels
436universe_${target}_kernels: universe_${target}_prologue .MAKE
437.if exists(${KERNSRCDIR}/${target}/conf/NOTES)
438	@(cd ${KERNSRCDIR}/${target}/conf && env __MAKE_CONF=/dev/null \
439	    ${SUB_MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
440	    (echo "${target} 'make LINT' failed," \
441	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
442.endif
443	@cd ${.CURDIR} && ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
444	    universe_kernels
445.endif
446	@echo ">> ${target} completed on `LC_ALL=C date`"
447.endfor
448universe_kernels: universe_kernconfs
449.if !defined(TARGET)
450TARGET!=	uname -m
451.endif
452KERNCONFS!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
453		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
454		! -name DEFAULTS ! -name NOTES
455universe_kernconfs:
456.for kernel in ${KERNCONFS}
457TARGET_ARCH_${kernel}!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
458	config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
459	grep -v WARNING: | cut -f 2
460.if empty(TARGET_ARCH_${kernel})
461.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
462.endif
463universe_kernconfs: universe_kernconf_${TARGET}_${kernel}
464universe_kernconf_${TARGET}_${kernel}: .MAKE
465	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
466	    ${SUB_MAKE} ${JFLAG} buildkernel \
467	    TARGET=${TARGET} \
468	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
469	    KERNCONF=${kernel} \
470	    > _.${TARGET}.${kernel} 2>&1 || \
471	    (echo "${TARGET} ${kernel} kernel failed," \
472	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
473.endfor
474universe: universe_epilogue
475universe_epilogue:
476	@echo "--------------------------------------------------------------"
477	@echo ">>> make universe completed on `LC_ALL=C date`"
478	@echo "                      (started ${STARTTIME})"
479	@echo "--------------------------------------------------------------"
480.if defined(DOING_TINDERBOX)
481	@if [ -e ${FAILFILE} ] ; then \
482		echo "Tinderbox failed:" ;\
483		cat ${FAILFILE} ;\
484		exit 1 ;\
485	fi
486.endif
487.endif
488
489buildLINT:
490	${MAKE} -C ${.CURDIR}/sys/${_TARGET}/conf LINT
491
492.if defined(.PARSEDIR)
493.if make(universe)
494# we do not want a failure of one branch abort all.
495MAKE_JOB_ERROR_TOKEN= no
496.export MAKE_JOB_ERROR_TOKEN
497.endif
498.endif
499