bsd.obj.mk revision 44755
144755Smarkm#	$Id: bsd.obj.mk,v 1.26 1998/08/30 20:33:27 jb Exp $
215353Swosch#
318566Sbde# The include file <bsd.obj.mk> handles creating the 'obj' directory
431859Sbde# and cleaning up object files, etc.
515353Swosch#
635789Sbde# Under construction: it also contains the _SUBDIR target (which is used
735789Sbde# by most `mk' files to recurse into subdirectories) and defaults for the
835789Sbde# cleandepend, depend and tags targets.  It may eventually be merged with
935789Sbde# with bsd.subdir.mk.
1015353Swosch#
1115353Swosch# +++ variables +++
1215353Swosch#
1333815Sbde# CLEANDIRS	Additional directories to remove for the clean target.
1415948Swosch#
1533815Sbde# CLEANFILES	Additional files to remove for the clean target.
1633815Sbde#
1718566Sbde# MAKEOBJDIR 	A pathname for the directory where the targets 
1818566Sbde#		are built.  Note: MAKEOBJDIR is an *enviroment* variable
1918566Sbde#		and works properly only if set as an enviroment variable,
2018566Sbde#		not as a global or command line variable!
2115353Swosch#
2218566Sbde#		E.g. use `env MAKEOBJDIR=temp-obj make'
2318566Sbde#
2418566Sbde# MAKEOBJDIRPREFIX  Specifies somewhere other than /usr/obj to root the object
2518566Sbde#		tree.  Note: MAKEOBJDIRPREFIX is an *enviroment* variable
2618566Sbde#		and works properly only if set as an enviroment variable,
2718566Sbde#		not as a global or command line variable!
2818566Sbde#
2918340Sswallace#		E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make'
3015948Swosch#
3118566Sbde# NOOBJ		Do not create object directories.  This should not be set
3218566Sbde#		if anything is built.
3315353Swosch#
3415353Swosch# +++ targets +++
3515353Swosch#
3615353Swosch#	clean:
3733815Sbde#		remove ${CLEANFILES}; remove ${CLEANDIRS} and all contents.
3815353Swosch#
3915353Swosch#	cleandir:
4016663Sjkh#		remove the build directory (and all its contents) created by obj
4115353Swosch#
4215353Swosch#	obj:
4316663Sjkh#		create build directory.
4415353Swosch#
4514801Swosch
4618340Sswallace.if defined(MAKEOBJDIRPREFIX)
4718340SswallaceCANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
4818340Sswallace.else
4918340SswallaceCANONICALOBJDIR:=/usr/obj${.CURDIR}
5018340Sswallace.endif
5114801Swosch
5218340Sswallace#
5318340Sswallace# Warn of unorthodox object directory
5418340Sswallace#
5518340Sswallaceobjwarn:
5618566Sbde.if !defined(NOOBJ) && ${.OBJDIR} != ${CANONICALOBJDIR}
5718340Sswallace.if ${.OBJDIR} == ${.CURDIR}
5818373Speter	@${ECHO} "Warning: Object directory not changed from original ${.CURDIR}"
5944755Smarkm.elif !defined(MAKEOBJDIR) && !defined(MAKEOBJDIRPREFIX)
6018373Speter	@${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\
6118340Sswallace		canonical ${CANONICALOBJDIR}"
6218340Sswallace.endif
6318340Sswallace.endif
6418340Sswallace
6514801Swosch.if !target(obj)
6614801Swosch.if defined(NOOBJ)
6714801Swoschobj:
6814801Swosch.else
6916663Sjkhobj:	_SUBDIR
7025316Sbde	@if ! test -d ${CANONICALOBJDIR}/; then \
7118340Sswallace		mkdir -p ${CANONICALOBJDIR}; \
7225316Sbde		if ! test -d ${CANONICALOBJDIR}/; then \
7318340Sswallace			${ECHO} "Unable to create ${CANONICALOBJDIR}."; \
7416663Sjkh			exit 1; \
7516663Sjkh		fi; \
7618340Sswallace		${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \
7716663Sjkh	fi
7814801Swosch.endif
7914801Swosch.endif
8014801Swosch
8115166Swosch#
8217116Spst# where would that obj directory be?
8317116Spst#
8417116Spst.if !target(whereobj)
8517116Spstwhereobj:
8636641Speter	@echo ${.OBJDIR}
8717116Spst.endif
8817116Spst
8916663Sjkhcleanobj:
9025316Sbde	@if [ -d ${CANONICALOBJDIR}/ ]; then \
9118340Sswallace		rm -rf ${CANONICALOBJDIR}; \
9216663Sjkh	else \
9316663Sjkh		cd ${.CURDIR} && ${MAKE} clean cleandepend; \
9416663Sjkh	fi
9516663Sjkh	@if [ -h ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi
9615166Swosch
9731859Sbde.if !target(clean)
9831859Sbdeclean: _SUBDIR
9931859Sbde.if defined(CLEANFILES) && !empty(CLEANFILES)
10031859Sbde	rm -f ${CLEANFILES} 
10116663Sjkh.endif
10233815Sbde.if defined(CLEANDIRS) && !empty(CLEANDIRS)
10333815Sbde	rm -rf ${CLEANDIRS}
10415166Swosch.endif
10533815Sbde.endif
10615166Swosch
10718427Sbde.if !target(checkdpadd)
10818427Sbdecheckdpadd: _SUBDIR
10918427Sbde.if (defined(DPADD) || defined(LDADD))
11018427Sbdecheckdpadd:
11138655Sjb.if ${OBJFORMAT} != aout
11234576Sbde	@ldadd=`echo \`for lib in ${DPADD} ; do \
11334576Sbde		echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
11434576Sbde	done \`` ; \
11534576Sbde	ldadd1=`echo ${LDADD}` ; \
11634576Sbde	if [ "$$ldadd" != "$$ldadd1" ] ; then \
11718427Sbde		echo ${.CURDIR} ; \
11834576Sbde		echo "DPADD -> $$ldadd" ; \
11934576Sbde		echo "LDADD -> $$ldadd1" ; \
12018427Sbde	fi
12131859Sbde.else
12231859Sbde	@dpadd=`echo \`ld -Bstatic -f ${LDDESTDIR} ${LDADD}\`` ; \
12331859Sbde	if [ "$$dpadd" != "${DPADD}" ] ; then \
12431859Sbde		echo ${.CURDIR} ; \
12534576Sbde		echo "LDADD -> $$dpadd" ; \
12634576Sbde		echo "DPADD =  ${DPADD}" ; \
12731859Sbde	fi
12818427Sbde.endif
12918427Sbde.endif
13031859Sbde.endif
13118427Sbde
13216663Sjkhcleandir: cleanobj _SUBDIR
13335789Sbde
13435789Sbde.for __target in cleandepend depend tags
13535789Sbde.if !target(${__target})
13635789Sbde${__target}: _SUBDIR
13735789Sbde.endif
13835789Sbde.endfor
13935789Sbde
14035789Sbde_SUBDIR: .USE
14135789Sbde.if defined(SUBDIR) && !empty(SUBDIR)
14235789Sbde	@for entry in ${SUBDIR}; do \
14335789Sbde		(${ECHODIR} "===> ${DIRPRFX}$$entry"; \
14435789Sbde		if test -d ${.CURDIR}/$${entry}.${MACHINE}; then \
14535789Sbde			cd ${.CURDIR}/$${entry}.${MACHINE}; \
14635789Sbde		else \
14735789Sbde			cd ${.CURDIR}/$${entry}; \
14835789Sbde		fi; \
14935789Sbde		${MAKE} ${.TARGET:S/realinstall/install/:S/.depend/depend/} DIRPRFX=${DIRPRFX}$$entry/); \
15035789Sbde	done
15135789Sbde.endif
152