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