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 ${MK_AUTO_OBJ} == "yes"
49 CANONICALOBJDIR= ${.OBJDIR}
51 # but this makefile does not want it!
54 .elif defined(MAKEOBJDIRPREFIX)
55 CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
56 .elif defined(MAKEOBJDIR) && ${MAKEOBJDIR:M/*} != ""
57 CANONICALOBJDIR:=${MAKEOBJDIR}
58 OBJTOP?= ${MAKEOBJDIR}
60 CANONICALOBJDIR:=/usr/obj${.CURDIR}
63 OBJTOP?= ${.OBJDIR:S,${.CURDIR},,}${SRCTOP}
66 # Warn of unorthodox object directory.
68 # The following directories are tried in order for ${.OBJDIR}:
70 # 1. ${MAKEOBJDIRPREFIX}/`pwd`
77 # If ${.OBJDIR} is constructed using canonical cases 1 or 5, or
78 # case 2 (using MAKEOBJDIR), don't issue a warning. Otherwise,
79 # issue a warning differentiating between cases 6 and (3 or 4).
82 .if !defined(NO_OBJ) && ${.OBJDIR} != ${CANONICALOBJDIR} && \
83 !(defined(MAKEOBJDIRPREFIX) && exists(${CANONICALOBJDIR}/)) && \
84 !(defined(MAKEOBJDIR) && exists(${MAKEOBJDIR}/))
85 .if ${.OBJDIR} == ${.CURDIR}
86 @${ECHO} "Warning: Object directory not changed from original ${.CURDIR}"
87 .elif exists(${.CURDIR}/obj.${MACHINE}/) || exists(${.CURDIR}/obj/)
88 @${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\
89 canonical ${CANONICALOBJDIR}"
97 @if ! test -d ${CANONICALOBJDIR}/; then \
98 mkdir -p ${CANONICALOBJDIR}; \
99 if ! test -d ${CANONICALOBJDIR}/; then \
100 ${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
103 ${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \
105 .for dir in ${SRCS:H:O:u}
106 @if ! test -d ${CANONICALOBJDIR}/${dir}/; then \
107 mkdir -p ${CANONICALOBJDIR}/${dir}; \
108 if ! test -d ${CANONICALOBJDIR}/${dir}/; then \
109 ${ECHO} "Unable to create ${CANONICALOBJDIR}/${dir}."; \
112 ${ECHO} "${CANONICALOBJDIR}/${dir} created for ${.CURDIR}"; \
119 @if test -d ${CANONICALOBJDIR}/; then \
120 rm -f ${.CURDIR}/obj; \
121 ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
123 echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \
126 .endif # !defined(NO_OBJ)
129 # where would that obj directory be?
131 .if !target(whereobj)
136 .if ${CANONICALOBJDIR} != ${.CURDIR} && exists(${CANONICALOBJDIR}/)
138 @-rm -rf ${CANONICALOBJDIR}
140 cleanobj: clean cleandepend
142 @if [ -L ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi
144 # Tell bmake not to look for generated files via .PATH
145 NOPATH_FILES+= ${CLEANFILES}
146 .if !empty(NOPATH_FILES)
147 .NOPATH: ${NOPATH_FILES}
152 .if defined(CLEANFILES) && !empty(CLEANFILES)
155 .if defined(CLEANDIRS) && !empty(CLEANDIRS)
162 .include <bsd.subdir.mk>
164 .if make(destroy*) && defined(OBJROOT)
165 # this (rm -rf objdir) is much faster and more reliable than cleaning.
167 # just in case we are playing games with these...
171 # destroy almost everything
175 # just remove our objdir
176 destroy-arch: .NOMETA
177 .if ${_OBJDIR} != ${_CURDIR}
178 cd ${_CURDIR} && rm -rf ${_OBJDIR}
181 .if defined(HOST_OBJTOP)
182 destroy-host: destroy.host
183 destroy.host: .NOMETA
184 cd ${_CURDIR} && rm -rf ${HOST_OBJTOP}/${RELDIR:N.}
187 .if make(destroy-all) && ${RELDIR} == "."
188 destroy-all: destroy-stage
191 # remove the stage tree
192 destroy-stage: .NOMETA
193 .if defined(STAGE_ROOT)
194 cd ${_CURDIR} && rm -rf ${STAGE_ROOT}
197 # allow parallel destruction
198 _destroy_machine_list = common host ${ALL_MACHINE_LIST}
199 .for m in ${_destroy_machine_list:O:u}
200 destroy-all: destroy.$m
201 .if !target(destroy.$m)
203 .if ${_OBJDIR} != ${_CURDIR}
204 cd ${_CURDIR} && rm -rf ${OBJROOT}$m*/${RELDIR:N.}
211 .endif # !target(__<bsd.obj.mk>__)