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