aboutsummaryrefslogtreecommitdiff
path: root/share/mk/auto.obj.mk
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2015-06-13 19:20:56 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2015-06-13 19:20:56 +0000
commitccfb965433c67f3bda935a3cdf334be2e3c4348d (patch)
tree224d8be23eae518123c5b6db18c9819fe6ac6c62 /share/mk/auto.obj.mk
parentcab10cc1d1135a912a7bd2d6178c8e951405167e (diff)
parent2b3dc5355754d7cfe6736c8c2f8d573ee7ac7fab (diff)
downloadsrc-ccfb965433c67f3bda935a3cdf334be2e3c4348d.tar.gz
src-ccfb965433c67f3bda935a3cdf334be2e3c4348d.zip
Add META_MODE support.
Off by default, build behaves normally. WITH_META_MODE we get auto objdir creation, the ability to start build from anywhere in the tree. Still need to add real targets under targets/ to build packages. Differential Revision: D2796 Reviewed by: brooks imp
Notes
Notes: svn path=/head/; revision=284345
Diffstat (limited to 'share/mk/auto.obj.mk')
-rw-r--r--share/mk/auto.obj.mk65
1 files changed, 65 insertions, 0 deletions
diff --git a/share/mk/auto.obj.mk b/share/mk/auto.obj.mk
new file mode 100644
index 000000000000..0c13ae538248
--- /dev/null
+++ b/share/mk/auto.obj.mk
@@ -0,0 +1,65 @@
+# $FreeBSD$
+# $Id: auto.obj.mk,v 1.10 2015/04/16 16:59:00 sjg Exp $
+#
+# @(#) Copyright (c) 2004, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+ECHO_TRACE ?= echo
+
+.ifndef Mkdirs
+# A race condition in some versions of mkdir, means that it can bail
+# if another process made a dir that mkdir expected to.
+# We repeat the mkdir -p a number of times to try and work around this.
+# We stop looping as soon as the dir exists.
+# If we get to the end of the loop, a plain mkdir will issue an error.
+Mkdirs= Mkdirs() { \
+ for d in $$*; do \
+ for i in 1 2 3 4 5 6; do \
+ mkdir -p $$d; \
+ test -d $$d && return 0; \
+ done > /dev/null 2>&1; \
+ mkdir $$d || exit $$?; \
+ done; }
+.endif
+
+# if MKOBJDIRS is set to auto (and NOOBJ isn't defined) do some magic...
+# This will automatically create objdirs as needed.
+# Skip it if we are just doing 'clean'.
+.if ${MK_AUTO_OBJ:Uno} == "yes"
+MKOBJDIRS= auto
+.endif
+.if !defined(NOOBJ) && !defined(NO_OBJ) && ${MKOBJDIRS:Uno} == auto
+# Use __objdir here so it is easier to tweak without impacting
+# the logic.
+.if !empty(MAKEOBJDIRPREFIX) && exists(${MAKEOBJDIRPREFIX})
+__objdir?= ${MAKEOBJDIRPREFIX}${.CURDIR}
+.endif
+__objdir?= ${MAKEOBJDIR:Uobj}
+__objdir:= ${__objdir:tA}
+.if ${.OBJDIR} != ${__objdir}
+# We need to chdir, make the directory if needed
+.if !exists(${__objdir}/) && \
+ (${.TARGETS} == "" || ${.TARGETS:Nclean*:N*clean:Ndestroy*} != "")
+# This will actually make it...
+__objdir_made != echo ${__objdir}/; umask ${OBJDIR_UMASK:U002}; \
+ ${ECHO_TRACE} "[Creating objdir ${__objdir}...]" >&2; \
+ ${Mkdirs}; Mkdirs ${__objdir}
+__objdir:= ${__objdir:tA}
+.endif
+# This causes make to use the specified directory as .OBJDIR
+.OBJDIR: ${__objdir}
+.if ${.OBJDIR} != ${__objdir} && ${__objdir_made:Uno:M${__objdir}/*} != ""
+.error could not use ${__objdir}: .OBJDIR=${.OBJDIR}
+.endif
+.endif
+.endif