make patch: let MAKEOBJDIR be more powerful

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

make patch: let MAKEOBJDIR be more powerful

Marc Espie-2
After some musings, I realized I just had to reorder a few things to
make MAKEOBJDIR way more powerful (and possibly useful)

The idea here is to init vars early, which is easy, and to set up
.CURDIR, MACHINE, MACHINE_ARCH, MACHINE_CPU, so that
MAKEOBJDIR can actually become a full-blown make expression.

e.g., with this something like

MAKEOBJDIR='${.CURDIR}:S/src/obj/}'

will work.

any takers ?


Index: init.c
===================================================================
RCS file: /cvs/src/usr.bin/make/init.c,v
retrieving revision 1.7
diff -u -p -r1.7 init.c
--- init.c 2 Oct 2012 10:29:30 -0000 1.7
+++ init.c 29 Aug 2019 11:01:19 -0000
@@ -48,8 +48,6 @@ Init(void)
  * can be processed correctly */
  Parse_Init(); /* Need to initialize the paths of #include
  * directories */
- Var_Init(); /* As well as the lists of variables for
- * parsing arguments */
  Arch_Init();
  Suff_Init();
 }
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/make/main.c,v
retrieving revision 1.123
diff -u -p -r1.123 main.c
--- main.c 22 Apr 2019 18:32:09 -0000 1.123
+++ main.c 29 Aug 2019 11:01:19 -0000
@@ -558,12 +558,16 @@ setup_CURDIR_OBJDIR(struct dirs *d)
  * and modify the paths for the Makefiles appropriately.  The
  * current directory is also placed as a variable for make scripts.
  */
- if ((path = getenv("MAKEOBJDIR")) == NULL) {
+ Var_Set(".CURDIR", d->current);
+ if ((path = getenv("MAKEOBJDIR")) == NULL)
  path = _PATH_OBJDIR;
- }
+ /* if there's a $ in there, allow substitution */
+ else if (strchr(path, '$'))
+ path = Var_Subst(path, NULL, false);
  d->object = chdir_verify_path(path, d);
  if (d->object == NULL)
  d->object = d->current;
+ Var_Set(".OBJDIR", d->object);
 }
 
 /*
@@ -656,6 +660,11 @@ main(int argc, char **argv)
  bool read_depend = true;/* false if we don't want to read .depend */
 
  MainParseChdir(argc, argv);
+ Var_Init(); /* do this early for OBJDIR */
+ Var_Set("MACHINE", machine);
+ Var_Set("MACHINE_ARCH", machine_arch);
+ Var_Set("MACHINE_CPU", machine_cpu);
+
  setup_CURDIR_OBJDIR(&d);
 
  esetenv("PWD", d.object);
@@ -687,8 +696,6 @@ main(int argc, char **argv)
 
  if (d.object != d.current)
  Dir_AddDir(defaultPath, d.current);
- Var_Set(".CURDIR", d.current);
- Var_Set(".OBJDIR", d.object);
  Parse_setcurdir(d.current);
  Targ_setdirs(d.current, d.object);
 
@@ -702,9 +709,6 @@ main(int argc, char **argv)
  Var_Set(".MAKE", argv[0]);
  Var_Set(MAKEFLAGS, "");
  Var_Set("MFLAGS", "");
- Var_Set("MACHINE", machine);
- Var_Set("MACHINE_ARCH", machine_arch);
- Var_Set("MACHINE_CPU", machine_cpu);
 
  /*
  * First snag any flags out of the MAKEFLAGS environment variable.

Reply | Threaded
Open this post in threaded view
|

Re: make patch: let MAKEOBJDIR be more powerful

Alexander Bluhm
On Thu, Aug 29, 2019 at 01:04:07PM +0200, Marc Espie wrote:

> After some musings, I realized I just had to reorder a few things to
> make MAKEOBJDIR way more powerful (and possibly useful)
>
> The idea here is to init vars early, which is easy, and to set up
> .CURDIR, MACHINE, MACHINE_ARCH, MACHINE_CPU, so that
> MAKEOBJDIR can actually become a full-blown make expression.
>
> e.g., with this something like
>
> MAKEOBJDIR='${.CURDIR}:S/src/obj/}'
>
> will work.
>
> any takers ?

I did a make regress without problems.

Although I have no use for the feature, why not.

OK bluhm@

> - if ((path = getenv("MAKEOBJDIR")) == NULL) {
> + Var_Set(".CURDIR", d->current);
> + if ((path = getenv("MAKEOBJDIR")) == NULL)
>   path = _PATH_OBJDIR;
> - }
> + /* if there's a $ in there, allow substitution */
> + else if (strchr(path, '$'))

I would keep the { } around the if block.  Technically not neccessary
as one of the two lines is a comment, but it looks odd anyway.