1246149Ssjg# $Id: srctop.mk,v 1.3 2012/11/11 23:20:18 sjg Exp $ 2246149Ssjg# 3246149Ssjg# @(#) Copyright (c) 2012, Simon J. Gerraty 4246149Ssjg# 5246149Ssjg# This file is provided in the hope that it will 6246149Ssjg# be of use. There is absolutely NO WARRANTY. 7246149Ssjg# Permission to copy, redistribute or otherwise 8246149Ssjg# use this file is hereby granted provided that 9246149Ssjg# the above copyright notice and this notice are 10246149Ssjg# left intact. 11246149Ssjg# 12246149Ssjg# Please send copies of changes and bug-fixes to: 13246149Ssjg# sjg@crufty.net 14246149Ssjg# 15246149Ssjg 16246149Ssjg.if !defined(SRCTOP) 17246149Ssjg# if using mk(1) SB will be set. 18246149Ssjg.ifdef SB 19246149Ssjg.if ${.CURDIR:S,${SB},,} != ${.CURDIR} 20246149Ssjg# we are actually within SB 21246149Ssjg.ifdef SB_SRC 22246149SsjgSRCTOP:= ${SB_SRC} 23246149Ssjg.elif exists(${SB}/src) 24246149SsjgSRCTOP:= ${SB}/src 25246149Ssjg.else 26246149SsjgSRCTOP:= ${SB} 27246149Ssjg.endif 28246149Ssjg.endif 29246149Ssjg.endif 30246149Ssjg 31246149Ssjg.if !defined(SRCTOP) 32246149Ssjg.for rd in share/mk build/mk mk 33246149Ssjg.if ${_this_mk_dir:M*${rd}} != "" 34246149Ssjg.if ${.CURDIR:S,${_this_mk_dir:${rd:C,[^/]+,H,g:S,/, ,g:ts:}},,} != ${.CURDIR} 35246149SsjgSRCTOP:= ${_this_mk_dir:${rd:C,[^/]+,H,g:S,/, ,g:ts:}} 36246149Ssjg.endif 37246149Ssjg.endif 38246149Ssjg.endfor 39246149Ssjg.endif 40246149Ssjg 41246149Ssjg.if !defined(SRCTOP) 42246149Ssjg_SRCTOP_TEST_?= [ -f ../.sandbox-env -o -d share/mk ] 43246149Ssjg# Linux at least has a bug where attempting to check an automounter 44246149Ssjg# directory will hang. So avoid looking above /a/b 45246149SsjgSRCTOP!= cd ${.CURDIR}; while :; do \ 46246149Ssjg here=`pwd`; \ 47246149Ssjg ${_SRCTOP_TEST_} && { echo $$here; break; }; \ 48246149Ssjg case $$here in /*/*/*) cd ..;; *) echo ""; break;; esac; \ 49246149Ssjg done 50246149Ssjg.endif 51246149Ssjg.if defined(SRCTOP) && exists(${SRCTOP}/.) 52246149Ssjg.export SRCTOP 53246149Ssjg.endif 54246149Ssjg.endif 55246149Ssjg 56246149Ssjg.if !defined(OBJTOP) && !empty(SRCTOP) 57246149Ssjg.if defined(MAKEOBJDIRPREFIX) && exists(${MAKEOBJDIRPREFIX}${SRCTOP}) 58246149SsjgOBJTOP= ${MAKEOBJDIRPREFIX}${SRCTOP} 59246149Ssjg.elif (exists(${SRCTOP}/Makefile) || exists(${SRCTOP}/makefile)) 60246149SsjgOBJTOP!= cd ${SRCTOP} && ${PRINTOBJDIR} 61246149Ssjg.endif 62246149Ssjg.if empty(OBJTOP) 63246149SsjgOBJTOP= ${SRCTOP} 64246149Ssjg.endif 65246149Ssjg.export OBJTOP 66246149Ssjg.endif 67