1 # $Id: srctop.mk,v 1.3 2012/11/11 23:20:18 sjg Exp $
3 # @(#) Copyright (c) 2012, Simon J. Gerraty
5 # This file is provided in the hope that it will
6 # be of use. There is absolutely NO WARRANTY.
7 # Permission to copy, redistribute or otherwise
8 # use this file is hereby granted provided that
9 # the above copyright notice and this notice are
12 # Please send copies of changes and bug-fixes to:
17 # if using mk(1) SB will be set.
19 .if ${.CURDIR:S,${SB},,} != ${.CURDIR}
20 # we are actually within SB
23 .elif exists(${SB}/src)
32 .for rd in share/mk build/mk mk
33 .if ${_this_mk_dir:M*${rd}} != ""
34 .if ${.CURDIR:S,${_this_mk_dir:${rd:C,[^/]+,H,g:S,/, ,g:ts:}},,} != ${.CURDIR}
35 SRCTOP:= ${_this_mk_dir:${rd:C,[^/]+,H,g:S,/, ,g:ts:}}
42 _SRCTOP_TEST_?= [ -f ../.sandbox-env -o -d share/mk ]
43 # Linux at least has a bug where attempting to check an automounter
44 # directory will hang. So avoid looking above /a/b
45 SRCTOP!= cd ${.CURDIR}; while :; do \
47 ${_SRCTOP_TEST_} && { echo $$here; break; }; \
48 case $$here in /*/*/*) cd ..;; *) echo ""; break;; esac; \
51 .if defined(SRCTOP) && exists(${SRCTOP}/.)
56 .if !defined(OBJTOP) && !empty(SRCTOP)
57 .if defined(MAKEOBJDIRPREFIX) && exists(${MAKEOBJDIRPREFIX}${SRCTOP})
58 OBJTOP= ${MAKEOBJDIRPREFIX}${SRCTOP}
59 .elif (exists(${SRCTOP}/Makefile) || exists(${SRCTOP}/makefile))
60 OBJTOP!= cd ${SRCTOP} && ${PRINTOBJDIR}