summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--UPDATING8
-rw-r--r--share/mk/src.sys.mk4
-rw-r--r--share/mk/src.sys.obj.mk63
-rw-r--r--share/mk/sys.mk6
-rw-r--r--tools/build/options/WITHOUT_AUTO_OBJ3
5 files changed, 81 insertions, 3 deletions
diff --git a/UPDATING b/UPDATING
index 3808ea0167af5..7cd3e3d9d988c 100644
--- a/UPDATING
+++ b/UPDATING
@@ -51,6 +51,14 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 12.x IS SLOW:
****************************** SPECIAL WARNING: ******************************
+20171102:
+ Building in a FreeBSD src checkout will automatically create object
+ directories now rather than store files in the current directory if
+ 'make obj' was not ran. Calling 'make obj' is no longer necesarry.
+ This feature can be disabled by setting WITHOUT_AUTO_OBJ=yes in
+ /etc/src-env.conf (not /etc/src.conf), or passing the option in the
+ environment.
+
20171101:
The default MAKEOBJDIR has changed from /usr/obj/<srcdir> for native
builds, and /usr/obj/<arch>/<srcdir> for cross-builds, to a unified
diff --git a/share/mk/src.sys.mk b/share/mk/src.sys.mk
index 9a627f647a9fa..fff26b477c611 100644
--- a/share/mk/src.sys.mk
+++ b/share/mk/src.sys.mk
@@ -14,7 +14,7 @@ SRCCONF?= /etc/src.conf
# Validate that the user didn't try setting an env-only variable in
# their src.conf. This benefits from already including bsd.mkopt.mk.
-.for var in ${__ENV_ONLY_OPTIONS}
+.for var in ${__ENV_ONLY_OPTIONS:O:u}
__presrcconf_${var}:= ${MK_${var}:U-}${WITHOUT_${var}:Uno:Dyes}${WITH_${var}:Uno:Dyes}
.endfor
@@ -22,7 +22,7 @@ __presrcconf_${var}:= ${MK_${var}:U-}${WITHOUT_${var}:Uno:Dyes}${WITH_${var}:Uno
_srcconf_included_: .NOTMAIN
# Validate the env-only variables.
-.for var in ${__ENV_ONLY_OPTIONS}
+.for var in ${__ENV_ONLY_OPTIONS:O:u}
__postrcconf_${var}:= ${MK_${var}:U-}${WITHOUT_${var}:Uno:Dyes}${WITH_${var}:Uno:Dyes}
.if ${__presrcconf_${var}} != ${__postrcconf_${var}}
.error Option ${var} may only be defined in ${SRC_ENV_CONF}, environment, or make argument, not ${SRCCONF}.
diff --git a/share/mk/src.sys.obj.mk b/share/mk/src.sys.obj.mk
index b2eeb3336cd52..7d32ea8360126 100644
--- a/share/mk/src.sys.obj.mk
+++ b/share/mk/src.sys.obj.mk
@@ -94,7 +94,68 @@ OBJTOP:= ${MAKEOBJDIRPREFIX}${SRCTOP}
OBJROOT:= ${OBJTOP}/
.endif
-# Assign this directory as .OBJDIR if possible
+# Try to enable MK_AUTO_OBJ by default if we can write to the OBJROOT. Only
+# do this if AUTO_OBJ is not disabled by the user, not cleaning, and this
+# is the first make ran.
+.if ${.MAKE.LEVEL} == 0 && \
+ ${MK_AUTO_OBJ} == "no" && empty(.MAKEOVERRIDES:MMK_AUTO_OBJ) && \
+ !defined(WITHOUT_AUTO_OBJ) && !make(showconfig) && !make(print-dir) && \
+ !defined(NO_OBJ) && \
+ (${.TARGETS} == "" || ${.TARGETS:Nclean*:N*clean:Ndestroy*} != "")
+# Find the last existing directory component and check if we can write to it.
+# If the last component is a symlink then recurse on the new path.
+CheckAutoObj= \
+DirIsCreatable() { \
+ [ -w "$${1}" ] && return 0; \
+ d="$${1}"; \
+ IFS=/; \
+ set -- $${d}; \
+ unset dir; \
+ while [ $$\# -gt 0 ]; do \
+ d="$${1}"; \
+ shift; \
+ if [ ! -d "$${dir}$${d}/" ]; then \
+ if [ -L "$${dir}$${d}" ]; then \
+ dir="$$(readlink "$${dir}$${d}")/"; \
+ for d in "$${@}"; do \
+ dir="$${dir}$${d}/"; \
+ done; \
+ ret=0; \
+ DirIsCreatable "$${dir%/}" || ret=$$?; \
+ return $${ret}; \
+ else \
+ break; \
+ fi; \
+ fi; \
+ dir="$${dir}$${d}/"; \
+ done; \
+ [ -w "$${dir}" ]; \
+}; \
+CheckAutoObj() { \
+ if DirIsCreatable "$${1}"; then \
+ echo yes; \
+ else \
+ echo no; \
+ fi; \
+}
+.if !empty(MAKEOBJDIRPREFIX)
+WANTED_OBJDIR= ${MAKEOBJDIRPREFIX}${.CURDIR}
+.else
+WANTED_OBJDIR= ${MAKEOBJDIR}
+.endif
+OBJDIR_WRITABLE!= \
+ ${CheckAutoObj}; CheckAutoObj "${WANTED_OBJDIR}" || echo no
+# Export the decision to sub-makes.
+MK_AUTO_OBJ:= ${OBJDIR_WRITABLE}
+.export MK_AUTO_OBJ
+.elif make(showconfig)
+# Need to export for showconfig internally running make -dg1. It is enabled
+# in sys.mk by default.
+.export MK_AUTO_OBJ
+.endif # ${MK_AUTO_OBJ} == "no" && ...
+
+# Assign this directory as .OBJDIR if possible after determining if AUTO_OBJ
+# can be enabled by default.
.if ${MK_AUTO_OBJ} == "no"
# The expected OBJDIR already exists, set it as .OBJDIR.
.if !empty(MAKEOBJDIRPREFIX) && exists(${MAKEOBJDIRPREFIX}${.CURDIR})
diff --git a/share/mk/sys.mk b/share/mk/sys.mk
index 379f9a34418a8..0e102fe84dcdb 100644
--- a/share/mk/sys.mk
+++ b/share/mk/sys.mk
@@ -20,6 +20,12 @@ MACHINE_CPUARCH=${MACHINE_ARCH:${__TO_CPUARCH}}
__DEFAULT_YES_OPTIONS+= \
UNIFIED_OBJDIR
+# src.sys.obj.mk enables AUTO_OBJ by default if possible but it is otherwise
+# disabled. Ensure src.conf.5 shows it as default on.
+.if make(showconfig)
+__DEFAULT_YES_OPTIONS+= AUTO_OBJ
+.endif
+
# Some options we need now
__DEFAULT_NO_OPTIONS= \
DIRDEPS_BUILD \
diff --git a/tools/build/options/WITHOUT_AUTO_OBJ b/tools/build/options/WITHOUT_AUTO_OBJ
new file mode 100644
index 0000000000000..69dd6c387bdb1
--- /dev/null
+++ b/tools/build/options/WITHOUT_AUTO_OBJ
@@ -0,0 +1,3 @@
+.\" $FreeBSD$
+Disable automatic creation of objdirs.
+This is enabled by default if the wanted OBJDIR is writable by the current user.