3 # The include file <bsd.obj.mk> handles creating the 'obj' directory
4 # and cleaning up object files, etc.
8 # CLEANDIRS Additional directories to remove for the clean target.
10 # CLEANFILES Additional files to remove for the clean target.
12 # MAKEOBJDIR A pathname for the directory where the targets
13 # are built. Note: MAKEOBJDIR is an *environment* variable
14 # and works properly only if set as an environment variable,
15 # not as a global or command line variable!
17 # E.g. use `env MAKEOBJDIR=temp-obj make'
19 # MAKEOBJDIRPREFIX Specifies somewhere other than /usr/obj to root the object
20 # tree. Note: MAKEOBJDIRPREFIX is an *environment* variable
21 # and works properly only if set as an environment variable,
22 # not as a global or command line variable!
24 # E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make'
26 # NO_OBJ Do not create object directories. This should not be set
27 # if anything is built.
32 # remove ${CLEANFILES}; remove ${CLEANDIRS} and all contents.
35 # remove the build directory (and all its contents) created by obj
38 # create build directory.
41 .if !target(__<bsd.obj.mk>__)
45 .if defined(MAKEOBJDIRPREFIX)
46 CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
48 CANONICALOBJDIR:=/usr/obj${.CURDIR}
52 # Warn of unorthodox object directory.
54 # The following directories are tried in order for ${.OBJDIR}:
56 # 1. ${MAKEOBJDIRPREFIX}/`pwd`
63 # If ${.OBJDIR} is constructed using canonical cases 1 or 5, or
64 # case 2 (using MAKEOBJDIR), don't issue a warning. Otherwise,
65 # issue a warning differentiating between cases 6 and (3 or 4).
68 .if !defined(NO_OBJ) && ${.OBJDIR} != ${CANONICALOBJDIR} && \
69 !(defined(MAKEOBJDIRPREFIX) && exists(${CANONICALOBJDIR}/)) && \
70 !(defined(MAKEOBJDIR) && exists(${MAKEOBJDIR}/))
71 .if ${.OBJDIR} == ${.CURDIR}
72 @${ECHO} "Warning: Object directory not changed from original ${.CURDIR}"
73 .elif exists(${.CURDIR}/obj.${MACHINE}/) || exists(${.CURDIR}/obj/)
74 @${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\
75 canonical ${CANONICALOBJDIR}"
82 @if ! test -d ${CANONICALOBJDIR}/; then \
83 mkdir -p ${CANONICALOBJDIR}; \
84 if ! test -d ${CANONICALOBJDIR}/; then \
85 ${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
88 ${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \
94 @if test -d ${CANONICALOBJDIR}/; then \
95 rm -f ${.CURDIR}/obj; \
96 ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
98 echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \
101 .endif # !defined(NO_OBJ)
104 # where would that obj directory be?
106 .if !target(whereobj)
111 .if ${CANONICALOBJDIR} != ${.CURDIR} && exists(${CANONICALOBJDIR}/)
113 @rm -rf ${CANONICALOBJDIR}
115 cleanobj: clean cleandepend
117 @if [ -L ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi
121 .if defined(CLEANFILES) && !empty(CLEANFILES)
124 .if defined(CLEANDIRS) && !empty(CLEANDIRS)
131 .include <bsd.subdir.mk>
133 .endif # !target(__<bsd.obj.mk>__)