freebsd-dev/share/mk
Bryan Drewery cf1eeb33be Add a FAST_DEPEND option, off by default, which speeds up the build significantly.
This speeds up buildworld by 16% on my system and buildkernel by 35%.

Rather than calling mkdep(1), which is just a wrapper around 'cc -E',
use the modern -MD -MT -MF flags to gather and generate dependencies during
compilation.  This flag was introduced in GCC "a long time ago", in GCC 3.0,
and is also supported by Clang.  (It appears that ICC also supports this but I
do not have access to test it).  This avoids running the preprocessor *twice*
for every build, in both 'make depend' and 'make all'.  This is especially
noticeable when using ccache since it does not cache preprocessor results from
mkdep(1) / 'cc -E', but still speeds up compilation with the -MD flags.

For 'make depend' a tree-walk is still done to ensure that all DPSRCS
are generated when expected, and that beforedepend/afterdepend and
_EXTRADEPEND are all still respected.  In time this may change but for now
I've been conservative.  The time for a tree-walk with -j combined with
SUBDIR_PARALLEL is not significant.  For example, it takes about 9 seconds
with -j15 to walk all of src/ for 'make depend' now on my system.

A .depend file is still generated with the various rules that apply to
the final target, or custom rules.  Otherwise there are now
per-built-object-file .depend files, such as .depend.filename.o.  These
are included directly by make rather than populating .depend with a loop
and .depend lines, which only added overhead to the now almost-NOP 'make
depend' phase.

Before this I experimented with having mkdep(1) called in parallel per-file.
While this improved the kernel and lib/libc 'make depend' phase, it resulted
in slower build times overall.

The -M flags are removed from CFLAGS when linking since they have no effect.

Enabling this by default, for src or out-of-src, can be done once more testing
has been done, such as a ports exp-run, and with more compilers.

The system I used for testing was:
  WITNESS
  Build options: -j20 WITH_LLDB=yes WITH_DEBUG_FILES=yes WITH_FAST_DEPEND=yes
  DISK: ZFS 3-way mirror with very slow disks using SSD l2arc/log.
        The arc was fully populated with src tree files.
  RAM: 76GiB
  CPU: Intel(R) Xeon(R) CPU L5520 @2.27GHz
       2 package(s) x 4 core(s) x 2 SMT threads = hw.ncpu=16

buildworld:
  x buildworld-before
  + buildworld-fastdep
  +-------------------------------------------------------------------------------+
  |+                                                                              |
  |+                                                                              |
  |+                                                                       xx    x|
  |                                                                       |_MA___||
  |A                                                                              |
  +-------------------------------------------------------------------------------+
      N           Min           Max        Median           Avg        Stddev
  x   3       3744.13       3794.31       3752.25     3763.5633     26.935139
  +   3       3153.34       3155.16        3154.2     3154.2333    0.91045776
  Difference at 95.0% confidence
          -609.33 +/- 43.1943
          -16.1902% +/- 1.1477%
          (Student's t, pooled s = 19.0569)

buildkernel:
  x buildkernel-before
  + buildkernel-fastdep
  +-------------------------------------------------------------------------------+
  |+                                                                            x |
  |++                                                                           xx|
  |                                                                             A||
  |A|                                                                             |
  +-------------------------------------------------------------------------------+
      N           Min           Max        Median           Avg        Stddev
  x   3        571.57        573.94        571.79     572.43333     1.3094401
  +   3        369.12        370.57         369.3     369.66333    0.79033748
  Difference at 95.0% confidence
          -202.77 +/- 2.45131
          -35.4225% +/- 0.428227%
          (Student's t, pooled s = 1.0815)

Sponsored by:	EMC / Isilon Storage Division
MFC after:	3 weeks
Relnotes:	yes
2015-11-06 04:45:29 +00:00
..
atf.test.mk Remove ALLOW_DEPRECATED_ATF_TOOLS/ATFFILE support from atf.test.mk 2015-06-15 06:38:59 +00:00
auto.obj.mk Add META_MODE support. 2015-06-13 19:20:56 +00:00
bsd.arch.inc.mk
bsd.compiler.mk Don't hide stderr when checking ${CC} --version. 2015-10-31 02:07:30 +00:00
bsd.confs.mk Use proper CONFDIR after r289148 2015-10-27 23:49:32 +00:00
bsd.cpu.mk After consultations with the arm community, don't define softfp for 2015-08-26 17:10:43 +00:00
bsd.crunchgen.mk Add bsd.crunchgen.mk to bsd.README. 2015-10-24 04:55:17 +00:00
bsd.dep.mk Add a FAST_DEPEND option, off by default, which speeds up the build significantly. 2015-11-06 04:45:29 +00:00
bsd.doc.mk Fix wrong use of .for; the iteration variable is not used in the loop. 2015-10-15 18:55:43 +00:00
bsd.dtb.mk Add infrastructure to build dtb files from dts files. 2015-01-08 18:28:06 +00:00
bsd.endian.mk Start to import support for the AArch64 architecture from ARM. This change 2015-03-19 13:53:47 +00:00
bsd.files.mk META MODE: Fix FILESNAME not being respected sans other FILES_group overrides. 2015-10-26 23:28:35 +00:00
bsd.incs.mk Make installing to a non-existent directory an error. 2015-10-15 22:49:56 +00:00
bsd.info.mk Make installing to a non-existent directory an error. 2015-10-15 22:49:56 +00:00
bsd.init.mk Avoid anoying warning 2015-06-14 03:27:22 +00:00
bsd.kmod.mk Eliminate bsd.sys.mk on purpose. Do not put it back. 2015-01-01 04:26:45 +00:00
bsd.lib.mk Add a FAST_DEPEND option, off by default, which speeds up the build significantly. 2015-11-06 04:45:29 +00:00
bsd.libnames.mk Significant upgrades to sa(4) and mt(1). 2015-02-23 21:59:30 +00:00
bsd.links.mk Fix DESTDIR support 2015-03-15 23:40:50 +00:00
bsd.man.mk Fix installation of manpages with WITHOUT_COMPRESS broken since r284685. 2015-10-22 22:29:25 +00:00
bsd.mkopt.mk Appy := to dependent opts once value determined. 2015-06-22 19:01:09 +00:00
bsd.nls.mk In jobs mode we can use .ORDER to force stage_links to run after other 2015-10-07 00:24:27 +00:00
bsd.obj.mk With MK_AUTO_OBJ=yes objdir is created during sys.mk 2015-06-11 13:53:15 +00:00
bsd.opts.mk Add a FAST_DEPEND option, off by default, which speeds up the build significantly. 2015-11-06 04:45:29 +00:00
bsd.own.mk Correct a comment which appears to be mistakingly mechanically changed in r265420. 2015-11-05 22:42:40 +00:00
bsd.port.mk Avoid sub-shell for realpath(1) for bmake by using its built-in :tA. 2015-09-03 17:01:58 +00:00
bsd.port.options.mk
bsd.port.post.mk
bsd.port.pre.mk
bsd.port.subdir.mk Avoid sub-shell for realpath(1) for bmake by using its built-in :tA. 2015-09-03 17:01:58 +00:00
bsd.prog.mk Add a FAST_DEPEND option, off by default, which speeds up the build significantly. 2015-11-06 04:45:29 +00:00
bsd.progs.mk Unbreak bsd.progs.mk with PROGS (but not PROGS_CXX) and when invoking the 2015-10-30 06:07:41 +00:00
bsd.README Sort properly. 2015-10-24 05:00:20 +00:00
bsd.snmpmod.mk
bsd.stand.mk Use CFLAGS_NO_SIMD in preference to varying lists of -mno-xxxx flags. 2015-08-27 23:46:42 +00:00
bsd.subdir.mk Fix regression from using .USEBEFORE in _SUBDIR in r289705. 2015-10-29 00:41:03 +00:00
bsd.symver.mk
bsd.sys.mk Only enable -fstack-protector-strong on gcc 4.9+ and default to -fstack-protector 2015-10-18 04:07:40 +00:00
bsd.test.mk Default TESTSDIR to /usr/tests/${RELDIR:H} 2015-10-11 21:29:24 +00:00
dirdeps.mk Add META_MODE support. 2015-06-13 19:20:56 +00:00
gendirdeps.mk Add META_MODE support. 2015-06-13 19:20:56 +00:00
host-target.mk Add META_MODE support. 2015-06-13 19:20:56 +00:00
install-new.mk Add META_MODE support. 2015-06-13 19:20:56 +00:00
local.autodep.mk To help bootstrap new local depends, 2015-10-07 00:32:33 +00:00
local.dirdeps.mk Watch out for bin/cat in host stage tree 2015-06-14 03:28:25 +00:00
local.gendirdeps.mk META_MODE: Remove unneeded groff/tmac special GENDIRDEPS_FILTER. 2015-09-30 20:40:51 +00:00
local.init.mk Allow 'make buildenv' to work anywhere in the src tree. 2015-11-05 22:28:31 +00:00
local.meta.sys.mk META_MODE: Set HOST_CXX and HOST_CPP and chain them down into CXX/CPP for host builds. 2015-09-30 23:14:23 +00:00
local.sys.env.mk Move include of make.conf back to its old position. 2015-06-19 14:56:24 +00:00
local.sys.mk Move include of make.conf back to its old position. 2015-06-19 14:56:24 +00:00
Makefile Install bsd.confs.mk 2015-10-10 10:48:09 +00:00
meta2deps.py Add META_MODE support. 2015-06-13 19:20:56 +00:00
meta2deps.sh Add META_MODE support. 2015-06-13 19:20:56 +00:00
meta.autodep.mk Add META_MODE support. 2015-06-13 19:20:56 +00:00
meta.stage.mk In jobs mode we can use .ORDER to force stage_links to run after other 2015-10-07 00:24:27 +00:00
meta.subdir.mk Add META_MODE support. 2015-06-13 19:20:56 +00:00
meta.sys.mk Add META_MODE support. 2015-06-13 19:20:56 +00:00
netbsd-tests.test.mk Simplify netbsd-tests.test.mk 2015-10-11 20:02:10 +00:00
plain.test.mk As an optimization (in simple, well used cases) only call cat ${.ALLSRC} when 2014-11-04 01:57:31 +00:00
src.init.mk Allow 'make buildenv' to work anywhere in the src tree. 2015-11-05 22:28:31 +00:00
src.libnames.mk Rename libohash to libopenbsd. 2015-11-04 07:20:55 +00:00
src.opts.mk Slightly rework the comments and logic for default Clang/GCC. 2015-10-24 04:03:32 +00:00
src.sys.env.mk RELDIR is useful without META_MODE. Always define it. 2015-09-23 23:30:57 +00:00
src.sys.mk Trim space 2015-09-17 21:51:48 +00:00
stage-install.sh Add META_MODE support. 2015-06-13 19:20:56 +00:00
suite.test.mk Remove 'set -e' that are no longer needed as it is already default. 2015-09-25 23:03:32 +00:00
sys.dependfile.mk Add META_MODE support. 2015-06-13 19:20:56 +00:00
sys.mk Rework the 'make -n -n' feature such that '-n' recurses and '-N' does not. 2015-10-17 16:42:54 +00:00
tap.test.mk As an optimization (in simple, well used cases) only call cat ${.ALLSRC} when 2014-11-04 01:57:31 +00:00
version_gen.awk