summaryrefslogtreecommitdiff
path: root/devel/bmake/files/mk/srctop.mk
blob: 411dabcef0e3cf669c0e7be95470f3af8bf50de2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# $Id: srctop.mk,v 1.1.1.1 2020/05/24 05:35:53 nia Exp $
#
#	@(#) Copyright (c) 2012, Simon J. Gerraty
#
#	This file is provided in the hope that it will
#	be of use.  There is absolutely NO WARRANTY.
#	Permission to copy, redistribute or otherwise
#	use this file is hereby granted provided that 
#	the above copyright notice and this notice are
#	left intact. 
#      
#	Please send copies of changes and bug-fixes to:
#	sjg@crufty.net
#

.if !defined(SRCTOP)
# if using mk(1) SB will be set.
.ifdef SB
.if ${.CURDIR:S,${SB},,} != ${.CURDIR}
# we are actually within SB
.ifdef SB_SRC
SRCTOP:= ${SB_SRC}
.elif exists(${SB}/src)
SRCTOP:= ${SB}/src
.else
SRCTOP:= ${SB}
.endif
.endif
.endif

.if !defined(SRCTOP)
.for rd in share/mk build/mk mk
.if ${_this_mk_dir:M*${rd}} != ""
.if ${.CURDIR:S,${_this_mk_dir:${rd:C,[^/]+,H,g:S,/, ,g:ts:}},,} != ${.CURDIR}
SRCTOP:= ${_this_mk_dir:${rd:C,[^/]+,H,g:S,/, ,g:ts:}}
.endif
.endif
.endfor
.endif

.if !defined(SRCTOP)
_SRCTOP_TEST_?= [ -f ../.sandbox-env -o -d share/mk ]
# Linux at least has a bug where attempting to check an automounter
# directory will hang.  So avoid looking above /a/b
SRCTOP!= cd ${.CURDIR}; while :; do \
		here=`pwd`; \
		${_SRCTOP_TEST_} && { echo $$here; break; }; \
		case $$here in /*/*/*) cd ..;; *) echo ""; break;; esac; \
		done 
.endif
.if defined(SRCTOP) && exists(${SRCTOP}/.)
.export SRCTOP
.endif
.endif

.if !defined(OBJTOP) && !empty(SRCTOP)
.if defined(MAKEOBJDIRPREFIX) && exists(${MAKEOBJDIRPREFIX}${SRCTOP})
OBJTOP= ${MAKEOBJDIRPREFIX}${SRCTOP}
.elif (exists(${SRCTOP}/Makefile) || exists(${SRCTOP}/makefile))
OBJTOP!= cd ${SRCTOP} && ${PRINTOBJDIR}
.endif
.if empty(OBJTOP)
OBJTOP= ${SRCTOP}
.endif
.export OBJTOP
.endif