]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - Makefile
MFC: r264460
[FreeBSD/stable/10.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
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 #
99 TGTS=   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
114 TGTS+=  ${SUBDIR_TARGETS}
115
116 BITGTS= files includes
117 BITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
118 TGTS+=  ${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
128 PATH=   /sbin:/bin:/usr/sbin:/usr/bin
129 MAKEOBJDIRPREFIX?=      /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)
143 WANT_MAKE=      bmake
144 .else
145 WANT_MAKE=      fmake
146 .endif
147 MYMAKE=         ${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}/${WANT_MAKE}
148 .if defined(.PARSEDIR)
149 HAVE_MAKE=      bmake
150 .else
151 HAVE_MAKE=      fmake
152 .endif
153 .if exists(${MYMAKE})
154 SUB_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.
158 SUB_MAKE= `test -x ${MYMAKE} && echo ${MYMAKE} || echo ${MAKE}` \
159         -m ${.CURDIR}/share/mk
160 .else
161 SUB_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)?/arm/}
172 .endif
173 # Legacy names, for another transition period mips:mips(n32|64)?eb -> mips:mips\1
174 .if defined(TARGET) && defined(TARGET_ARCH) && \
175     ${TARGET} == "mips" && ${TARGET_ARCH:Mmips*eb}
176 _TARGET_ARCH=           ${TARGET_ARCH:C/eb$//}
177 .warning "TARGET_ARCH of ${TARGET_ARCH} is deprecated in favor of ${_TARGET_ARCH}"
178 .endif
179 .if defined(TARGET) && ${TARGET} == "mips" && defined(TARGET_BIG_ENDIAN)
180 .warning "TARGET_BIG_ENDIAN is no longer necessary for MIPS.  Big-endian is not the default."
181 .endif
182 # arm with TARGET_BIG_ENDIAN -> armeb
183 .if defined(TARGET_ARCH) && ${TARGET_ARCH} == "arm" && defined(TARGET_BIG_ENDIAN)
184 .warning "TARGET_ARCH of arm with TARGET_BIG_ENDIAN is deprecated.  use armeb"
185 _TARGET_ARCH=armeb
186 .endif
187 .if defined(TARGET) && !defined(_TARGET)
188 _TARGET=${TARGET}
189 .endif
190 .if defined(TARGET_ARCH) && !defined(_TARGET_ARCH)
191 _TARGET_ARCH=${TARGET_ARCH}
192 .endif
193 # Otherwise, default to current machine type and architecture.
194 _TARGET?=       ${MACHINE}
195 _TARGET_ARCH?=  ${MACHINE_ARCH}
196
197 #
198 # Make sure we have an up-to-date make(1). Only world and buildworld
199 # should do this as those are the initial targets used for upgrades.
200 # The user can define ALWAYS_CHECK_MAKE to have this check performed
201 # for all targets.
202 #
203 .if defined(ALWAYS_CHECK_MAKE)
204 ${TGTS}: upgrade_checks
205 .else
206 buildworld: upgrade_checks
207 .endif
208
209 #
210 # This 'cleanworld' target is not included in TGTS, because it is not a
211 # recursive target.  All of the work for it is done right here.   It is
212 # expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
213 # created by bsd.obj.mk, except that we don't want to .include that file
214 # in this makefile.  
215 #
216 # In the following, the first 'rm' in a series will usually remove all
217 # files and directories.  If it does not, then there are probably some
218 # files with file flags set, so this unsets them and tries the 'rm' a
219 # second time.  There are situations where this target will be cleaning
220 # some directories via more than one method, but that duplication is
221 # needed to correctly handle all the possible situations.  Removing all
222 # files without file flags set in the first 'rm' instance saves time,
223 # because 'chflags' will need to operate on fewer files afterwards.
224 #
225 BW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
226 cleanworld:
227 .if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
228 .if exists(${BW_CANONICALOBJDIR}/)
229         -rm -rf ${BW_CANONICALOBJDIR}/*
230         -chflags -R 0 ${BW_CANONICALOBJDIR}
231         rm -rf ${BW_CANONICALOBJDIR}/*
232 .endif
233         #   To be safe in this case, fall back to a 'make cleandir'
234         ${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
235 .else
236         -rm -rf ${.OBJDIR}/*
237         -chflags -R 0 ${.OBJDIR}
238         rm -rf ${.OBJDIR}/*
239 .endif
240
241 #
242 # Handle the user-driven targets, using the source relative mk files.
243 #
244
245 .if empty(.MAKEFLAGS:M-n)
246 # skip this for -n to avoid changing previous behavior of 
247 # 'make -n buildworld' etc.
248 ${TGTS}: .MAKE
249 tinderbox toolchains kernel-toolchains: .MAKE
250 .endif
251
252 ${TGTS}:
253         ${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET}
254
255 # Set a reasonable default
256 .MAIN:  all
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 .elif ${WANT_MAKE} == "fmake"
329         @if ! (cd ${.CURDIR}/tools/build/make_check && \
330             PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
331             PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
332         then \
333             (cd ${.CURDIR} && ${MAKE} make); \
334         fi
335 .endif
336
337 #
338 # Upgrade make(1) to the current version using the installed
339 # headers, libraries and tools.  Also, allow the location of
340 # the system bsdmake-like utility to be overridden.
341 #
342 MMAKEENV=       MAKEOBJDIRPREFIX=${MYMAKE:H} \
343                 DESTDIR= \
344                 INSTALL="sh ${.CURDIR}/tools/install.sh"
345 MMAKE=          ${MMAKEENV} ${MAKE} \
346                 -D_UPGRADING \
347                 -DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
348                 -DNO_CPU_CFLAGS -DNO_WERROR DESTDIR= PROGNAME=${MYMAKE:T}
349
350 make bmake: .PHONY
351         @echo
352         @echo "--------------------------------------------------------------"
353         @echo ">>> Building an up-to-date make(1)"
354         @echo "--------------------------------------------------------------"
355         ${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \
356                 ${MMAKE} obj && \
357                 ${MMAKE} depend && \
358                 ${MMAKE} all && \
359                 ${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR=
360
361 tinderbox toolchains kernel-toolchains: upgrade_checks
362
363 tinderbox:
364         @cd ${.CURDIR} && ${SUB_MAKE} DOING_TINDERBOX=YES universe
365
366 toolchains:
367         @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe
368
369 kernel-toolchains:
370         @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe
371
372 #
373 # universe
374 #
375 # Attempt to rebuild *everything* for all supported architectures,
376 # with a reasonable chance of success, regardless of how old your
377 # existing system is.
378 #
379 .if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
380 TARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64
381 TARGET_ARCHES_arm?=     arm armeb armv6
382 TARGET_ARCHES_mips?=    mipsel mips mips64el mips64 mipsn32
383 TARGET_ARCHES_powerpc?= powerpc powerpc64
384 TARGET_ARCHES_pc98?=    i386
385 .for target in ${TARGETS}
386 TARGET_ARCHES_${target}?= ${target}
387 .endfor
388
389 .if defined(UNIVERSE_TARGET)
390 MAKE_JUST_WORLDS=       YES
391 .else
392 UNIVERSE_TARGET?=       buildworld
393 .endif
394 KERNSRCDIR?=            ${.CURDIR}/sys
395
396 targets:
397         @echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
398 .for target in ${TARGETS}
399 .for target_arch in ${TARGET_ARCHES_${target}}
400         @echo "    ${target}/${target_arch}"
401 .endfor
402 .endfor
403
404 .if defined(DOING_TINDERBOX)
405 FAILFILE=${.CURDIR}/_.tinderbox.failed
406 MAKEFAIL=tee -a ${FAILFILE}
407 .else
408 MAKEFAIL=cat
409 .endif
410
411 universe_prologue:  upgrade_checks
412 universe: universe_prologue
413 universe_prologue:
414         @echo "--------------------------------------------------------------"
415         @echo ">>> make universe started on ${STARTTIME}"
416         @echo "--------------------------------------------------------------"
417 .if defined(DOING_TINDERBOX)
418         @rm -f ${FAILFILE}
419 .endif
420 .for target in ${TARGETS}
421 universe: universe_${target}
422 universe_epilogue: universe_${target}
423 universe_${target}: universe_${target}_prologue
424 universe_${target}_prologue: universe_prologue
425         @echo ">> ${target} started on `LC_ALL=C date`"
426 .if !defined(MAKE_JUST_KERNELS)
427 .for target_arch in ${TARGET_ARCHES_${target}}
428 universe_${target}: universe_${target}_${target_arch}
429 universe_${target}_${target_arch}: universe_${target}_prologue .MAKE
430         @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
431         @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
432             ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
433             TARGET=${target} \
434             TARGET_ARCH=${target_arch} \
435             > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
436             (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
437             "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
438             ${MAKEFAIL}))
439         @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
440 .endfor
441 .endif
442 .if !defined(MAKE_JUST_WORLDS)
443 # If we are building world and kernels wait for the required worlds to finish
444 .if !defined(MAKE_JUST_KERNELS)
445 .for target_arch in ${TARGET_ARCHES_${target}}
446 universe_${target}_kernels: universe_${target}_${target_arch}
447 .endfor
448 .endif
449 universe_${target}: universe_${target}_kernels
450 universe_${target}_kernels: universe_${target}_prologue .MAKE
451 .if exists(${KERNSRCDIR}/${target}/conf/NOTES)
452         @(cd ${KERNSRCDIR}/${target}/conf && env __MAKE_CONF=/dev/null \
453             ${SUB_MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
454             (echo "${target} 'make LINT' failed," \
455             "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
456 .endif
457         @cd ${.CURDIR} && ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
458             universe_kernels
459 .endif
460         @echo ">> ${target} completed on `LC_ALL=C date`"
461 .endfor
462 universe_kernels: universe_kernconfs
463 .if !defined(TARGET)
464 TARGET!=        uname -m
465 .endif
466 KERNCONFS!=     cd ${KERNSRCDIR}/${TARGET}/conf && \
467                 find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
468                 ! -name DEFAULTS ! -name NOTES
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