bsd.obj.mk revision 139761
150476Speter# $FreeBSD: head/share/mk/bsd.obj.mk 139761 2005-01-06 11:12:43Z krion $
215353Swosch#
318566Sbde# The include file <bsd.obj.mk> handles creating the 'obj' directory
431859Sbde# and cleaning up object files, etc.
515353Swosch#
615353Swosch# +++ variables +++
715353Swosch#
833815Sbde# CLEANDIRS	Additional directories to remove for the clean target.
915948Swosch#
1033815Sbde# CLEANFILES	Additional files to remove for the clean target.
1133815Sbde#
12139761Skrion# MAKEOBJDIR 	A pathname for the directory where the targets
1399202Sru#		are built.  Note: MAKEOBJDIR is an *environment* variable
1499202Sru#		and works properly only if set as an environment variable,
1518566Sbde#		not as a global or command line variable!
1615353Swosch#
1718566Sbde#		E.g. use `env MAKEOBJDIR=temp-obj make'
1818566Sbde#
1918566Sbde# MAKEOBJDIRPREFIX  Specifies somewhere other than /usr/obj to root the object
2099202Sru#		tree.  Note: MAKEOBJDIRPREFIX is an *environment* variable
2199202Sru#		and works properly only if set as an environment variable,
2218566Sbde#		not as a global or command line variable!
2318566Sbde#
2418340Sswallace#		E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make'
2515948Swosch#
26139103Sru# NO_OBJ	Do not create object directories.  This should not be set
2718566Sbde#		if anything is built.
2815353Swosch#
2915353Swosch# +++ targets +++
3015353Swosch#
3115353Swosch#	clean:
3233815Sbde#		remove ${CLEANFILES}; remove ${CLEANDIRS} and all contents.
3315353Swosch#
3415353Swosch#	cleandir:
3516663Sjkh#		remove the build directory (and all its contents) created by obj
3615353Swosch#
3715353Swosch#	obj:
3816663Sjkh#		create build directory.
3915353Swosch#
4014801Swosch
4194940Sru.if !target(__<bsd.obj.mk>__)
4294940Sru__<bsd.obj.mk>__:
4394940Sru.include <bsd.own.mk>
4494940Sru
4564784Ssheldonh.if defined(MAKEOBJDIRPREFIX)
4618340SswallaceCANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
4718340Sswallace.else
4818340SswallaceCANONICALOBJDIR:=/usr/obj${.CURDIR}
4918340Sswallace.endif
5014801Swosch
5118340Sswallace#
5276896Sru# Warn of unorthodox object directory.
5318340Sswallace#
5476896Sru# The following directories are tried in order for ${.OBJDIR}:
5576896Sru#
5676896Sru# 1.  ${MAKEOBJDIRPREFIX}/`pwd`
5776896Sru# 2.  ${MAKEOBJDIR}
5876896Sru# 3.  obj.${MACHINE}
5976896Sru# 4.  obj
6076896Sru# 5.  /usr/obj/`pwd`
6176896Sru# 6.  ${.CURDIR}
6276896Sru#
6376896Sru# If ${.OBJDIR} is constructed using canonical cases 1 or 5, or
6476896Sru# case 2 (using MAKEOBJDIR), don't issue a warning.  Otherwise,
6576896Sru# issue a warning differentiating between cases 6 and (3 or 4).
6676896Sru#
6718340Sswallaceobjwarn:
68139103Sru.if !defined(NO_OBJ) && ${.OBJDIR} != ${CANONICALOBJDIR} && \
6976896Sru    !(defined(MAKEOBJDIRPREFIX) && exists(${CANONICALOBJDIR}/)) && \
7076896Sru    !(defined(MAKEOBJDIR) && exists(${MAKEOBJDIR}/))
7118340Sswallace.if ${.OBJDIR} == ${.CURDIR}
7218373Speter	@${ECHO} "Warning: Object directory not changed from original ${.CURDIR}"
7376896Sru.elif exists(${.CURDIR}/obj.${MACHINE}/) || exists(${.CURDIR}/obj/)
7418373Speter	@${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\
7518340Sswallace		canonical ${CANONICALOBJDIR}"
7618340Sswallace.endif
7718340Sswallace.endif
7818340Sswallace
79139103Sru.if !defined(NO_OBJ)
8098546Sru.if !target(obj)
81128188Sruobj: .PHONY
8225316Sbde	@if ! test -d ${CANONICALOBJDIR}/; then \
8318340Sswallace		mkdir -p ${CANONICALOBJDIR}; \
8425316Sbde		if ! test -d ${CANONICALOBJDIR}/; then \
8518340Sswallace			${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
8616663Sjkh			exit 1; \
8716663Sjkh		fi; \
8818340Sswallace		${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \
8916663Sjkh	fi
9014801Swosch.endif
9114801Swosch
9244922Sbde.if !target(objlink)
9395306Sruobjlink:
9444922Sbde	@if test -d ${CANONICALOBJDIR}/; then \
9544922Sbde		rm -f ${.CURDIR}/obj; \
9644922Sbde		ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
9744922Sbde	else \
9844922Sbde		echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \
9944922Sbde	fi
10044922Sbde.endif
101139103Sru.endif !defined(NO_OBJ)
10244922Sbde
10315166Swosch#
10417116Spst# where would that obj directory be?
10517116Spst#
10617116Spst.if !target(whereobj)
10717116Spstwhereobj:
10836641Speter	@echo ${.OBJDIR}
10917116Spst.endif
11017116Spst
111124061Sgreen.if ${CANONICALOBJDIR} != ${.CURDIR} && exists(${CANONICALOBJDIR}/)
11216663Sjkhcleanobj:
11376021Sru	@rm -rf ${CANONICALOBJDIR}
11476021Sru.else
115124061Sgreencleanobj: clean cleandepend
11676021Sru.endif
117102660Skris	@if [ -L ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi
11815166Swosch
11931859Sbde.if !target(clean)
12095306Sruclean:
12131859Sbde.if defined(CLEANFILES) && !empty(CLEANFILES)
122139761Skrion	rm -f ${CLEANFILES}
12316663Sjkh.endif
12433815Sbde.if defined(CLEANDIRS) && !empty(CLEANDIRS)
12533815Sbde	rm -rf ${CLEANDIRS}
12615166Swosch.endif
12733815Sbde.endif
12815166Swosch
12995306Srucleandir: cleanobj
13035789Sbde
13195306Sru.include <bsd.subdir.mk>
13235789Sbde
13394940Sru.endif !target(__<bsd.obj.mk>__)
134