bsd.obj.mk revision 25316
125316Sbde#	$Id: bsd.obj.mk,v 1.19 1997/02/22 13:56:12 peter Exp $
215353Swosch#
318566Sbde# The include file <bsd.obj.mk> handles creating the 'obj' directory
415353Swosch# and cleaning up object files, log files etc.
515353Swosch#
615353Swosch#
715353Swosch# +++ variables +++
815353Swosch#
915948Swosch# CLEANFILES	Additional files to remove for the clean and cleandir targets.
1015948Swosch#
1118566Sbde# MAKEOBJDIR 	A pathname for the directory where the targets 
1218566Sbde#		are built.  Note: MAKEOBJDIR is an *enviroment* variable
1318566Sbde#		and works properly only if set as an enviroment variable,
1418566Sbde#		not as a global or command line variable!
1515353Swosch#
1618566Sbde#		E.g. use `env MAKEOBJDIR=temp-obj make'
1718566Sbde#
1818566Sbde# MAKEOBJDIRPREFIX  Specifies somewhere other than /usr/obj to root the object
1918566Sbde#		tree.  Note: MAKEOBJDIRPREFIX is an *enviroment* variable
2018566Sbde#		and works properly only if set as an enviroment variable,
2118566Sbde#		not as a global or command line variable!
2218566Sbde#
2318340Sswallace#		E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make'
2415948Swosch#
2518566Sbde# NOOBJ		Do not create object directories.  This should not be set
2618566Sbde#		if anything is built.
2715353Swosch#
2818566Sbde# OBJLINK	Create a symbolic link from ${.CURDIR}/obj to
2918566Sbde#		${CANONICALOBJDIR}.  Note: this BREAKS the read-only source
3018566Sbde#		tree rule!
3115353Swosch#
3215353Swosch# +++ targets +++
3315353Swosch#
3415353Swosch#	clean:
3515353Swosch#		remove a.out Errs errs mklog ${CLEANFILES} 
3615353Swosch#
3715353Swosch#	cleandir:
3816663Sjkh#		remove the build directory (and all its contents) created by obj
3915353Swosch#
4015353Swosch#	obj:
4116663Sjkh#		create build directory.
4215353Swosch#
4314801Swosch
4418340Sswallace.if defined(MAKEOBJDIRPREFIX)
4518340SswallaceCANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
4618340Sswallace.else
4718340SswallaceCANONICALOBJDIR:=/usr/obj${.CURDIR}
4818340Sswallace.endif
4914801Swosch
5018340Sswallace#
5118340Sswallace# Warn of unorthodox object directory
5218340Sswallace#
5318340Sswallaceobjwarn:
5418566Sbde.if !defined(NOOBJ) && ${.OBJDIR} != ${CANONICALOBJDIR}
5518340Sswallace.if ${.OBJDIR} == ${.CURDIR}
5618373Speter	@${ECHO} "Warning: Object directory not changed from original ${.CURDIR}"
5718566Sbde.elif !defined(MAKEOBJDIR) && !defined(MAKEOBJDIRPREFIX) && !defined(OBJLINK)
5818373Speter	@${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\
5918340Sswallace		canonical ${CANONICALOBJDIR}"
6018340Sswallace.endif
6118340Sswallace.endif
6218340Sswallace
6314801Swosch.if !target(obj)
6414801Swosch.if defined(NOOBJ)
6514801Swoschobj:
6614801Swosch.else
6716663Sjkh.if !defined(OBJLINK)
6816663Sjkhobj:	_SUBDIR
6925316Sbde	@if ! test -d ${CANONICALOBJDIR}/; then \
7018340Sswallace		mkdir -p ${CANONICALOBJDIR}; \
7125316Sbde		if ! test -d ${CANONICALOBJDIR}/; then \
7218340Sswallace			${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
7316663Sjkh			exit 1; \
7416663Sjkh		fi; \
7518340Sswallace		${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \
7616663Sjkh	fi
7715353Swosch.else
7816663Sjkhobj:	_SUBDIR
7925316Sbde	@if ! test -d ${CANONICALOBJDIR}/; then \
8018340Sswallace		mkdir -p ${CANONICALOBJDIR}; \
8125316Sbde		if ! test -d ${CANONICALOBJDIR}/; then \
8218340Sswallace			${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
8316663Sjkh			exit 1; \
8416663Sjkh		fi; \
8518051Sbde		rm -f ${.CURDIR}/obj; \
8618340Sswallace		ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
8718340Sswallace		${ECHO} "${.CURDIR} -> ${CANONICALOBJDIR}"; \
8814801Swosch	fi
8914801Swosch.endif
9014801Swosch.endif
9115353Swosch.endif
9214801Swosch
9316663Sjkh.if !target(objlink)
9416663Sjkhobjlink: _SUBDIR
9525316Sbde	@if test -d ${CANONICALOBJDIR}/; then \
9618051Sbde		rm -f ${.CURDIR}/obj; \
9718340Sswallace		ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
9816663Sjkh	else \
9918340Sswallace		echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \
10016663Sjkh	fi
10116663Sjkh.endif
10216663Sjkh
10315166Swosch#
10417116Spst# where would that obj directory be?
10517116Spst#
10617116Spst.if !target(whereobj)
10717116Spstwhereobj:
10818426Sbde	@cd ${.CURDIR}; ${MAKE} -V .OBJDIR
10917116Spst.endif
11017116Spst
11117116Spst#
11215166Swosch# cleanup
11315166Swosch#
11416663Sjkhcleanobj:
11525316Sbde	@if [ -d ${CANONICALOBJDIR}/ ]; then \
11618340Sswallace		rm -rf ${CANONICALOBJDIR}; \
11716663Sjkh	else \
11816663Sjkh		cd ${.CURDIR} && ${MAKE} clean cleandepend; \
11916663Sjkh	fi
12016663Sjkh	@if [ -h ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi
12115166Swosch
12216663Sjkh.if !target(cleanfiles)
12315166Swoschcleanfiles:
12415166Swosch	rm -f a.out Errs errs mklog ${CLEANFILES} 
12516663Sjkh.endif
12615166Swosch
12715166Swosch# see bsd.dep.mk
12815166Swosch.if !target(cleandepend)
12915166Swoschcleandepend:
13016663Sjkh	@rm -f .depend
13115166Swosch.endif
13215166Swosch
13315166Swosch.if !target(clean)
13416663Sjkhclean: cleanfiles _SUBDIR
13515166Swosch.endif
13615166Swosch
13718427Sbde.if !target(checkdpadd)
13818427Sbdecheckdpadd: _SUBDIR
13918427Sbde.if (defined(DPADD) || defined(LDADD))
14018427Sbdecheckdpadd:
14118427Sbde	@if [ "${DPADD:S;^/usr/lib/lib;-l;S;.a$;;}" != "${LDADD}" ] ; then \
14218427Sbde		echo ${.CURDIR} ; \
14318427Sbde		echo "DPADD -> " ${DPADD:S;^/usr/lib/lib;-l;S;.a$;;} ; \
14418427Sbde		echo "LDADD =  " ${LDADD} ; \
14518427Sbde	fi
14618427Sbde.endif
14718427Sbde.endif
14818427Sbde
14916663Sjkhcleandir: cleanobj _SUBDIR
150