xref: /freebsd/contrib/bmake/mk/obj.mk (revision c59c3bf34db360695f07735bebc76a768cac5afc)
1*c59c3bf3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause
2*c59c3bf3SSimon J. Gerraty#
3*c59c3bf3SSimon J. Gerraty# $Id: obj.mk,v 1.19 2024/02/19 00:06:19 sjg Exp $
43cbdda60SSimon J. Gerraty#
53cbdda60SSimon J. Gerraty#	@(#) Copyright (c) 1999-2010, Simon J. Gerraty
63cbdda60SSimon J. Gerraty#
73cbdda60SSimon J. Gerraty#	This file is provided in the hope that it will
83cbdda60SSimon J. Gerraty#	be of use.  There is absolutely NO WARRANTY.
93cbdda60SSimon J. Gerraty#	Permission to copy, redistribute or otherwise
103cbdda60SSimon J. Gerraty#	use this file is hereby granted provided that
113cbdda60SSimon J. Gerraty#	the above copyright notice and this notice are
123cbdda60SSimon J. Gerraty#	left intact.
133cbdda60SSimon J. Gerraty#
143cbdda60SSimon J. Gerraty#	Please send copies of changes and bug-fixes to:
153cbdda60SSimon J. Gerraty#	sjg@crufty.net
163cbdda60SSimon J. Gerraty#
173cbdda60SSimon J. Gerraty
18*c59c3bf3SSimon J. Gerraty# should be set properly in sys.mk
19*c59c3bf3SSimon J. Gerraty_this ?= ${.PARSEFILE:S,bsd.,,}
20*c59c3bf3SSimon J. Gerraty
21*c59c3bf3SSimon J. Gerraty.if !target(__${_this}__)
22*c59c3bf3SSimon J. Gerraty__${_this}__: .NOTMAIN
233cbdda60SSimon J. Gerraty
243cbdda60SSimon J. Gerraty.include <init.mk>
253cbdda60SSimon J. Gerraty
263cbdda60SSimon J. GerratyECHO_TRACE ?= echo
273cbdda60SSimon J. Gerraty
283cbdda60SSimon J. Gerraty.if ${MK_OBJDIRS} == "no"
293cbdda60SSimon J. Gerratyobj:
303cbdda60SSimon J. Gerratyobjlink:
313cbdda60SSimon J. Gerratyobjwarn:
323cbdda60SSimon J. Gerraty.else
333cbdda60SSimon J. Gerraty
343cbdda60SSimon J. Gerraty# this has to match how make behaves
353cbdda60SSimon J. Gerraty.if defined(MAKEOBJDIRPREFIX) || defined(MAKEOBJDIR)
363cbdda60SSimon J. Gerraty.if defined(MAKEOBJDIRPREFIX)
373cbdda60SSimon J. Gerraty__objdir:= ${MAKEOBJDIRPREFIX}${.CURDIR}
383cbdda60SSimon J. Gerraty.else
393cbdda60SSimon J. Gerraty__objdir:= ${MAKEOBJDIR}
403cbdda60SSimon J. Gerraty.endif
413cbdda60SSimon J. Gerraty.else
423cbdda60SSimon J. Gerraty__objdir= ${__objlink}
433cbdda60SSimon J. Gerraty.endif
443cbdda60SSimon J. Gerraty
453cbdda60SSimon J. Gerraty.if defined(OBJMACHINE)
463cbdda60SSimon J. Gerraty__objlink=	obj.${MACHINE}
473cbdda60SSimon J. Gerraty.else
483cbdda60SSimon J. Gerraty__objlink=	obj
493cbdda60SSimon J. Gerraty.endif
503cbdda60SSimon J. Gerraty
513cbdda60SSimon J. Gerraty.if ${MK_AUTO_OBJ} == "yes"
523cbdda60SSimon J. Gerraty.-include "auto.obj.mk"
533cbdda60SSimon J. Gerraty.endif
543cbdda60SSimon J. Gerraty
553cbdda60SSimon J. Gerraty.NOPATH:	${__objdir}
563cbdda60SSimon J. Gerraty.PHONY:		obj
573cbdda60SSimon J. Gerraty
583cbdda60SSimon J. Gerratyobj: _SUBDIRUSE
593cbdda60SSimon J. Gerraty	@if test ! -d ${__objdir}/.; then \
603cbdda60SSimon J. Gerraty		mkdir -p ${__objdir}; \
613cbdda60SSimon J. Gerraty		if test ! -d ${__objdir}; then \
623cbdda60SSimon J. Gerraty			mkdir ${__objdir}; exit 1; \
633cbdda60SSimon J. Gerraty		fi; \
643cbdda60SSimon J. Gerraty		${ECHO_TRACE} "[Creating objdir ${__objdir}...]" >&2; \
653cbdda60SSimon J. Gerraty	fi
663cbdda60SSimon J. Gerraty
673cbdda60SSimon J. Gerraty.if !target(_SUBDIRUSE)
683cbdda60SSimon J. Gerraty# this just allows us to be included by ourselves
693cbdda60SSimon J. Gerraty_SUBDIRUSE:
703cbdda60SSimon J. Gerraty.endif
713cbdda60SSimon J. Gerraty
723cbdda60SSimon J. Gerraty# so we can interact with freebsd makefiles
733cbdda60SSimon J. Gerraty.if !target(objwarn)
743cbdda60SSimon J. Gerratyobjwarn:
753cbdda60SSimon J. Gerraty.if ${.OBJDIR} == ${.CURDIR}
763cbdda60SSimon J. Gerraty	@echo "Warning Object directory is ${.CURDIR}"
773cbdda60SSimon J. Gerraty.elif ${.OBJDIR} != ${__objdir}
783cbdda60SSimon J. Gerraty	@echo "Warning Object directory is ${.OBJDIR} vs. ${__objdir}"
793cbdda60SSimon J. Gerraty.endif
803cbdda60SSimon J. Gerraty.endif
813cbdda60SSimon J. Gerraty
823cbdda60SSimon J. Gerraty.if !target(objlink)
833cbdda60SSimon J. Gerratyobjlink:
843cbdda60SSimon J. Gerraty.if ${__objdir:T} != ${__objlink}
853cbdda60SSimon J. Gerraty	@if test -d ${__objdir}/.; then \
863cbdda60SSimon J. Gerraty		${RM} -f ${.CURDIR}/${__objlink}; \
873cbdda60SSimon J. Gerraty		${LN} -s ${__objdir} ${.CURDIR}/${__objlink}; \
883cbdda60SSimon J. Gerraty		echo "${__objlink} -> ${__objdir}"; \
893cbdda60SSimon J. Gerraty	else \
903cbdda60SSimon J. Gerraty		echo "No ${__objdir} to link to - do a 'make obj'"; \
913cbdda60SSimon J. Gerraty	fi
923cbdda60SSimon J. Gerraty.endif
933cbdda60SSimon J. Gerraty.endif
943cbdda60SSimon J. Gerraty.endif
953cbdda60SSimon J. Gerraty
963cbdda60SSimon J. Gerraty_CURDIR?= ${.CURDIR}
973cbdda60SSimon J. Gerraty_OBJDIR?= ${.OBJDIR}
983cbdda60SSimon J. Gerraty
993cbdda60SSimon J. Gerraty.if !target(print-objdir)
1003cbdda60SSimon J. Gerratyprint-objdir:
1013cbdda60SSimon J. Gerraty	@echo ${_OBJDIR}
1023cbdda60SSimon J. Gerraty.endif
1033cbdda60SSimon J. Gerraty
1043cbdda60SSimon J. Gerraty.if !target(whereobj)
1053cbdda60SSimon J. Gerratywhereobj:
1063cbdda60SSimon J. Gerraty	@echo ${_OBJDIR}
1073cbdda60SSimon J. Gerraty.endif
1083cbdda60SSimon J. Gerraty
1093cbdda60SSimon J. Gerraty.if !target(destroy)
1103cbdda60SSimon J. Gerraty.if ${.CURDIR} != ${.OBJDIR}
1113cbdda60SSimon J. Gerratydestroy:
1123cbdda60SSimon J. Gerraty	(cd ${_CURDIR} && rm -rf ${_OBJDIR})
1133cbdda60SSimon J. Gerraty.else
1143cbdda60SSimon J. Gerratydestroy:  clean
1153cbdda60SSimon J. Gerraty.endif
1163cbdda60SSimon J. Gerraty.endif
1173cbdda60SSimon J. Gerraty
1183cbdda60SSimon J. Gerraty.endif
119