2017-10-31 00:26:42 +00:00
|
|
|
# $FreeBSD$
|
2017-11-01 21:22:05 +00:00
|
|
|
#
|
|
|
|
# Early setup of MAKEOBJDIR
|
|
|
|
#
|
|
|
|
# Default format is: /usr/obj/usr/src/[${TARGET}.${TARGET_ARCH}/]bin/sh
|
|
|
|
# MAKEOBJDIRPREFIX is /usr/obj
|
|
|
|
# OBJROOT is /usr/obj/usr/src/
|
|
|
|
# OBJTOP is /usr/obj/usr/src/[${TARGET}.${TARGET_ARCH}/]
|
|
|
|
# MAKEOBJDIR is /usr/obj/usr/src/[${TARGET}.${TARGET_ARCH}/]bin/sh
|
|
|
|
#
|
|
|
|
# MAKEOBJDIRPREFIX will override the default pattern above and internally
|
|
|
|
# set MAKEOBJDIR. If OBJROOT is set then MAKEOBJDIRPREFIX is rooted inside
|
|
|
|
# of there.
|
|
|
|
#
|
|
|
|
# If MK_UNIFIED_OBJDIR is no then OBJROOT will always match OBJTOP.
|
|
|
|
#
|
|
|
|
# If .MAKE.LEVEL == 0 then the TARGET.TARGET_ARCH is potentially added on.
|
|
|
|
# If .MAKE.LEVEL > 0 and MAKEOBJDIRPREFIX is set then it will not get
|
|
|
|
# TARGET.TARGET_ARCH added in as it assumes that MAKEOBJDIRPREFIX is
|
|
|
|
# nested in the existing OBJTOP with TARGET.TARGET_ARCH in it.
|
|
|
|
#
|
2017-11-18 20:01:15 +00:00
|
|
|
# The expected OBJDIR is stored in __objdir for auto.obj.mk to use.
|
|
|
|
#
|
|
|
|
# AUTO_OBJ is opportunistically enabled if the computed .OBJDIR is writable
|
|
|
|
# by the current user. Some top-level targets disable this behavior in
|
|
|
|
# Makefile.sys.inc.
|
|
|
|
#
|
2017-10-31 00:26:42 +00:00
|
|
|
|
2017-11-01 21:22:05 +00:00
|
|
|
_default_makeobjdirprefix?= /usr/obj
|
2017-10-31 00:26:42 +00:00
|
|
|
_default_makeobjdir= $${.CURDIR:S,^$${SRCTOP},$${OBJTOP},}
|
|
|
|
|
2017-11-01 21:22:05 +00:00
|
|
|
.include <bsd.mkopt.mk>
|
|
|
|
|
|
|
|
.if ${.MAKE.LEVEL} == 0 || empty(OBJROOT)
|
2017-11-11 01:11:00 +00:00
|
|
|
.if ${MK_UNIFIED_OBJDIR} == "no" && ${MK_DIRDEPS_BUILD} == "no"
|
2017-11-01 21:22:05 +00:00
|
|
|
# Fall back to historical behavior.
|
|
|
|
# We always want to set a default MAKEOBJDIRPREFIX...
|
|
|
|
MAKEOBJDIRPREFIX?= ${_default_makeobjdirprefix}
|
|
|
|
# but don't enforce TARGET.TARGET_ARCH unless we're at the top-level directory.
|
|
|
|
.if ${.CURDIR} == ${SRCTOP} && \
|
|
|
|
!(defined(TARGET) && defined(TARGET_ARCH) && \
|
|
|
|
${MACHINE} == ${TARGET} && ${MACHINE_ARCH} == ${TARGET_ARCH} && \
|
|
|
|
!defined(CROSS_BUILD_TESTING))
|
|
|
|
MAKEOBJDIRPREFIX:= ${MAKEOBJDIRPREFIX}${TARGET:D/${TARGET}.${TARGET_ARCH}}
|
|
|
|
.endif
|
|
|
|
.endif # ${MK_UNIFIED_OBJDIR} == "no"
|
|
|
|
|
|
|
|
.if !empty(MAKEOBJDIRPREFIX)
|
2017-10-31 00:26:42 +00:00
|
|
|
# put things approximately where they want
|
|
|
|
OBJROOT:= ${MAKEOBJDIRPREFIX}${SRCTOP}/
|
|
|
|
MAKEOBJDIRPREFIX=
|
2017-11-02 04:05:03 +00:00
|
|
|
# export but do not track
|
|
|
|
.export-env MAKEOBJDIRPREFIX
|
2017-10-31 00:26:42 +00:00
|
|
|
.endif
|
|
|
|
.if empty(MAKEOBJDIR)
|
|
|
|
# OBJTOP set below
|
|
|
|
MAKEOBJDIR= ${_default_makeobjdir}
|
|
|
|
# export but do not track
|
|
|
|
.export-env MAKEOBJDIR
|
|
|
|
# Expand for our own use
|
|
|
|
MAKEOBJDIR:= ${MAKEOBJDIR}
|
|
|
|
.endif
|
2017-11-01 21:22:05 +00:00
|
|
|
# SB documented at http://www.crufty.net/sjg/docs/sb-tools.htm
|
2017-10-31 00:26:42 +00:00
|
|
|
.if !empty(SB)
|
|
|
|
SB_OBJROOT?= ${SB}/obj/
|
|
|
|
# this is what we use below
|
|
|
|
OBJROOT?= ${SB_OBJROOT}
|
|
|
|
.endif
|
2017-11-01 21:22:05 +00:00
|
|
|
OBJROOT?= ${_default_makeobjdirprefix}${SRCTOP}/
|
2017-10-31 00:26:42 +00:00
|
|
|
.if ${OBJROOT:M*/} != ""
|
|
|
|
OBJROOT:= ${OBJROOT:H:tA}/
|
|
|
|
.else
|
|
|
|
OBJROOT:= ${OBJROOT:H:tA}/${OBJROOT:T}
|
|
|
|
.endif
|
2017-11-01 21:22:05 +00:00
|
|
|
# Must export since OBJDIR will dynamically be based on it
|
2017-10-31 00:26:42 +00:00
|
|
|
.export OBJROOT SRCTOP
|
|
|
|
.endif
|
|
|
|
|
2017-11-11 01:11:00 +00:00
|
|
|
.if ${MK_DIRDEPS_BUILD} == "no"
|
2017-11-10 19:52:31 +00:00
|
|
|
.if empty(OBJTOP)
|
2017-11-10 02:09:33 +00:00
|
|
|
# SRCTOP == OBJROOT only happens with clever MAKEOBJDIRPREFIX=/. Don't
|
|
|
|
# append TARGET.TARGET_ARCH for that case since the user wants to build
|
|
|
|
# in the source tree.
|
|
|
|
.if ${MK_UNIFIED_OBJDIR} == "yes" && ${SRCTOP} != ${OBJROOT:tA}
|
2017-11-11 01:10:55 +00:00
|
|
|
.if defined(TARGET) && defined(TARGET_ARCH)
|
|
|
|
OBJTOP:= ${OBJROOT}${TARGET}.${TARGET_ARCH}
|
|
|
|
.elif defined(TARGET) && ${.CURDIR} == ${SRCTOP}
|
|
|
|
# Not enough information, just use basic OBJDIR. This can happen with some
|
|
|
|
# 'make universe' targets or if TARGET is not being used as expected.
|
|
|
|
OBJTOP:= ${OBJROOT:H}
|
|
|
|
.else
|
|
|
|
OBJTOP:= ${OBJROOT}${MACHINE}.${MACHINE_ARCH}
|
|
|
|
.endif
|
2017-11-01 21:22:05 +00:00
|
|
|
.else
|
|
|
|
# TARGET.TARGET_ARCH handled in OBJROOT already.
|
|
|
|
OBJTOP:= ${OBJROOT:H}
|
|
|
|
.endif # ${MK_UNIFIED_OBJDIR} == "yes"
|
2017-11-11 01:10:55 +00:00
|
|
|
.endif # empty(OBJTOP)
|
2017-11-01 21:22:05 +00:00
|
|
|
|
2017-11-11 01:11:00 +00:00
|
|
|
# Fixup OBJROOT/OBJTOP if using MAKEOBJDIRPREFIX.
|
|
|
|
# This intenionally comes after adding TARGET.TARGET_ARCH so that is truncated
|
|
|
|
# away for nested objdirs. This logic also will not trigger if the OBJROOT
|
|
|
|
# block above unsets MAKEOBJDIRPREFIX.
|
|
|
|
.if !empty(MAKEOBJDIRPREFIX)
|
2017-11-01 21:22:05 +00:00
|
|
|
OBJTOP:= ${MAKEOBJDIRPREFIX}${SRCTOP}
|
|
|
|
OBJROOT:= ${OBJTOP}/
|
|
|
|
.endif
|
|
|
|
|
2017-11-05 00:12:02 +00:00
|
|
|
# Wait to validate MAKEOBJDIR until OBJTOP is set.
|
|
|
|
.if defined(MAKEOBJDIR)
|
|
|
|
.if ${MAKEOBJDIR:M/*} == ""
|
|
|
|
.error Cannot use MAKEOBJDIR=${MAKEOBJDIR}${.newline}Unset MAKEOBJDIR to get default: MAKEOBJDIR='${_default_makeobjdir}'
|
|
|
|
.endif
|
|
|
|
.endif
|
|
|
|
|
2017-11-05 00:12:09 +00:00
|
|
|
# __objdir is the expected .OBJDIR we want to use and that auto.obj.mk will
|
|
|
|
# try to create.
|
|
|
|
.if !empty(MAKEOBJDIRPREFIX)
|
2017-11-11 01:10:41 +00:00
|
|
|
.if ${.CURDIR:M${MAKEOBJDIRPREFIX}/*} != ""
|
|
|
|
# we are already in obj tree!
|
|
|
|
__objdir= ${.CURDIR}
|
|
|
|
.else
|
2017-11-05 00:12:09 +00:00
|
|
|
__objdir:= ${MAKEOBJDIRPREFIX}${.CURDIR}
|
2017-11-11 01:10:41 +00:00
|
|
|
.endif
|
2017-11-05 00:12:09 +00:00
|
|
|
.elif !empty(MAKEOBJDIR)
|
|
|
|
__objdir:= ${MAKEOBJDIR}
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# Try to enable MK_AUTO_OBJ by default if we can write to the __objdir. Only
|
2017-11-10 02:09:33 +00:00
|
|
|
# do this if AUTO_OBJ is not disabled by the user, and this is the first make
|
|
|
|
# ran.
|
2017-11-07 18:20:08 +00:00
|
|
|
.if ${.MAKE.LEVEL} == 0 && \
|
2017-11-02 18:09:07 +00:00
|
|
|
${MK_AUTO_OBJ} == "no" && empty(.MAKEOVERRIDES:MMK_AUTO_OBJ) && \
|
|
|
|
!defined(WITHOUT_AUTO_OBJ) && !make(showconfig) && !make(print-dir) && \
|
2018-06-20 17:20:39 +00:00
|
|
|
!make(test-system-*) && \
|
2018-01-12 01:09:41 +00:00
|
|
|
!defined(NO_OBJ) && \
|
|
|
|
empty(RELDIR:Msys/*/compile/*)
|
2017-11-02 18:09:07 +00:00
|
|
|
# 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() { \
|
2017-12-05 21:30:17 +00:00
|
|
|
if [ -w "$${1}" ]; then \
|
|
|
|
[ -d "$${1}" ] || return 1; \
|
|
|
|
return 0; \
|
|
|
|
fi; \
|
2017-11-02 18:09:07 +00:00
|
|
|
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}; \
|
2017-12-05 21:30:17 +00:00
|
|
|
elif [ -e "/$${dir}$${d}" ]; then \
|
|
|
|
return 1; \
|
2017-11-02 18:09:07 +00:00
|
|
|
else \
|
|
|
|
break; \
|
|
|
|
fi; \
|
|
|
|
fi; \
|
|
|
|
dir="$${dir}$${d}/"; \
|
|
|
|
done; \
|
2017-12-05 21:30:17 +00:00
|
|
|
[ -w "$${dir}" ] && [ -d "$${dir}" ] && return 0; \
|
|
|
|
return 1; \
|
2017-11-02 18:09:07 +00:00
|
|
|
}; \
|
|
|
|
CheckAutoObj() { \
|
|
|
|
if DirIsCreatable "$${1}"; then \
|
|
|
|
echo yes; \
|
|
|
|
else \
|
|
|
|
echo no; \
|
|
|
|
fi; \
|
|
|
|
}
|
2017-11-05 00:12:09 +00:00
|
|
|
.if !empty(__objdir)
|
2018-02-24 01:33:17 +00:00
|
|
|
.if ${.CURDIR} == ${__objdir} || \
|
|
|
|
(exists(${__objdir}) && ${.TARGETS:M*install*} == ${.TARGETS})
|
2017-11-10 02:09:33 +00:00
|
|
|
__objdir_writable?= yes
|
2017-12-05 21:29:47 +00:00
|
|
|
.elif empty(__objdir_writable)
|
2017-11-05 00:12:09 +00:00
|
|
|
__objdir_writable!= \
|
|
|
|
${CheckAutoObj}; CheckAutoObj "${__objdir}" || echo no
|
2017-11-02 18:09:07 +00:00
|
|
|
.endif
|
2017-11-10 02:09:33 +00:00
|
|
|
.endif
|
2017-11-05 00:12:09 +00:00
|
|
|
__objdir_writable?= no
|
2017-11-02 18:09:07 +00:00
|
|
|
# Export the decision to sub-makes.
|
2017-11-05 00:12:09 +00:00
|
|
|
MK_AUTO_OBJ:= ${__objdir_writable}
|
2017-11-02 18:09:07 +00:00
|
|
|
.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" && ...
|
|
|
|
|
2017-11-05 00:12:05 +00:00
|
|
|
# Assign this directory as .OBJDIR if possible.
|
|
|
|
#
|
2017-11-01 21:22:05 +00:00
|
|
|
# The expected OBJDIR already exists, set it as .OBJDIR.
|
2017-11-05 00:12:09 +00:00
|
|
|
.if !empty(__objdir) && exists(${__objdir})
|
|
|
|
.OBJDIR: ${__objdir}
|
2017-11-05 00:12:05 +00:00
|
|
|
.else
|
|
|
|
# The OBJDIR we wanted does not yet exist, ensure we default to safe .CURDIR
|
|
|
|
# in case make started with a bogus MAKEOBJDIR, that expanded before OBJTOP
|
|
|
|
# was set, that happened to match some unexpected directory. Either
|
|
|
|
# auto.obj.mk or bsd.obj.mk will create the directory and fix .OBJDIR later.
|
|
|
|
.OBJDIR: ${.CURDIR}
|
2017-10-31 02:25:47 +00:00
|
|
|
.endif
|
2017-11-10 02:09:33 +00:00
|
|
|
|
|
|
|
# Ensure .OBJDIR=.CURDIR cases have a proper OBJTOP and .OBJDIR
|
|
|
|
.if defined(NO_OBJ) || ${__objdir_writable:Uunknown} == "no" || \
|
|
|
|
${__objdir} == ${.CURDIR}
|
|
|
|
OBJTOP= ${SRCTOP}
|
|
|
|
OBJROOT= ${SRCTOP}/
|
|
|
|
# Compare only to avoid an unneeded chdir(2), :tA purposely left out.
|
|
|
|
.if ${.OBJDIR} != ${.CURDIR}
|
|
|
|
.OBJDIR: ${.CURDIR}
|
|
|
|
.endif
|
|
|
|
.endif # defined(NO_OBJ)
|
2017-11-11 01:11:00 +00:00
|
|
|
|
|
|
|
.endif # ${MK_DIRDEPS_BUILD} == "no"
|