bsd.obj.mk revision 76021
150476Speter# $FreeBSD: head/share/mk/bsd.obj.mk 76021 2001-04-26 11:14:50Z ru $
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
4664784Ssheldonh.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
8144922Sbde.if !target(objlink)
8244922Sbdeobjlink: _SUBDIR
8344922Sbde	@if test -d ${CANONICALOBJDIR}/; then \
8444922Sbde		rm -f ${.CURDIR}/obj; \
8544922Sbde		ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \
8644922Sbde	else \
8744922Sbde		echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \
8844922Sbde	fi
8944922Sbde.endif
9044922Sbde
9115166Swosch#
9217116Spst# where would that obj directory be?
9317116Spst#
9417116Spst.if !target(whereobj)
9517116Spstwhereobj:
9636641Speter	@echo ${.OBJDIR}
9717116Spst.endif
9817116Spst
9916663Sjkhcleanobj:
10076021Sru.if ${CANONICALOBJDIR} != ${.CURDIR} && exists(${CANONICALOBJDIR}/)
10176021Sru	@rm -rf ${CANONICALOBJDIR}
10276021Sru.else
10376021Sru	@cd ${.CURDIR} && ${MAKE} clean cleandepend
10476021Sru.endif
10516663Sjkh	@if [ -h ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi
10615166Swosch
10731859Sbde.if !target(clean)
10831859Sbdeclean: _SUBDIR
10931859Sbde.if defined(CLEANFILES) && !empty(CLEANFILES)
11031859Sbde	rm -f ${CLEANFILES} 
11116663Sjkh.endif
11233815Sbde.if defined(CLEANDIRS) && !empty(CLEANDIRS)
11333815Sbde	rm -rf ${CLEANDIRS}
11415166Swosch.endif
11533815Sbde.endif
11615166Swosch
11718427Sbde.if !target(checkdpadd)
11818427Sbdecheckdpadd: _SUBDIR
11918427Sbde.if (defined(DPADD) || defined(LDADD))
12018427Sbdecheckdpadd:
12138655Sjb.if ${OBJFORMAT} != aout
12234576Sbde	@ldadd=`echo \`for lib in ${DPADD} ; do \
12334576Sbde		echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
12434576Sbde	done \`` ; \
12534576Sbde	ldadd1=`echo ${LDADD}` ; \
12634576Sbde	if [ "$$ldadd" != "$$ldadd1" ] ; then \
12718427Sbde		echo ${.CURDIR} ; \
12834576Sbde		echo "DPADD -> $$ldadd" ; \
12934576Sbde		echo "LDADD -> $$ldadd1" ; \
13018427Sbde	fi
13131859Sbde.else
13231859Sbde	@dpadd=`echo \`ld -Bstatic -f ${LDDESTDIR} ${LDADD}\`` ; \
13331859Sbde	if [ "$$dpadd" != "${DPADD}" ] ; then \
13431859Sbde		echo ${.CURDIR} ; \
13534576Sbde		echo "LDADD -> $$dpadd" ; \
13634576Sbde		echo "DPADD =  ${DPADD}" ; \
13731859Sbde	fi
13818427Sbde.endif
13918427Sbde.endif
14031859Sbde.endif
14118427Sbde
14216663Sjkhcleandir: cleanobj _SUBDIR
14335789Sbde
14435789Sbde.for __target in cleandepend depend tags
14535789Sbde.if !target(${__target})
14635789Sbde${__target}: _SUBDIR
14735789Sbde.endif
14835789Sbde.endfor
14935789Sbde
15035789Sbde_SUBDIR: .USE
15135789Sbde.if defined(SUBDIR) && !empty(SUBDIR)
15235789Sbde	@for entry in ${SUBDIR}; do \
15335789Sbde		(${ECHODIR} "===> ${DIRPRFX}$$entry"; \
15453152Smarcel		if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \
15553152Smarcel			cd ${.CURDIR}/$${entry}.${MACHINE_ARCH}; \
15635789Sbde		else \
15735789Sbde			cd ${.CURDIR}/$${entry}; \
15835789Sbde		fi; \
15935789Sbde		${MAKE} ${.TARGET:S/realinstall/install/:S/.depend/depend/} DIRPRFX=${DIRPRFX}$$entry/); \
16035789Sbde	done
16135789Sbde.endif
162