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