Subject: make and read-only src
To: None <tech-toolchain@netbsd.org>
From: Simon J. Gerraty <sjg@quick.com.au>
List: tech-toolchain
Date: 02/02/2000 14:34:56
I'm guessing that tech-toolchain is the appropriate list?
I'm not subscribed so please cc me on any followups.

Our make supports building from read only src trees via the
environment variables $MAKEOBJDIR and $MAKEOBJDIRPREFIX.
These work well (though our bsd.obj.mk does not support using them)
but the resulting path ${MAKEOBJDIRPREFIX}${.CURDIR} can be pretty
cumbersome. 

The patch below initializes the Var system before using $MAKEOBJDIR*
and modifies chdir_verify_path() to do variable expansion on the path
given to it.  This allows one to do:

MAKEOBJDIR="/tmp/\${.CURDIR:S,$HOME/src/,,}" make

or other freaky stuff.  Note that apart from ${.CURDIR}, ${MACHINE}
and ${MACHINE_ARCH} you only have access to environment variables at
this point.  I'd like to commit this if no one objects.

Also, it would be handy if make obj worked when using MAKEOBJDIR*.
FreeBSD's bsd.obj.mk deals sanely with MAKEOBJDIRPREFIX but ignores
MAKEOBJDIR (perhaps reasonable without the feature added below), again
if noone objects too strenuously I propose to add support for these.

--sjg

Index: main.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/make/main.c,v
retrieving revision 1.50
diff -c -b -r1.50 main.c
*** main.c	1999/09/15 10:47:37	1.50
--- main.c	2000/02/02 03:34:00
***************
*** 419,424 ****
--- 419,427 ----
  {
  	struct stat sb;
  
+ 	if (strchr(path, '$') != 0) {
+ 		path = Var_Subst(NULL, path, VAR_GLOBAL, 0);
+ 	}
  	if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
  		if (chdir(path)) {
  			(void)fprintf(stderr, "make warning: %s: %s.\n",
***************
*** 547,552 ****
--- 550,564 ----
  	}
  
  	/*
+ 	 * Just in case MAKEOBJDIR wants us to do something tricky.
+ 	 */
+ 	Var_Init();		/* Initialize the lists of variables for
+ 				 * parsing arguments */
+ 	Var_Set(".CURDIR", curdir, VAR_GLOBAL);
+ 	Var_Set("MACHINE", machine, VAR_GLOBAL);
+ 	Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL);
+ 
+ 	/*
  	 * If the MAKEOBJDIR (or by default, the _PATH_OBJDIR) directory
  	 * exists, change into it and build there.  (If a .${MACHINE} suffix
  	 * exists, use that directory instead).
***************
*** 624,632 ****
  	Dir_Init(curdir != objdir ? curdir : NULL);
  	Parse_Init();		/* Need to initialize the paths of #include
  				 * directories */
- 	Var_Init();		/* As well as the lists of variables for
- 				 * parsing arguments */
- 	Var_Set(".CURDIR", curdir, VAR_GLOBAL);
  	Var_Set(".OBJDIR", objdir, VAR_GLOBAL);
  
  	/*
--- 636,641 ----
***************
*** 639,646 ****
  	Var_Set(".MAKE", argv[0], VAR_GLOBAL);
  	Var_Set(MAKEFLAGS, "", VAR_GLOBAL);
  	Var_Set("MFLAGS", "", VAR_GLOBAL);
- 	Var_Set("MACHINE", machine, VAR_GLOBAL);
- 	Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL);
  
  	/*
  	 * First snag any flags out of the MAKE environment variable.
--- 648,653 ----