bsd.obj.mk revision 18340
1#	$Id: bsd.obj.mk,v 1.8 1996/09/05 17:53:13 bde Exp $
2#
3# The include file <bsd.obj.mk> handles creating 'obj' directory
4# and cleaning up object files, log files etc.
5#
6#
7# +++ variables +++
8#
9# CLEANFILES	Additional files to remove for the clean and cleandir targets.
10#
11# MAKEOBJDIRPREFIX  Specify somewhere other than /usr/obj to root the object
12#		tree. Note: MAKEOBJDIRPREFIX is an *enviroment* variable
13#		and does work proper only if set as enviroment variable,
14#		not as global or command line variable! [obj]
15#
16#		E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make'
17#
18# NOOBJ		Do not create build directory in object tree.
19#
20# OBJLINK	Create a symbolic link from ${CANONICALOBJDIR} to ${.CURDIR}/obj
21#		Note:  This BREAKS the read-only src tree rule!
22#
23# +++ targets +++
24#
25#	clean:
26#		remove a.out Errs errs mklog ${CLEANFILES} 
27#
28#	cleandir:
29#		remove the build directory (and all its contents) created by obj
30#
31#	obj:
32#		create build directory.
33#
34
35.if defined(MAKEOBJDIRPREFIX)
36CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
37.else
38CANONICALOBJDIR:=/usr/obj${.CURDIR}
39.endif
40
41#
42# Warn of unorthodox object directory
43#
44objwarn:
45.if ${.OBJDIR} == ${.CURDIR}
46	${ECHO}	"Warning: Object directory not changed from original ${.CURDIR}"
47.elif !defined(MAKEOBJDIRPREFIX) && ${.OBJDIR} != ${CANONICALOBJDIR}
48.if !defined(MAKEOBJDIR)
49	${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\
50		canonical ${CANONICALOBJDIR}"
51.endif
52.endif
53
54
55
56.if !target(obj)
57.if defined(NOOBJ)
58obj:
59.else
60.if !defined(OBJLINK)
61obj:	_SUBDIR
62	@if ! test -d ${CANONICALOBJDIR}; then \
63		mkdir -p ${CANONICALOBJDIR}; \
64		if ! test -d ${CANONICALOBJDIR}; then \
65			${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
66			exit 1; \
67		fi; \
68		${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \
69	fi
70.else
71obj:	_SUBDIR
72	@if ! test -d ${CANONICALOBJDIR}; then \
73		mkdir -p ${CANONICALOBJDIR}; \
74		if ! test -d ${CANONICALOBJDIR}; then \
75			${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
76			exit 1; \
77		fi; \
78		rm -f ${.CURDIR}/obj; \
79		ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
80		${ECHO} "${.CURDIR} -> ${CANONICALOBJDIR}"; \
81	fi
82.endif
83.endif
84.endif
85
86.if !target(objlink)
87objlink: _SUBDIR
88	@if test -d ${CANONICALOBJDIR}; then \
89		rm -f ${.CURDIR}/obj; \
90		ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
91	else \
92		echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \
93	fi
94.endif
95
96#
97# where would that obj directory be?
98#
99.if !target(whereobj)
100whereobj:
101.if defined(NOOBJ)
102	@echo ${.CURDIR}
103.else
104	@if ! test -d ${CANONICALOBJDIR}; then \
105	    echo ${.CURDIR}; \
106	else \
107	    echo ${CANONICALOBJDIR}; \
108	fi
109.endif
110.endif
111
112#
113# cleanup
114#
115cleanobj:
116	@if [ -d ${CANONICALOBJDIR} ]; then \
117		rm -rf ${CANONICALOBJDIR}; \
118	else \
119		cd ${.CURDIR} && ${MAKE} clean cleandepend; \
120	fi
121.if defined(OBJLINK)
122	@if [ -h ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi
123.endif
124
125.if !target(cleanfiles)
126cleanfiles:
127	rm -f a.out Errs errs mklog ${CLEANFILES} 
128.endif
129
130# see bsd.dep.mk
131.if !target(cleandepend)
132cleandepend:
133	@rm -f .depend
134.endif
135
136.if !target(clean)
137clean: cleanfiles _SUBDIR
138.endif
139
140cleandir: cleanobj _SUBDIR
141