Subject: Re: Problem in new toolchain builds (need comments)
To: James Chacon <jchacon@genuity.net>
From: James Chacon <jchacon@genuity.net>
List: tech-toolchain
Date: 10/24/2001 01:39:20
>>.ifndef SRCTOP
>>SRCTOP!=	[shellcode here]
>>MAKEFLAGS+=	SRCTOP=${SRCTOP:Q}
>>.endif
>>
>>As an aside, you'd automagically also get the location of the top of the
>>source tree, if you add a `pwd` resolver into the end of the script.  It
>>could even be used to set BSDSRCDIR implicitly, come to think of it....
>>
>>Feel free to try implementing this and let me know what you come up with.  A
>>check that looks for a file named "build.sh" and a directory named "tools"
>>in the same dir should give you a usable result.
>

Ok, got it. It's about 20 lines of changes plus a new file in the top level.

I moved the USE_NEW_TOOLCHAIN/USETOOLS checks to there in my version but
I'm not wedded to this structure so much as the idea works. AS Todd also
pointed out, once you find a valid _SRC_TOP_ you can use it to infer 
BSDSRCDIR as well.

Thoughts? Comments? 

James

Index: share/mk/bsd.own.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.own.mk,v
retrieving revision 1.193
diff -u -r1.193 bsd.own.mk
--- share/mk/bsd.own.mk 2001/10/23 22:55:30     1.193
+++ share/mk/bsd.own.mk 2001/10/24 05:34:26
@@ -9,20 +9,35 @@
 .include "${MAKECONF}"
 .endif
 
-# Temporary; this will become default when all platforms have migrated.
-.if defined(USE_NEW_TOOLCHAIN) && ${USE_NEW_TOOLCHAIN} == "no"
-.undef USE_NEW_TOOLCHAIN       # unset
-.else
-.if ${MACHINE_ARCH} == "i386" || \
-    ${MACHINE_ARCH} == "sparc64"
-USE_NEW_TOOLCHAIN=yes  # set
+.if !defined(_SRC_TOP_)
+# Find Makefile.build
+_SRC_TOP_!=    MF="${.CURDIR}"; \
+               while `/usr/bin/true`; \
+               do \
+                       echo $${MF} >&2;  \
+                       if [ -f "$${MF}/Makefile.build" ]; then \
+                               echo "$${MF}/"; \
+                               break; \
+                       fi; \
+                       dir1=`cd $${MF}; pwd`; \
+                       dir2=`cd $${MF}/..; pwd`; \
+                       if [ "$$dir1" = "$$dir2" ]; then \
+                               echo ""; \
+                               break; \
+                       else \
+                               MF="$${MF}/.."; \
+                       fi; \
+               done
+MAKE+= _SRC_TOP_=${_SRC_TOP_:Q}
 .endif
+
+.if ${_SRC_TOP_} != ""
+.include "${_SRC_TOP_}/Makefile.build"
 .endif
 
-.if defined(BSD_PKG_MK) || !defined(USE_NEW_TOOLCHAIN)
-USETOOLS:=     no
+.ifndef (USETOOLS)
+USETOOLS:=no
 .endif
-USETOOLS?=     yes
 
 .if ${MACHINE_ARCH} == "mips" || ${MACHINE_ARCH} == "sh3"
 .BEGIN:


And in /usr/src/Makefile.build:

#       $NetBSD$

# Temporary; this will become default when all platforms have migrated.
.if defined(USE_NEW_TOOLCHAIN) && ${USE_NEW_TOOLCHAIN} == "no"
.undef USE_NEW_TOOLCHAIN        # unset
.else
.if ${MACHINE_ARCH} == "i386" || \
    ${MACHINE_ARCH} == "sparc64"
USE_NEW_TOOLCHAIN=yes   # set
.endif
.endif

.if !defined(USE_NEW_TOOLCHAIN)
USETOOLS:=      no
.endif
USETOOLS?=      yes

MAKE+=  USETOOLS=${USETOOLS:Q}

.if defined(USE_NEW_TOOLCHAIN)
MAKE+=  USE_NEW_TOOLCHAIN=${USE_NEW_TOOLCHAIN:Q}
.endif