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