xref: /freebsd/contrib/bmake/mk/srctop.mk (revision c59c3bf34db360695f07735bebc76a768cac5afc)
1*c59c3bf3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause
2*c59c3bf3SSimon J. Gerraty#
3*c59c3bf3SSimon J. Gerraty# $Id: srctop.mk,v 1.5 2024/02/17 17:26:57 sjg Exp $
43cbdda60SSimon J. Gerraty#
53cbdda60SSimon J. Gerraty#	@(#) Copyright (c) 2012, 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
183cbdda60SSimon J. Gerraty.if !defined(SRCTOP)
193cbdda60SSimon J. Gerraty# if using mk(1) SB will be set.
203cbdda60SSimon J. Gerraty.ifdef SB
213cbdda60SSimon J. Gerraty.if ${.CURDIR:S,${SB},,} != ${.CURDIR}
223cbdda60SSimon J. Gerraty# we are actually within SB
233cbdda60SSimon J. Gerraty.ifdef SB_SRC
243cbdda60SSimon J. GerratySRCTOP:= ${SB_SRC}
253cbdda60SSimon J. Gerraty.elif exists(${SB}/src)
263cbdda60SSimon J. GerratySRCTOP:= ${SB}/src
273cbdda60SSimon J. Gerraty.else
283cbdda60SSimon J. GerratySRCTOP:= ${SB}
293cbdda60SSimon J. Gerraty.endif
303cbdda60SSimon J. Gerraty.endif
313cbdda60SSimon J. Gerraty.endif
323cbdda60SSimon J. Gerraty
333cbdda60SSimon J. Gerraty.if !defined(SRCTOP)
343cbdda60SSimon J. Gerraty.for rd in share/mk build/mk mk
353cbdda60SSimon J. Gerraty.if ${_this_mk_dir:M*${rd}} != ""
363cbdda60SSimon J. Gerraty.if ${.CURDIR:S,${_this_mk_dir:${rd:C,[^/]+,H,g:S,/, ,g:ts:}},,} != ${.CURDIR}
373cbdda60SSimon J. GerratySRCTOP:= ${_this_mk_dir:${rd:C,[^/]+,H,g:S,/, ,g:ts:}}
383cbdda60SSimon J. Gerraty.endif
393cbdda60SSimon J. Gerraty.endif
403cbdda60SSimon J. Gerraty.endfor
413cbdda60SSimon J. Gerraty.endif
423cbdda60SSimon J. Gerraty
433cbdda60SSimon J. Gerraty.if !defined(SRCTOP)
443cbdda60SSimon J. Gerraty_SRCTOP_TEST_?= [ -f ../.sandbox-env -o -d share/mk ]
453cbdda60SSimon J. Gerraty# Linux at least has a bug where attempting to check an automounter
463cbdda60SSimon J. Gerraty# directory will hang.  So avoid looking above /a/b
473cbdda60SSimon J. GerratySRCTOP!= cd ${.CURDIR}; while :; do \
483cbdda60SSimon J. Gerraty		here=`pwd`; \
493cbdda60SSimon J. Gerraty		${_SRCTOP_TEST_} && { echo $$here; break; }; \
503cbdda60SSimon J. Gerraty		case $$here in /*/*/*) cd ..;; *) echo ""; break;; esac; \
513cbdda60SSimon J. Gerraty		done
523cbdda60SSimon J. Gerraty.endif
533cbdda60SSimon J. Gerraty.if defined(SRCTOP) && exists(${SRCTOP}/.)
543cbdda60SSimon J. Gerraty.export SRCTOP
553cbdda60SSimon J. Gerraty.endif
563cbdda60SSimon J. Gerraty.endif
573cbdda60SSimon J. Gerraty
583cbdda60SSimon J. Gerraty.if !defined(OBJTOP) && !empty(SRCTOP)
593cbdda60SSimon J. Gerraty.if defined(MAKEOBJDIRPREFIX) && exists(${MAKEOBJDIRPREFIX}${SRCTOP})
603cbdda60SSimon J. GerratyOBJTOP= ${MAKEOBJDIRPREFIX}${SRCTOP}
613cbdda60SSimon J. Gerraty.elif (exists(${SRCTOP}/Makefile) || exists(${SRCTOP}/makefile))
623cbdda60SSimon J. GerratyOBJTOP!= cd ${SRCTOP} && ${PRINTOBJDIR}
633cbdda60SSimon J. Gerraty.endif
643cbdda60SSimon J. Gerraty.if empty(OBJTOP)
653cbdda60SSimon J. GerratyOBJTOP= ${SRCTOP}
663cbdda60SSimon J. Gerraty.endif
673cbdda60SSimon J. Gerraty.export OBJTOP
683cbdda60SSimon J. Gerraty.endif
69