bsd.obj.mk revision 25316
140123Sdes#	$Id: bsd.obj.mk,v 1.19 1997/02/22 13:56:12 peter Exp $
240123Sdes#
3709Swollman# The include file <bsd.obj.mk> handles creating the 'obj' directory
437Srgrimes# and cleaning up object files, log files etc.
537Srgrimes#
637Srgrimes#
737Srgrimes# +++ variables +++
837Srgrimes#
937Srgrimes# CLEANFILES	Additional files to remove for the clean and cleandir targets.
108460Sjkh#
1125184Sjkh# MAKEOBJDIR 	A pathname for the directory where the targets 
128460Sjkh#		are built.  Note: MAKEOBJDIR is an *enviroment* variable
138460Sjkh#		and works properly only if set as an enviroment variable,
1437Srgrimes#		not as a global or command line variable!
1537Srgrimes#
1637Srgrimes#		E.g. use `env MAKEOBJDIR=temp-obj make'
1737Srgrimes#
1837Srgrimes# MAKEOBJDIRPREFIX  Specifies somewhere other than /usr/obj to root the object
1937Srgrimes#		tree.  Note: MAKEOBJDIRPREFIX is an *enviroment* variable
2037Srgrimes#		and works properly only if set as an enviroment variable,
2137Srgrimes#		not as a global or command line variable!
2220684Sjoerg#
2337Srgrimes#		E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make'
2437Srgrimes#
2515568Sasami# NOOBJ		Do not create object directories.  This should not be set
2625184Sjkh#		if anything is built.
2715568Sasami#
2815568Sasami# OBJLINK	Create a symbolic link from ${.CURDIR}/obj to
2915568Sasami#		${CANONICALOBJDIR}.  Note: this BREAKS the read-only source
303843Sdg#		tree rule!
313843Sdg#
3225184Sjkh# +++ targets +++
3337Srgrimes#
3437Srgrimes#	clean:
3537Srgrimes#		remove a.out Errs errs mklog ${CLEANFILES} 
3637Srgrimes#
3737Srgrimes#	cleandir:
3837Srgrimes#		remove the build directory (and all its contents) created by obj
3937Srgrimes#
4037Srgrimes#	obj:
4137Srgrimes#		create build directory.
4237Srgrimes#
4337Srgrimes
4437Srgrimes.if defined(MAKEOBJDIRPREFIX)
4537SrgrimesCANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
4637Srgrimes.else
4737SrgrimesCANONICALOBJDIR:=/usr/obj${.CURDIR}
4837Srgrimes.endif
4937Srgrimes
5037Srgrimes#
5137Srgrimes# Warn of unorthodox object directory
5237Srgrimes#
5337Srgrimesobjwarn:
5437Srgrimes.if !defined(NOOBJ) && ${.OBJDIR} != ${CANONICALOBJDIR}
5537Srgrimes.if ${.OBJDIR} == ${.CURDIR}
5637Srgrimes	@${ECHO} "Warning: Object directory not changed from original ${.CURDIR}"
5737Srgrimes.elif !defined(MAKEOBJDIR) && !defined(MAKEOBJDIRPREFIX) && !defined(OBJLINK)
5837Srgrimes	@${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\
5937Srgrimes		canonical ${CANONICALOBJDIR}"
6037Srgrimes.endif
6137Srgrimes.endif
6237Srgrimes
632164Sdg.if !target(obj)
642164Sdg.if defined(NOOBJ)
6537Srgrimesobj:
6637Srgrimes.else
6737Srgrimes.if !defined(OBJLINK)
6837Srgrimesobj:	_SUBDIR
693036Sdg	@if ! test -d ${CANONICALOBJDIR}/; then \
703036Sdg		mkdir -p ${CANONICALOBJDIR}; \
713036Sdg		if ! test -d ${CANONICALOBJDIR}/; then \
728530Sdg			${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
738530Sdg			exit 1; \
748530Sdg		fi; \
758530Sdg		${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \
761692Sphk	fi
7737Srgrimes.else
788530Sdgobj:	_SUBDIR
7937Srgrimes	@if ! test -d ${CANONICALOBJDIR}/; then \
808530Sdg		mkdir -p ${CANONICALOBJDIR}; \
818530Sdg		if ! test -d ${CANONICALOBJDIR}/; then \
828530Sdg			${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
838530Sdg			exit 1; \
8437Srgrimes		fi; \
8525184Sjkh		rm -f ${.CURDIR}/obj; \
8625184Sjkh		ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
8739384Sbrian		${ECHO} "${.CURDIR} -> ${CANONICALOBJDIR}"; \
8825184Sjkh	fi
8925184Sjkh.endif
9025184Sjkh.endif
9125184Sjkh.endif
9225184Sjkh
9325184Sjkh.if !target(objlink)
9425184Sjkhobjlink: _SUBDIR
9525184Sjkh	@if test -d ${CANONICALOBJDIR}/; then \
964091Sache		rm -f ${.CURDIR}/obj; \
97872Sache		ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
9838237Sbrian	else \
9939384Sbrian		echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \
10039384Sbrian	fi
10139384Sbrian.endif
10239384Sbrian
10339384Sbrian#
10439384Sbrian# where would that obj directory be?
10539384Sbrian#
10639384Sbrian.if !target(whereobj)
10739384Sbrianwhereobj:
10839384Sbrian	@cd ${.CURDIR}; ${MAKE} -V .OBJDIR
10938237Sbrian.endif
11026450Sache
11138237Sbrian#
11239384Sbrian# cleanup
11339384Sbrian#
11439384Sbriancleanobj:
11539384Sbrian	@if [ -d ${CANONICALOBJDIR}/ ]; then \
11638237Sbrian		rm -rf ${CANONICALOBJDIR}; \
11721197Sphk	else \
11817767Sjkh		cd ${.CURDIR} && ${MAKE} clean cleandepend; \
11919363Sjoerg	fi
12017767Sjkh	@if [ -h ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi
12125184Sjkh
12217767Sjkh.if !target(cleanfiles)
12317767Sjkhcleanfiles:
1241675Sache	rm -f a.out Errs errs mklog ${CLEANFILES} 
1257219Sjkh.endif
1267293Sjkh
1271675Sache# see bsd.dep.mk
1281675Sache.if !target(cleandepend)
12914596Snatecleandepend:
13014624Snate	@rm -f .depend
13114624Snate.endif
13214596Snate
13314596Snate.if !target(clean)
13425184Sjkhclean: cleanfiles _SUBDIR
13525184Sjkh.endif
13625184Sjkh
13725184Sjkh.if !target(checkdpadd)
1387460Sjkhcheckdpadd: _SUBDIR
1397460Sjkh.if (defined(DPADD) || defined(LDADD))
14038456Sphkcheckdpadd:
14129319Sbrian	@if [ "${DPADD:S;^/usr/lib/lib;-l;S;.a$;;}" != "${LDADD}" ] ; then \
14238456Sphk		echo ${.CURDIR} ; \
1437487Srgrimes		echo "DPADD -> " ${DPADD:S;^/usr/lib/lib;-l;S;.a$;;} ; \
1447487Srgrimes		echo "LDADD =  " ${LDADD} ; \
14520828Sjoerg	fi
1467487Srgrimes.endif
1477487Srgrimes.endif
1487487Srgrimes
1497487Srgrimescleandir: cleanobj _SUBDIR
15038237Sbrian