Subject: Build identifier variable for obj dirs
To: None <tech-toolchain@netbsd.org>
From: Jason R Thorpe <thorpej@wasabisystems.com>
List: tech-toolchain
Date: 03/05/2002 10:25:51
--huq684BweRXVnRxX
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi folks...

The following patch adds a BUILDID variable to the build system
which can be used to, you guessed it, identify specific builds.

Mostly, it affects the objdir name, such that you end up with
objdir names like "obj.${MACHINE}.${BUILDID}".

You can also test for this variable in mk.conf, and set additional
build parameters, such as compiler flags, etc.

Example uses:

# Build an all-dynamic userland for my Soekris net4501, with special
# compiler options.  Don't bother building any LINT or PROFILING stuff
# for that system, either.
.if ${BUILDID} == "net4501"
LDSTATIC=
COPTS+= -Os -mcpu=i486
MKLINT=no
MKPROFILE=no
.endif

# If I'm building for my AlphaServer, add -mcpu=ev56
.if ${BUILDID} == "as1200"
COPTS+= -mcpu=mev6
.endif

Comments?  I personally think it's useful, and would like to see it
in the tree :-)

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>

--huq684BweRXVnRxX
Content-Type: text/plain; charset=us-ascii
Content-Description: buildid.patch
Content-Disposition: attachment; filename=foo

Index: BUILDING
===================================================================
RCS file: /cvsroot/basesrc/BUILDING,v
retrieving revision 1.6
diff -c -r1.6 BUILDING
*** BUILDING	2001/11/25 18:40:34	1.6
--- BUILDING	2002/03/05 18:11:26
***************
*** 93,98 ****
--- 93,103 ----
       wise specified, these variables may be set in either the process environ-
       ment or the make(1) configuration file specified by MAKECONF.
  
+      BUILDID     Identifier for the build.  The identifier will be appended to
+                  object directory names, and can be consulted in the make(1)
+                  configuration file in order to set additional build parame-
+                  ters, such as compiler flags.
+ 
       DESTDIR     Directory to contain the built NetBSD system.  If set, spe-
                   cial options are passed to the compilation tools to prevent
                   their default use of the host system's /usr/include,
***************
*** 391,396 ****
--- 396,407 ----
       build.sh:
  
       -a arch   Set the value of MACHINE_ARCH to arch.
+ 
+      -B buildid
+                Set the value of BUILDID to buildid.  This will also append the
+                build idenfitier to the name of the ``make'' wrapper script so
+                that the resulting name is of the form ``nbmake-MACHINE-
+                BUILDID''.
  
       -b        Bootstrap ``make'' and create a nbmake-MACHINE script (see be-
                 low).
Index: BUILDING.mdoc
===================================================================
RCS file: /cvsroot/basesrc/BUILDING.mdoc,v
retrieving revision 1.12
diff -c -r1.12 BUILDING.mdoc
*** BUILDING.mdoc	2001/11/25 18:40:34	1.12
--- BUILDING.mdoc	2002/03/05 18:11:27
***************
*** 211,216 ****
--- 211,223 ----
  .
  .Bl -tag -width "MKCATPAGES"
  .
+ .It Sy BUILDID
+ Identifier for the build.  The identifier will be appended to
+ object directory names, and can be consulted in the
+ .Xr make 1
+ configuration file in order to set additional build parameters,
+ such as compiler flags.
+ .
  .It Sy DESTDIR
  Directory to contain the built
  .Nx
***************
*** 706,711 ****
--- 713,728 ----
  .Sy MACHINE_ARCH
  to
  .Em arch .
+ .
+ .It Sy -B Em buildid
+ Set the value of
+ .Sy BUILDID
+ to
+ .Em buildid .
+ This will also append the build idenfitier to the name of the
+ .Dq make
+ wrapper script so that the resulting name is of the form
+ .Dq Sy nbmake-MACHINE-BUILDID .
  .
  .It Sy -b
  Bootstrap
Index: build.sh
===================================================================
RCS file: /cvsroot/basesrc/build.sh,v
retrieving revision 1.45
diff -c -r1.45 build.sh
*** build.sh	2002/02/27 21:19:08	1.45
--- build.sh	2002/03/05 18:11:51
***************
*** 90,99 ****
  
  usage () {
  	echo "Usage:"
! 	echo "$0 [-bdorUu] [-a arch] [-j njob] [-m mach] [-w wrapper]"
! 	echo "   [-D dest] [-O obj] [-R release] [-T tools]"
  	echo ""
  	echo "    -a: set MACHINE_ARCH to arch (otherwise deduced from MACHINE)"
  	echo "    -b: build nbmake and nbmake wrapper script, if needed"
  	echo "    -D: set DESTDIR to dest"
  	echo "    -d: build a full distribution into DESTDIR (including etc files)"
--- 90,100 ----
  
  usage () {
  	echo "Usage:"
! 	echo "$0 [-bdorUu] [-a arch] [-B buildid] [-j njob] [-m mach] "
! 	echo "   [-w wrapper] [-D dest] [-O obj] [-R release] [-T tools]"
  	echo ""
  	echo "    -a: set MACHINE_ARCH to arch (otherwise deduced from MACHINE)"
+ 	echo "    -B: set BUILDID to buildid"
  	echo "    -b: build nbmake and nbmake wrapper script, if needed"
  	echo "    -D: set DESTDIR to dest"
  	echo "    -d: build a full distribution into DESTDIR (including etc files)"
***************
*** 126,132 ****
  makeenv=
  makewrapper=
  opt_a=no
! opts='a:bdhj:m:nortuw:D:O:R:T:U'
  runcmd=
  
  if type getopts >/dev/null 2>&1; then
--- 127,133 ----
  makeenv=
  makewrapper=
  opt_a=no
! opts='a:B:bdhj:m:nortuw:D:O:R:T:U'
  runcmd=
  
  if type getopts >/dev/null 2>&1; then
***************
*** 150,155 ****
--- 151,159 ----
  	-a)	eval $optargcmd
  		MACHINE_ARCH=$OPTARG; opt_a=yes;;
  
+ 	-B)	eval $optargcmd
+ 		BUILDID=$OPTARG;;
+ 
  	-b)	do_buildsystem=false;;
  
  	-d)	buildtarget=distribution;;
***************
*** 211,216 ****
--- 215,223 ----
  
  # Set up default make(1) environment.
  makeenv="$makeenv TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
+ if [ ! -z "$BUILDID" ]; then
+ 	makeenv="$makeenv BUILDID"
+ fi
  MAKEFLAGS="-m $cwd/share/mk $MAKEFLAGS MKOBJDIRS=${MKOBJDIRS-yes}"
  export MAKEFLAGS MACHINE MACHINE_ARCH
  
***************
*** 334,339 ****
--- 341,349 ----
  # Build a nbmake wrapper script, usable by hand as well as by build.sh.
  if [ -z "$makewrapper" ]; then
  	makewrapper=$TOOLDIR/bin/nbmake-$MACHINE
+ 	if [ ! -z "$BUILDID" ]; then
+ 		makewrapper=$makewrapper-$BUILDID
+ 	fi
  fi
  
  $runcmd rm -f $makewrapper
Index: share/mk/bsd.README
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.README,v
retrieving revision 1.92
diff -c -r1.92 bsd.README
*** share/mk/bsd.README	2002/01/27 23:33:51	1.92
--- share/mk/bsd.README	2002/03/05 18:12:01
***************
*** 699,704 ****
--- 699,708 ----
  		otherwise, create it in the corresponding subdirectory
  		of ${BSDOBJDIR}
  
+ BUILDID		If set, the contents of this variable are appended
+ 		to the object directory name.  If OBJMACHINE is also
+ 		set, ".${BUILDID}" is added after ".${MACHINE}".
+ 
  =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  
  The include file <bsd.kernobj.mk> defines variables related to the
Index: share/mk/bsd.obj.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.obj.mk,v
retrieving revision 1.39
diff -c -r1.39 bsd.obj.mk
*** share/mk/bsd.obj.mk	2001/11/29 11:57:21	1.39
--- share/mk/bsd.obj.mk	2002/03/05 18:12:01
***************
*** 41,46 ****
--- 41,52 ----
  __usrobjdir=	${BSDOBJDIR}${USR_OBJMACHINE:D.${MACHINE}}
  __usrobjdirpf=	${USR_OBJMACHINE:D:U${OBJMACHINE:D.${MACHINE}}}
  
+ .if defined(BUILDID)
+ __objdir:=	${__objdir}.${BUILDID}
+ __usrobjdirpf:=	${__usrobjdirpf}.${BUILDID}
+ __need_objdir_target=yes
+ .endif
+ 
  .if defined(OBJHOSTMACHINE) && (${MKHOSTOBJ:Uno} != "no")
  # In case .CURDIR has been twiddled by a .mk file and is now relative,
  # make it absolute again.
***************
*** 50,55 ****
--- 56,65 ----
  
  __objdir:=	${__objdir}.${HOST_OSTYPE}
  __usrobjdirpf:=	${__usrobjdirpf}.${HOST_OSTYPE}
+ __need_objdir_target=yes
+ .endif
+ 
+ .if defined(__need_objdir_target)
  .OBJDIR:	${__objdir}
  .endif
  

--huq684BweRXVnRxX--