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