tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: make: exporting MAKEOBJDIR



On Thu, 3 Jun 2010 07:55:33 +0000, David Holland writes:
> > # the $$'s delay expansion
> > MAKEOBJDIR= $${.CURDIR:S,${SRCTOP},${OBJPREFIX}$${MACHINE},}
> > .export MAKEOBJDIR=${MAKEOBJDIR}
> > # now resolve it for ourselves
> > MAKEOBJDIR := ${MAKEOBJDIR}
>
>This is a misuse of $$. Even if this works right now, it arguably
>shouldn't, and certainly it should not be encouraged.

I disagree, but that's beside the point for .export var=val
Consider a different example:

UT_A = a
UT_B = b
.export UT_A=A UT_B UT_C=C

all:
        @echo 'UT_A=${UT_A} UT_B=${UT_B} UT_C=${UT_C}'
        @env | grep UT_

produces:

UT_A=a UT_B=b UT_C=C
UT_A=A
UT_B=b
UT_C=C

the single quote for the echo is to show that the variables are being
expanded by make not the shell.

The point is that the value in .export variable=value has no bearing on
the value set (if any) in make.  UT_C was never set in make, so the only
value is that put into the environment.

>Instead, what about .export FOO=${BAR} and .export FOO:=${BAR}? That

I'm not sure how that would help?
Apart from $$ make lack's the shell's ability to do things like

MAKEOBJDIR='${.CURDIR:S,${SRCTOP},${OBJPREFIX}${MACHINE},}'
or
MAKEOBJDIR="\${.CURDIR:S,${SRCTOP},${OBJPREFIX}\${MACHINE},}"

Anyway, the alternate (original) implementation I had for this idea 
is much simpler and perhaps might be preferable.
It allows for

var=what ever
# do not track the fact that we have exported var
.export-env var
# so when we change its value, the environment will not be updated
var=something else

The net effect is the same - we can export to the environment something
different to what we use internally.  The $$ trick is orthogonal.
Actually I originally used -raw for this, but -env is perhaps more
analagous to how .unexport-env differs from .unexport

Either syntax works for me.

Index: var.c
===================================================================
RCS file: /cvs/juniper/src/buildtools/bmake/var.c,v
retrieving revision 1.34
diff -u -p -r1.34 var.c
--- var.c       21 Apr 2010 04:54:39 -0000      1.34
+++ var.c       1 Jun 2010 16:37:55 -0000
@@ -682,6 +683,7 @@ Var_Export(char *str, int isExport)
     char *val;
     char **av;
     char *as;
+    int flag;
     int ac;
     int i;
 
@@ -690,6 +692,12 @@ Var_Export(char *str, int isExport)
        return;
     }
 
+    if (strncmp(str, "-env", 4) == 0) {
+       flag = 0;
+       str += 4;
+    } else {
+       flag = VAR_EXPORT_PARENT;
+    }
     val = Var_Subst(NULL, str, VAR_GLOBAL, 0);
     av = brk_string(val, &ac, FALSE, &as);
     for (i = 0; i < ac; i++) {
@@ -709,10 +717,10 @@ Var_Export(char *str, int isExport)
                continue;
            }
        }
-       if (Var_Export1(name, VAR_EXPORT_PARENT)) {
+       if (Var_Export1(name, flag)) {
            if (VAR_EXPORTED_ALL != var_exportedVars)
                var_exportedVars = VAR_EXPORTED_YES;
-           if (isExport) {
+           if (isExport && flag) {
                Var_Append(MAKE_EXPORTED, name, VAR_GLOBAL);
            }
        }


Home | Main Index | Thread Index | Old Index