1 # $Id: auto.obj.mk,v 1.10 2015/04/16 16:59:00 sjg Exp $
3 # @(#) Copyright (c) 2004, Simon J. Gerraty
5 # This file is provided in the hope that it will
6 # be of use. There is absolutely NO WARRANTY.
7 # Permission to copy, redistribute or otherwise
8 # use this file is hereby granted provided that
9 # the above copyright notice and this notice are
12 # Please send copies of changes and bug-fixes to:
19 # A race condition in some versions of mkdir, means that it can bail
20 # if another process made a dir that mkdir expected to.
21 # We repeat the mkdir -p a number of times to try and work around this.
22 # We stop looping as soon as the dir exists.
23 # If we get to the end of the loop, a plain mkdir will issue an error.
26 for i in 1 2 3 4 5 6; do \
28 test -d $$d && return 0; \
29 done > /dev/null 2>&1; \
30 mkdir $$d || exit $$?; \
34 # if MKOBJDIRS is set to auto (and NOOBJ isn't defined) do some magic...
35 # This will automatically create objdirs as needed.
36 # Skip it if we are just doing 'clean'.
37 .if ${MK_AUTO_OBJ:Uno} == "yes"
40 .if !defined(NOOBJ) && !defined(NO_OBJ) && ${MKOBJDIRS:Uno} == auto
41 # Use __objdir here so it is easier to tweak without impacting
43 __objdir?= ${MAKEOBJDIR}
44 __objdir:= ${__objdir:tA}
45 .if ${.OBJDIR} != ${__objdir}
46 # We need to chdir, make the directory if needed
47 .if !exists(${__objdir}/) && \
48 (${.TARGETS} == "" || ${.TARGETS:Nclean*:N*clean:Ndestroy*} != "")
49 # This will actually make it...
50 __objdir_made != echo ${__objdir}/; umask ${OBJDIR_UMASK:U002}; \
51 ${ECHO_TRACE} "[Creating objdir ${__objdir}...]" >&2; \
52 ${Mkdirs}; Mkdirs ${__objdir}
53 __objdir:= ${__objdir:tA}
55 # This causes make to use the specified directory as .OBJDIR
57 .if ${.OBJDIR} != ${__objdir} && ${__objdir_made:Uno:M${__objdir}/*} != ""
58 .error could not use ${__objdir}: .OBJDIR=${.OBJDIR}