4 # Copyright (c) 2014 Kevin Lo. All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 S= ${.CURDIR}/../../..
30 .PATH: $S/dev/usb/misc
33 SRCS= opt_bus.h opt_usb.h device_if.h bus_if.h usb_if.h vnode_if.h usbdevs.h \
36 .include <bsd.kmod.mk>
40 # The user-driven targets are:
42 # universe - *Really* build *everything* (buildworld and
43 # all kernels on all architectures).
44 # tinderbox - Same as universe, but presents a list of failed build
45 # targets and exits with an error if there were any.
46 # buildworld - Rebuild *everything*, including glue to help do
48 # installworld - Install everything built by "buildworld".
49 # world - buildworld + installworld, no kernel.
50 # buildkernel - Rebuild the kernel and the kernel-modules.
51 # installkernel - Install the kernel and the kernel-modules.
53 # reinstallkernel - Reinstall the kernel and the kernel-modules.
54 # reinstallkernel.debug
55 # kernel - buildkernel + installkernel.
56 # kernel-toolchain - Builds the subset of world necessary to build a kernel
57 # kernel-toolchains - Build kernel-toolchain for all universe targets.
58 # doxygen - Build API documentation of the kernel, needs doxygen.
59 # update - Convenient way to update your source tree(s).
60 # check-old - List obsolete directories/files/libraries.
61 # check-old-dirs - List obsolete directories.
62 # check-old-files - List obsolete files.
63 # check-old-libs - List obsolete libraries.
64 # delete-old - Delete obsolete directories/files.
65 # delete-old-dirs - Delete obsolete directories.
66 # delete-old-files - Delete obsolete files.
67 # delete-old-libs - Delete obsolete libraries.
68 # targets - Print a list of supported TARGET/TARGET_ARCH pairs
69 # for world and kernel targets.
70 # toolchains - Build a toolchain for all world and kernel targets.
71 # xdev - xdev-build + xdev-install for the architecture
72 # specified with XDEV and XDEV_ARCH.
73 # xdev-build - Build cross-development tools.
74 # xdev-install - Install cross-development tools.
75 # xdev-links - Create traditional links in /usr/bin for cc, etc
76 # native-xtools - Create host binaries that produce target objects
77 # for use in qemu user-mode jails.
79 # "quick" way to test all kernel builds:
80 # _jflag=`sysctl -n hw.ncpu`
81 # _jflag=$(($_jflag * 2))
82 # [ $_jflag -gt 12 ] && _jflag=12
83 # make universe -DMAKE_JUST_KERNELS JFLAG=-j${_jflag}
85 # This makefile is simple by design. The FreeBSD make automatically reads
86 # the /usr/share/mk/sys.mk unless the -m argument is specified on the
87 # command line. By keeping this makefile simple, it doesn't matter too
88 # much how different the installed mk files are from those in the source
89 # tree. This makefile executes a child make process, forcing it to use
90 # the mk files from the source tree which are supposed to DTRT.
92 # Most of the user-driven targets (as listed above) are implemented in
93 # Makefile.inc1. The exceptions are universe, tinderbox and targets.
95 # If you want to build your system from source be sure that /usr/obj has
96 # at least 1GB of diskspace available. A complete 'universe' build requires
97 # about 15GB of space.
99 # For individuals wanting to build from the sources currently on their
100 # system, the simple instructions are:
102 # 1. `cd /usr/src' (or to the directory containing your source tree).
103 # 2. Define `HISTORICAL_MAKE_WORLD' variable (see README).
106 # For individuals wanting to upgrade their sources (even if only a
107 # delta of a few days):
109 # 1. `cd /usr/src' (or to the directory containing your source tree).
110 # 2. `make buildworld'
111 # 3. `make buildkernel KERNCONF=YOUR_KERNEL_HERE' (default is GENERIC).
112 # 4. `make installkernel KERNCONF=YOUR_KERNEL_HERE' (default is GENERIC).
113 # [steps 3. & 4. can be combined by using the "kernel" target]
114 # 5. `reboot' (in single user mode: boot -s from the loader prompt).
115 # 6. `mergemaster -p'
116 # 7. `make installworld'
117 # 8. `mergemaster' (you may wish to use -i, along with -U or -F).
118 # 9. `make delete-old'
120 # 11. `make delete-old-libs' (in case no 3rd party program uses them anymore)
122 # See src/UPDATING `COMMON ITEMS' for more complete information.
124 # If TARGET=machine (e.g. powerpc, sparc64, ...) is specified you can
125 # cross build world for other machine types using the buildworld target,
126 # and once the world is built you can cross build a kernel using the
127 # buildkernel target.
129 # Define the user-driven targets. These are listed here in alphabetical
130 # order, but that's not important.
132 # Targets that begin with underscore are internal targets intended for
133 # developer convenience only. They are intentionally not documented and
134 # completely subject to change without notice.
136 # For more information, see the build(7) manual page.
138 TGTS= all all-man buildenv buildenvvars buildkernel buildworld \
139 check-old check-old-dirs check-old-files check-old-libs \
140 checkdpadd clean cleandepend cleandir \
141 delete-old delete-old-dirs delete-old-files delete-old-libs \
142 depend distribute distributekernel distributekernel.debug \
143 distributeworld distrib-dirs distribution doxygen \
144 everything hier hierarchy install installcheck installkernel \
145 installkernel.debug packagekernel packageworld \
146 reinstallkernel reinstallkernel.debug \
147 installworld kernel-toolchain libraries lint maninstall \
148 obj objlink regress rerelease showconfig tags toolchain update \
149 _worldtmp _legacy _bootstrap-tools _cleanobj _obj \
150 _build-tools _cross-tools _includes _libraries _depend \
151 build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
152 xdev-links native-xtools \
154 TGTS+= ${SUBDIR_TARGETS}
156 BITGTS= files includes
157 BITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
160 .ORDER: buildworld installworld
161 .ORDER: buildworld distributeworld
162 .ORDER: buildworld buildkernel
163 .ORDER: buildkernel installkernel
164 .ORDER: buildkernel installkernel.debug
165 .ORDER: buildkernel reinstallkernel
166 .ORDER: buildkernel reinstallkernel.debug
168 PATH= /sbin:/bin:/usr/sbin:/usr/bin
169 MAKEOBJDIRPREFIX?= /usr/obj
170 _MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
171 ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
172 -f /dev/null -V MAKEOBJDIRPREFIX dummy
173 .if !empty(_MAKEOBJDIRPREFIX)
174 .error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
175 (in make.conf(5)) or command-line variable.
178 # We often need to use the tree's version of make to build it.
179 # Choices add to complexity though.
180 # We cannot blindly use a make which may not be the one we want
181 # so be exlicit - until all choice is removed.
183 MYMAKE= ${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}/${WANT_MAKE}
184 .if defined(.PARSEDIR)
189 .if exists(${MYMAKE})
190 SUB_MAKE:= ${MYMAKE} -m ${.CURDIR}/share/mk
191 .elif ${WANT_MAKE} != ${HAVE_MAKE}
192 # It may not exist yet but we may cause it to.
193 # In the case of fmake, upgrade_checks may cause a newer version to be built.
194 SUB_MAKE= `test -x ${MYMAKE} && echo ${MYMAKE} || echo ${MAKE}` \
195 -m ${.CURDIR}/share/mk
197 SUB_MAKE= ${MAKE} -m ${.CURDIR}/share/mk
200 _MAKE= PATH=${PATH} ${SUB_MAKE} -f Makefile.inc1 TARGET=${_TARGET} TARGET_ARCH=${_TARGET_ARCH}
202 # Guess machine architecture from machine type, and vice versa.
203 .if !defined(TARGET_ARCH) && defined(TARGET)
204 _TARGET_ARCH= ${TARGET:S/pc98/i386/}
205 .elif !defined(TARGET) && defined(TARGET_ARCH) && \
206 ${TARGET_ARCH} != ${MACHINE_ARCH}
207 _TARGET= ${TARGET_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb|hf)?/arm/}
209 .if defined(TARGET) && !defined(_TARGET)
212 .if defined(TARGET_ARCH) && !defined(_TARGET_ARCH)
213 _TARGET_ARCH=${TARGET_ARCH}
215 # for historical compatibility for xdev targets
219 .if defined(XDEV_ARCH)
220 _TARGET_ARCH= ${XDEV_ARCH}
222 # Otherwise, default to current machine type and architecture.
224 _TARGET_ARCH?= ${MACHINE_ARCH}
227 # Make sure we have an up-to-date make(1). Only world and buildworld
228 # should do this as those are the initial targets used for upgrades.
229 # The user can define ALWAYS_CHECK_MAKE to have this check performed
232 .if defined(ALWAYS_CHECK_MAKE)
233 ${TGTS}: upgrade_checks
235 buildworld: upgrade_checks
239 # This 'cleanworld' target is not included in TGTS, because it is not a
240 # recursive target. All of the work for it is done right here. It is
241 # expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
242 # created by bsd.obj.mk, except that we don't want to .include that file
245 # In the following, the first 'rm' in a series will usually remove all
246 # files and directories. If it does not, then there are probably some
247 # files with file flags set, so this unsets them and tries the 'rm' a
248 # second time. There are situations where this target will be cleaning
249 # some directories via more than one method, but that duplication is
250 # needed to correctly handle all the possible situations. Removing all
251 # files without file flags set in the first 'rm' instance saves time,
252 # because 'chflags' will need to operate on fewer files afterwards.
254 BW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
256 .if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
257 .if exists(${BW_CANONICALOBJDIR}/)
258 -rm -rf ${BW_CANONICALOBJDIR}/*
259 -chflags -R 0 ${BW_CANONICALOBJDIR}
260 rm -rf ${BW_CANONICALOBJDIR}/*
262 # To be safe in this case, fall back to a 'make cleandir'
263 ${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
266 -chflags -R 0 ${.OBJDIR}
271 # Handle the user-driven targets, using the source relative mk files.
274 .if empty(.MAKEFLAGS:M-n)
275 # skip this for -n to avoid changing previous behavior of
276 # 'make -n buildworld' etc.
278 tinderbox toolchains kernel-toolchains: .MAKE
282 ${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET}
284 # The historic default "all" target creates files which may cause stale
285 # or (in the cross build case) unlinkable results. Fail with an error
286 # when no target is given. The users can explicitly specify "all"
287 # if they want the historic behavior.
292 @echo "Explicit target required (use \"all\" for historic behavior)"
296 STARTTIME!= LC_ALL=C date
297 CHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0s ; echo
298 .if !empty(CHECK_TIME)
299 .error check your date/time: ${STARTTIME}
302 .if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
306 # Attempt to rebuild and reinstall everything. This target is not to be
307 # used for upgrading an existing FreeBSD system, because the kernel is
308 # not included. One can argue that this target doesn't build everything
311 world: upgrade_checks
312 @echo "--------------------------------------------------------------"
313 @echo ">>> make world started on ${STARTTIME}"
314 @echo "--------------------------------------------------------------"
315 .if target(pre-world)
317 @echo "--------------------------------------------------------------"
318 @echo ">>> Making 'pre-world' target"
319 @echo "--------------------------------------------------------------"
320 ${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
322 ${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
323 ${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
324 .if target(post-world)
326 @echo "--------------------------------------------------------------"
327 @echo ">>> Making 'post-world' target"
328 @echo "--------------------------------------------------------------"
329 ${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
332 @echo "--------------------------------------------------------------"
333 @echo ">>> make world completed on `LC_ALL=C date`"
334 @echo " (started ${STARTTIME})"
335 @echo "--------------------------------------------------------------"
338 @echo "WARNING: make world will overwrite your existing FreeBSD"
339 @echo "installation without also building and installing a new"
340 @echo "kernel. This can be dangerous. Please read the handbook,"
341 @echo "'Rebuilding world', for how to upgrade your system."
342 @echo "Define DESTDIR to where you want to install FreeBSD,"
343 @echo "including /, to override this warning and proceed as usual."
345 @echo "Bailing out now..."
352 # Short hand for `make buildkernel installkernel'
354 kernel: buildkernel installkernel
357 # Perform a few tests to determine if the installed tools are adequate
358 # for building the world.
360 # Note: if we ever need to care about the version of bmake, simply testing
361 # MAKE_VERSION against a required version should suffice.
364 .if ${HAVE_MAKE} != ${WANT_MAKE}
365 @(cd ${.CURDIR} && ${MAKE} ${WANT_MAKE:S,^f,,})
369 # Upgrade make(1) to the current version using the installed
370 # headers, libraries and tools. Also, allow the location of
371 # the system bsdmake-like utility to be overridden.
373 MMAKEENV= MAKEOBJDIRPREFIX=${MYMAKE:H} \
375 INSTALL="sh ${.CURDIR}/tools/install.sh"
376 MMAKE= ${MMAKEENV} ${MAKE} \
377 -DNO_MAN -DNO_SHARED \
378 -DNO_CPU_CFLAGS -DNO_WERROR \
380 DESTDIR= PROGNAME=${MYMAKE:T}
384 @echo "--------------------------------------------------------------"
385 @echo ">>> Building an up-to-date ${.TARGET}(1)"
386 @echo "--------------------------------------------------------------"
387 ${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \
391 ${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR=
393 tinderbox toolchains kernel-toolchains: upgrade_checks
396 @cd ${.CURDIR} && ${SUB_MAKE} DOING_TINDERBOX=YES universe
399 @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe
402 @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe
407 # Attempt to rebuild *everything* for all supported architectures,
408 # with a reasonable chance of success, regardless of how old your
409 # existing system is.
411 .if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
412 TARGETS?=amd64 arm i386 mips pc98 powerpc sparc64
413 TARGET_ARCHES_arm?= arm armeb armv6 armv6hf
414 TARGET_ARCHES_mips?= mipsel mips mips64el mips64 mipsn32
415 TARGET_ARCHES_powerpc?= powerpc powerpc64
416 TARGET_ARCHES_pc98?= i386
417 .for target in ${TARGETS}
418 TARGET_ARCHES_${target}?= ${target}
421 .if defined(UNIVERSE_TARGET)
422 MAKE_JUST_WORLDS= YES
424 UNIVERSE_TARGET?= buildworld
426 KERNSRCDIR?= ${.CURDIR}/sys
429 @echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
430 .for target in ${TARGETS}
431 .for target_arch in ${TARGET_ARCHES_${target}}
432 @echo " ${target}/${target_arch}"
436 .if defined(DOING_TINDERBOX)
437 FAILFILE=${.CURDIR}/_.tinderbox.failed
438 MAKEFAIL=tee -a ${FAILFILE}
443 universe_prologue: upgrade_checks
444 universe: universe_prologue
446 @echo "--------------------------------------------------------------"
447 @echo ">>> make universe started on ${STARTTIME}"
448 @echo "--------------------------------------------------------------"
449 .if defined(DOING_TINDERBOX)
452 .for target in ${TARGETS}
453 universe: universe_${target}
454 universe_epilogue: universe_${target}
455 universe_${target}: universe_${target}_prologue
456 universe_${target}_prologue: universe_prologue
457 @echo ">> ${target} started on `LC_ALL=C date`"
458 .if !defined(MAKE_JUST_KERNELS)
459 .for target_arch in ${TARGET_ARCHES_${target}}
460 universe_${target}: universe_${target}_${target_arch}
461 universe_${target}_${target_arch}: universe_${target}_prologue .MAKE
462 @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
463 @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
464 ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
466 TARGET_ARCH=${target_arch} \
467 > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
468 (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
469 "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
471 @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
474 .if !defined(MAKE_JUST_WORLDS)
475 # If we are building world and kernels wait for the required worlds to finish
476 .if !defined(MAKE_JUST_KERNELS)
477 .for target_arch in ${TARGET_ARCHES_${target}}
478 universe_${target}_kernels: universe_${target}_${target_arch}
481 universe_${target}: universe_${target}_kernels
482 universe_${target}_kernels: universe_${target}_prologue .MAKE
483 .if exists(${KERNSRCDIR}/${target}/conf/NOTES)
484 @(cd ${KERNSRCDIR}/${target}/conf && env __MAKE_CONF=/dev/null \
485 ${SUB_MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
486 (echo "${target} 'make LINT' failed," \
487 "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
489 @cd ${.CURDIR} && ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
492 @echo ">> ${target} completed on `LC_ALL=C date`"
494 universe_kernels: universe_kernconfs
498 .if defined(MAKE_ALL_KERNELS)
501 _THINNER=xargs grep -L "^.NO_UNIVERSE" || true
503 KERNCONFS!= cd ${KERNSRCDIR}/${TARGET}/conf && \
504 find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
505 ! -name DEFAULTS ! -name NOTES | \
508 .for kernel in ${KERNCONFS}
509 TARGET_ARCH_${kernel}!= cd ${KERNSRCDIR}/${TARGET}/conf && \
510 config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
511 grep -v WARNING: | cut -f 2
512 .if empty(TARGET_ARCH_${kernel})
513 .error "Target architecture for ${TARGET}/conf/${kernel} unknown. config(8) likely too old."
515 universe_kernconfs: universe_kernconf_${TARGET}_${kernel}
516 universe_kernconf_${TARGET}_${kernel}: .MAKE
517 @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
518 ${SUB_MAKE} ${JFLAG} buildkernel \
520 TARGET_ARCH=${TARGET_ARCH_${kernel}} \
522 > _.${TARGET}.${kernel} 2>&1 || \
523 (echo "${TARGET} ${kernel} kernel failed," \
524 "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
526 universe: universe_epilogue
528 @echo "--------------------------------------------------------------"
529 @echo ">>> make universe completed on `LC_ALL=C date`"
530 @echo " (started ${STARTTIME})"
531 @echo "--------------------------------------------------------------"
532 .if defined(DOING_TINDERBOX)
533 @if [ -e ${FAILFILE} ] ; then \
534 echo "Tinderbox failed:" ;\
542 ${MAKE} -C ${.CURDIR}/sys/${_TARGET}/conf LINT
544 .if defined(.PARSEDIR)
546 # we do not want a failure of one branch abort all.
547 MAKE_JOB_ERROR_TOKEN= no
548 .export MAKE_JOB_ERROR_TOKEN