Sun Jun 6 01:13:12 2010 UTC ()
Add .export-env which tells make to export a variable to the environment
but not to track it - as is done for .export
This allows the variable to be updated without affecting what was put
into the environment.
Older versions of make will simply treat this as .export


(sjg)
diff -r1.172 -r1.173 src/usr.bin/make/make.1
diff -r1.158 -r1.159 src/usr.bin/make/var.c

cvs diff -r1.172 -r1.173 src/usr.bin/make/make.1 (expand / switch to unified diff)

--- src/usr.bin/make/make.1 2010/05/13 18:10:16 1.172
+++ src/usr.bin/make/make.1 2010/06/06 01:13:12 1.173
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: make.1,v 1.172 2010/05/13 18:10:16 joerg Exp $ 1.\" $NetBSD: make.1,v 1.173 2010/06/06 01:13:12 sjg Exp $
2.\" 2.\"
3.\" Copyright (c) 1990, 1993 3.\" Copyright (c) 1990, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
5.\" 5.\"
6.\" Redistribution and use in source and binary forms, with or without 6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions 7.\" modification, are permitted provided that the following conditions
8.\" are met: 8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright 9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer. 10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the 12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution. 13.\" documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors 14.\" 3. Neither the name of the University nor the names of its contributors
@@ -781,28 +781,30 @@ is set in the environment or on the comm @@ -781,28 +781,30 @@ is set in the environment or on the comm
781is set in the environment or on the command line.) 781is set in the environment or on the command line.)
782.It 782.It
783.Ev ${.CURDIR} Ns Pa /obj. Ns Ev ${MACHINE} 783.Ev ${.CURDIR} Ns Pa /obj. Ns Ev ${MACHINE}
784.It 784.It
785.Ev ${.CURDIR} Ns Pa /obj 785.Ev ${.CURDIR} Ns Pa /obj
786.It 786.It
787.Pa /usr/obj/ Ns Ev ${.CURDIR} 787.Pa /usr/obj/ Ns Ev ${.CURDIR}
788.It 788.It
789.Ev ${.CURDIR} 789.Ev ${.CURDIR}
790.El 790.El
791.Pp 791.Pp
792Variable expansion is performed on the value before it's used, 792Variable expansion is performed on the value before it's used,
793so expressions such as 793so expressions such as
794.Dl ${.CURDIR:C,^/usr/src,/var/obj,} 794.Dl ${.CURDIR:S,^/usr/src,/var/obj,}
795may be used. 795may be used.
 796This is especially useful with
 797.Ql Ev MAKEOBJDIR .
796.Pp 798.Pp
797.Ql Va .OBJDIR 799.Ql Va .OBJDIR
798may be modified in the makefile as a global variable. 800may be modified in the makefile as a global variable.
799In all cases, 801In all cases,
800.Nm 802.Nm
801will 803will
802.Xr chdir 2 804.Xr chdir 2
803to 805to
804.Ql Va .OBJDIR 806.Ql Va .OBJDIR
805and set 807and set
806.Ql Ev PWD 808.Ql Ev PWD
807to that directory before executing any targets. 809to that directory before executing any targets.
808. 810.
@@ -1310,26 +1312,35 @@ then @@ -1310,26 +1312,35 @@ then
1310will exit. 1312will exit.
1311.It Ic .export Ar variable ... 1313.It Ic .export Ar variable ...
1312Export the specified global variable. 1314Export the specified global variable.
1313If no variable list is provided, all globals are exported 1315If no variable list is provided, all globals are exported
1314except for internal variables (those that start with 1316except for internal variables (those that start with
1315.Ql \&. ) . 1317.Ql \&. ) .
1316This is not affected by the 1318This is not affected by the
1317.Fl X 1319.Fl X
1318flag, so should be used with caution. 1320flag, so should be used with caution.
1319.Pp 1321.Pp
1320Appending a variable name to 1322Appending a variable name to
1321.Va .MAKE.EXPORTED 1323.Va .MAKE.EXPORTED
1322is equivalent to exporting a variable. 1324is equivalent to exporting a variable.
 1325.It Ic .export-env Ar variable ...
 1326The same as
 1327.Ql .export ,
 1328except that the variable is not appended to
 1329.Va .MAKE.EXPORTED .
 1330This allows exporting a value to the environment which is different from that
 1331used by
 1332.Nm
 1333internally.
1323.It Ic .info Ar message 1334.It Ic .info Ar message
1324The message is printed along with the name of the makefile and line number. 1335The message is printed along with the name of the makefile and line number.
1325.It Ic .undef Ar variable 1336.It Ic .undef Ar variable
1326Un-define the specified global variable. 1337Un-define the specified global variable.
1327Only global variables may be un-defined. 1338Only global variables may be un-defined.
1328.It Ic .unexport Ar variable ... 1339.It Ic .unexport Ar variable ...
1329The opposite of 1340The opposite of
1330.Ql .export . 1341.Ql .export .
1331The specified global 1342The specified global
1332.Va variable 1343.Va variable
1333will be removed from 1344will be removed from
1334.Va .MAKE.EXPORTED . 1345.Va .MAKE.EXPORTED .
1335If no variable list is provided, all globals are unexported, 1346If no variable list is provided, all globals are unexported,

cvs diff -r1.158 -r1.159 src/usr.bin/make/var.c (expand / switch to unified diff)

--- src/usr.bin/make/var.c 2010/04/21 04:25:27 1.158
+++ src/usr.bin/make/var.c 2010/06/06 01:13:12 1.159
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.158 2010/04/21 04:25:27 sjg Exp $ */ 1/* $NetBSD: var.c,v 1.159 2010/06/06 01:13:12 sjg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: var.c,v 1.158 2010/04/21 04:25:27 sjg Exp $"; 72static char rcsid[] = "$NetBSD: var.c,v 1.159 2010/06/06 01:13:12 sjg Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; 77static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
78#else 78#else
79__RCSID("$NetBSD: var.c,v 1.158 2010/04/21 04:25:27 sjg Exp $"); 79__RCSID("$NetBSD: var.c,v 1.159 2010/06/06 01:13:12 sjg Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * var.c -- 85 * var.c --
86 * Variable-handling functions 86 * Variable-handling functions
87 * 87 *
88 * Interface: 88 * Interface:
89 * Var_Set Set the value of a variable in the given 89 * Var_Set Set the value of a variable in the given
90 * context. The variable is created if it doesn't 90 * context. The variable is created if it doesn't
91 * yet exist. The value and variable name need not 91 * yet exist. The value and variable name need not
92 * be preserved. 92 * be preserved.
@@ -672,57 +672,64 @@ Var_ExportVars(void) @@ -672,57 +672,64 @@ Var_ExportVars(void)
672 672
673/* 673/*
674 * This is called when .export is seen or 674 * This is called when .export is seen or
675 * .MAKE.EXPORTED is modified. 675 * .MAKE.EXPORTED is modified.
676 * It is also called when any exported var is modified. 676 * It is also called when any exported var is modified.
677 */ 677 */
678void 678void
679Var_Export(char *str, int isExport) 679Var_Export(char *str, int isExport)
680{ 680{
681 char *name; 681 char *name;
682 char *val; 682 char *val;
683 char **av; 683 char **av;
684 char *as; 684 char *as;
 685 int track;
685 int ac; 686 int ac;
686 int i; 687 int i;
687 688
688 if (isExport && (!str || !str[0])) { 689 if (isExport && (!str || !str[0])) {
689 var_exportedVars = VAR_EXPORTED_ALL; /* use with caution! */ 690 var_exportedVars = VAR_EXPORTED_ALL; /* use with caution! */
690 return; 691 return;
691 } 692 }
692 693
 694 if (strncmp(str, "-env", 4) == 0) {
 695 track = 0;
 696 str += 4;
 697 } else {
 698 track = VAR_EXPORT_PARENT;
 699 }
693 val = Var_Subst(NULL, str, VAR_GLOBAL, 0); 700 val = Var_Subst(NULL, str, VAR_GLOBAL, 0);
694 av = brk_string(val, &ac, FALSE, &as); 701 av = brk_string(val, &ac, FALSE, &as);
695 for (i = 0; i < ac; i++) { 702 for (i = 0; i < ac; i++) {
696 name = av[i]; 703 name = av[i];
697 if (!name[1]) { 704 if (!name[1]) {
698 /* 705 /*
699 * A single char. 706 * A single char.
700 * If it is one of the vars that should only appear in 707 * If it is one of the vars that should only appear in
701 * local context, skip it, else we can get Var_Subst 708 * local context, skip it, else we can get Var_Subst
702 * into a loop. 709 * into a loop.
703 */ 710 */
704 switch (name[0]) { 711 switch (name[0]) {
705 case '@': 712 case '@':
706 case '%': 713 case '%':
707 case '*': 714 case '*':
708 case '!': 715 case '!':
709 continue; 716 continue;
710 } 717 }
711 } 718 }
712 if (Var_Export1(name, VAR_EXPORT_PARENT)) { 719 if (Var_Export1(name, track)) {
713 if (VAR_EXPORTED_ALL != var_exportedVars) 720 if (VAR_EXPORTED_ALL != var_exportedVars)
714 var_exportedVars = VAR_EXPORTED_YES; 721 var_exportedVars = VAR_EXPORTED_YES;
715 if (isExport) { 722 if (isExport && track) {
716 Var_Append(MAKE_EXPORTED, name, VAR_GLOBAL); 723 Var_Append(MAKE_EXPORTED, name, VAR_GLOBAL);
717 } 724 }
718 } 725 }
719 } 726 }
720 free(val); 727 free(val);
721 free(as); 728 free(as);
722 free(av); 729 free(av);
723} 730}
724 731
725 732
726/* 733/*
727 * This is called when .unexport[-env] is seen. 734 * This is called when .unexport[-env] is seen.
728 */ 735 */