1999-08-28 00:22:10 +00:00
|
|
|
# $FreeBSD$
|
1996-04-22 23:31:39 +00:00
|
|
|
#
|
1996-09-29 18:28:55 +00:00
|
|
|
# The include file <bsd.obj.mk> handles creating the 'obj' directory
|
1997-12-19 18:48:45 +00:00
|
|
|
# and cleaning up object files, etc.
|
1996-04-22 23:31:39 +00:00
|
|
|
#
|
|
|
|
# +++ variables +++
|
|
|
|
#
|
1998-02-25 02:48:28 +00:00
|
|
|
# CLEANDIRS Additional directories to remove for the clean target.
|
|
|
|
#
|
|
|
|
# CLEANFILES Additional files to remove for the clean target.
|
1996-05-27 23:05:54 +00:00
|
|
|
#
|
2005-01-06 11:12:43 +00:00
|
|
|
# MAKEOBJDIR A pathname for the directory where the targets
|
2002-07-01 07:25:02 +00:00
|
|
|
# are built. Note: MAKEOBJDIR is an *environment* variable
|
|
|
|
# and works properly only if set as an environment variable,
|
1996-09-29 18:28:55 +00:00
|
|
|
# not as a global or command line variable!
|
|
|
|
#
|
|
|
|
# E.g. use `env MAKEOBJDIR=temp-obj make'
|
|
|
|
#
|
|
|
|
# MAKEOBJDIRPREFIX Specifies somewhere other than /usr/obj to root the object
|
2002-07-01 07:25:02 +00:00
|
|
|
# tree. Note: MAKEOBJDIRPREFIX is an *environment* variable
|
|
|
|
# and works properly only if set as an environment variable,
|
1996-09-29 18:28:55 +00:00
|
|
|
# not as a global or command line variable!
|
1996-05-27 23:05:54 +00:00
|
|
|
#
|
1996-09-18 06:09:19 +00:00
|
|
|
# E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make'
|
1996-04-22 23:31:39 +00:00
|
|
|
#
|
2004-12-21 08:47:35 +00:00
|
|
|
# NO_OBJ Do not create object directories. This should not be set
|
1996-09-29 18:28:55 +00:00
|
|
|
# if anything is built.
|
1996-04-22 23:31:39 +00:00
|
|
|
#
|
|
|
|
# +++ targets +++
|
|
|
|
#
|
|
|
|
# clean:
|
1998-02-25 02:48:28 +00:00
|
|
|
# remove ${CLEANFILES}; remove ${CLEANDIRS} and all contents.
|
1996-04-22 23:31:39 +00:00
|
|
|
#
|
|
|
|
# cleandir:
|
1996-06-24 04:26:21 +00:00
|
|
|
# remove the build directory (and all its contents) created by obj
|
1996-04-22 23:31:39 +00:00
|
|
|
#
|
|
|
|
# obj:
|
1996-06-24 04:26:21 +00:00
|
|
|
# create build directory.
|
1996-04-22 23:31:39 +00:00
|
|
|
#
|
1996-03-24 22:49:16 +00:00
|
|
|
|
2002-04-17 13:49:29 +00:00
|
|
|
.if !target(__<bsd.obj.mk>__)
|
|
|
|
__<bsd.obj.mk>__:
|
|
|
|
.include <bsd.own.mk>
|
|
|
|
|
2015-06-10 18:09:05 +00:00
|
|
|
.if ${MK_AUTO_OBJ} == "yes"
|
|
|
|
# it is done by now
|
|
|
|
objwarn:
|
|
|
|
obj:
|
|
|
|
CANONICALOBJDIR= ${.OBJDIR}
|
2015-06-11 13:53:15 +00:00
|
|
|
.if defined(NO_OBJ)
|
|
|
|
# but this makefile does not want it!
|
|
|
|
.OBJDIR: ${.CURDIR}
|
|
|
|
.endif
|
2016-08-30 22:48:05 +00:00
|
|
|
# Handle special case where SRCS is full-pathed and requires
|
|
|
|
# nested objdirs. This duplicates some auto.obj.mk logic.
|
|
|
|
.if (!empty(SRCS:M*/*) || !empty(DPSRCS:M*/*)) && \
|
|
|
|
(${.TARGETS} == "" || ${.TARGETS:Nclean*:N*clean:Ndestroy*} != "")
|
|
|
|
_wantdirs= ${SRCS:M*/*:H} ${DPSRCS:M*/*:H}
|
|
|
|
.if !empty(_wantdirs)
|
|
|
|
_wantdirs:= ${_wantdirs:O:u}
|
|
|
|
_needdirs=
|
|
|
|
.for _dir in ${_wantdirs}
|
|
|
|
.if !exists(${.OBJDIR}/${_dir}/)
|
|
|
|
_needdirs+= ${_dir}
|
|
|
|
.endif
|
|
|
|
.endfor
|
|
|
|
.endif
|
|
|
|
.if !empty(_needdirs)
|
|
|
|
#_mkneededdirs!= umask ${OBJDIR_UMASK:U002}; ${Mkdirs} ${_needdirs}
|
|
|
|
__objdir_made != umask ${OBJDIR_UMASK:U002}; ${Mkdirs}; \
|
|
|
|
for dir in ${_needdirs}; do \
|
|
|
|
dir=${.OBJDIR}/$${dir}; \
|
|
|
|
${ECHO_TRACE} "[Creating nested objdir $${dir}...]" >&2; \
|
|
|
|
Mkdirs $${dir}; \
|
|
|
|
done
|
|
|
|
.endif
|
|
|
|
.endif # !empty(SRCS:M*/*) || !empty(DPSRCS:M*/*)
|
2015-06-10 18:09:05 +00:00
|
|
|
.elif defined(MAKEOBJDIRPREFIX)
|
1996-09-18 06:09:19 +00:00
|
|
|
CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
|
2012-08-22 19:25:57 +00:00
|
|
|
.elif defined(MAKEOBJDIR) && ${MAKEOBJDIR:M/*} != ""
|
|
|
|
CANONICALOBJDIR:=${MAKEOBJDIR}
|
2015-11-26 01:47:56 +00:00
|
|
|
OBJTOP?= ${MAKEOBJDIR}
|
1996-09-18 06:09:19 +00:00
|
|
|
.else
|
|
|
|
CANONICALOBJDIR:=/usr/obj${.CURDIR}
|
|
|
|
.endif
|
|
|
|
|
2015-11-26 01:47:56 +00:00
|
|
|
OBJTOP?= ${.OBJDIR:S,${.CURDIR},,}${SRCTOP}
|
|
|
|
|
1996-09-18 06:09:19 +00:00
|
|
|
#
|
2001-05-20 12:14:17 +00:00
|
|
|
# Warn of unorthodox object directory.
|
|
|
|
#
|
|
|
|
# The following directories are tried in order for ${.OBJDIR}:
|
|
|
|
#
|
|
|
|
# 1. ${MAKEOBJDIRPREFIX}/`pwd`
|
|
|
|
# 2. ${MAKEOBJDIR}
|
|
|
|
# 3. obj.${MACHINE}
|
|
|
|
# 4. obj
|
|
|
|
# 5. /usr/obj/`pwd`
|
|
|
|
# 6. ${.CURDIR}
|
|
|
|
#
|
|
|
|
# If ${.OBJDIR} is constructed using canonical cases 1 or 5, or
|
|
|
|
# case 2 (using MAKEOBJDIR), don't issue a warning. Otherwise,
|
|
|
|
# issue a warning differentiating between cases 6 and (3 or 4).
|
1996-09-18 06:09:19 +00:00
|
|
|
#
|
2017-06-21 17:11:49 +00:00
|
|
|
objwarn: .PHONY
|
2004-12-21 08:47:35 +00:00
|
|
|
.if !defined(NO_OBJ) && ${.OBJDIR} != ${CANONICALOBJDIR} && \
|
2001-05-20 12:14:17 +00:00
|
|
|
!(defined(MAKEOBJDIRPREFIX) && exists(${CANONICALOBJDIR}/)) && \
|
|
|
|
!(defined(MAKEOBJDIR) && exists(${MAKEOBJDIR}/))
|
1996-09-18 06:09:19 +00:00
|
|
|
.if ${.OBJDIR} == ${.CURDIR}
|
1996-09-19 06:58:26 +00:00
|
|
|
@${ECHO} "Warning: Object directory not changed from original ${.CURDIR}"
|
2001-05-20 12:14:17 +00:00
|
|
|
.elif exists(${.CURDIR}/obj.${MACHINE}/) || exists(${.CURDIR}/obj/)
|
1996-09-19 06:58:26 +00:00
|
|
|
@${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\
|
1996-09-18 06:09:19 +00:00
|
|
|
canonical ${CANONICALOBJDIR}"
|
|
|
|
.endif
|
|
|
|
.endif
|
2016-02-16 02:09:48 +00:00
|
|
|
beforebuild: objwarn
|
1996-03-24 22:49:16 +00:00
|
|
|
|
2004-12-21 08:47:35 +00:00
|
|
|
.if !defined(NO_OBJ)
|
2002-06-21 07:30:51 +00:00
|
|
|
.if !target(obj)
|
2004-04-13 12:36:00 +00:00
|
|
|
obj: .PHONY
|
1997-04-30 17:04:11 +00:00
|
|
|
@if ! test -d ${CANONICALOBJDIR}/; then \
|
1996-09-18 06:09:19 +00:00
|
|
|
mkdir -p ${CANONICALOBJDIR}; \
|
1997-04-30 17:04:11 +00:00
|
|
|
if ! test -d ${CANONICALOBJDIR}/; then \
|
1996-09-18 06:09:19 +00:00
|
|
|
${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
|
1996-06-24 04:26:21 +00:00
|
|
|
exit 1; \
|
|
|
|
fi; \
|
1996-09-18 06:09:19 +00:00
|
|
|
${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \
|
1996-06-24 04:26:21 +00:00
|
|
|
fi
|
2016-08-23 19:31:43 +00:00
|
|
|
.for dir in ${SRCS:H:O:u} ${DPSRCS:H:O:u}
|
2015-03-14 12:29:44 +00:00
|
|
|
@if ! test -d ${CANONICALOBJDIR}/${dir}/; then \
|
|
|
|
mkdir -p ${CANONICALOBJDIR}/${dir}; \
|
|
|
|
if ! test -d ${CANONICALOBJDIR}/${dir}/; then \
|
|
|
|
${ECHO} "Unable to create ${CANONICALOBJDIR}/${dir}."; \
|
|
|
|
exit 1; \
|
|
|
|
fi; \
|
|
|
|
${ECHO} "${CANONICALOBJDIR}/${dir} created for ${.CURDIR}"; \
|
|
|
|
fi
|
|
|
|
.endfor
|
1996-04-22 23:31:39 +00:00
|
|
|
.endif
|
1996-06-24 04:26:21 +00:00
|
|
|
|
1999-03-21 06:43:40 +00:00
|
|
|
.if !target(objlink)
|
2002-04-23 09:03:56 +00:00
|
|
|
objlink:
|
1999-03-21 06:43:40 +00:00
|
|
|
@if test -d ${CANONICALOBJDIR}/; then \
|
|
|
|
rm -f ${.CURDIR}/obj; \
|
|
|
|
ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
|
|
|
|
else \
|
|
|
|
echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \
|
|
|
|
fi
|
|
|
|
.endif
|
2005-04-11 07:13:29 +00:00
|
|
|
.endif # !defined(NO_OBJ)
|
1999-03-21 06:43:40 +00:00
|
|
|
|
1996-07-12 06:01:55 +00:00
|
|
|
#
|
|
|
|
# where would that obj directory be?
|
|
|
|
#
|
|
|
|
.if !target(whereobj)
|
|
|
|
whereobj:
|
1998-06-04 15:31:55 +00:00
|
|
|
@echo ${.OBJDIR}
|
1996-07-12 06:01:55 +00:00
|
|
|
.endif
|
|
|
|
|
2017-07-24 17:54:03 +00:00
|
|
|
# Same check in bsd.progs.mk
|
2001-04-26 11:14:50 +00:00
|
|
|
.if ${CANONICALOBJDIR} != ${.CURDIR} && exists(${CANONICALOBJDIR}/)
|
2004-01-02 05:05:48 +00:00
|
|
|
cleanobj:
|
2017-07-24 17:53:45 +00:00
|
|
|
-rm -rf ${CANONICALOBJDIR}
|
2001-04-26 11:14:50 +00:00
|
|
|
.else
|
2004-01-02 05:05:48 +00:00
|
|
|
cleanobj: clean cleandepend
|
2001-04-26 11:14:50 +00:00
|
|
|
.endif
|
2002-08-31 02:22:33 +00:00
|
|
|
@if [ -L ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi
|
1996-04-09 22:43:33 +00:00
|
|
|
|
2012-08-22 19:25:57 +00:00
|
|
|
# Tell bmake not to look for generated files via .PATH
|
2014-07-22 00:42:55 +00:00
|
|
|
NOPATH_FILES+= ${CLEANFILES}
|
|
|
|
.if !empty(NOPATH_FILES)
|
|
|
|
.NOPATH: ${NOPATH_FILES}
|
2012-08-22 19:25:57 +00:00
|
|
|
.endif
|
|
|
|
|
1996-04-09 22:43:33 +00:00
|
|
|
.if !target(clean)
|
2002-04-23 09:03:56 +00:00
|
|
|
clean:
|
1997-12-19 18:48:45 +00:00
|
|
|
.if defined(CLEANFILES) && !empty(CLEANFILES)
|
2005-01-06 11:12:43 +00:00
|
|
|
rm -f ${CLEANFILES}
|
1997-12-19 18:48:45 +00:00
|
|
|
.endif
|
1998-02-25 02:48:28 +00:00
|
|
|
.if defined(CLEANDIRS) && !empty(CLEANDIRS)
|
2014-11-06 17:19:41 +00:00
|
|
|
-rm -rf ${CLEANDIRS}
|
1998-02-25 02:48:28 +00:00
|
|
|
.endif
|
1996-04-09 22:43:33 +00:00
|
|
|
.endif
|
2016-08-29 18:31:34 +00:00
|
|
|
.ORDER: clean all
|
1996-04-09 22:43:33 +00:00
|
|
|
|
2002-04-23 09:03:56 +00:00
|
|
|
.include <bsd.subdir.mk>
|
2002-04-17 13:49:29 +00:00
|
|
|
|
2017-07-25 00:12:48 +00:00
|
|
|
cleandir: .WAIT cleanobj
|
|
|
|
|
2014-05-02 01:39:30 +00:00
|
|
|
.if make(destroy*) && defined(OBJROOT)
|
2015-06-10 19:31:10 +00:00
|
|
|
# this (rm -rf objdir) is much faster and more reliable than cleaning.
|
2014-05-02 01:39:30 +00:00
|
|
|
|
|
|
|
# just in case we are playing games with these...
|
|
|
|
_OBJDIR?= ${.OBJDIR}
|
|
|
|
_CURDIR?= ${.CURDIR}
|
|
|
|
|
2014-05-05 18:17:26 +00:00
|
|
|
# destroy almost everything
|
|
|
|
destroy: destroy-all
|
|
|
|
destroy-all:
|
|
|
|
|
|
|
|
# just remove our objdir
|
2014-05-02 01:39:30 +00:00
|
|
|
destroy-arch: .NOMETA
|
|
|
|
.if ${_OBJDIR} != ${_CURDIR}
|
|
|
|
cd ${_CURDIR} && rm -rf ${_OBJDIR}
|
|
|
|
.endif
|
|
|
|
|
2014-05-05 18:17:26 +00:00
|
|
|
.if defined(HOST_OBJTOP)
|
|
|
|
destroy-host: destroy.host
|
|
|
|
destroy.host: .NOMETA
|
|
|
|
cd ${_CURDIR} && rm -rf ${HOST_OBJTOP}/${RELDIR:N.}
|
|
|
|
.endif
|
2014-05-02 01:39:30 +00:00
|
|
|
|
2014-05-05 18:17:26 +00:00
|
|
|
.if make(destroy-all) && ${RELDIR} == "."
|
|
|
|
destroy-all: destroy-stage
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# remove the stage tree
|
|
|
|
destroy-stage: .NOMETA
|
|
|
|
.if defined(STAGE_ROOT)
|
|
|
|
cd ${_CURDIR} && rm -rf ${STAGE_ROOT}
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# allow parallel destruction
|
2014-05-10 00:24:32 +00:00
|
|
|
_destroy_machine_list = common host ${ALL_MACHINE_LIST}
|
|
|
|
.for m in ${_destroy_machine_list:O:u}
|
2014-05-02 01:39:30 +00:00
|
|
|
destroy-all: destroy.$m
|
2014-05-05 18:17:26 +00:00
|
|
|
.if !target(destroy.$m)
|
2014-05-02 01:39:30 +00:00
|
|
|
destroy.$m: .NOMETA
|
2014-05-05 18:17:26 +00:00
|
|
|
.if ${_OBJDIR} != ${_CURDIR}
|
2014-05-02 01:39:30 +00:00
|
|
|
cd ${_CURDIR} && rm -rf ${OBJROOT}$m*/${RELDIR:N.}
|
|
|
|
.endif
|
2014-05-05 18:17:26 +00:00
|
|
|
.endif
|
|
|
|
.endfor
|
2014-05-02 01:39:30 +00:00
|
|
|
|
|
|
|
.endif
|
|
|
|
|
2005-04-11 07:13:29 +00:00
|
|
|
.endif # !target(__<bsd.obj.mk>__)
|