bsd.obj.mk revision 17168
12061Sjkh#	$Id: bsd.obj.mk,v 1.6 1996/07/12 06:01:55 pst Exp $
250479Speter#
32061Sjkh# The include file <bsd.obj.mk> handles creating 'obj' directory
438666Sjb# and cleaning up object files, log files etc.
532427Sjb#
6111131Sru#
7111131Sru# +++ variables +++
838666Sjb#
938666Sjb# CLEANFILES	Additional files to remove for the clean and cleandir targets.
1038666Sjb#
1138666Sjb# MAKEOBJDIR 	Specify somewhere other than /usr/obj to root the object
1264049Salex#		tree. Note: MAKEOBJDIR is an *enviroment* variable
1364049Salex#		and does work proper only if set as enviroment variable,
14116679Ssimokawa#		not as global or command line variable! [obj]
1566071Smarkm#
16116679Ssimokawa#		E.g. use `env MAKEOBJDIR=/somewhere/obj make'
1773504Sobrien#
1838666Sjb# NOOBJ		Do not create build directory in object tree.
19148330Snetchild#
20148330Snetchild# OBJLINK	Create a symbolic link from ${.TARGETOBJDIR} to ${.CURDIR}/obj
21148330Snetchild#		Note:  This BREAKS the read-only src tree rule!
2232427Sjb#
2338666Sjb# +++ targets +++
24108451Sschweikh#
2538666Sjb#	clean:
2638666Sjb#		remove a.out Errs errs mklog ${CLEANFILES} 
2738666Sjb#
2838666Sjb#	cleandir:
2917308Speter#		remove the build directory (and all its contents) created by obj
3091606Skeramida#
3119175Sbde#	obj:
3296205Sjwd#		create build directory.
3396205Sjwd#
3438042Sbde
3596205Sjwd
3696205Sjwd.if !target(obj)
3738042Sbde.if defined(NOOBJ)
3896205Sjwdobj:
3996205Sjwd.else
4017308Speter.if !defined(OBJLINK)
4196205Sjwdobj:	_SUBDIR
4296205Sjwd	@if ! test -d ${.TARGETOBJDIR}; then \
4317308Speter		mkdir -p ${.TARGETOBJDIR}; \
44148330Snetchild		if ! test -d ${.TARGETOBJDIR}; then \
45148330Snetchild			${ECHO} "Unable to create ${.TARGETOBJDIR}."; \
46148330Snetchild			exit 1; \
47148330Snetchild		fi; \
48148330Snetchild		${ECHO} "${.TARGETOBJDIR} created for ${.CURDIR}"; \
49148330Snetchild	fi
50148330Snetchild.else
51148330Snetchildobj:	_SUBDIR
52148330Snetchild	@if ! test -d ${.TARGETOBJDIR}; then \
53148330Snetchild		mkdir -p ${.TARGETOBJDIR}; \
54148330Snetchild		if ! test -d ${.TARGETOBJDIR}; then \
5596205Sjwd			${ECHO} "Unable to create ${.TARGETOBJDIR}."; \
5696205Sjwd			exit 1; \
5796205Sjwd		fi; \
5898775Sdillon		ln -fs ${.TARGETOBJDIR} ${.CURDIR}/obj; \
5998723Sdillon		${ECHO} "${.CURDIR} -> ${.TARGETOBJDIR}"; \
6098723Sdillon	fi
6198723Sdillon.endif
6298723Sdillon.endif
6338666Sjb.endif
6438666Sjb
6517308Speter.if !target(objlink)
66123311Speterobjlink: _SUBDIR
67123311Speter	@if test -d ${.TARGETOBJDIR}; then \
68123311Speter		ln -fs ${.TARGETOBJDIR} ${.CURDIR}/obj; \
69123311Speter	else \
70148330Snetchild		echo "No ${.TARGETOBJDIR} to link to - do a make obj."; \
71148330Snetchild	fi
72148330Snetchild.endif
73116679Ssimokawa
74120760Sru#
75128189Sdes# where would that obj directory be?
76127360Sru#
77123311Speter.if !target(whereobj)
78137288Speterwhereobj:
79147425Sru.if defined(NOOBJ)
802061Sjkh	@echo ${.CURDIR}
8197769Sru.else
8297252Sru	@if ! test -d ${.TARGETOBJDIR}; then \
83119579Sru	    echo ${.CURDIR}; \
8497252Sru	else \
8595730Sru	    echo ${.TARGETOBJDIR}; \
8695793Sru	fi
87111617Sru.endif
8895730Sru.endif
89116679Ssimokawa
9095730Sru#
91116679Ssimokawa# cleanup
9295730Sru#
93110035Srucleanobj:
94107516Sru	@if [ -d ${.TARGETOBJDIR} ]; then \
95138921Sru		rm -rf ${.TARGETOBJDIR}; \
96156145Syar	else \
97138921Sru		cd ${.CURDIR} && ${MAKE} clean cleandepend; \
98133942Sru	fi
99133942Sru.if defined(OBJLINK)
100156145Syar	@if [ -h ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi
101133942Sru.endif
102110035Sru
103117234Sru.if !target(cleanfiles)
104110035Srucleanfiles:
105117229Sru	rm -f a.out Errs errs mklog ${CLEANFILES} 
106117234Sru.endif
10754324Smarcel
10817308Speter# see bsd.dep.mk
109119519Smarcel.if !target(cleandepend)
110119519Smarcelcleandepend:
111119519Smarcel	@rm -f .depend
112119519Smarcel.endif
113119519Smarcel
114119519Smarcel.if !target(clean)
115119579Sruclean: cleanfiles _SUBDIR
116119519Smarcel.endif
117119519Smarcel
118119519Smarcelcleandir: cleanobj _SUBDIR
119119519Smarcel