summaryrefslogtreecommitdiffstats
path: root/share/mk
diff options
context:
space:
mode:
authorbdrewery <bdrewery@FreeBSD.org>2015-11-06 04:45:29 +0000
committerbdrewery <bdrewery@FreeBSD.org>2015-11-06 04:45:29 +0000
commita175970362c0b42ce2ec8b2de664870b0edbcacc (patch)
tree6c99cd7369f3154f392e847a99d64007e79daa8d /share/mk
parent0731342a6997de4a6d6a58691febbcdc2ed399ce (diff)
downloadFreeBSD-src-a175970362c0b42ce2ec8b2de664870b0edbcacc.zip
FreeBSD-src-a175970362c0b42ce2ec8b2de664870b0edbcacc.tar.gz
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
Diffstat (limited to 'share/mk')
-rw-r--r--share/mk/bsd.dep.mk23
-rw-r--r--share/mk/bsd.lib.mk2
-rw-r--r--share/mk/bsd.opts.mk1
-rw-r--r--share/mk/bsd.prog.mk8
4 files changed, 27 insertions, 7 deletions
diff --git a/share/mk/bsd.dep.mk b/share/mk/bsd.dep.mk
index 965f703..8cc814d 100644
--- a/share/mk/bsd.dep.mk
+++ b/share/mk/bsd.dep.mk
@@ -54,6 +54,18 @@ MKDEPCMD?= CC='${CC} ${DEPFLAGS}' mkdep
MKDEPCMD?= mkdep
.endif
DEPENDFILE?= .depend
+DEPENDFILES= ${DEPENDFILE}
+.if ${MK_FAST_DEPEND} == "yes"
+DEPENDFILES+= ${DEPENDFILE}.*
+DEPEND_CFLAGS+= -MD -MP -MF${DEPENDFILE}.${.TARGET}
+DEPEND_CFLAGS+= -MT${.TARGET}
+CFLAGS+= ${DEPEND_CFLAGS}
+DEPENDOBJS+= ${OBJS} ${POBJS} ${SOBJS}
+.for __obj in ${DEPENDOBJS:O:u}
+.sinclude "${DEPENDFILE}.${__obj}"
+DEPENDFILES_OBJS+= ${DEPENDFILE}.${__obj}
+.endfor
+.endif # ${MK_FAST_DEPEND} == "yes"
# Keep `tags' here, before SRCS are mangled below for `depend'.
.if !target(tags) && defined(SRCS) && !defined(NO_TAGS)
@@ -161,7 +173,7 @@ afterdepend: beforedepend
depend: beforedepend ${DEPENDFILE} afterdepend
# Tell bmake not to look for generated files via .PATH
-.NOPATH: ${DEPENDFILE}
+.NOPATH: ${DEPENDFILE} ${DEPENDFILES_OBJS}
# Different types of sources are compiled with slightly different flags.
# Split up the sources, and filter out headers and non-applicable flags.
@@ -172,6 +184,7 @@ MKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BIDU]*} \
DPSRCS+= ${SRCS}
${DEPENDFILE}: ${DPSRCS}
+.if ${MK_FAST_DEPEND} == "no"
rm -f ${DEPENDFILE}
.if !empty(DPSRCS:M*.[cS])
${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
@@ -182,7 +195,11 @@ ${DEPENDFILE}: ${DPSRCS}
${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
${MKDEP_CXXFLAGS} \
${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
+.else
.endif
+.else
+ : > ${.TARGET}
+.endif # ${MK_FAST_DEPEND} == "no"
.if target(_EXTRADEPEND)
_EXTRADEPEND: .USE
${DEPENDFILE}: _EXTRADEPEND
@@ -207,12 +224,12 @@ afterdepend:
cleandepend:
.if defined(SRCS)
.if ${CTAGS:T} == "gtags"
- rm -f ${DEPENDFILE} GPATH GRTAGS GSYMS GTAGS
+ rm -f ${DEPENDFILES} GPATH GRTAGS GSYMS GTAGS
.if defined(HTML)
rm -rf HTML
.endif
.else
- rm -f ${DEPENDFILE} tags
+ rm -f ${DEPENDFILES} tags
.endif
.endif
.endif
diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk
index e906ab7..579e36c 100644
--- a/share/mk/bsd.lib.mk
+++ b/share/mk/bsd.lib.mk
@@ -305,10 +305,12 @@ all: _manpages
.endif
_EXTRADEPEND:
+.if ${MK_FAST_DEPEND} == "no"
@TMP=_depend$$$$; \
sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
> $$TMP; \
mv $$TMP ${DEPENDFILE}
+.endif
.if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME)
.if defined(DPADD) && !empty(DPADD)
echo ${SHLIB_NAME_FULL}: ${DPADD} >> ${DEPENDFILE}
diff --git a/share/mk/bsd.opts.mk b/share/mk/bsd.opts.mk
index 88f5196..a1f4cce 100644
--- a/share/mk/bsd.opts.mk
+++ b/share/mk/bsd.opts.mk
@@ -66,6 +66,7 @@ __DEFAULT_YES_OPTIONS = \
WARNS
__DEFAULT_NO_OPTIONS = \
+ FAST_DEPEND \
CTF \
DEBUG_FILES \
INSTALL_AS_USER \
diff --git a/share/mk/bsd.prog.mk b/share/mk/bsd.prog.mk
index fbb6922..37ede4c9 100644
--- a/share/mk/bsd.prog.mk
+++ b/share/mk/bsd.prog.mk
@@ -82,9 +82,9 @@ ${PROG_FULL}: beforelinking
.endif
${PROG_FULL}: ${OBJS}
.if defined(PROG_CXX)
- ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
+ ${CXX} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
.else
- ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
+ ${CC} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
.endif
.if ${MK_CTF} != "no"
${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
@@ -112,9 +112,9 @@ ${PROG_FULL}: beforelinking
.endif
${PROG_FULL}: ${OBJS}
.if defined(PROG_CXX)
- ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
+ ${CXX} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
.else
- ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
+ ${CC} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
.endif
.if ${MK_CTF} != "no"
${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
OpenPOWER on IntegriCloud