units(1): parse config file after setting defaults
[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|hf)?/arm/}
168 .endif
169 .if defined(TARGET) && !defined(_TARGET)
170 _TARGET=${TARGET}
171 .endif
172 .if defined(TARGET_ARCH) && !defined(_TARGET_ARCH)
173 _TARGET_ARCH=${TARGET_ARCH}
174 .endif
175 # Otherwise, default to current machine type and architecture.
176 _TARGET?=       ${MACHINE}
177 _TARGET_ARCH?=  ${MACHINE_ARCH}
178
179 #
180 # Make sure we have an up-to-date make(1). Only world and buildworld
181 # should do this as those are the initial targets used for upgrades.
182 # The user can define ALWAYS_CHECK_MAKE to have this check performed
183 # for all targets.
184 #
185 .if defined(ALWAYS_CHECK_MAKE)
186 ${TGTS}: upgrade_checks
187 .else
188 buildworld: upgrade_checks
189 .endif
190
191 #
192 # This 'cleanworld' target is not included in TGTS, because it is not a
193 # recursive target.  All of the work for it is done right here.   It is
194 # expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
195 # created by bsd.obj.mk, except that we don't want to .include that file
196 # in this makefile.  
197 #
198 # In the following, the first 'rm' in a series will usually remove all
199 # files and directories.  If it does not, then there are probably some
200 # files with file flags set, so this unsets them and tries the 'rm' a
201 # second time.  There are situations where this target will be cleaning
202 # some directories via more than one method, but that duplication is
203 # needed to correctly handle all the possible situations.  Removing all
204 # files without file flags set in the first 'rm' instance saves time,
205 # because 'chflags' will need to operate on fewer files afterwards.
206 #
207 BW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
208 cleanworld:
209 .if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
210 .if exists(${BW_CANONICALOBJDIR}/)
211         -rm -rf ${BW_CANONICALOBJDIR}/*
212         -chflags -R 0 ${BW_CANONICALOBJDIR}
213         rm -rf ${BW_CANONICALOBJDIR}/*
214 .endif
215         #   To be safe in this case, fall back to a 'make cleandir'
216         ${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
217 .else
218         -rm -rf ${.OBJDIR}/*
219         -chflags -R 0 ${.OBJDIR}
220         rm -rf ${.OBJDIR}/*
221 .endif
222
223 #
224 # Handle the user-driven targets, using the source relative mk files.
225 #
226
227 .if empty(.MAKEFLAGS:M-n)
228 # skip this for -n to avoid changing previous behavior of 
229 # 'make -n buildworld' etc.
230 ${TGTS}: .MAKE
231 tinderbox toolchains kernel-toolchains: .MAKE
232 .endif
233
234 ${TGTS}:
235         ${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET}
236
237 # Set a reasonable default
238 .MAIN:  all
239
240 STARTTIME!= LC_ALL=C date
241 CHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0s ; echo
242 .if !empty(CHECK_TIME)
243 .error check your date/time: ${STARTTIME}
244 .endif
245
246 .if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
247 #
248 # world
249 #
250 # Attempt to rebuild and reinstall everything. This target is not to be
251 # used for upgrading an existing FreeBSD system, because the kernel is
252 # not included. One can argue that this target doesn't build everything
253 # then.
254 #
255 world: upgrade_checks
256         @echo "--------------------------------------------------------------"
257         @echo ">>> make world started on ${STARTTIME}"
258         @echo "--------------------------------------------------------------"
259 .if target(pre-world)
260         @echo
261         @echo "--------------------------------------------------------------"
262         @echo ">>> Making 'pre-world' target"
263         @echo "--------------------------------------------------------------"
264         ${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
265 .endif
266         ${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
267         ${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
268 .if target(post-world)
269         @echo
270         @echo "--------------------------------------------------------------"
271         @echo ">>> Making 'post-world' target"
272         @echo "--------------------------------------------------------------"
273         ${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
274 .endif
275         @echo
276         @echo "--------------------------------------------------------------"
277         @echo ">>> make world completed on `LC_ALL=C date`"
278         @echo "                   (started ${STARTTIME})"
279         @echo "--------------------------------------------------------------"
280 .else
281 world:
282         @echo "WARNING: make world will overwrite your existing FreeBSD"
283         @echo "installation without also building and installing a new"
284         @echo "kernel.  This can be dangerous.  Please read the handbook,"
285         @echo "'Rebuilding world', for how to upgrade your system."
286         @echo "Define DESTDIR to where you want to install FreeBSD,"
287         @echo "including /, to override this warning and proceed as usual."
288         @echo ""
289         @echo "Bailing out now..."
290         @false
291 .endif
292
293 #
294 # kernel
295 #
296 # Short hand for `make buildkernel installkernel'
297 #
298 kernel: buildkernel installkernel
299
300 #
301 # Perform a few tests to determine if the installed tools are adequate
302 # for building the world.
303 #
304 # Note: if we ever need to care about the version of bmake, simply testing
305 # MAKE_VERSION against a required version should suffice.
306 #
307 upgrade_checks:
308 .if ${HAVE_MAKE} != ${WANT_MAKE}
309         @(cd ${.CURDIR} && ${MAKE} ${WANT_MAKE:S,^f,,})
310 .elif ${WANT_MAKE} == "fmake"
311         @if ! (cd ${.CURDIR}/tools/build/make_check && \
312             PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
313             PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
314         then \
315             (cd ${.CURDIR} && ${MAKE} make); \
316         fi
317 .endif
318
319 #
320 # Upgrade make(1) to the current version using the installed
321 # headers, libraries and tools.  Also, allow the location of
322 # the system bsdmake-like utility to be overridden.
323 #
324 MMAKEENV=       MAKEOBJDIRPREFIX=${MYMAKE:H} \
325                 DESTDIR= \
326                 INSTALL="sh ${.CURDIR}/tools/install.sh"
327 MMAKE=          ${MMAKEENV} ${MAKE} \
328                 -D_UPGRADING -DNO_MAN -DNO_SHARED \
329                 -DNO_CPU_CFLAGS -DNO_WERROR DESTDIR= PROGNAME=${MYMAKE:T}
330
331 make bmake: .PHONY
332         @echo
333         @echo "--------------------------------------------------------------"
334         @echo ">>> Building an up-to-date make(1)"
335         @echo "--------------------------------------------------------------"
336         ${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \
337                 ${MMAKE} obj && \
338                 ${MMAKE} depend && \
339                 ${MMAKE} all && \
340                 ${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR=
341
342 tinderbox toolchains kernel-toolchains: upgrade_checks
343
344 tinderbox:
345         @cd ${.CURDIR} && ${SUB_MAKE} DOING_TINDERBOX=YES universe
346
347 toolchains:
348         @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe
349
350 kernel-toolchains:
351         @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe
352
353 #
354 # universe
355 #
356 # Attempt to rebuild *everything* for all supported architectures,
357 # with a reasonable chance of success, regardless of how old your
358 # existing system is.
359 #
360 .if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
361 TARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64
362 TARGET_ARCHES_arm?=     arm armeb armv6 armv6hf
363 TARGET_ARCHES_mips?=    mipsel mips mips64el mips64 mipsn32
364 TARGET_ARCHES_powerpc?= powerpc powerpc64
365 TARGET_ARCHES_pc98?=    i386
366 .for target in ${TARGETS}
367 TARGET_ARCHES_${target}?= ${target}
368 .endfor
369
370 .if defined(UNIVERSE_TARGET)
371 MAKE_JUST_WORLDS=       YES
372 .else
373 UNIVERSE_TARGET?=       buildworld
374 .endif
375 KERNSRCDIR?=            ${.CURDIR}/sys
376
377 targets:
378         @echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
379 .for target in ${TARGETS}
380 .for target_arch in ${TARGET_ARCHES_${target}}
381         @echo "    ${target}/${target_arch}"
382 .endfor
383 .endfor
384
385 .if defined(DOING_TINDERBOX)
386 FAILFILE=${.CURDIR}/_.tinderbox.failed
387 MAKEFAIL=tee -a ${FAILFILE}
388 .else
389 MAKEFAIL=cat
390 .endif
391
392 universe_prologue:  upgrade_checks
393 universe: universe_prologue
394 universe_prologue:
395         @echo "--------------------------------------------------------------"
396         @echo ">>> make universe started on ${STARTTIME}"
397         @echo "--------------------------------------------------------------"
398 .if defined(DOING_TINDERBOX)
399         @rm -f ${FAILFILE}
400 .endif
401 .for target in ${TARGETS}
402 universe: universe_${target}
403 universe_epilogue: universe_${target}
404 universe_${target}: universe_${target}_prologue
405 universe_${target}_prologue: universe_prologue
406         @echo ">> ${target} started on `LC_ALL=C date`"
407 .if !defined(MAKE_JUST_KERNELS)
408 .for target_arch in ${TARGET_ARCHES_${target}}
409 universe_${target}: universe_${target}_${target_arch}
410 universe_${target}_${target_arch}: universe_${target}_prologue .MAKE
411         @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
412         @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
413             ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
414             TARGET=${target} \
415             TARGET_ARCH=${target_arch} \
416             > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
417             (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
418             "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
419             ${MAKEFAIL}))
420         @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
421 .endfor
422 .endif
423 .if !defined(MAKE_JUST_WORLDS)
424 # If we are building world and kernels wait for the required worlds to finish
425 .if !defined(MAKE_JUST_KERNELS)
426 .for target_arch in ${TARGET_ARCHES_${target}}
427 universe_${target}_kernels: universe_${target}_${target_arch}
428 .endfor
429 .endif
430 universe_${target}: universe_${target}_kernels
431 universe_${target}_kernels: universe_${target}_prologue .MAKE
432 .if exists(${KERNSRCDIR}/${target}/conf/NOTES)
433         @(cd ${KERNSRCDIR}/${target}/conf && env __MAKE_CONF=/dev/null \
434             ${SUB_MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
435             (echo "${target} 'make LINT' failed," \
436             "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
437 .endif
438         @cd ${.CURDIR} && ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
439             universe_kernels
440 .endif
441         @echo ">> ${target} completed on `LC_ALL=C date`"
442 .endfor
443 universe_kernels: universe_kernconfs
444 .if !defined(TARGET)
445 TARGET!=        uname -m
446 .endif
447 KERNCONFS!=     cd ${KERNSRCDIR}/${TARGET}/conf && \
448                 find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
449                 ! -name DEFAULTS ! -name NOTES
450 universe_kernconfs:
451 .for kernel in ${KERNCONFS}
452 TARGET_ARCH_${kernel}!= cd ${KERNSRCDIR}/${TARGET}/conf && \
453         config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
454         grep -v WARNING: | cut -f 2
455 .if empty(TARGET_ARCH_${kernel})
456 .error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
457 .endif
458 universe_kernconfs: universe_kernconf_${TARGET}_${kernel}
459 universe_kernconf_${TARGET}_${kernel}: .MAKE
460         @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
461             ${SUB_MAKE} ${JFLAG} buildkernel \
462             TARGET=${TARGET} \
463             TARGET_ARCH=${TARGET_ARCH_${kernel}} \
464             KERNCONF=${kernel} \
465             > _.${TARGET}.${kernel} 2>&1 || \
466             (echo "${TARGET} ${kernel} kernel failed," \
467             "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
468 .endfor
469 universe: universe_epilogue
470 universe_epilogue:
471         @echo "--------------------------------------------------------------"
472         @echo ">>> make universe completed on `LC_ALL=C date`"
473         @echo "                      (started ${STARTTIME})"
474         @echo "--------------------------------------------------------------"
475 .if defined(DOING_TINDERBOX)
476         @if [ -e ${FAILFILE} ] ; then \
477                 echo "Tinderbox failed:" ;\
478                 cat ${FAILFILE} ;\
479                 exit 1 ;\
480         fi
481 .endif
482 .endif
483
484 buildLINT:
485         ${MAKE} -C ${.CURDIR}/sys/${_TARGET}/conf LINT
486
487 .if defined(.PARSEDIR)
488 .if make(universe)
489 # we do not want a failure of one branch abort all.
490 MAKE_JOB_ERROR_TOKEN= no
491 .export MAKE_JOB_ERROR_TOKEN
492 .endif
493 .endif